u
This commit is contained in:
1 parent
18a0a81c20
commit
5bc05923f2
28 files changed
+834
-237
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { useUserStore } from '@/store'
|
||||
|
||||
const whiteList = [
|
||||
'/pages-sub/login/index',
|
||||
]
|
||||
|
||||
export const navigateToInterceptor = {
|
||||
invoke(args: UniApp.NavigateToOptions) {
|
||||
const userStore = useUserStore()
|
||||
|
||||
console.log('switch')
|
||||
|
||||
// 白名单直接放行
|
||||
if (whiteList.some(path => args.url.startsWith(path))) {
|
||||
return args
|
||||
}
|
||||
console.log('放行')
|
||||
|
||||
// 调用 requireLogin,如果未登录,会自动提示并跳转
|
||||
const ok = userStore.requireLogin()
|
||||
|
||||
console.log(`验证结果:${ok}`)
|
||||
|
||||
if (!ok) {
|
||||
return false // 阻止路由跳转
|
||||
}
|
||||
|
||||
console.log('已登录放行')
|
||||
|
||||
return args // 已登录则放行
|
||||
},
|
||||
}
|
||||
|
||||
export const routeInterceptor = {
|
||||
install() {
|
||||
uni.addInterceptor('navigateTo', navigateToInterceptor)
|
||||
uni.addInterceptor('reLaunch', navigateToInterceptor)
|
||||
uni.addInterceptor('redirectTo', navigateToInterceptor)
|
||||
uni.addInterceptor('switchTab', navigateToInterceptor)
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user