123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import Vue from 'vue';
- import VueRouter from 'vue-router';
- import store from '@/store/index';
- const jwt = require('jsonwebtoken');
- Vue.use(VueRouter);
- const admin = [
- {
- path: '/admin/index',
- meta: { title: '统计报表', isleftarrow: false },
- component: () => import('../views/adminCenter/index.vue'),
- },
- {
- path: '/adminRefute',
- meta: { title: '科技文章', isleftarrow: false },
- component: () => import('../views/adminCenter/adminRefute.vue'),
- },
- {
- path: '/adminRefute/edit',
- meta: { title: '科技文章', isleftarrow: false },
- component: () => import('../views/adminCenter/refute/edit.vue'),
- },
- {
- path: '/adminCommunity',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/adminCenter/adminCommunity.vue'),
- },
- {
- path: '/adminCommunity/edit',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/adminCenter/topic/edit.vue'),
- },
- {
- path: '/adminServe',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/adminCenter/adminServe.vue'),
- },
- {
- path: '/adminServe/edit',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/adminCenter/serve/edit.vue'),
- },
- ];
- const routes = [
- {
- path: '/',
- meta: { title: '系统首页', isleftarrow: false },
- component: () => import('../views/index.vue'),
- },
- {
- path: '/login',
- meta: { title: '管理登陆', isleftarrow: false },
- component: () => import('../views/login.vue'),
- },
- // 科技文章
- {
- path: '/refute/index',
- meta: { title: '科技文章', isleftarrow: false },
- component: () => import('../views/refute/index.vue'),
- },
- {
- path: '/refute/detail',
- meta: { title: '文章正文', isleftarrow: false },
- component: () => import('../views/refute/detail.vue'),
- },
- // 社区话题
- {
- path: '/community/index',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/community/index.vue'),
- },
- {
- path: '/community/detail',
- meta: { title: '话题正文', isleftarrow: false },
- component: () => import('../views/community/detail.vue'),
- },
- // 咨询服务
- {
- path: '/service/index',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/service/index.vue'),
- },
- {
- path: '/service/detail',
- meta: { title: '文章正文', isleftarrow: false },
- component: () => import('../views/service/detail.vue'),
- },
- // 引用管理员
- ...admin,
- ];
- const router = new VueRouter({
- mode: 'history',
- base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
- routes,
- });
- router.beforeEach(async (to, form, next) => {
- // 检查session中是否有user信息
- store.commit('getUser');
- const user = store.state.user;
- if (!user) {
- // 有没有openid
- const { openid } = to.query;
- if (openid) {
- // 使用openid换取用户信息
- const res = await store.dispatch('weixin/login', openid);
- if (!res) console.warn('未获取到用户信息');
- } else {
- // 没有openid,很可能是没用微信浏览器打开
- console.warn('未获取到用户信息');
- }
- }
- next();
- });
- router.afterEach(async (to, form) => {
- const title = to.meta.title;
- const img = 'http://broadcast.waityou24.cn/files/article/icon.png';
- const desc = '吉林省计算中心文章发布系统';
- const url = encodeURIComponent(location.href.split('#')[0]);
- const wx = Vue.prototype.$wx;
- const res = await store.dispatch('weixin/jsAuth', { url });
- if (res.errcode == '0') {
- const { data } = res;
- const shareUrl = 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=' + url;
- wx.config({
- debug: false,
- appId: data.appid,
- timestamp: data.timestamp,
- nonceStr: data.noncestr,
- signature: data.sign,
- jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'],
- });
- wx.ready(() => {
- wx.updateAppMessageShareData({
- title: title,
- desc: desc,
- imgUrl: img,
- link: shareUrl,
- success: res => {},
- error: err => {
- alert(JSON.stringify(err));
- },
- });
- wx.updateTimelineShareData({
- title: title,
- imgUrl: img,
- link: shareUrl,
- success: res => {},
- error: err => {
- alert(JSON.stringify(err));
- },
- });
- });
- }
- });
- const originalPush = VueRouter.prototype.push;
- VueRouter.prototype.push = function push(location, onResolve, onReject) {
- if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
- return originalPush.call(this, location).catch(err => err);
- };
- export default router;
|