import Vue from "vue";
import Router from "vue-router";
import TeacherRouter from "./teacherRouter";
import AppRouter from "./appRouter";
import AuditionRouter from "./auditionRouter";
import ServiceRouter from "./serviceRouter";
import ShopRouter from "./shopRouter";

Vue.use(Router);

let defaultRouter = [
  {
    path: "/",
    redirect: {
      name: "business",
    },
  },
  {
    path: "/queryFortuneBag",
    name: "FortuneBag",
    component: () => import(/* webpackChunkName:'CallNames'*/ "@/views/teacher/queryList/queryFortuneBag"),
    meta: {
      descrition: "页面查看",
      weight: 1, // 页面权重
    },
  },
  {
    path: "/queryActiveList",
    name: "ActiveList",
    component: () => import(/* webpackChunkName:'CallNames'*/ "@/views/teacher/queryList/queryActiveList"),
    meta: {
      descrition: "页面查看",
      weight: 1, // 页面权重
    },
  },
  {
    path: "/guide",
    name: "guide",
    component: () => import(/* webpackChunkName:'CallNames'*/ "@/views/rules/guide"),
    meta: {
      descrition: "投屏引导",
      weight: 1, // 页面权重
    },
  },
  {
    path: "/applyActive",
    name: "applyActive",
    component: () => import(/* webpackChunkName:'applyActive' */ "@/views/applyActive/index.vue"),
    meta: {
      descrition: "考级活动",
      weight: 0,
    },
  },
  {
    path: "/registerProtocol",
    name: "registerProtocol",
    component: () => import(/* webpackChunkName:'registerProtocol' */ "@/views/protocol/registerProtocol.vue"),
    meta: {
      descrition: "查看协议",
      weight: 0,
    },
  },
  {
    path: "/auth",
    name: "auth",
    component: () => import(/* webpackChunkName:'auth' */ "@/views/protocol/auth.vue"),
    meta: {
      descrition: "实名认证",
      weight: 0,
    },
  },
  {
    path: "/afterClassEvaluate",
    name: "afterClassEvaluate",
    component: () => import(/* webpackChunkName:'afterClassEvaluate' */ "@/views/afterClassEvaluate/index.vue"),
    meta: {
      descrition: "课后评价",
      weight: 0,
    },
  },
  {
    path: "/afterClassEvaluateDetail",
    name: "afterClassEvaluateDetail",
    component: () => import(/* webpackChunkName:'afterClassEvaluateDetail' */ "@/views/afterClassEvaluate/detail.vue"),
    meta: {
      descrition: "课后详情",
      weight: 0,
    },
  },
  {
    path: "/massMessage",
    name: "massMessage",
    component: () => import(/* webpackChunkName:'massMessage' */ "@/views/massMessage/index"),
    meta: {
      descrition: "群发消息",
      weight: 2,
    },
  },
  {
    path: "/massOperation",
    name: "massOperation",
    component: () => import(/* webpackChunkName:'massOperation' */ "@/views/massMessage/operation"),
    meta: {
      descrition: "定时消息",
      weight: 2,
    },
  },
  {
    path: "/abnormalCourse",
    name: "abnormalCourse",
    component: () => import(/* webpackChunkName:'massOperation' */ "@/views/abnormalCourse"),
    meta: {
      descrition: "异常课程",
      weight: 2,
    },
  },
  {
    path: "/creation",
    name: "classroom",
    component: () => import(/* webpackChunkName:'creation'*/ "@/views/creation/index"),
    meta: {
      clearAuth: 1,
      title: "作品详情",
    },
  },
  {
    path: "/creation-edit",
    name: "creation-edit",
    component: () => import(/* webpackChunkName:'creationedit'*/ "@/views/creation/edit/index"),
    meta: {
      clearAuth: 1,
      title: "作品详情",
    },
  },
  {
    path: "/shareCreation",
    name: "shareCreation",
    component: () => import(/* webpackChunkName: "creationindex-share" */ "@/views/creation/index-share"),
    meta: {
      descrition: "作品详情",
      weight: 8, // 页面权重
    },
  }, //
];

defaultRouter = defaultRouter.concat(TeacherRouter).concat(AppRouter).concat(AuditionRouter).concat(ServiceRouter).concat(ShopRouter);

const router = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: defaultRouter,
  scrollBehavior() {
    return { x: 0, y: 0 };
  },
});
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
});

export default router;
