import Vue from 'vue';
import VueRouter from 'vue-router';
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);
// 信息展示
const infoview = [
  {
    path: '/infoview/laboratory/index',
    meta: { title: '重点实验室信息展示' },
    component: () => import('../views/infoview/laboratory/index.vue'),
  },
  {
    path: '/infoview/research/index',
    meta: { title: '研究方向信息展示' },
    component: () => import('../views/infoview/research/index.vue'),
  },
  {
    path: '/infoview/equipment/index',
    meta: { title: '设备信息展示' },
    component: () => import('../views/infoview/equipment/index.vue'),
  },
  {
    path: '/infoview/achievement/index',
    meta: { title: '重要成果信息展示' },
    component: () => import('../views/infoview/achievement/index.vue'),
  },
  {
    path: '/infoview/task/index',
    meta: { title: '实验室建设期内承担项目明细' },
    component: () => import('../views/infoview/task/index.vue'),
  },
];
// 科研信息
const scientific = [
  {
    path: '/scientific/award/index',
    meta: { title: '实验室建设期内获奖明细' },
    component: () => import('../views/scientific/award/index.vue'),
  },
  {
    path: '/scientific/paper/index',
    meta: { title: '实验室建设期内发表学术论文明细' },
    component: () => import('../views/scientific/paper/index.vue'),
  },
  {
    path: '/scientific/otherachieve/index',
    meta: { title: '其他成果' },
    component: () => import('../views/scientific/otherachieve/index.vue'),
  },
];
// 人员信息
const personnel = [
  {
    path: '/personnel/index',
    meta: { title: '人员信息' },
    component: () => import('../views/personnel/index.vue'),
  },
  {
    path: '/personnel/director/index',
    meta: { title: '主任及科研助理信息列表' },
    component: () => import('../views/personnel/director/index.vue'),
  },
  {
    path: '/personnel/learning/index',
    meta: { title: '学术委员会' },
    component: () => import('../views/personnel/learning/index.vue'),
  },
];
// 学术交流
const learning = [
  {
    path: '/learning/index',
    meta: { title: '学术交流' },
    component: () => import('../views/learning/index.vue'),
  },
  {
    path: '/learning/sociology/index',
    meta: { title: '社会服务活动' },
    component: () => import('../views/learning/sociology/index.vue'),
  },
  {
    path: '/learning/technology/index',
    meta: { title: '技术服务活动' },
    component: () => import('../views/learning/technology/index.vue'),
  },
  {
    path: '/learning/science/index',
    meta: { title: '科普活动' },
    component: () => import('../views/learning/science/index.vue'),
  },
  {
    path: '/learning/report/index',
    meta: { title: '分析/建议/决策/咨询报告' },
    component: () => import('../views/learning/report/index.vue'),
  },
];
// 队伍建设与人才培养;
const ranks = [
  {
    path: '/ranks/index',
    meta: { title: '队伍建设与人才培养' },
    component: () => import('../views/ranks/index.vue'),
  },
  {
    path: '/ranks/personnel/index',
    meta: { title: '人才称号' },
    component: () => import('../views/ranks/personnel/index.vue'),
  },
  {
    path: '/ranks/title/index',
    meta: { title: '职称晋升' },
    component: () => import('../views/ranks/title/index.vue'),
  },
  {
    path: '/ranks/boshuo/index',
    meta: { title: '博硕培养' },
    component: () => import('../views/ranks/boshuo/index.vue'),
  },
];
const web = [
  {
    path: '/',
    meta: { title: '网站首页' },
    component: () => import('../views/index.vue'),
  },
  // 信息展示
  ...infoview,
  // 科研信息
  ...scientific,
  // 平台活动时间段公示
  // 人员信息
  ...personnel,
  // 学术交流
  ...learning,
  // 队伍建设与人才培养
  ...ranks,

  {
    path: '/activity/time/index',
    meta: { title: '活动时间段' },
    component: () => import('../views/activity/time/index.vue'),
  },
];
const routes = [...web];
const router = new VueRouter({
  mode: 'history',
  base: process.env.VUE_APP_ROUTER,
  routes,
});
// router.beforeEach((to, from, next) => {
//   document.title = `${to.meta.title} `;
//   const token = localStorage.getItem('token');
//   // 不带参数
//   if (to.path == '/work/userCenter/index') {
//     if (!token) {
//       next(`/login?path=${to.path}&&type=2`);
//     } else {
//       let user = jwt.decode(token);
//       store.commit('setUser', user, { root: true });
//       next();
//     }
//   } else {
//     let user = jwt.decode(token);
//     store.commit('setUser', user, { root: true });
//     next();
//   }
// });

export default router;
