This commit is contained in:
@@ -7,6 +7,12 @@ const HEADER_NONCE = 'X-Nonce'
|
||||
const HEADER_SIGNATURE = 'X-Signature'
|
||||
const HEADER_SIGNATURE_VERSION = 'X-Sign-Version'
|
||||
|
||||
/**
|
||||
* 服务端协议同意拦截返回的业务码:登录用户未同意最新版协议时返回 4510。
|
||||
*/
|
||||
const AGREEMENT_VERSION_REQUIRED_CODE = 4510
|
||||
let agreementPrompting = false
|
||||
|
||||
function buildUrl(url, params) {
|
||||
const sourceParams = params || {}
|
||||
const baseUrl = sourceParams.__baseUrl ? sourceParams.__baseUrl : API_DOMAIN
|
||||
@@ -65,6 +71,37 @@ function handleUnauthorized(response, url) {
|
||||
return normalizeError(message, response)
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 4510:提示协议已更新并跳转登录页重新阅读同意。
|
||||
* 登录页已有协议勾选与弹层,重新登录时会带上最新版本同意,避免重复弹窗用 agreementPrompting 去重。
|
||||
*/
|
||||
function handleAgreementVersionRequired(response, url) {
|
||||
const message = resolveResponseMessage(response, '用户协议与隐私政策已更新,请阅读并同意后继续使用')
|
||||
if (isAuthFreePath(url)) {
|
||||
return normalizeError(message, response)
|
||||
}
|
||||
if (!agreementPrompting) {
|
||||
agreementPrompting = true
|
||||
clearRuntimeSession()
|
||||
wx.showModal({
|
||||
title: '协议版本已更新',
|
||||
content: message,
|
||||
showCancel: false,
|
||||
confirmText: '去同意',
|
||||
success() {
|
||||
agreementPrompting = false
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
},
|
||||
fail() {
|
||||
agreementPrompting = false
|
||||
}
|
||||
})
|
||||
}
|
||||
return normalizeError(message, response)
|
||||
}
|
||||
|
||||
function extractPath(value) {
|
||||
const target = String(value || '')
|
||||
if (!target) {
|
||||
@@ -174,6 +211,10 @@ function request(options) {
|
||||
resolve(payload.data)
|
||||
return
|
||||
}
|
||||
if (Number(payload.code) === AGREEMENT_VERSION_REQUIRED_CODE) {
|
||||
reject(handleAgreementVersionRequired({ data: payload }, options.url))
|
||||
return
|
||||
}
|
||||
if (Number(payload.code) === 401) {
|
||||
reject(handleUnauthorized({ data: payload }, options.url))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user