产品化: 统一title
This commit is contained in:
@@ -11,6 +11,38 @@ interceptorChooseImage()
|
||||
// #endif
|
||||
const db = uniCloud.database()
|
||||
|
||||
/**
|
||||
* 跳转到登录页面
|
||||
*/
|
||||
function redirectToLogin() {
|
||||
const loginPage = '/uni_modules/uni-id-pages/pages/login/login-withpwd'
|
||||
const pages = getCurrentPages()
|
||||
|
||||
// 如果当前已经在登录页,不重复跳转
|
||||
if (pages.length > 0) {
|
||||
const currentPage = pages[pages.length - 1]
|
||||
if (currentPage.route && currentPage.route.includes('login')) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
uni.reLaunch({
|
||||
url: loginPage,
|
||||
fail: (err) => {
|
||||
console.error('跳转登录页失败:', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为登录相关接口(不需要租户ID的接口)
|
||||
*/
|
||||
function isLoginApi(url) {
|
||||
if (!url) return false
|
||||
// 登录接口不需要租户ID
|
||||
return url.includes('/api/sys/auth/login')
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置全局 uni.request 拦截器,自动添加 X-Tenant-Id header
|
||||
*/
|
||||
@@ -30,6 +62,14 @@ function setupRequestInterceptor() {
|
||||
console.error('获取 tenantId 失败:', e)
|
||||
}
|
||||
|
||||
// 检查是否需要登录:如果不是登录接口且租户ID为空,则跳转到登录页
|
||||
if (!isLoginApi(url) && !tenantId) {
|
||||
console.warn('[Request Interceptor] 租户ID为空,跳转到登录页面')
|
||||
redirectToLogin()
|
||||
// 返回一个被拒绝的Promise,阻止请求继续执行
|
||||
return Promise.reject(new Error('未登录,请先登录'))
|
||||
}
|
||||
|
||||
// 构建新的 header(保留原有的 header,避免覆盖)
|
||||
const newHeader = {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user