feat(salon): 服务端拦截未同意最新协议的用户并补充端侧 4510 处理
自动发布开发环境 Nacos 配置 / publish (push) Successful in 18s

This commit is contained in:
2026-11-05 09:43:01 +08:00
parent 88589e2575
commit fb19fcf05f
10 changed files with 503 additions and 45 deletions
+41
View File
@@ -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