OfficeApp/router/router.js

43 lines
976 B
JavaScript
Raw Normal View History

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) => {
2023-08-11 09:12:18 +08:00
try{
if (whiteList.indexOf(url) !== -1 || whiteList.indexOf(url.split('?')[0]) || uni.getStorageSync("TOKEN")) {
return true;
}
return false;
}catch(e){
console.log(e);
return false;
2023-07-25 15:27:07 +08:00
}
}
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;