This commit is contained in:
那些花儿
2025-04-30 10:12:46 +08:00
parent bb394ce8e3
commit 29d286319a
5 changed files with 102 additions and 31 deletions
+27 -1
View File
@@ -10,6 +10,32 @@ export const setupRouterInterceptor = (whiteList = []) => {
addNavigationInterceptors(whiteList)
}
export const checkAuth = () => {
debugger
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({
url: '/pages/login/index'
})
}
}
}
}
/**
* 添加所有导航方法的拦截器
* @param {Array} whiteList - 白名单页面列表
@@ -111,4 +137,4 @@ export const getDefaultWhiteList = () => {
'/pages/index/index',
'/pages/login/index'
]
}
}