| | |
| | | * @param {string} path |
| | | * @returns {boolean} 是否有权限 |
| | | */ |
| | | export function hasPerm(path = "") { |
| | | export function hasPerm (path = "") { |
| | | if (!isPathExists(path) && path !== "/") { |
| | | uni.redirectTo({ |
| | | url: ERROR404_PATH |
| | |
| | | return hasPermission |
| | | } |
| | | |
| | | function setupPermission() { |
| | | function setupPermission () { |
| | | // 注意:拦截uni.switchTab本身没有问题。但是在微信小程序端点击tabbar的底层逻辑并不是触发uni.switchTab。 |
| | | // 所以误认为拦截无效,此类场景的解决方案是在tabbar页面的页面生命周期onShow中处理。 |
| | | ;["navigateTo", "redirectTo", "reLaunch", "switchTab"].forEach(item => { |
| | | // https://uniapp.dcloud.net.cn/api/interceptor.html |
| | | uni.addInterceptor(item, { |
| | | // 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转 |
| | | invoke(args) { |
| | | invoke (args) { |
| | | // args为所拦截api中的参数,比如拦截的是uni.redirectTo(OBJECT),则args对应的是OBJECT参数 |
| | | return hasPerm(args.url) |
| | | } |