2023-07-25 15:27:07 +08:00
|
|
|
import { Toast } from "../libs/uniApi";
|
|
|
|
|
|
|
|
const functionList = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
|
|
|
|
|
|
|
|
const whiteList = ['/','/pages/oaHome/oaHome', '/pages/oaExamine/oaExamine', '/pages/oaTask/oaTask', '/pages/oaMy/oaMy',
|
2023-08-04 17:43:13 +08:00
|
|
|
'/pages/oaLogin/oaLogin', '/pages/business/business'
|
2023-07-25 15:27:07 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
const hasPermission = (url) => {
|
|
|
|
if (whiteList.indexOf(url) !== -1 || uni.getStorageSync("TOKEN")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const initRouter = () => {
|
|
|
|
functionList.forEach(item => {
|
|
|
|
uni.addInterceptor(item, {
|
|
|
|
invoke(args) {
|
|
|
|
if (!hasPermission(args.url)) {
|
|
|
|
Toast('登录后查看更多')
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
success(args) {
|
|
|
|
},
|
|
|
|
fail(err) {
|
|
|
|
console.log('拦截失败', err)
|
|
|
|
},
|
|
|
|
complete(res) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initRouter;
|