feat: establish teaching feedback mini program
Connect student profiles, defaults, and feedback records to the Rust API. Configure the WeChat AppID, custom tab bar, and local development workflow for version 0.1.0.
This commit is contained in:
54
pages/profile/index.ts
Normal file
54
pages/profile/index.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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()
|
||||
this.setData({
|
||||
connectionText: health.databaseConfigured ? '服务和数据库连接正常' : '服务正常,数据库尚未配置',
|
||||
connectionTone: health.databaseConfigured ? 'success' : 'warning'
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ connectionText: getApiErrorMessage(error), connectionTone: 'error' })
|
||||
} finally {
|
||||
this.setData({ testing: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user