import Vue from 'vue'
|
import Router from 'vue-router'
|
import routes from './routers'
|
import store from '@/store'
|
import iView, {
|
Message,
|
Modal
|
} from 'view-design'
|
import {
|
setToken,
|
getToken,
|
canTurnTo
|
} from '@/libs/util'
|
import config from '@/config'
|
import axios from '@/libs/api.request'
|
|
const {
|
homeName
|
} = config
|
Vue.use(Router)
|
|
|
// 获取原型对象push函数
|
const originalPush = Router.prototype.push
|
|
// 获取原型对象replace函数
|
const originalReplace = Router.prototype.replace
|
|
// 修改原型对象中的push函数
|
Router.prototype.push = function push(location) {
|
return originalPush.call(this, location).catch(err => err)
|
}
|
|
// 修改原型对象中的replace函数
|
Router.prototype.replace = function replace(location) {
|
return originalReplace.call(this, location).catch(err => err)
|
}
|
|
const router = new Router({
|
routes
|
})
|
const LOGIN_PAGE_NAME = 'login'
|
|
const turnTo = (to, access, next) => {
|
|
if (canTurnTo(to.name, access, routes)) { // 有权限,可访问
|
// console.log(to);
|
next()
|
} else { // 无权限,重定向到401页面
|
access = ['error_401']
|
next({
|
replace: true,
|
name: localStorage.setItem('setUrlRec', 'error_401')
|
})
|
}
|
}
|
let routesTop1 = [{
|
index: 0,
|
route: ['/']
|
},
|
{
|
index: 1,
|
route: [
|
'originalText',
|
'project',
|
]
|
},
|
{
|
index: 2,
|
route: [
|
'fastMatch',
|
'precise',
|
|
]
|
},
|
{
|
index: 3,
|
route: [
|
'IntelligentAgent',
|
// '_homeEx',
|
// 'rentExchangeCompany',
|
// 'rentExchangeCompanyZF',
|
// 'rentExchangeZF',
|
// 'controlList',
|
// 'chooseAssess'
|
]
|
},
|
|
]
|
let routesTop2 = [{
|
index: 0,
|
route: ['/']
|
},
|
{
|
index: 1,
|
route: [
|
'originalText',
|
'project',
|
]
|
},
|
{
|
index: 2,
|
route: [
|
'fastMatch',
|
'precise',
|
|
]
|
},
|
{
|
index: 3,
|
route: [
|
'FindAgent',
|
// 'enterpriseRelationshipMining',
|
// '_homeEx',
|
// 'rentExchangeCompany',
|
// 'rentExchangeCompanyZF',
|
// 'rentExchangeZF',
|
// 'controlList',
|
// 'chooseAssess'
|
]
|
},
|
]
|
|
let bool = true
|
let nameList = ["forget", '_homeEx', 'rentExchangeZF', 'newsFlashEx_tool', 'piaoDetail', 'piaoOverdue', 'piaoOverAlways', 'piaoNoInfo', 'piaoDelayInfo', 'piaoNotice', 'bankCreditNo', 'bankMarket', 'rentMarket', 'receivablesMarket',
|
'trustMarket', 'AssetManagementFinancing', 'PledgeMovableProperty', 'MovablePropertyRegistration', 'zoneAnalyse', 'zhengxinAreas', 'zhengxinCompanys', 'zhengxinCompanys', 'zonedynamics', 'zonedynamics',
|
'financeCollateralPledge', 'rongziDebt', 'rongziBank', 'rongziRent', 'rongziYingshou', 'rongziXintuo', 'rongziZiguan', 'rongziDiya', 'shangShiInfo', 'shangShiInfos', 'xinSanBanInfo', 'xinSanBanInfos', 'basicAttributes_tool', 'bankPunishNewEvent'
|
] //无权限控制的页面
|
let arr = ['newsDetail', 'rongziDebtDetail', 'menuPublicInfo', 'loanSchemeAndRecoveryPlan', 'offSiteCheckQYTP', 'fundMonitoring', 'paymentMonitoring', 'siteCheck', 'controlList', 'managementItem', 'basicAttributes_tool', 'reportFormsManageEx', 'rentExchange', 'rentExchangeCompany', ]
|
// 'publicMessage_tool',
|
router.beforeEach((to, from, next) => {
|
// console.log(to, from);
|
localStorage.setItem('powerAccess', to.name)
|
store.commit('routeNameChange', JSON.stringify({
|
url: to.name,
|
title: to.meta.title
|
}))
|
if (to.name == from.name) {
|
// console.log(to, from);
|
to.query = from.query
|
}
|
|
if (arr.indexOf(to.name) > -1) {
|
bool = false
|
}
|
if (from.name) {
|
localStorage.setItem('setUrlRec', to.name)
|
}
|
const token = getToken()
|
if (token) {
|
for (let i = 0; i < routesTop1.length; i++) {
|
for (let j = 0; j < routesTop1[i].route.length; j++) {
|
if (routesTop1[i].route[j] == to.name) {
|
|
store.commit('routeIndexChange', routesTop1[i].index)
|
}
|
}
|
}
|
} else {
|
for (let i = 0; i < routesTop2.length; i++) {
|
for (let j = 0; j < routesTop2[i].route.length; j++) {
|
if (routesTop2[i].route[j] == to.name) {
|
store.commit('routeIndexChange', routesTop2[i].index)
|
}
|
}
|
}
|
}
|
if (to.name == LOGIN_PAGE_NAME || to.name == 'register' || to.name == 'forgot'|| to.name == 'originalText'|| to.name == 'project') {
|
next()
|
} else if (!token && nameList.indexOf(to.name) > -1) {
|
let data = {
|
name: localStorage.getItem('powerAccess'),
|
id: null
|
}
|
axios.request({
|
url: '/User/GetUserInfo',
|
data,
|
method: 'post'
|
}).then(res => {
|
if (res.data.Check) {
|
store.commit('setAccess', res.data.Data.access)
|
let a = {
|
name: localStorage.getItem('setUrlRec')
|
}
|
turnTo(a, res.data.Data.access, next)
|
} else {}
|
}, res => {})
|
// 未登陆且要跳转的页面是白名单
|
// next() // 跳转
|
// 跳转
|
} else if (!token && nameList.indexOf(to.name) < 0) {
|
store.commit('openloginModal', true)
|
} else {
|
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']
|
if (user && user.Check) {
|
store.commit('setAccess', user.Data.access)
|
let a = {
|
name: localStorage.getItem('setUrlRec')
|
}
|
turnTo(a, user.Data.access, next)
|
} else {
|
setToken('')
|
next({
|
name: 'login'
|
})
|
}
|
//取消"系统无默认项目,请选择已有项目或创建新项目!"弹窗
|
// if (user.Msg.indexOf('系统无默认项目') > -1 && ['newsFlash_tool', 'originalText', 'basicAttributes_tool', 'fundMonitoring', 'editFundMonitoring', 'paymentMonitoring', 'flowAnalysis', 'flowAnalysisTab3', 'flowAnalysisTab2', 'checkGQJGT', 'offSiteCheckQYTP'].indexOf(to.name) == -1) {
|
// switch (user.ShowType) {
|
// case 'tips_info':
|
// Message.info(user.Msg)
|
// break
|
// case 'tips_success':
|
// Message.success(user.Msg)
|
// break
|
// case 'tips_warning':
|
// Message.warning(user.Msg)
|
// break
|
// case 'tips_error':
|
// Message.error(user.Msg)
|
// break
|
// case 'modal_info':
|
// Modal.info({
|
// title: '消息',
|
// content: user.Msg
|
// })
|
// break
|
// case 'modal_success':
|
// Modal.success({
|
// title: '成功',
|
// content: user.Msg
|
// })
|
// break
|
// case 'modal_warning':
|
// Modal.warning({
|
// title: '警告',
|
// content: user.Msg
|
// })
|
// break
|
// case 'modal_error':
|
// Modal.error({
|
// title: '错误',
|
// content: user.Msg
|
// })
|
// break
|
// }
|
// }
|
}).catch(() => {
|
setToken('')
|
next({
|
name: 'login'
|
})
|
})
|
}
|
}
|
})
|
router.beforeEach((to, from, next) => {
|
iView.Modal.remove()
|
if (to.name == 'logout') {
|
store.dispatch('handleLogOut').then(() => {
|
next({
|
name: 'login'
|
})
|
})
|
return false
|
}
|
localStorage.setItem('BelongLtdId', '')
|
localStorage.setItem('BelongLtdId_g', '')
|
localStorage.setItem('BelongLtdId_c', '')
|
localStorage.setItem('BelongLtdId_c_g', '')
|
let userType = localStorage.getItem('userType')
|
if (userType == 'superAdmin' && to.name == homeName) {
|
store.commit('setMainTag', 'AccountManagement_s')
|
next({
|
name: 'accountManagement_s'
|
})
|
} else if (userType == 'admin' && to.name == homeName) {
|
store.commit('setMainTag', 'AccountManagement')
|
next({
|
name: 'accountManagement'
|
})
|
} else {
|
try {
|
store.dispatch('setMainTag', to.matched[0].name)
|
} catch (err) {
|
|
}
|
next()
|
}
|
})
|
router.afterEach(to => {
|
// iView.LoadingBar.finish()
|
window.scrollTo(0, 0)
|
})
|
|
|
export default router
|