67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import {
|
|
DEVELOPMENT_USER_ID,
|
|
getApiBaseUrl,
|
|
getApiErrorMessage,
|
|
getHealth,
|
|
setApiBaseUrl
|
|
} from '../../utils/api'
|
|
|
|
type InputEvent = { detail: { value: string } }
|
|
|
|
Page({
|
|
data: {
|
|
apiBaseUrl: getApiBaseUrl(),
|
|
developmentUserId: DEVELOPMENT_USER_ID,
|
|
connectionText: '尚未检测',
|
|
connectionTone: 'idle',
|
|
testing: false
|
|
},
|
|
|
|
onShow() {
|
|
this.getTabBar()?.setData({ selected: 3 })
|
|
this.setData({ apiBaseUrl: getApiBaseUrl() })
|
|
void this.checkConnection()
|
|
},
|
|
|
|
onUrlInput(event: InputEvent) {
|
|
this.setData({ apiBaseUrl: event.detail.value })
|
|
},
|
|
|
|
async saveAndCheck() {
|
|
try {
|
|
const apiBaseUrl = setApiBaseUrl(this.data.apiBaseUrl)
|
|
this.setData({ apiBaseUrl })
|
|
await this.checkConnection()
|
|
} catch (error) {
|
|
this.setData({ connectionText: getApiErrorMessage(error), connectionTone: 'error' })
|
|
}
|
|
},
|
|
|
|
async checkConnection() {
|
|
this.setData({ testing: true, connectionText: '正在检测服务...', connectionTone: 'idle' })
|
|
try {
|
|
const health = await getHealth()
|
|
let connectionText = '服务、数据库和语音转录正常'
|
|
let connectionTone = 'success'
|
|
if (!health.databaseConfigured) {
|
|
connectionText = '服务正常,数据库尚未配置'
|
|
connectionTone = 'warning'
|
|
} else if (!health.speechConfigured) {
|
|
connectionText = '服务和数据库正常,语音转录尚未配置'
|
|
connectionTone = 'warning'
|
|
} else if (!health.speechAvailable) {
|
|
connectionText = '服务和数据库正常,本地语音模型尚未就绪'
|
|
connectionTone = 'warning'
|
|
}
|
|
this.setData({
|
|
connectionText,
|
|
connectionTone
|
|
})
|
|
} catch (error) {
|
|
this.setData({ connectionText: getApiErrorMessage(error), connectionTone: 'error' })
|
|
} finally {
|
|
this.setData({ testing: false })
|
|
}
|
|
}
|
|
})
|