import { useLoginUserStore } from '@/stores/loginUser' const loginUserStore = useLoginUserStore() let repaireRouterList = [ "/pages/homePage/homePage", //登录页 "/pages/repairEntrance/repairEntrance", //绑定工号 ] let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]; //用遍历的方式分别为uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器 list.forEach(item => { uni.addInterceptor(item, { invoke(e) { // 调用前拦截 const url = e.url.split('?')[0]; // 报修人不可以访问除了登录页,绑定工号页的其他页面 if (!repaireRouterList.includes(url) && loginUserStore.loginUser.user && loginUserStore.loginUser.user .engineer !== 1) { uni.reLaunch({ url: "/pages/repairEntrance/repairEntrance" }) return false } return true }, fail(err) { // 失败回调拦截 console.log(err); }, }) })