feat: add WeChat session authentication

This commit is contained in:
2026-07-20 14:47:16 +08:00
parent 2ada52f35a
commit 67d29d3ca0
26 changed files with 1289 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
import {
DEVELOPMENT_USER_ID,
ensureAuthentication,
getApiBaseUrl,
getApiErrorMessage,
getHealth,
@@ -11,16 +11,19 @@ type InputEvent = { detail: { value: string } }
Page({
data: {
apiBaseUrl: getApiBaseUrl(),
developmentUserId: DEVELOPMENT_USER_ID,
connectionText: '尚未检测',
connectionTone: 'idle',
testing: false
testing: false,
authText: '尚未登录',
authTone: 'idle',
authUserId: ''
},
onShow() {
this.getTabBar()?.setData({ selected: 3 })
this.setData({ apiBaseUrl: getApiBaseUrl() })
void this.checkConnection()
void this.checkAuthentication()
},
onUrlInput(event: InputEvent) {
@@ -32,6 +35,7 @@ Page({
const apiBaseUrl = setApiBaseUrl(this.data.apiBaseUrl)
this.setData({ apiBaseUrl })
await this.checkConnection()
await this.checkAuthentication()
} catch (error) {
this.setData({ connectionText: getApiErrorMessage(error), connectionTone: 'error' })
}
@@ -52,6 +56,9 @@ Page({
} else if (!health.speechAvailable) {
connectionText = '服务和数据库正常,本地语音模型尚未就绪'
connectionTone = 'warning'
} else if (!health.wechatAuthConfigured) {
connectionText = '服务正常,微信登录尚未配置'
connectionTone = 'warning'
}
this.setData({
connectionText,
@@ -62,5 +69,23 @@ Page({
} finally {
this.setData({ testing: false })
}
},
async checkAuthentication() {
this.setData({ authText: '正在登录...', authTone: 'idle', authUserId: '' })
try {
const session = await ensureAuthentication()
this.setData({
authText: '微信身份已登录',
authTone: 'success',
authUserId: session.userId
})
} catch (error) {
this.setData({
authText: getApiErrorMessage(error),
authTone: 'error',
authUserId: ''
})
}
}
})