Commit 7ef22274 authored by mzx's avatar mzx

路由跳转拦截

parent 3bc36e51
......@@ -24,11 +24,21 @@ router.beforeEach((to, from, next) => {
// 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then(() => {
isRelogin.show = false
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
})
// console.log('------', store.state.user.user.enterpriseId)
// 当公司id为null时跳至企业基本信息页面 否则跳首页
if (store.state.user.user.enterpriseId === null) {
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next('/informationReport/basicInformation/index')
})
} else {
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
})
}
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err)
......
......@@ -272,6 +272,18 @@ import { getCompany, saveCompany } from '@/api/informationReport'
export default {
name: 'Index',
dicts: ['bhxq_business_type', 'bhxq_enterprise_transport_type', 'bhxq_enterprise_register_status', 'bhxq_area_scope', 'bhxq_enterprise_trade_status'],
beforeRouteLeave(to, from, next) {
// 在这里进行路由跳转控制 当公司id为空时 完善公司信息后才能跳转到其他页面
if (this.$store.state.user.user.enterpriseId === null) {
if (this.$message.error('请完善企业基本信息')) {
// next()
} else {
next(false)
}
} else {
next()
}
},
data() {
return {
companyId: this.$store.state.user.user.enterpriseId, // 公司id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment