适配小程序代码结构
This commit is contained in:
92
App.vue
92
App.vue
@@ -16,12 +16,12 @@
|
||||
$i18n: {},
|
||||
$t: {}
|
||||
},
|
||||
onLaunch: function() {
|
||||
onLaunch: async function() {
|
||||
console.log('App Launch')
|
||||
this.globalData.$i18n = this.$i18n
|
||||
this.globalData.$t = str => this.$t(str)
|
||||
initApp();
|
||||
uniIdPageInit()
|
||||
await uniIdPageInit()
|
||||
|
||||
// #ifdef H5
|
||||
this.hideEduTabIfNeed() // 初始化尝试隐藏教务 tab(非教务角色)
|
||||
@@ -31,10 +31,24 @@
|
||||
// 设置全局路由拦截,检查登录状态
|
||||
this.setupRouteInterceptor()
|
||||
|
||||
// 延迟检查登录状态,确保 store 已初始化
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:先快速检查登录状态,如果未登录则立即跳转,避免首页闪烁
|
||||
// 延迟一小段时间确保页面栈已初始化
|
||||
setTimeout(() => {
|
||||
if (!this.isLoggedIn()) {
|
||||
this.redirectToLogin()
|
||||
} else {
|
||||
// 已登录,检查当前页面
|
||||
this.checkCurrentPageLogin()
|
||||
}
|
||||
}, 300)
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
// 其他平台:延迟检查登录状态
|
||||
setTimeout(() => {
|
||||
this.checkCurrentPageLogin()
|
||||
}, 100)
|
||||
// #endif
|
||||
|
||||
// #ifdef APP
|
||||
//checkIsAgree(); APP端暂时先用原生默认生成的。目前,自定义方式启动vue界面时,原生层已经请求了部分权限这并不符合国家的法规
|
||||
@@ -284,12 +298,56 @@
|
||||
}
|
||||
}
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:登录页在subPackage中,必须使用reLaunch
|
||||
// redirectTo不能用于跳转到subPackage页面,只能用于主包页面
|
||||
uni.reLaunch({
|
||||
url: loginPage,
|
||||
success: () => {
|
||||
console.log('跳转登录页成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转登录页失败:', err)
|
||||
// 如果reLaunch失败,可能是路径问题,尝试不带前导斜杠
|
||||
const loginPageWithoutSlash = loginPage.startsWith('/') ? loginPage.substring(1) : loginPage
|
||||
uni.reLaunch({
|
||||
url: loginPageWithoutSlash,
|
||||
fail: (err2) => {
|
||||
console.error('跳转登录页失败(重试):', err2)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
// 其他平台使用reLaunch
|
||||
uni.reLaunch({
|
||||
url: loginPage,
|
||||
fail: (err) => {
|
||||
console.error('跳转登录页失败:', err)
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断是否为tabBar页面
|
||||
*/
|
||||
isTabBarPage(route) {
|
||||
if (!route) return false
|
||||
const tabBarPages = [
|
||||
'pages/reception/reception',
|
||||
'pages/customer/customer',
|
||||
'pages/team/team',
|
||||
'pages/meeting_summary/meeting_summary',
|
||||
'pages/furniture_reception/furniture_reception',
|
||||
'pages/furniture_reception/common_begin_reception',
|
||||
'pages/furniture_customer/furniture_customer',
|
||||
'pages/furniture_top_sales/furniture_top_sales',
|
||||
'pages/ucenter/ucenter'
|
||||
]
|
||||
return tabBarPages.includes(route)
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -297,10 +355,26 @@
|
||||
*/
|
||||
checkCurrentPageLogin() {
|
||||
const pages = getCurrentPages()
|
||||
if (pages.length === 0) return
|
||||
if (pages.length === 0) {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:如果页面栈为空,延迟重试
|
||||
setTimeout(() => {
|
||||
this.checkCurrentPageLogin()
|
||||
}, 200)
|
||||
// #endif
|
||||
return
|
||||
}
|
||||
|
||||
const currentPage = pages[pages.length - 1]
|
||||
if (!currentPage || !currentPage.route) return
|
||||
if (!currentPage || !currentPage.route) {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:如果页面信息不完整,延迟重试
|
||||
setTimeout(() => {
|
||||
this.checkCurrentPageLogin()
|
||||
}, 200)
|
||||
// #endif
|
||||
return
|
||||
}
|
||||
|
||||
const currentRoute = '/' + currentPage.route
|
||||
|
||||
@@ -313,7 +387,15 @@
|
||||
|
||||
// 如果未登录,跳转到登录页
|
||||
if (!this.isLoggedIn()) {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:确保页面已完全加载后再跳转,使用setTimeout代替$nextTick
|
||||
setTimeout(() => {
|
||||
this.redirectToLogin()
|
||||
}, 100)
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
this.redirectToLogin()
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user