修复管理师端预约与登录体验

This commit is contained in:
2026-06-26 11:07:54 +08:00
parent f1fdf6e5d3
commit 078a2b32cd
48 changed files with 1044 additions and 276 deletions
+49 -3
View File
@@ -9,6 +9,8 @@ const HEADER_NONCE = 'X-Nonce'
const HEADER_SIGNATURE = 'X-Signature'
const HEADER_SIGNATURE_VERSION = 'X-Sign-Version'
let sessionExpiredHandling = false
function buildUrl(url, params) {
const sourceParams = params || {}
const baseUrl = sourceParams.__baseUrl ? sourceParams.__baseUrl : ADMIN_API_BASE_URL
@@ -27,6 +29,47 @@ function normalizeError(message, raw) {
return error
}
function resolveResponseMessage(response, fallbackMessage) {
const data = response && response.data ? response.data : {}
return data.message || fallbackMessage
}
function clearRuntimeSession() {
const app = getApp()
if (app && typeof app.clearSession === 'function') {
app.clearSession()
return
}
auth.clearSession()
}
function redirectToLoginAfterExpired(message) {
if (sessionExpiredHandling) {
return
}
sessionExpiredHandling = true
clearRuntimeSession()
wx.showToast({
title: message,
icon: 'none',
duration: 1200
})
setTimeout(() => {
wx.reLaunch({
url: '/pages/login/index',
complete() {
sessionExpiredHandling = false
}
})
}, 700)
}
function handleUnauthorized(response) {
const message = resolveResponseMessage(response, '登录已过期,请重新登录')
redirectToLoginAfterExpired(message)
return normalizeError(message, response)
}
function extractPath(value) {
const target = String(value || '')
if (!target) {
@@ -71,6 +114,7 @@ function isAuthFreePath(url) {
'/auth/register',
'/user/send-verification-code',
'/user/phone-login',
'/user/check/login-shops/',
'/legal-agreement/current'
].some(path => String(url || '').includes(path))
}
@@ -134,9 +178,7 @@ function request(options) {
},
success(response) {
if (response.statusCode === 401) {
auth.clearSession()
wx.reLaunch({ url: '/pages/login/index' })
reject(normalizeError('登录已失效,请重新登录', response))
reject(handleUnauthorized(response))
return
}
if (response.statusCode >= 400) {
@@ -149,6 +191,10 @@ function request(options) {
resolve(payload.data)
return
}
if (payload.code === 401) {
reject(handleUnauthorized({ data: payload }))
return
}
reject(normalizeError(payload.message || '请求失败', payload))
return
}