..
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import {setupRouterInterceptor, getDefaultWhiteList} from './utils/routerInterceptor'
|
||||
import {checkAuth, setupRouterInterceptor, getDefaultWhiteList} from './utils/routerInterceptor'
|
||||
|
||||
export default {
|
||||
globalData: {
|
||||
@@ -7,7 +7,9 @@ export default {
|
||||
},
|
||||
onLaunch: function () {
|
||||
console.log('App Launch')
|
||||
|
||||
console.log(process.env.VUE_APP_PLATFORM)
|
||||
// 检查访问页面是否需要登录(不走拦截器 直接从地址栏进入)
|
||||
checkAuth()
|
||||
// 初始化路由拦截器
|
||||
setupRouterInterceptor(getDefaultWhiteList())
|
||||
},
|
||||
|
||||
@@ -65,8 +65,14 @@
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"h5": {
|
||||
"title": "趣味运动会",
|
||||
"router": {
|
||||
"mode": "history"
|
||||
}
|
||||
},
|
||||
"vueVersion" : "3"
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user