jialh
2024-12-18 b131e9bb15cd8ffe062231f43c3c2f0ae90cf844
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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