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 })
|
||||
|
||||
@@ -40,16 +40,21 @@ const reader = createPage('')
|
||||
pageDefinition.onUnload.call(reader)
|
||||
assert.strictEqual(discardCalls, 0)
|
||||
|
||||
// 切后台(来电、复制协议文本)不应结算挂起请求:协议页不再提供 onHide 结算入口
|
||||
assert.strictEqual(typeof pageDefinition.onHide, 'undefined')
|
||||
const hiddenPage = createPage('accept')
|
||||
pageDefinition.onHide.call(hiddenPage)
|
||||
assert.strictEqual(discardCalls, 1)
|
||||
if (pageDefinition.onHide) {
|
||||
pageDefinition.onHide.call(hiddenPage)
|
||||
}
|
||||
assert.strictEqual(discardCalls, 0)
|
||||
|
||||
// 真正离开协议页(返回触发页面卸载)仍然结算
|
||||
const unloadedPage = createPage('accept')
|
||||
pageDefinition.onUnload.call(unloadedPage)
|
||||
assert.strictEqual(discardCalls, 2)
|
||||
assert.strictEqual(discardCalls, 1)
|
||||
|
||||
const acceptedPage = createPage('accept', true)
|
||||
pageDefinition.onUnload.call(acceptedPage)
|
||||
assert.strictEqual(discardCalls, 2)
|
||||
assert.strictEqual(discardCalls, 1)
|
||||
|
||||
console.log('legal page agreement discard test passed')
|
||||
|
||||
Reference in New Issue
Block a user