This commit is contained in:
那些花儿
2025-04-30 13:34:37 +08:00
parent ad9a7bc7b8
commit baa6f7284a
12 changed files with 567 additions and 284 deletions
+9 -20
View File
@@ -1,5 +1,6 @@
import {Dialog} from "tdesign-mobile-vue";
import {useRequest} from "@/utils/request";
import {useUserStore} from "@/store";
/**
* 路由拦截器配置
@@ -10,24 +11,15 @@ export const setupRouterInterceptor = (whiteList = []) => {
addNavigationInterceptors(whiteList)
}
export const checkAuth = () => {
debugger
export const checkAuth = async () => {
if (process.env.VUE_APP_PLATFORM === 'h5' && window.location.pathname !== '/') {
const path = window.location.pathname.replace(/^\//, '')
if (!getDefaultWhiteList().includes(path)) {
const token = uni.getStorageSync('token')
if(token){
// 获取用户信息
const {user} = getApp().globalData
if(user == null){
return useRequest().get('/client/auth/info').then(({code, data, msg}) => {
if(code === 0){
getApp().globalData.user = data
}
})
}
}else{
uni.redirectTo({
if (token) {
await useUserStore().getUserInfo()
} else {
await uni.redirectTo({
url: '/pages/login/index'
})
}
@@ -84,17 +76,14 @@ async function routeInterceptor(args, whiteList) {
}
console.log('路由拦截检查:', {url: targetUrl, isInWhiteList, hasToken: !!token})
// 如果不在白名单且未登录,则跳转到登录页
if (!isInWhiteList) {
if (token) {
// 获取用户信息
const {user} = getApp().globalData
const user = useUserStore().userInfo
if (user == null) {
const {code, data, msg} = await useRequest().get('/client/auth/info')
if (code === 0) {
getApp().globalData.user = data
return args
}
await userStore().getUserInfo()
}
return args
} else {