This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const auth = require('../../utils/auth')
|
||||
const request = require('../../utils/request')
|
||||
const { showErrorToast } = require('../../utils/toast')
|
||||
|
||||
Page({
|
||||
data: { loading: true, agreement: null, mode: '', agreements: [], accepted: false, accepting: false },
|
||||
@@ -23,7 +24,7 @@ Page({
|
||||
const agreement = (Array.isArray(agreements) ? agreements : []).find(item => item.agreementType === agreementType)
|
||||
this.setData({ agreement: agreement || null })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '协议加载失败', icon: 'none' })
|
||||
showErrorToast(error, '协议加载失败')
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
@@ -35,23 +36,19 @@ Page({
|
||||
const agreements = await authApi.getCurrentAgreements()
|
||||
this.setData({ agreements: Array.isArray(agreements) ? agreements : [] })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '协议加载失败', icon: 'none' })
|
||||
showErrorToast(error, '协议加载失败')
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onHide() {
|
||||
this.discardPendingIfNotAccepted()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this.discardPendingIfNotAccepted()
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户未完成同意就离开协议页(返回/隐藏/卸载)时,立即结算被 4510 挂起的请求,
|
||||
* 避免调用方 loading 永久卡住;同意成功后不再触发。
|
||||
* 只有真正离开协议页(返回导致页面卸载)才结算被 4510 挂起的请求,避免调用方 loading 永久卡住;
|
||||
* 切后台(如来电、复制协议文本)只触发 onHide,不结算;同意成功后也不再触发。
|
||||
*/
|
||||
discardPendingIfNotAccepted() {
|
||||
if (this.data.mode !== 'accept' || this.agreementAccepted) {
|
||||
@@ -86,7 +83,7 @@ Page({
|
||||
} catch (error) {
|
||||
// accept 返回 401 时请求层已清会话并跳登录页,这里不再叠加提示。
|
||||
if (auth.getAccessToken()) {
|
||||
wx.showToast({ title: error.message || '同意失败,请重试', icon: 'none' })
|
||||
showErrorToast(error, '同意失败,请重试')
|
||||
}
|
||||
} finally {
|
||||
this.setData({ accepting: false })
|
||||
|
||||
Reference in New Issue
Block a user