permission.js 775 Bytes
import router from "./routers";
import store from "./store";
import { Message } from "element-ui";

/**
 * 可在这里做鉴权
 */
router.beforeEach(async (to, from, next) => {
  // 限制页签的数量
  if (to.path.startsWith("/business")) {
    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;
      }
    }
  }
  next();
});

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