|
|
|
@ -10,6 +10,7 @@ import http from '@/utils/httpRequest' |
|
|
|
import { isURL } from '@/utils/validate' |
|
|
|
import { clearLoginInfo } from '@/utils' |
|
|
|
import i18n from '@/i18n/i18n' |
|
|
|
import store from '@/store' |
|
|
|
|
|
|
|
Vue.use(Router) |
|
|
|
|
|
|
|
@ -70,6 +71,20 @@ const router = new Router({ |
|
|
|
routes: globalRoutes.concat(mainRoutes) |
|
|
|
}) |
|
|
|
|
|
|
|
/** |
|
|
|
* 菜单拉取前统一解析当前工厂,并兜底回写到store.user.site - rqrq |
|
|
|
*/ |
|
|
|
function resolveCurrentMenuSite () { |
|
|
|
const storeSiteRaw = store.state.user.site |
|
|
|
const storeSite = (storeSiteRaw === null || storeSiteRaw === undefined) ? '' : String(storeSiteRaw).trim() |
|
|
|
const cacheSite = (localStorage.getItem('site') || '').trim() |
|
|
|
const currentSite = (storeSite && storeSite !== '0') ? storeSite : cacheSite |
|
|
|
if (currentSite) { |
|
|
|
store.commit('user/updateSite', currentSite) |
|
|
|
} |
|
|
|
return currentSite |
|
|
|
} |
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => { |
|
|
|
// 检查登录状态(除了登录页和404页)
|
|
|
|
if (to.name !== 'login' && to.name !== '404' && !to.path.startsWith('/dashboard-')) { |
|
|
|
@ -87,12 +102,20 @@ router.beforeEach((to, from, next) => { |
|
|
|
if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') { |
|
|
|
next() |
|
|
|
} else { |
|
|
|
const currentSite = resolveCurrentMenuSite() |
|
|
|
if (!currentSite) { |
|
|
|
console.log('当前登录工厂为空,跳转至登录页') |
|
|
|
clearLoginInfo() |
|
|
|
next({ name: 'login' }) |
|
|
|
return |
|
|
|
} |
|
|
|
http({ |
|
|
|
url: http.adornUrl('/sys/menu/nav'), |
|
|
|
method: 'get', |
|
|
|
params: { |
|
|
|
'l': i18n.locale, //i18n.locale
|
|
|
|
menuType: "pc" |
|
|
|
menuType: "pc", |
|
|
|
site: currentSite |
|
|
|
} |
|
|
|
}).then(({data}) => { |
|
|
|
if (data && data.code === 0) { |
|
|
|
|