feat: add WeChat session authentication
This commit is contained in:
@@ -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: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
</view>
|
||||
|
||||
<view class="identity-card surface">
|
||||
<text class="section-title">开发身份</text>
|
||||
<text class="identity-value">{{developmentUserId}}</text>
|
||||
<text class="identity-note">微信登录接入前,业务数据按此开发用户隔离。</text>
|
||||
<text class="section-title">微信身份</text>
|
||||
<view class="connection-row">
|
||||
<text class="connection-dot connection-{{authTone}}"></text>
|
||||
<text class="connection-text">{{authText}}</text>
|
||||
</view>
|
||||
<text wx:if="{{authUserId}}" class="identity-value">{{authUserId}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
}
|
||||
|
||||
.section-title,
|
||||
.identity-value,
|
||||
.identity-note {
|
||||
.identity-value {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -82,10 +81,3 @@
|
||||
font-weight: 700;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.identity-note {
|
||||
margin-top: 12rpx;
|
||||
color: #718096;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user