fix(salon): 后台管理端豁免协议版本校验并移除后台同意弹层
自动发布开发环境 Nacos 配置 / publish (push) Successful in 19s

This commit is contained in:
2026-11-05 16:32:55 +08:00
parent 385c4b06ec
commit 3a91246e0c
4 changed files with 54 additions and 74 deletions
+11 -7
View File
@@ -162,10 +162,10 @@ const showError = (msg: string) => {
/**
* 处理服务端 4510(未同意最新协议):
* 锁定后续业务请求、广播事件让后台布局弹出既有的同意弹层,并提示用户。
* 非后台场景没有弹层,直接新开协议阅读页,引导用户阅读后重新登录同意。
* 仅用于用户端(小程序由独立实现处理,C 端页面走这里):锁定后续业务请求、提示用户并打开协议阅读页。
* 后台管理端不做协议版本校验,不会进入该分支。
*/
const handleAgreementRequired = (res: any, isAdminRequest: boolean) => {
const handleAgreementRequired = (res: any) => {
setAgreementPending(true)
if (typeof window !== 'undefined') {
window.dispatchEvent(new CustomEvent(AGREEMENT_REQUIRED_EVENT, { detail: res?.data || {} }))
@@ -175,7 +175,7 @@ const handleAgreementRequired = (res: any, isAdminRequest: boolean) => {
}
lastAgreementRequiredTime = Date.now()
showError(normalizeApiErrorMessage(res?.message || '用户协议与隐私政策已更新,请阅读并同意后继续使用'))
if (!isAdminRequest && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.open('/legal/user-terms.html', '_blank', 'noopener')
}
}
@@ -277,11 +277,12 @@ const handleTokenExpired = (isAdmin = false, failedToken: string | null = null)
api.interceptors.request.use(
async config => {
if (isAgreementPending() && !AGREEMENT_GATE_ALLOWLIST.some(path => config.url?.includes(path))) {
const isAdminRequest = isAdminScopedUrl(config.url)
// 后台管理端不做协议版本校验:既不进入未同意门禁,也不因门禁状态被拦截。
if (!isAdminRequest && isAgreementPending() && !AGREEMENT_GATE_ALLOWLIST.some(path => config.url?.includes(path))) {
return Promise.reject(new Error('请先阅读并同意最新版用户协议与隐私政策'))
}
const isAdminRequest = isAdminScopedUrl(config.url)
let token = isAdminRequest
? (localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
@@ -313,7 +314,10 @@ api.interceptors.response.use(
const res = response.data
if (Number(res?.code) === AGREEMENT_VERSION_REQUIRED_CODE) {
const errorMsg = normalizeApiErrorMessage(res?.message || '用户协议与隐私政策已更新,请阅读并同意后继续使用')
handleAgreementRequired(res, isAdminScopedUrl(response.config?.url))
// 后台管理端已由服务端放行,若历史服务端仍返回 4510,也不触发门禁/提示,避免后台被锁死。
if (!isAdminScopedUrl(response.config?.url)) {
handleAgreementRequired(res)
}
return Promise.reject(new Error(errorMsg))
}
if (res.code !== 200) {