hailu
2024-06-26 93c7b159d571632c8127a56e72553e6eef8485a3
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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'
// localStorage.setItem('powerAccess','login')
// console.log(localStorage.getItem('powerAccess'));
 
const { homeName } = config
Vue.use(Router)
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: [
      'publicMessage_tool',
      'financeCollateralPledge',
      // 'shangShiInfos',
      // 'shangShiInfos',
      // 'shangshihq', 
      "shangshihq", "shangshigs", "shangshigb", "shangshicw", "shangshigg", "shangshizd",
      'xinSanBanInfos',
      'xinSanBanInfos',
    ]
  },
  {
    index: 2, route: [
      'newsFlashEx_tool',
      'piaoDetail',
      'bankMarket',
      'rentMarket',
      'receivablesMarket',
      'trustMarket',
      'AssetManagementFinancing',
      'PledgeMovableProperty',
      'MovablePropertyRegistration',
    ]
  },
  {
    index: 3, route: [
      'zoneAnalyse',
      'zhengxinCompanys',
      'zhengxinCompanys',
      'zonedynamics',
      'zonedynamics',
      'zongheEvaluates',
    ]
  },
 
  {
    index: 4, route: [
      // 'fundMonitoring',
      // 'controlList',
      'bankPunishNewEvent',
    ]
  },
  {
    index: 5, route: [
      'enterpriseRelationshipMining',
      '_homeEx',
      'rentExchangeCompany',
      'rentExchangeCompanyZF',
      'rentExchangeZF',
      'controlList',
 
    ]
  },
  
]
let routesTop2 = [
  { index: 0, route: ['/'] },
  {
    index: 1, route: [
      'publicMessage_tool',
      'financeCollateralPledge',
      // 'shangShiInfos',
      // 'shangShiInfos',
      // 'shangshihq', 
      "shangshihq", "shangshigs", "shangshigb", "shangshicw", "shangshigg", "shangshizd",
      'xinSanBanInfos',
      'xinSanBanInfos',
    ]
  },
  {
    index: 2, route: [
      'newsFlashEx_tool',
      'piaoDetail',
      'bankMarket',
      'rentMarket',
      'receivablesMarket',
      'trustMarket',
      'AssetManagementFinancing',
      'PledgeMovableProperty',
      'MovablePropertyRegistration',
    ]
  },
  {
    index: 3, route: [
      'zoneAnalyse',
      'zhengxinCompanys',
      'zhengxinCompanys',
      'zonedynamics',
      'zonedynamics',
      'zongheEvaluates',
    ]
  },
  
  {
    index: 4, route: [
      // 'fundMonitoring',
      
      'bankPunishNewEvent',
    ]
  },
  {
    index: 5, route: [
      'enterpriseRelationshipMining',
      '_homeEx',
      'rentExchangeCompany',
      'rentExchangeCompanyZF',
      'rentExchangeZF',
      'controlList',
 
    ]
  },
  
]
 
let bool = true
let nameList = ['_homeEx', 'rentExchangeZF', 'newsFlashEx_tool', 'piaoDetail', 'piaoOverdue', 'piaoOverAlways', 'piaoNoInfo', 'piaoDelayInfo', 'piaoNotice', 'bankCreditNo', 'bankMarket', 'rentMarket', 'receivablesMarket',
  'trustMarket', 'AssetManagementFinancing', 'PledgeMovableProperty', 'MovablePropertyRegistration', 'zoneAnalyse', 'zhengxinAreas', 'zhengxinCompanys', 'zhengxinCompanys', 'zonedynamics', 'zonedynamics',
  'publicMessage_tool', 'financeCollateralPledge', 'rongziDebt', 'rongziBank', 'rongziRent', 'rongziYingshou', 'rongziXintuo', 'rongziZiguan', 'rongziDiya', 'shangShiInfo', 'shangShiInfos', 'xinSanBanInfo', 'xinSanBanInfos', 'basicAttributes_tool', 'bankPunishNewEvent'] //无权限控制的页面
let arr = ['newsDetail', 'rongziDebtDetail', 'publicMessage_tool', '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)
  }
  // if (bool && from.name === null && localStorage.getItem('setUrlRec')) {
  //   bool = false
  //   router.replace({
  //     name: localStorage.getItem('setUrlRec')
  //   })
  // }
  // console.log(localStorage.getItem('setUrlRec'));
  // iView.LoadingBar.start()
  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) {
          // console.log( routesTop1[i].index,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 == 'newPushDetail') {
    next()
    //   // 未登录且要跳转的页面不是登录页
    //   next({
    //     name: LOGIN_PAGE_NAME // 跳转到登录页
    //   })
    // } else if (!token && to.name === LOGIN_PAGE_NAME) {
    //   // 未登陆且要跳转的页面是登录页
    //   next() // 跳转
    // } else if (token && to.name === LOGIN_PAGE_NAME) {
    //   // 已登录且要跳转的页面是登录页
    //   next({
    //     name: homeName // 跳转到homeName页
    //   })
  } else if (!token && nameList.indexOf(to.name) > -1) {
    // console.log(to.name);
    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) {
      // console.log(store.state.user.hasGetInfo,to, store.state.user.access);
      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', 'publicMessage_tool', '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