适配小程序代码结构

This commit is contained in:
zhonghua1
2026-01-20 08:46:36 +08:00
parent 3b169467ac
commit 9c00db8ff5
615 changed files with 62726 additions and 8 deletions

92
App.vue
View File

@@ -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
}
}
}