refactor: App.vue统一路由守卫 — onLaunch总是重定向(已登录→扫码/未登录→登录)
This commit is contained in:
@ -5,14 +5,17 @@ export default {
|
||||
onLaunch() {
|
||||
console.log("生产流转 T1.0.2 启动");
|
||||
|
||||
// 无登录态跳转登录页 — 双重检测防止部分手机划掉App后storage丢失
|
||||
// 🚦 统一路由守卫:根据登录态重定向到正确页面
|
||||
const token = uni.getStorageSync("access_token") || uni.getStorageSync("refresh_token");
|
||||
const user = uni.getStorageSync("user");
|
||||
if (!token && !user) {
|
||||
|
||||
if (token && user) {
|
||||
// 已登录 → 直接进扫码干活页
|
||||
uni.reLaunch({ url: "/pages/scan/index" });
|
||||
} else {
|
||||
// 未登录 → 去登录页
|
||||
uni.reLaunch({ url: "/pages/login/login" });
|
||||
return;
|
||||
}
|
||||
// token可能已过期但存在 → 正常启动,让401拦截器自动续期
|
||||
|
||||
// 🚀 OTA 热更新检测(仅 App 端生效)
|
||||
// #ifdef APP-PLUS
|
||||
|
||||
Reference in New Issue
Block a user