|
@@ -49,16 +49,40 @@ router.beforeEach(async (to, from, next) => {
|
|
|
} else {
|
|
|
try {
|
|
|
const treeData = await store.dispatch('user/getMenuInfo')
|
|
|
- const nd = treeData.filter(item => item.pageconfigurationid)
|
|
|
- store.dispatch('auth/changeAuthArrs', nd)
|
|
|
- // const typeData = setType(treeData, 'up_auth_id', 'auth_id')
|
|
|
- const menusArray = parseMenuItem(nd)
|
|
|
- const treeMenu = listToTree(menusArray, 'up_auth_id', 'auth_id')
|
|
|
- const dataMenu = _.unionBy(treeMenu, 'auth_id')
|
|
|
- const menus = parseMenu(dataMenu)
|
|
|
- store.dispatch('permission/setRoutes', menus)
|
|
|
- router.addRoutes(menus)
|
|
|
- next({ ...to, replace: true })
|
|
|
+ if (Array.isArray(treeData)) {
|
|
|
+ const nd = treeData.filter(item => item.pageconfigurationid)
|
|
|
+ store.dispatch('auth/changeAuthArrs', nd)
|
|
|
+ // const typeData = setType(treeData, 'up_auth_id', 'auth_id')
|
|
|
+ const menusArray = parseMenuItem(nd)
|
|
|
+ const treeMenu = listToTree(menusArray, 'up_auth_id', 'auth_id')
|
|
|
+ const dataMenu = _.unionBy(treeMenu, 'auth_id')
|
|
|
+ const menus = parseMenu(dataMenu)
|
|
|
+ store.dispatch('permission/setRoutes', menus)
|
|
|
+ router.addRoutes(menus)
|
|
|
+ next({ ...to, replace: true })
|
|
|
+ } else {
|
|
|
+ // remove token and go to login page to re-login
|
|
|
+ if (store.getters.UserId) {
|
|
|
+ const res = await store.dispatch('user/logout')
|
|
|
+ if (res) {
|
|
|
+ store.dispatch('app/toggleOutflag', false)
|
|
|
+ setTimeout(() => {
|
|
|
+ sessionStorage.removeItem('userName')
|
|
|
+ router.push(`/login`)
|
|
|
+ }, 1000);
|
|
|
+ } else {
|
|
|
+ await store.dispatch('user/resetToken')
|
|
|
+ Message.error(error || 'Has Error')
|
|
|
+ next(`/login?redirect=${to.path}`)
|
|
|
+ NProgress.done()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ await store.dispatch('user/resetToken')
|
|
|
+ Message.error(error || 'Has Error')
|
|
|
+ next(`/login?redirect=${to.path}`)
|
|
|
+ NProgress.done()
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
// remove token and go to login page to re-login
|
|
|
await store.dispatch('user/resetToken')
|
|
@@ -82,6 +106,7 @@ router.beforeEach(async (to, from, next) => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+
|
|
|
function parseMenuItem (data) {
|
|
|
//pagetype 1模块 2页面 3按钮 4表格 5树形 6弹窗
|
|
|
const menus = []
|
|
@@ -90,7 +115,7 @@ function parseMenuItem (data) {
|
|
|
menus.push({
|
|
|
auth_id: item.pageconfigurationid,
|
|
|
up_auth_id: item.superiorid,
|
|
|
- path: "/"+item.pageroute,
|
|
|
+ path: "/" + item.pageroute,
|
|
|
name: item.pagename,
|
|
|
meta: {
|
|
|
title: item.pagename,
|
|
@@ -105,7 +130,7 @@ function parseMenuItem (data) {
|
|
|
menus.push({
|
|
|
auth_id: item.pageconfigurationid,
|
|
|
up_auth_id: item.superiorid,
|
|
|
- path: "/"+item.pageroute,
|
|
|
+ path: "/" + item.pageroute,
|
|
|
name: item.pagename,
|
|
|
meta: {
|
|
|
title: item.pagename,
|