|
@@ -1,41 +1,37 @@
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
+import { getToken } from "@/utils/auth";
|
|
|
|
|
|
// 登录页面
|
|
|
-const loginPage = "/pages/login"
|
|
|
-
|
|
|
+const loginPage = "/pages/login";
|
|
|
+
|
|
|
// 页面白名单
|
|
|
-const whiteList = [
|
|
|
- '/pages/login', '/pages/common/webview/index',
|
|
|
- '/pages/business/mhxf/unitInfoCollection/index', '/pages/business/mhxf/unitInfoCollection/index',
|
|
|
-]
|
|
|
+const whiteList = ["/pages/login", "/pages/common/webview/index", "/pages/business/mhxf/unitInfoCollection/index"];
|
|
|
|
|
|
// 检查地址白名单
|
|
|
function checkWhite(url) {
|
|
|
- const path = url.split('?')[0]
|
|
|
- return whiteList.indexOf(path) !== -1
|
|
|
+ const path = url.split("?")[0];
|
|
|
+ return whiteList.indexOf(path) !== -1;
|
|
|
}
|
|
|
|
|
|
// 页面跳转验证拦截器
|
|
|
-let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
|
|
|
-list.forEach(item => {
|
|
|
+let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
|
|
|
+list.forEach((item) => {
|
|
|
uni.addInterceptor(item, {
|
|
|
invoke(to) {
|
|
|
- console.log(to)
|
|
|
if (getToken()) {
|
|
|
if (to.url === loginPage) {
|
|
|
- uni.reLaunch({ url: "/" })
|
|
|
+ uni.reLaunch({ url: "/" });
|
|
|
}
|
|
|
- return true
|
|
|
+ return true;
|
|
|
} else {
|
|
|
if (checkWhite(to.url)) {
|
|
|
- return true
|
|
|
+ return true;
|
|
|
}
|
|
|
- uni.reLaunch({ url: loginPage })
|
|
|
- return false
|
|
|
+ uni.reLaunch({ url: loginPage });
|
|
|
+ return false;
|
|
|
}
|
|
|
},
|
|
|
fail(err) {
|
|
|
- console.log(err)
|
|
|
- }
|
|
|
- })
|
|
|
-})
|
|
|
+ console.log(err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+});
|