解决微信小程序首页空白问题。
This commit is contained in:
@@ -63,12 +63,32 @@ function setupRequestInterceptor() {
|
||||
console.error('获取 tenantId 失败:', e)
|
||||
}
|
||||
|
||||
// 检查是否需要登录:如果不是登录接口且租户ID为空,则跳转到登录页
|
||||
// 检查是否需要登录:如果不是登录接口且租户ID为空
|
||||
// 只在页面完全加载后才跳转,避免扫码进入时页面空白
|
||||
if (!isLoginApi(url) && !tenantId) {
|
||||
console.warn('[Request Interceptor] 租户ID为空,跳转到登录页面')
|
||||
redirectToLogin()
|
||||
// 返回一个被拒绝的Promise,阻止请求继续执行
|
||||
return Promise.reject(new Error('未登录,请先登录'))
|
||||
// 获取当前页面栈,检查是否页面已完全加载
|
||||
const pages = getCurrentPages()
|
||||
const hasLoadedPages = pages.length > 0 && pages[pages.length - 1].route
|
||||
|
||||
// 如果页面已加载,检查是否在首页或登录相关页面
|
||||
if (hasLoadedPages) {
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const currentRoute = '/' + currentPage.route
|
||||
|
||||
// 在首页或登录相关页面时,不立即跳转,让页面先加载
|
||||
const isHomePage = currentRoute.includes('/pages/furniture_reception/furniture_reception')
|
||||
const isLoginRelated = currentRoute.includes('/uni_modules/uni-id-pages/pages/login') ||
|
||||
currentRoute.includes('/uni_modules/uni-id-pages/pages/register') ||
|
||||
currentRoute.includes('/uni_modules/uni-id-pages/pages/retrieve')
|
||||
|
||||
if (!isHomePage && !isLoginRelated) {
|
||||
console.warn('[Request Interceptor] 租户ID为空,跳转到登录页面')
|
||||
redirectToLogin()
|
||||
// 返回一个被拒绝的Promise,阻止请求继续执行
|
||||
return Promise.reject(new Error('未登录,请先登录'))
|
||||
}
|
||||
}
|
||||
// 如果页面还没加载完成,不立即跳转,避免扫码进入时空白
|
||||
}
|
||||
|
||||
// 构建新的 header(保留原有的 header,避免覆盖)
|
||||
@@ -163,9 +183,16 @@ export default async function() {
|
||||
|
||||
// uniStarterConfig挂载到getApp().globalData.config
|
||||
setTimeout(() => {
|
||||
getApp({
|
||||
allowDefault: true
|
||||
}).globalData.config = uniStarterConfig;
|
||||
try {
|
||||
const app = getApp({
|
||||
allowDefault: true
|
||||
});
|
||||
if (app && app.globalData) {
|
||||
app.globalData.config = uniStarterConfig;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[appInit] 挂载配置失败:', e);
|
||||
}
|
||||
}, 1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user