router-interceptors.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import router from '@/router/router'
  2. import store from '@/store/'
  3. import { powerCheck } from '@/utils/bigmember/'
  4. import { getEntNicheAuth } from '@/api/modules'
  5. // 权限控制白名单-路由path
  6. const powerCheckPathWhiteRegList = [
  7. /free_*/,
  8. /\/big\/page\/index/,
  9. /medical/,
  10. /order/
  11. ]
  12. // 权限控制白名单-路由名
  13. const powerCheckWhiteList = [
  14. '404',
  15. 'ent_search',
  16. 'ent_ser_portrait',
  17. 'unit_portrayal',
  18. 'ent_follow',
  19. 'big_subscribe',
  20. 'workspace_dashboard',
  21. 'report_analysis',
  22. 'pro_follow_detail', // 项目详情
  23. 'my_client', // 客户监控
  24. 'config',
  25. 'coupon',
  26. 'datapack_buy',
  27. 'buy-data-export', // 使用路由别名时候的兼容处理
  28. 'buy-big-member',
  29. 'buy-data-pack',
  30. 'push_setting'
  31. ]
  32. const regListCheck = function (regList, path) {
  33. if (!Array.isArray(regList)) return false
  34. return regList.some(reg => {
  35. return reg.test(path)
  36. })
  37. }
  38. router.beforeEach(async (to, from, next) => {
  39. let { power, info } = store.state.user
  40. if (!Object.keys(info).length) {
  41. info = await store.dispatch('user/getUserPower')
  42. power = info.power ? info.power : []
  43. }
  44. // 判断是否进入画像分析系统页面
  45. if (to.name?.indexOf('custom_') > -1) {
  46. const entNiche = await getEntNicheAuth()
  47. // 调用商机管理权限接口 查用户有无画像分析系统权限 有则执行下一步 无则返回首页
  48. if (entNiche.privatedata) {
  49. next()
  50. } else {
  51. location.href = location.origin
  52. }
  53. return
  54. }
  55. if (powerCheckWhiteList.includes(to.name) || regListCheck(powerCheckPathWhiteRegList, to.path)) {
  56. if (to.name === 'ent_ser_portrait') {
  57. console.log(to.query.ismedical)
  58. if (info.memberStatus > 0 && (power.indexOf(4) !== -1 || power.indexOf(13) !== -1)) {
  59. if (to.query.ismedical === '1') {
  60. next({
  61. path: `/ent_portrait/${encodeURIComponent(to.params.eId)}?ismedical=1`,
  62. replace: true
  63. })
  64. } else {
  65. next({
  66. path: `/ent_portrait/${encodeURIComponent(to.params.eId)}`,
  67. replace: true
  68. })
  69. }
  70. } else {
  71. next()
  72. }
  73. } else {
  74. next()
  75. }
  76. } else {
  77. let href = '/big/page/index'
  78. const { pass, anchor } = powerCheck(info, power, to, from)
  79. if (pass) {
  80. next()
  81. } else {
  82. // TODO 可优化 临时判断是否旧项目大会员支付路由,skip
  83. if (to.fullPath.startsWith('/front/member/memberDetail')) {
  84. // skip
  85. } else {
  86. if (anchor) {
  87. href = `${href}#${anchor}`
  88. }
  89. location.href = href
  90. }
  91. }
  92. }
  93. })
  94. /**
  95. * 非工作桌面环境下,修改页面 title
  96. */
  97. router.beforeEach((to, from, next) => {
  98. if (location.href.indexOf('page_workDesktop') === -1) {
  99. // 标题设置
  100. if (to?.meta?.title) {
  101. document.title = to.meta.title
  102. } else {
  103. document.title = '剑鱼标讯'
  104. }
  105. }
  106. next()
  107. })