优化小程序部分

This commit is contained in:
hero920103 committed 2026-10-31 19:17:37 +08:00
1 parent 727319a6eb
commit d4e89788c5
46 files changed
+4906 -63

No files matched your search

+33
View File
@@ -1,5 +1,37 @@
<script>
import { getBaseURL } from '@/api/request.js'
import { isLoggedIn } from '@/utils/auth.js'
const LOGIN_PAGE = '/pages/login/login'
// 不需要登录即可停留的页面:登录 / 注册 / 忘记密码 / 人机验证 / 小程序码确认页 / 启动跳板页
const PUBLIC_ROUTES = [
'pages/login/login',
'pages/login/register',
'pages/login/forget',
'pages/login/geetest-webview',
'pages/register/confirm',
'pages/index/index'
]
/** 当前页面路由(取不到时返回空串,交给页面级检测兜底) */
function currentRoute() {
try {
const pages = getCurrentPages()
if (!pages.length) return ''
const cur = pages[pages.length - 1]
return (cur && (cur.route || (cur.$page && cur.$page.path))) || ''
} catch (e) {
return ''
}
}
/** 未登录一律回登录页:覆盖「切后台回来」「从其他入口直接进内页」等场景 */
function ensureLogin() {
const route = currentRoute()
if (!route || PUBLIC_ROUTES.indexOf(route) !== -1) return
if (isLoggedIn()) return
uni.reLaunch({ url: LOGIN_PAGE })
}
export default {
onLaunch() {
@@ -7,6 +39,7 @@
},
onShow() {
console.log('App Show')
ensureLogin()
},
onHide() {
console.log('App Hide')