• wangxl's avatar
    333 · b56a1391
    wangxl authored
    b56a1391
index.js 17.6 KB
// @ts-nocheck
import Vue from 'vue'
import VueRouter from 'vue-router'
// import Layout from '@/components/layout'
import Layout from '@/components/layout/Layout.vue'
import store from '@/store'
import { getToken, removeToken, getType, setType } from '@/views/utils/auth'
// 进度条
import NProgress from 'nprogress'
import { ConsoleSqlOutlined } from '@ant-design/icons'
import api from '@/api'

NProgress.inc(0.2)
NProgress.configure({
  easing: 'ease',
  speed: 600,
  showSpinner: false,
  trickle: false,
})
// NProgress.configure({ parent: '.main' });

Vue.use(VueRouter)

export const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    hidden: true,
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index'),
        name: 'home',
        meta: { title: '首页', icon: '', affix: true }
      }
    ]
  },
  {
    path: '/sys',
    component: () => import('@/views/systemType/index.vue'),
    hidden: true
  },
  {
    path: '/web',
    component: () => import('@/views/web/index.vue'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    hidden: true,
    children: [
      { path: '/403', component: () => import('@/views/errorPage/403.vue'), name: '403', meta: { title: '403', noCache: true } },
      { path: '/404', component: () => import('@/views/errorPage/404.vue'), name: '404', meta: { title: '404', noCache: true } }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    hidden: true
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register/Index'),
    hidden: true
  },
  {
    path: '/reset',
    name: 'reset',
    component: () => import('@/views/reset/index'),
    hidden: true
  },
  {
    path: '/personInfo',
    name: 'personInfo',
    component: Layout,
    meta: { title: '个人设置', icon: 'el-icon-user' },
    hidden: false,
    children: [
      { path: '/person/info', name: '个人设置', component: () => import('@/views/basicSetting/person/index.vue'), meta: { title: '个人设置', icon: '', noCache: true } },
    ]
  },
  {
    path: '/unitInfo',
    name: 'unitInfo',
    component: Layout,
    meta: { title: '单位设置', icon: 'el-icon-user' },
    hidden: false,
    children: [
      { path: '/unit/info', name: '单位基础信息设置', component: () => import('@/views/basicSetting/unit/index.vue'), meta: { title: '单位基础信息设置', icon: '', noCache: true } },
    ]
  },
  {
    path: '/personal',
    name: 'report',
    component: Layout,
    meta: { title: '个人中心', icon: 'el-icon-user' },
    hidden: false,
    children: [
      { path: '/report/project', name: '项目申报', component: () => import('@/views/report/project/Index.vue'), meta: { title: '项目申报', icon: '', noCache: true } },
      { path: '/report/task', name: '任务书填报1', component: () => import('@/views/report/task/Index.vue'), meta: { title: '任务书填报1', icon: '', noCache: true } },
      { path: '/report/projectTask', name: '任务书填报2', component: () => import('@/views/report/task/projectTask.vue'), meta: { title: '任务书填报2', icon: '', noCache: true } },
      { path: '/report/check', name: '中期考核填报', component: () => import('@/views/report/check/Index.vue'), meta: { title: '中期考核填报', icon: '', noCache: true } },
      { path: '/report/conclusion', name: '项目结题', component: () => import('@/views/conclusion/index.vue'), meta: { title: '项目结题', icon: '', noCache: true } },
      { path: '/project/create', name: '项目创建', component: () => import('@/views/report/project/components/projectCreate'), meta: { title: '项目创建', icon: '', noCache: true } },
      { path: '/query/project', name: '项目申报查询1', component: () => import('@/views/query/project/Index.vue'), meta: { title: '项目申报查询', icon: '', noCache: true } },
      { path: '/query/task', name: '任务书上报查询1', component: () => import('@/views/query/task/Index.vue'), meta: { title: '任务书上报查询', icon: '', noCache: true } },
      { path: '/query/check', name: '中期考核上报查询1', component: () => import('@/views/query/check/Index.vue'), meta: { title: '中期考核上报查询', icon: '', noCache: true } },
    ]
  },
  {
    path: '/project',
    name: 'project',
    component: Layout,
    meta: { title: '项目管理', icon: 'component' },
    hidden: false,
    children: [
      { path: '/audit/project', name: '项目审核', component: () => import('@/views/audit/project/Index.vue'), meta: { title: '项目审核', icon: '', noCache: true } },
      { path: '/audit/preliminary', name: '项目预审', component: () => import('@/views/audit/project/Index.vue'), meta: { title: '项目预审', icon: '', noCache: true } },
      { path: '/audit/final', name: '项目终审', component: () => import('@/views/audit/project/final.vue'), meta: { title: '项目审核', icon: '', noCache: true } },
      { path: '/audit/taskAudit', name: '任务书审核', component: () => import('@/views/audit/task/Index.vue'), meta: { title: '任务书审核', icon: '', noCache: true } },
      { path: '/audit/checkAudit', name: '中期考核表审核', component: () => import('@/views/audit/check/Index.vue'), meta: { title: '中期考核表审核', icon: '', noCache: true } },
      // { path: '/peAssign', name: '项目组分配', component: () => import('@/views/peAssign/index.vue'), meta: { title: '项目分配', icon: '', noCache: true } },
      { path: '/peAssign', name: '项目组分配1', component: () => import('@/views/peAssign/projAssign.vue'), meta: { title: '项目分配', icon: '', noCache: true } },
      { path: '/assign', name: '项目组分配2', component: () => import('@/views/assign/assignProjectGroup.vue'), meta: { title: '项目分配', icon: '', noCache: true } },
      { path: '/project/assign', name: '项目分配', component: () => import('@/views/assign/assignProject.vue'), meta: { title: '项目分配', icon: '', noCache: true } },
      { path: '/expert/evaluation', name: '项目评分', component: () => import('@/views/evaluation/index.vue'), meta: { title: '项目评分', icon: '', noCache: true } },
      { path: '/expert/evaluation1', name: '项目评审', component: () => import('@/views/evaluation/evaluation.vue'), meta: { title: '项目评审', icon: '', noCache: true } },
      { path: '/audit/conclusion', name: '项目结题审核', component: () => import('@/views/audit/conclusion/index.vue'), meta: { title: '项目结题审核', icon: '', noCache: true } },
    ]
  },
  {
    path: '/thesis',
    name: 'thesis',
    component: Layout,
    meta: { title: '论文管理', icon: 'search' },
    hidden: false,
    children: [
      { path: '/thesis/audit', name: '论文审核', component: () => import('@/views/audit/thesis/index.vue'), meta: { title: '论文审核', icon: '', noCache: true } },
      { path: '/thesis/list', name: '论文管理', component: () => import('@/views/thesis/index.vue'), meta: { title: '论文管理', icon: '', noCache: true } },
    ]
  },
  {
    path: '/user',
    name: 'user',
    component: Layout,
    meta: { title: '用户人员管理', icon: 'search' },
    hidden: false,
    children: [
      { path: '/manager/user', name: '用户管理', component: () => import('@/views/manager/user/index.vue'), meta: { title: '用户管理', icon: '', noCache: true } },
      { path: '/manager/person', name: '人员管理(后台)', component: () => import('@/views/manager/person/index.vue'), meta: { title: '人员管理(后台)', icon: '', noCache: true } },
    ]
  },
  {
    path: '/person',
    name: 'person',
    component: Layout,
    meta: { title: '人员管理', icon: 'search' },
    hidden: false,
    children: [
      { path: '/person/list', name: '人员管理', component: () => import('@/views/person/index.vue'), meta: { title: '人员管理', icon: '', noCache: true } },
      { path: '/person/audit', name: '人员审核', component: () => import('@/views/person/audit.vue'), meta: { title: '人员审核', icon: '', noCache: true } },
    ]
  },
  {
    path: '/unit',
    name: 'unit',
    component: Layout,
    meta: { title: '单位管理', icon: 'search' },
    hidden: false,
    children: [
      { path: '/unit/list', name: '单位管理', component: () => import('@/views/unit/Index.vue'), meta: { title: '单位管理', icon: '', noCache: true } },
      { path: '/unit/audit', name: '单位审核', component: () => import('@/views/unit/audit.vue'), meta: { title: '单位审核', icon: '', noCache: true } },
      { path: '/manager/unit', name: '单位管理(后台)', component: () => import('@/views/manager/unit/index.vue'), meta: { title: '单位管理(后台)', icon: '', noCache: true } },
    ]
  },
  {
    path: '/notice',
    name: 'notice',
    component: Layout,
    meta: { title: '通知公告', icon: 'search' },
    hidden: false,
    children: [
      { path: '/notice/list', name: '通知发布', component: () => import('@/views/notice/index.vue'), meta: { title: '通知发布', icon: '', noCache: true } },
    ]
  },
  {
    path: '/manager',
    name: 'manager',
    component: Layout,
    meta: { title: '项目管理(后台)', icon: 'search' },
    hidden: false,
    children: [
      { path: '/manager/project', name: '项目管理(后台)', component: () => import('@/views/manager/project/index.vue'), meta: { title: '项目管理(后台)', icon: '', noCache: true } },
    ]
  },
  {
    path: '/statistic',
    name: 'statistic',
    component: Layout,
    meta: { title: '统计查询', icon: 'search' },
    hidden: false,
    children: [
      { path: '/statistic/project', name: '项目申报查询', component: () => import('@/views/statistic/project/Index.vue'), meta: { title: '项目申报查询', icon: '', noCache: true } },
      { path: '/statistic/task', name: '任务书上报查询', component: () => import('@/views/statistic/task/Index.vue'), meta: { title: '任务书上报查询', icon: '', noCache: true } },
      { path: '/statistic/check', name: '中期考核上报查询', component: () => import('@/views/statistic/check/Index.vue'), meta: { title: '中期考核上报查询', icon: '', noCache: true } },
      { path: '/expert/evaluationQuery', name: '评分项目查询', component: () => import('@/views/evaluation/query.vue'), meta: { title: '评分项目查询', icon: '', noCache: true } },
    ]
  },
  {
    path: '/expert',
    name: 'expert',
    component: Layout,
    meta: { title: '专家管理', icon: 'solution' },
    hidden: false,
    children: [
      { path: '/expert/list', name: '专家管理', component: () => import('@/views/expert/index.vue'), meta: { title: '专家管理', icon: '', noCache: true } },
      { path: '/expert/expertBRegister', name: '专家导入', component: () => import('@/views/expert/components/expertImport.vue'), meta: { title: '专家导入', icon: '', noCache: true } },
      { path: '/expert/group', name: '专家组管理', component: () => import('@/views/expertGroup/expertBatch.vue'), meta: { title: '专家组管理', icon: '', noCache: true } },
      { path: '/expert/group/members', name: '专家组成员管理', component: () => import('@/views/expertGroup/expertGroupMembers.vue'), meta: { title: '专家组成员管理', icon: '', noCache: true } },
      { path: '/expert/report', name: '专家推荐', component: () => import('@/views/expert/index.vue'), meta: { title: '专家推荐', icon: '', noCache: true } },
    ]
  },
  {
    path: '/systemSet',
    name: 'timeSet',
    component: Layout,
    meta: { title: '系统设置', icon: 'el-icon-s-tools' },
    hidden: false,
    children: [
      { path: '/timeSet/projectTimeSet', name: '申报时间设置', component: () => import('@/views/timeSet/projectTimeSet/Index.vue'), meta: { title: '申报时间设置', icon: '', noCache: true } },
      { path: '/timeSet/taskTimeSet', name: '任务书时间设置', component: () => import('@/views/timeSet/taskTimeSet/Index.vue'), meta: { title: '任务书时间设置', icon: '', noCache: true } },
      { path: '/timeSet/checkTimeSet', name: '中期考核时间设置', component: () => import('@/views/timeSet/checkTimeSet/Index.vue'), meta: { title: '中期考核时间设置', icon: '', noCache: true } },
      { path: '/setting/batch', name: '申报批次设置', component: () => import('@/views/timeSet/batch/Index.vue'), meta: { title: '申报批次设置', icon: '', noCache: true } },
      { path: '/setting/count', name: '申报名额配比', component: () => import('@/views/projAcountSet/projAcountSet.vue'), meta: { title: '申报名额配比管理', icon: '', noCache: true } },
      { path: '/system/evaluationStandard', name: '年度评审标准设置', component: () => import('@/views/system/evaluationStandard/index.vue'), meta: { title: '年度评审标准设置', icon: '', noCache: true } },
      //后台
      { path: '/system/role', name: '角色管理', component: () => import('@/views/system/role/index.vue'), meta: { title: '角色管理', icon: '', noCache: true } },
      { path: '/system/menu/', name: '菜单管理', component: () => import('@/views/system/menu/index.vue'), meta: { title: '菜单管理', icon: '', noCache: true } },
      { path: '/system/role/menu', name: '角色菜单管理', component: () => import('@/views/system/role/roleRight.vue'), meta: { title: '角色权限管理', icon: '', noCache: true } },
      { path: '/system/evaluation', name: '评审表设置', component: () => import('@/views/system/evaluation/index.vue'), meta: { title: '评审表设置', icon: '', noCache: true } },
      { path: '/system/set', name: '系统设置', component: () => import('@/views/system/set/index.vue'), meta: { title: '系统配置', icon: '', noCache: true } },
    ]
  },
  {
    path: '/log',
    name: 'log',
    component: Layout,
    meta: { title: '日志管理', icon: 'education' },
    hidden: false,
    children: [
      { path: '/log/login', name: '登录日志', component: () => import('@/views/log/login.vue'), meta: { title: '登录日志', icon: '', noCache: true } },
      { path: '/log/operation', name: '操作日志', component: () => import('@/views/log/operation.vue'), meta: { title: '操作日志', icon: '', noCache: true } },
      { path: '/log/exception', name: '异常日志', component: () => import('@/views/log/exception.vue'), meta: { title: '异常日志', icon: '', noCache: true } },
      { path: '/log/login/exception', name: '异常登录日志', component: () => import('@/views/log/loginException.vue'), meta: { title: '异常登录日志', icon: '', noCache: true } },
    ]
  },
  {
    path: '/para',
    name: 'parameter',
    component: Layout,
    meta: { title: '字典管理', icon: 'excel' },
    hidden: false,
    children: [
      { path: '/parameter', name: '字典管理', component: () => import('@/views/system/parameter/index.vue'), meta: { title: '字典管理', icon: '', noCache: true } },
      { path: '/parameter/type', name: '字典类型管理', component: () => import('@/views/system/parameterType/index.vue'), meta: { title: '字典类型管理', icon: '', noCache: true } },
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new VueRouter({
    // mode: 'history', // require service support
    mode: 'hash',
    base: process.env.BASE_URL,
    scrollBehavior: () => ({ y: 0 }),
    routes
  })

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export function changeProjType (type) {
  new Promise(async (resolve, reject) => {
    try {
      this.$store.commit('app/clearStore')
      setType(type + '')
      this.$store.commit('app/setProjType', type)
      let menuList = JSON.parse(window.sessionStorage.getItem('menuList'))
      this.$store.commit('app/initStore', [menuList[0].id])
      this.$router.push('/')
      resolve(true)
    } catch (e) {
      reject(false)
    }
  })
}

const whiteList = ['/login', '/register', '/reset', '/web']

router.beforeEach(async (to, from, next) => {
  document.title = process.env.VUE_APP_SYSTEM_TITLE
  NProgress.start()
  const token = getToken()
  if (token) {
    try {
      if (whiteList.indexOf(to.path) !== -1) {
        next({ path: '/' })
        NProgress.done()
      } else {
        const hasUser = JSON.parse(window.sessionStorage.getItem('user'))
        const hasMenu = JSON.parse(window.sessionStorage.getItem('menuList'))
        if (hasUser && hasMenu) {
          if (hasUser.type === '3' && !!!hasUser.projType && hasUser.roles != '4') {
            if (to.path === '/sys') {
              next()
              NProgress.done()
            } else {
              next(`/sys`)
              NProgress.done()
            }
          } else {
            await store.dispatch('app/auth', to.path)
            next()
            NProgress.done()
          }
        } else {
          await store.dispatch('user/getUser')
          next({ ...to, replace: true })
          NProgress.done()
        }
      }
    } catch (error) {
      removeToken()
      next(`/login`)
      NProgress.done()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
      NProgress.done()
    } else {
      // next(`/login?redirect=${to.path}`)
      next(`/login`)
      NProgress.done()
    }
  }
})

router.afterEach((to, form, next) => {
  NProgress.done()
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err)
}

export default router