hailu
2024-11-08 ff25271eba1f7f957cf41dd5bb750643ee93e001
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import store from '@/store'
import iView from 'iview'
import {
    setToken,
    getToken,
    canTurnTo,
    setTitle
} from '@/libs/util'
import config from '@/config'
 
const {
    homeName
} = config
 
const originalPush = Router.prototype.push
Router.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)
}
Vue.use(Router)
const router = new Router({
    routes
})
const LOGIN_PAGE_NAME = 'login'
 
const turnTo = (to, access, next) => {
    if (canTurnTo(to.name, access, routes)) {
        next()
    } // 有权限,可访问
    else {
        next({
            replace: true,
            name: 'error_401'
        })
    } // 无权限,重定向到401页面
}
 
let nameList = ['login', 'forgot', 'register', 'newList', 'newsDetail','UserAgreement','privacyPolicy'] //无权限控制的页面
 
router.beforeEach((to, from, next) => {
    iView.LoadingBar.start()
    const token = getToken()
    if (!token && nameList.indexOf(to.name) == -1) {
        // 未登录且要跳转的页面不是登录页
        next({
            name: LOGIN_PAGE_NAME // 跳转到登录页
        })
    } else if (!token && nameList.indexOf(to.name) > -1) {
        // 未登陆且要跳转的页面是登录页
        next() // 跳转
    } else if (token && to.name === LOGIN_PAGE_NAME) {
        // 已登录且要跳转的页面是登录页
        next({
            name: homeName // 跳转到homeName页
        })
    } else {
        if ((to.path == '/financingLease' || to.path == '/financingReceivable' || to.path == '/financingTrust' || to.path == '/financingPrivate' || to.path == '/financingMortgage' || to.path == '/MovablePropertyRegistration'|| to.path == '/SRRHaig'|| to.path == '/enterpriseSemiconductor' || to.name == 'RRHaigDetailPage' || to.name == 'semiconductorPage') && localStorage.getItem('usergrade') == "免费版") {
          console.log('VIP页面');
          store.state.showGoVipModal=true
        //    that.$store.commit("getshowGoVipModal", true);
            return false
        }else if (to.path == '/testPage/myOrders' || to.path == '/semiconductorPage/myOrders' || to.path == '/maPage/myOrders' || to.path == '/investPage/myOrders'|| to.path == '/RRHaigDetailPage/myOrders') {
            next({
                name: 'myOrders' 
            })
        } else if (to.path == '/testPage/authority' || to.path == '/semiconductorPage/authority' || to.path == '/maPage/authority' || to.path == '/investPage/authority'|| to.path == '/RRHaigDetailPage/authority') {
            next({
                name: 'authority' 
            })
        } else if (to.path == '/testPage/changePassword' || to.path == '/semiconductorPage/changePassword' || to.path == '/maPage/changePassword' || to.path == '/investPage/changePassword'|| to.path == '/RRHaigDetailPage/changePassword') {
            next({
                name: 'changePassword' 
            })
        }else if (to.path == '/testPage/rechargeManagement' || to.path == '/semiconductorPage/rechargeManagement' || to.path == '/maPage/rechargeManagement' || to.path == '/investPage/rechargeManagement'|| to.path == '/RRHaigDetailPage/rechargeManagement') {
            next({
                name: 'rechargeManagement' 
            })
        }else if (to.path == '/testPage/consumptionRecords' || to.path == '/semiconductorPage/consumptionRecords' || to.path == '/maPage/consumptionRecords' || to.path == '/investPage/consumptionRecords'|| to.path == '/RRHaigDetailPage/consumptionRecords') {
            next({
                name: 'consumptionRecords' 
            })
        }else if (to.path == '/intelligentPush') {
            window.open('http://fingpt.rensofter.com/')
            return false
            
 
            // next({
            //     name: 'consumptionRecords' 
            // })
        }
        if (store.state.user.hasGetInfo) {
            turnTo(to, store.state.user.access, next)
        } else {
            store.dispatch('getUserInfo').then(user => {
                // 拉取用户信息,通过用户权限和跳转的页面的name来判断是否有权限访问;access必须是一个数组,如:['super_admin'] ['super_admin', 'admin']
                turnTo(to, user.Data.access, next)
            }).catch(() => {
                setToken('')
                next({
                    name: 'login'
                })
            })
        }
    }
})
 
router.afterEach(to => {
    setTitle(to, router.app)
    iView.LoadingBar.finish()
    window.scrollTo(0, 0)
})
 
export default router