123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import router from '@/router/router'
- import store from '@/store/'
- import { powerCheck } from '@/utils/bigmember/'
- import { getEntNicheAuth } from '@/api/modules'
- // 权限控制白名单-路由path
- const powerCheckPathWhiteRegList = [
- /free_*/,
- /\/big\/page\/index/,
- /medical/,
- /order/
- ]
- // 权限控制白名单-路由名
- const powerCheckWhiteList = [
- '404',
- 'ent_search',
- 'ent_ser_portrait',
- 'unit_portrayal',
- 'ent_follow',
- 'big_subscribe',
- 'workspace_dashboard',
- 'report_analysis',
- 'pro_follow_detail', // 项目详情
- 'my_client', // 客户监控
- 'config',
- 'coupon',
- 'datapack_buy',
- 'buy-data-export', // 使用路由别名时候的兼容处理
- 'buy-big-member',
- 'buy-data-pack',
- 'push_setting'
- ]
- const regListCheck = function (regList, path) {
- if (!Array.isArray(regList)) return false
- return regList.some(reg => {
- return reg.test(path)
- })
- }
- router.beforeEach(async (to, from, next) => {
- let { power, info } = store.state.user
- if (!Object.keys(info).length) {
- info = await store.dispatch('user/getUserPower')
- power = info.power ? info.power : []
- }
- // 判断是否进入画像分析系统页面
- if (to.name?.indexOf('custom_') > -1) {
- const entNiche = await getEntNicheAuth()
- // 调用商机管理权限接口 查用户有无画像分析系统权限 有则执行下一步 无则返回首页
- if (entNiche.privatedata) {
- next()
- } else {
- location.href = location.origin
- }
- return
- }
- if (powerCheckWhiteList.includes(to.name) || regListCheck(powerCheckPathWhiteRegList, to.path)) {
- if (to.name === 'ent_ser_portrait') {
- console.log(to.query.ismedical)
- if (info.memberStatus > 0 && (power.indexOf(4) !== -1 || power.indexOf(13) !== -1)) {
- if (to.query.ismedical === '1') {
- next({
- path: `/ent_portrait/${encodeURIComponent(to.params.eId)}?ismedical=1`,
- replace: true
- })
- } else {
- next({
- path: `/ent_portrait/${encodeURIComponent(to.params.eId)}`,
- replace: true
- })
- }
- } else {
- next()
- }
- } else {
- next()
- }
- } else {
- let href = '/big/page/index'
- const { pass, anchor } = powerCheck(info, power, to, from)
- if (pass) {
- next()
- } else {
- // TODO 可优化 临时判断是否旧项目大会员支付路由,skip
- if (to.fullPath.startsWith('/front/member/memberDetail')) {
- // skip
- } else {
- if (anchor) {
- href = `${href}#${anchor}`
- }
- location.href = href
- }
- }
- }
- })
- /**
- * 非工作桌面环境下,修改页面 title
- */
- router.beforeEach((to, from, next) => {
- if (location.href.indexOf('page_workDesktop') === -1) {
- // 标题设置
- if (to?.meta?.title) {
- document.title = to.meta.title
- } else {
- document.title = '剑鱼标讯'
- }
- }
- next()
- })
|