|
@@ -14,6 +14,7 @@ import ViewUI from "view-design";
|
|
import "./assets/styles/index.less";
|
|
import "./assets/styles/index.less";
|
|
// regist v-chart
|
|
// regist v-chart
|
|
import "./plugins/VueCharts";
|
|
import "./plugins/VueCharts";
|
|
|
|
+import { checkRouterValid } from "./constants/authority";
|
|
|
|
|
|
Vue.use(ViewUI);
|
|
Vue.use(ViewUI);
|
|
ViewUI.Message.config({
|
|
ViewUI.Message.config({
|
|
@@ -30,24 +31,23 @@ Vue.prototype.GLOBAL = GLOBAL;
|
|
Vue.config.productionTip = false;
|
|
Vue.config.productionTip = false;
|
|
|
|
|
|
// route interceptor
|
|
// route interceptor
|
|
-// router.beforeEach((to, from, next) => {
|
|
|
|
-// const token = Vue.ls.get("token");
|
|
|
|
-// if (to.meta.noRequire) {
|
|
|
|
-// // 不需要登录的页面
|
|
|
|
-// next();
|
|
|
|
-// } else {
|
|
|
|
-// // 需要登录的路由
|
|
|
|
-// if (token) {
|
|
|
|
-// next();
|
|
|
|
-// } else {
|
|
|
|
-// // 登录失效的处理
|
|
|
|
-// Vue.ls.clear();
|
|
|
|
-// // Vue.ls.remove("token");
|
|
|
|
-// // Vue.ls.remove("user");
|
|
|
|
-// next({ name: "Login" });
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
|
|
+router.beforeEach((to, from, next) => {
|
|
|
|
+ const user = Vue.ls.get("user");
|
|
|
|
+ if (to.meta.noRequire) {
|
|
|
|
+ // 不需要登录的页面
|
|
|
|
+ next();
|
|
|
|
+ } else {
|
|
|
|
+ // 需要登录的路由
|
|
|
|
+ if (user && checkRouterValid(user["role"], to.name)) {
|
|
|
|
+ next();
|
|
|
|
+ } else {
|
|
|
|
+ ViewUI.Notice.error({ title: "错误提示", desc: "权限失效!" });
|
|
|
|
+ // 登录失效的处理
|
|
|
|
+ Vue.ls.clear();
|
|
|
|
+ next({ name: "Login" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
|
|
// axios interceptors
|
|
// axios interceptors
|
|
var load = "";
|
|
var load = "";
|
|
@@ -82,7 +82,7 @@ axios.interceptors.request.use(
|
|
},
|
|
},
|
|
error => {
|
|
error => {
|
|
// 关闭loading提示
|
|
// 关闭loading提示
|
|
- // 串联并发请求,延时处理是为防止多个loading实例闪屏。
|
|
|
|
|
|
+ // 继发请求,延时处理是为防止出现多个loading实例
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
queue.shift();
|
|
queue.shift();
|
|
if (!queue.length) load();
|
|
if (!queue.length) load();
|