123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- import Vue from 'vue';
- import VueRouter from 'vue-router';
- import store from '@/store/index';
- const jwt = require('jsonwebtoken');
- const originalPush = VueRouter.prototype.push;
- VueRouter.prototype.push = function push(location) {
- return originalPush.call(this, location).catch((err) => err);
- };
- Vue.use(VueRouter);
- // 科普教育
- const education = [
- {
- path: '/education/videos',
- name: 'education_videos',
- meta: { title: '科普微视频' },
- component: () => import('../views/education/videos.vue'),
- },
- {
- path: '/education/videoDetail',
- name: 'education_videoDetail',
- meta: { title: '科普微视频' },
- component: () => import('../views/education/videoDetail.vue'),
- },
- {
- path: '/education/refute',
- name: 'education_refute',
- meta: { title: '科学辟谣' },
- component: () => import('../views/education/refute.vue'),
- },
- {
- path: '/education/refuteDetail',
- name: 'education_refuteDetail',
- meta: { title: '科学辟谣' },
- component: () => import('../views/education/refuteDetail.vue'),
- },
- {
- path: '/education/expert',
- name: 'education_expert',
- meta: { title: '专家观点' },
- component: () => import('../views/education/expert.vue'),
- },
- {
- path: '/education/expertDetail',
- name: 'education_expertDetail',
- meta: { title: '专家观点' },
- component: () => import('../views/education/expertDetail.vue'),
- },
- ];
- // 科教服务
- const service = [
- {
- path: '/service/zhongke',
- name: 'service_zhongke',
- meta: { title: '中科在线' },
- component: () => import('../views/service/zhongke.vue'),
- },
- {
- path: '/service/zhongkeDetail',
- name: 'service_zhongkeDetail',
- meta: { title: '中科在线' },
- component: () => import('../views/service/zhongkeDetail.vue'),
- },
- {
- path: '/service/jike',
- name: 'service_jike',
- meta: { title: '吉科在线' },
- component: () => import('../views/service/jike.vue'),
- },
- {
- path: '/service/jikeDetail',
- name: 'service_jikeDetail',
- meta: { title: '吉科在线' },
- component: () => import('../views/service/jikeDetail.vue'),
- },
- {
- path: '/service/make',
- name: 'service_make',
- meta: { title: '预约服务' },
- component: () => import('../views/service/make.vue'),
- },
- ];
- // 研发杂记
- const research = [
- {
- path: '/research/remember',
- name: 'research_remember',
- meta: { title: '研发杂记' },
- component: () => import('../views/research/remember.vue'),
- },
- ];
- // 用户中心
- const userCenter = [
- {
- path: '/userCenter/index',
- name: 'userCenter_index',
- meta: { title: '个人中心' },
- component: () => import('../views/userCenter/index.vue'),
- },
- // 科普教育
- {
- path: '/userCenter/education/videos',
- name: 'userCenter_education_videos',
- meta: { title: '科普微视频' },
- component: () => import('../views/userCenter/education/videos.vue'),
- },
- {
- path: '/userCenter/education/videosDetail',
- name: 'userCenter_education_videosDetail',
- meta: { title: '科普微视频' },
- component: () => import('../views/userCenter/education/videosDetail.vue'),
- },
- {
- path: '/userCenter/education/refute',
- name: 'userCenter_education_refute',
- meta: { title: '科学辟谣' },
- component: () => import('../views/userCenter/education/refute.vue'),
- },
- {
- path: '/userCenter/education/refuteDetail',
- name: 'userCenter_education_refuteDetail',
- meta: { title: '科学辟谣' },
- component: () => import('../views/userCenter/education/refuteDetail.vue'),
- },
- {
- path: '/userCenter/education/expert',
- name: 'userCenter_education_expert',
- meta: { title: '专家观点' },
- component: () => import('../views/userCenter/education/expert.vue'),
- },
- {
- path: '/userCenter/education/expertDetail',
- name: 'userCenter_education_expertDetail',
- meta: { title: '专家观点' },
- component: () => import('../views/userCenter/education/expertDetail.vue'),
- },
- // 科教服务
- {
- path: '/userCenter/service/zhongke',
- name: 'userCenter_service_zhongke',
- meta: { title: '中科在线' },
- component: () => import('../views/userCenter/service/zhongke.vue'),
- },
- {
- path: '/userCenter/service/zhongkeDetail',
- name: 'userCenter_service_zhongkeDetail',
- meta: { title: '中科在线' },
- component: () => import('../views/userCenter/service/zhongkeDetail.vue'),
- },
- {
- path: '/userCenter/service/jike',
- name: 'userCenter_service_jike',
- meta: { title: '吉科在线' },
- component: () => import('../views/userCenter/service/jike.vue'),
- },
- {
- path: '/userCenter/service/jikeDetail',
- name: 'userCenter_service_jikeDetail',
- meta: { title: '吉科在线' },
- component: () => import('../views/userCenter/service/jikeDetail.vue'),
- },
- {
- path: '/userCenter/service/project',
- name: 'userCenter_service_project',
- meta: { title: '服务项目' },
- component: () => import('../views/userCenter/service/project.vue'),
- },
- {
- path: '/userCenter/service/projectDetail',
- name: 'userCenter_service_projectDetail',
- meta: { title: '服务项目' },
- component: () => import('../views/userCenter/service/projectDetail.vue'),
- },
- {
- path: '/userCenter/service/equipment',
- name: 'userCenter_service_equipment',
- meta: { title: '设备共享' },
- component: () => import('../views/userCenter/service/equipment.vue'),
- },
- {
- path: '/userCenter/service/equipmentDetail',
- name: 'userCenter_service_equipmentDetail',
- meta: { title: '设备共享' },
- component: () => import('../views/userCenter/service/equipmentDetail.vue'),
- },
- ];
- const mechCenter = [
- {
- path: '/mechCenter/index',
- name: 'mechCenter_index',
- meta: { title: '个人中心' },
- component: () => import('../views/mechCenter/index.vue'),
- },
- {
- path: '/mechCenter/service/index',
- name: 'mechCenter_service_index',
- meta: { title: '预约服务' },
- component: () => import('../views/mechCenter/service/index.vue'),
- },
- ];
- const perCenter = [
- {
- path: '/perCenter/index',
- name: 'perCenter_index',
- meta: { title: '个人中心' },
- component: () => import('../views/perCenter/index.vue'),
- },
- {
- path: '/perCenter/service/index',
- name: 'perCenter_service_index',
- meta: { title: '预约服务' },
- component: () => import('../views/perCenter/service/index.vue'),
- },
- ];
- const web = [
- {
- path: '/',
- name: 'index',
- meta: { title: '网站首页' },
- component: () => import('../views/index.vue'),
- },
- {
- path: '/login',
- name: 'login',
- meta: { title: '登录' },
- component: () => import('../views/login.vue'),
- },
- ...education,
- ...service,
- ...research,
- ...userCenter,
- ...mechCenter,
- ...perCenter,
- ];
- 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.name == 'mechCenter_index') {
- // if (!token) {
- // next(`/login?path=${to.path}`);
- // } else {
- // let user = jwt.decode(token);
- // store.commit('setUser', user, { root: true });
- // next();
- // }
- // } else if (to.name == 'login') {
- // next(`/login?path=${to.path}`);
- // } else {
- // let user = jwt.decode(token);
- // store.commit('setUser', user, { root: true });
- // next();
- // }
- if (to.name == 'mechCenter_index') {
- if (!token) {
- next(`/login?path=${to.path}`);
- } 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;
|