fix(wechat): 协议 4510 改为原地同意并自动重试原请求
自动发布开发环境 Nacos 配置 / publish (push) Successful in 19s

This commit is contained in:
2026-11-05 10:29:10 +08:00
parent fb19fcf05f
commit 702c186f65
6 changed files with 318 additions and 51 deletions
+53 -1
View File
@@ -1,9 +1,17 @@
const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
const request = require('../../utils/request')
Page({
data: { loading: true, agreement: null },
data: { loading: true, agreement: null, mode: '', agreements: [], accepted: false, accepting: false },
onLoad(options) {
if (options && options.mode === 'accept') {
wx.setNavigationBarTitle({ title: '阅读并同意协议' })
this.setData({ mode: 'accept' })
this.loadAll()
return
}
this.load(options && options.type)
},
@@ -19,5 +27,49 @@ Page({
} finally {
this.setData({ loading: false })
}
},
async loadAll() {
this.setData({ loading: true })
try {
const agreements = await authApi.getCurrentAgreements()
this.setData({ agreements: Array.isArray(agreements) ? agreements : [] })
} catch (error) {
wx.showToast({ title: error.message || '协议加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
toggleAgreement() {
if (this.data.accepting) {
return
}
this.setData({ accepted: !this.data.accepted })
},
async acceptAndContinue() {
if (!this.data.accepted || this.data.accepting) {
return
}
this.setData({ accepting: true })
try {
await authApi.acceptAgreements('WECHAT_MINI')
wx.showToast({ title: '已同意', icon: 'success' })
// 同意成功后重放首个被 4510 拦下的请求一次;失败不再循环。
request.retryPendingAfterAgreement()
setTimeout(() => {
wx.navigateBack({
fail: () => wx.reLaunch({ url: '/pages/planning/index' })
})
}, 300)
} catch (error) {
// accept 返回 401 时请求层已清会话并跳登录页,这里不再叠加提示。
if (auth.getAccessToken()) {
wx.showToast({ title: error.message || '同意失败,请重试', icon: 'none' })
}
} finally {
this.setData({ accepting: false })
}
}
})