Skip to content

Commit

Permalink
feat(router): 路由处理分离
Browse files Browse the repository at this point in the history
  • Loading branch information
h7ml committed Jun 10, 2022
1 parent 1c47a45 commit e2023ed
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/config/setting.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = {
'_mimg',
'fileServer',
],
recordRoute: process.env.NODE_ENV == 'development' ? true : false,
recordRoute: false,
logo: 'vuejs-fill',
i18n: 'zh',
messageDuration: 1500,
Expand Down
64 changes: 4 additions & 60 deletions src/store/modules/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { defaultRoutes, errorRoutes } from '@/config/router.config'
import { getRouterList } from '@/api/User'
import { convertRouter, filterRoutes } from '@/utils/router/routes'
import { getToken } from '@/utils/vue'

import router from '@/utils/router/utils'
const utilsRouter = new router()
const state = () => ({
routes: [],
cachedRoutes: [],
Expand Down Expand Up @@ -83,66 +84,9 @@ const actions = {
/**
* 处理路由
*/
let data = []
results.forEach((item, key) => {
if (item.children && item.meta) {
item.children.forEach((i, k) => {
if (i.meta) {
// i.name = i.name
i.path = i.url
i.component = i.meta.component
i.hidden = i.meta.hidden || false
i.meta.noKeepAlive = i.meta.noKeepAlive || false
i.menuHidden = i.meta.menuHidden || false
i.alwaysShow = i.meta.alwaysShow || false
// i.meta.title = i.meta.title
// i.meta.icon = i.meta.icon
}
})
}
if (item.meta && item.meta.redirect) {
data.push({
hidden: item.meta.hidden || false,
menuHidden: item.meta.menuHidden || false,
alwaysShow: item.meta.alwaysShow || false,
name: item.name,
path: item.url,
component: item.meta.component,
redirect: item.meta.redirect,
meta: {
title: item.meta.title,
icon: item.meta.icon,
noKeepAlive: item.meta.noKeepAlive || false,
},
children: item.children,
})
} else if (item.meta) {
data.push({
hidden: item.hidden || false,
menuHidden: item.menuHidden || false,
alwaysShow: item.alwaysShow || false,
name: item.name,
path: item.url,
component: item.meta.component,
meta: {
title: item.meta.title,
icon: item.meta.icon,
noKeepAlive: item.meta.noKeepAlive || false,
},
children: item.children,
})
} else {
Vue.prototype.$baseMessage(
'后端没有正确的返回路由,将展示默认路由',
'error',
false,
'dgiot-hey-message-error'
)
data = _defaultRoutes
}
})
let data = _.merge(utilsRouter.compute(results, errorRoutes))
console.log(data)
if (data[data.length - 1].path !== '*') {
data.push(errorRoutes)
routes = convertRouter(data)
}

Expand Down
62 changes: 62 additions & 0 deletions src/utils/router/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @description 路由统一处理
*/
export default class router {
constructor() {
this.menu = []
}

compute(router) {
this.menu = []
router.forEach((item) => {
if (item.children && item.meta) {
item.children.forEach((i, k) => {
if (i.meta) {
// i.name = i.name
i.path = i.url
i.component = i.meta.component
i.hidden = i.meta.hidden || false
i.meta.noKeepAlive = i.meta.noKeepAlive || false
i.menuHidden = i.meta.menuHidden || false
i.alwaysShow = i.meta.alwaysShow || false
// i.meta.title = i.meta.title
// i.meta.icon = i.meta.icon
}
})
}
if (item.meta && item.meta.redirect) {
this.menu.push({
hidden: item.meta.hidden || false,
menuHidden: item.meta.menuHidden || false,
alwaysShow: item.meta.alwaysShow || false,
name: item.name,
path: item.url,
component: item.meta.component,
redirect: item.meta.redirect,
meta: {
title: item.meta.title,
icon: item.meta.icon,
noKeepAlive: item.meta.noKeepAlive || false,
},
children: item.children,
})
} else if (item.meta) {
this.menu.push({
hidden: item.hidden || false,
menuHidden: item.menuHidden || false,
alwaysShow: item.alwaysShow || false,
name: item.name,
path: item.url,
component: item.meta.component,
meta: {
title: item.meta.title,
icon: item.meta.icon,
noKeepAlive: item.meta.noKeepAlive || false,
},
children: item.children,
})
}
})
return this.menu
}
}
8 changes: 6 additions & 2 deletions src/views/CloudPressure/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,12 @@
where: { name: 'zeta压测报告' },
})
const { results: product = [] } = await queryProduct({
excludeKeys:
'channel,category,children,config,decoder,desc,producttemplet,topics,profile,content',
where: zeta?.[0]?.objectId
? { producttemplet: zeta?.[0]?.objectId }
? {
producttemplet: zeta?.[0]?.objectId,
}
: {},
})
product?.[0]?.objectId ? (this.product = product?.[0]?.objectId) : ''
Expand Down Expand Up @@ -824,7 +828,7 @@
limit: this.queryForm.limit,
count: 'objectId',
order: '-createdAt',
excludeKeys: 'properties',
excludeKeys: 'product,profile,content',
where: {
product: this.product,
},
Expand Down

0 comments on commit e2023ed

Please sign in to comment.