|
|
@@ -110,67 +110,71 @@ const actions = {
|
|
|
getRouter({ commit, dispatch }, data) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const userId = sessionStorage.getItem('userId') || userx.state.userId
|
|
|
- getUserMenu(userId)
|
|
|
- .then((res) => {
|
|
|
- if (res.result.length !== 0) {
|
|
|
- const data = res.result.filter((item) => !disabledMenus.includes(item.type || ''))
|
|
|
- const result = {}
|
|
|
- for (const item of data) {
|
|
|
- const obj = {}
|
|
|
- obj[item.type] = packageRouter(item.childrens)
|
|
|
- Object.assign(result, obj)
|
|
|
- }
|
|
|
- commit('SET_DYNAMICROUTES', result)
|
|
|
- const exclude = ['map', 'dashboard', ...gisNames]
|
|
|
- const autoLink = (type, arr) => {
|
|
|
- if (!exclude.includes(type)) {
|
|
|
- // return `${arr.childrens[0].path}/${arr.childrens[0].childrens[0].path}`
|
|
|
- if (arr.childrens.length > 0 && arr.childrens[0].childrens.length > 0) {
|
|
|
- return `${arr.childrens[0].path}/${arr.childrens[0].childrens[0].path}`
|
|
|
- } else {
|
|
|
- return ''
|
|
|
- }
|
|
|
- } else return ''
|
|
|
- }
|
|
|
- const menus = data.map((item) => {
|
|
|
- return {
|
|
|
- title: item.label,
|
|
|
- name: item.type,
|
|
|
- path: autoLink(item.type, item)
|
|
|
- }
|
|
|
- })
|
|
|
- menus.some((item, i) => {if (item.name === 'prjSelection') menus.splice(i, 1)})
|
|
|
- commit('SET_NAVMENUS', menus)
|
|
|
- let routes = data.map((item) => item.childrens)
|
|
|
- routes = routes.flat()
|
|
|
+ const addRouter = []
|
|
|
+ commit('SET_ROUTES', addRouter)
|
|
|
+ addRouter.unshift(groupPageRoutes)
|
|
|
+ resolve(addRouter)
|
|
|
+ // getUserMenu(userId)
|
|
|
+ // .then((res) => {
|
|
|
+ // if (res.result.length !== 0) {
|
|
|
+ // const data = res.result.filter((item) => !disabledMenus.includes(item.type || ''))
|
|
|
+ // const result = {}
|
|
|
+ // for (const item of data) {
|
|
|
+ // const obj = {}
|
|
|
+ // obj[item.type] = packageRouter(item.childrens)
|
|
|
+ // Object.assign(result, obj)
|
|
|
+ // }
|
|
|
+ // commit('SET_DYNAMICROUTES', result)
|
|
|
+ // const exclude = ['map', 'dashboard', ...gisNames]
|
|
|
+ // const autoLink = (type, arr) => {
|
|
|
+ // if (!exclude.includes(type)) {
|
|
|
+ // // return `${arr.childrens[0].path}/${arr.childrens[0].childrens[0].path}`
|
|
|
+ // if (arr.childrens.length > 0 && arr.childrens[0].childrens.length > 0) {
|
|
|
+ // return `${arr.childrens[0].path}/${arr.childrens[0].childrens[0].path}`
|
|
|
+ // } else {
|
|
|
+ // return ''
|
|
|
+ // }
|
|
|
+ // } else return ''
|
|
|
+ // }
|
|
|
+ // const menus = data.map((item) => {
|
|
|
+ // return {
|
|
|
+ // title: item.label,
|
|
|
+ // name: item.type,
|
|
|
+ // path: autoLink(item.type, item)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // menus.some((item, i) => {if (item.name === 'prjSelection') menus.splice(i, 1)})
|
|
|
+ // commit('SET_NAVMENUS', menus)
|
|
|
+ // let routes = data.map((item) => item.childrens)
|
|
|
+ // routes = routes.flat()
|
|
|
|
|
|
- const addRouter = packageRouter(routes)
|
|
|
- commit('SET_ROUTES', addRouter)
|
|
|
- if (data.some((item) => item.type === 'groupPage')) addRouter.unshift(groupPageRoutes)
|
|
|
- if (data.some((item) => item.type === 'prjSelection')) addRouter.unshift(prjSelectionRoutes)
|
|
|
- if (data.some((item) => item.type === 'map' || gisNames.includes(item.type))) addRouter.unshift(mapRoute)
|
|
|
- if (data.some((item) => item.type === 'dashboard')) addRouter.unshift(dashboardRoute)
|
|
|
- else if (!data.some((item) => item.type === 'dashboard') && data.some((item) => item.type === 'map')) {
|
|
|
- const redirectParent = state.addRoutes[0]
|
|
|
- noDashboardRedict.redirect =
|
|
|
- redirectParent.path !== '/map' ? `${redirectParent.path}/${redirectParent.children[0].path}` : '/map'
|
|
|
- addRouter.unshift(noDashboardRedict)
|
|
|
- const firstKey = Object.keys(state.dynamicRoutes)
|
|
|
- if (redirectParent.path === '/map')
|
|
|
- commit(
|
|
|
- 'SET_ROUTES',
|
|
|
- firstKey[0] === 'sysSetting' ? state.dynamicRoutes[firstKey[1]] : state.dynamicRoutes[firstKey[0]]
|
|
|
- )
|
|
|
- else commit('SET_ROUTES', state.dynamicRoutes[data[0].type])
|
|
|
- }
|
|
|
- resolve(addRouter)
|
|
|
- } else {
|
|
|
- reject(res)
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- reject(error)
|
|
|
- })
|
|
|
+ // const addRouter = packageRouter(routes)
|
|
|
+ // commit('SET_ROUTES', addRouter)
|
|
|
+ // if (data.some((item) => item.type === 'groupPage')) addRouter.unshift(groupPageRoutes)
|
|
|
+ // if (data.some((item) => item.type === 'prjSelection')) addRouter.unshift(prjSelectionRoutes)
|
|
|
+ // if (data.some((item) => item.type === 'map' || gisNames.includes(item.type))) addRouter.unshift(mapRoute)
|
|
|
+ // if (data.some((item) => item.type === 'dashboard')) addRouter.unshift(dashboardRoute)
|
|
|
+ // else if (!data.some((item) => item.type === 'dashboard') && data.some((item) => item.type === 'map')) {
|
|
|
+ // const redirectParent = state.addRoutes[0]
|
|
|
+ // noDashboardRedict.redirect =
|
|
|
+ // redirectParent.path !== '/map' ? `${redirectParent.path}/${redirectParent.children[0].path}` : '/map'
|
|
|
+ // addRouter.unshift(noDashboardRedict)
|
|
|
+ // const firstKey = Object.keys(state.dynamicRoutes)
|
|
|
+ // if (redirectParent.path === '/map')
|
|
|
+ // commit(
|
|
|
+ // 'SET_ROUTES',
|
|
|
+ // firstKey[0] === 'sysSetting' ? state.dynamicRoutes[firstKey[1]] : state.dynamicRoutes[firstKey[0]]
|
|
|
+ // )
|
|
|
+ // else commit('SET_ROUTES', state.dynamicRoutes[data[0].type])
|
|
|
+ // }
|
|
|
+ // resolve(addRouter)
|
|
|
+ // } else {
|
|
|
+ // reject(res)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .catch((error) => {
|
|
|
+ // reject(error)
|
|
|
+ // })
|
|
|
})
|
|
|
},
|
|
|
// 退出清空
|