123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import Vue from 'vue'
- import router from './router'
- import store from './store'
- import { getToken, getWxToken } from '@/utils/auth'
- //课程免登录名单
- const whiteList = ['/courseHome', '/courseLogin','/courseUser','/courseError','/courseAuth','/courseDeal', '/course/adlist', '/course/limitChange', '/course/courseManage', '/course/courseCreate', '/course/dealerManage']
- const whiteList2 = ['/courseDeal/', '/courseDetail/','/courseTeam/', '/courseAdDetail/', '/course/limitChange/', '/course/transfer/', '/course/video/', '/course/dealOrder/']
- function filterWhite(path) {
- return whiteList2.some(item => {
- return path.includes(item)
- })
- }
- router.beforeEach((to, from, next) => {
- if (Vue.$httpRequestList.length > 0) { //强行中断时才向下执行
- Vue.$httpRequestList.forEach(item => {
- item('interrupt'); //给个标志,中断请求
- })
- }
- if (getToken() && whiteList.indexOf(to.path) == -1 && !filterWhite(to.path)) {
- if (to.path == '/login' || to.path == '/') { // 在免登录白名单,直接进入
- next({ name: 'home' })
- return false
- }
- if (typeof (window.$routes_map[to.name]) != 'undefined') {
- window.document.title = window.$routes_map[to.name].label
- } else {
- window.document.title = '管理中心'
- }
- // 初始一些数据
- init(next);
- // next();
- } else if (whiteList.indexOf(to.path) != -1 || filterWhite(to.path)) {
- if ((getWxToken()&&localStorage.getItem('wx_user_info')) || to.path == '/courseAuth') {
- if (typeof (window.$routes_map[to.name]) != 'undefined') {
- window.document.title = window.$routes_map[to.name].label
- } else {
- window.document.title = '功道云课程'
- }
- next()
- } else{
- if(to.path.includes('/courseDetail/')&&to.query&&to.query.code){
- next({
- path:`/courseAuth`,
- query:{
- code:`${to.query.code}-${to.params.id}`
- }
- })
- }else if(to.fullPath.includes('/courseLogin')&&to.query&&to.query.pid != undefined){
- next({
- path:`/courseAuth`,
- query:{
- pid:to.query.pid
- }
- })
- }else{
- // sessionStorage.setItem('cur_path',to.path)
- next({
- path:`/courseAuth`,
- })
- }
- }
- }else if(((to.path == '/verify') || (to.path == '/accountVf') || (to.path == '/iosIntercept')) && localStorage.getItem('a-token-temp')){
- next()
- } else {
- if (!window.$routes_map[to.name].need_login) { // 在免登录白名单,直接进入
- if (typeof (window.$routes_map[to.name]) != 'undefined') {
- window.document.title = window.$routes_map[to.name].label
- }
- next()
- } else {
- window.document.title = '用户登录'
- next('/login')
- }
- }
- })
- /* 路由异常错误处理,尝试解析一个异步组件时发生错误,重新渲染目标页面 */
- 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);
- }
- });
- function init(next) {
- store.dispatch('get_user_info').then((res) => { //获取用户信息
- if (router.history.current.name == 'login') {
- router.push({ name: 'home' })
- return false
- }
- next()
- }).catch(() => {
- next()
- })
- store.dispatch('get_point_types').then(res => { }); //获取积分类型
- // 数据更新,每两分钟更新一次
- store.dispatch('get_employee_map').then((res) => { }); //获取人员列表
- store.dispatch('get_account_info').then((res) => { }); //获取公司信息
- store.dispatch('get_site_info').then((res) => { })//公司信息
- }
|