permission.js 775 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
import router from "./routers";
import store from "./store";
import { Message } from "element-ui";

/**
 * 可在这里做鉴权
 */
router.beforeEach(async (to, from, next) => {
  // 限制页签的数量
  if (to.path.startsWith("/business")) {
潘际乾 committed
11 12 13 14 15 16 17 18 19 20 21 22
    const visitedViews = store.state.TagsView.visitedViews;
    const visitedViewsMaxVal = store.state.TagsView.visitedViewsMaxVal;
    const fullPaths = visitedViews.map((tv) => tv.fullPath);
    if (fullPaths.includes(to.fullPath)) {
      next();
    } else {
      if (visitedViews.length >= visitedViewsMaxVal) {
        Message.warning(
          `页签数超过最大限制(${visitedViewsMaxVal}),请先关闭其他页签!`
        );
        return;
      }
23 24 25 26 27 28
    }
  }
  next();
});

router.afterEach(() => {});