diff --git a/src/store/menu.ts b/src/store/menu.ts index 87937da4..6d77d988 100644 --- a/src/store/menu.ts +++ b/src/store/menu.ts @@ -74,12 +74,20 @@ export const useMenuStore = defineStore({ hasMenu(code: string) { return this.menus[code]?.path }, - jumpPage(code: string, params: Record, query: Record) { - const path = this.menus[code]?.path + /** + * 路由跳转 + * @param name 菜单code + * @param params 路由参数 + * @param query 路由参数 + */ + jumpPage(name: string, params?: Record, query?: Record) { + const path = this.hasMenu(name) if (path) { router.push({ - path, params, query + name, params, query }) + } else { + console.warn(`没有找到对应的页面: ${name}`) } }, queryMenuTree(isCommunity = false): Promise { diff --git a/src/views/Northbound/AliCloud/index.vue b/src/views/Northbound/AliCloud/index.vue index 52228bac..5300d43f 100644 --- a/src/views/Northbound/AliCloud/index.vue +++ b/src/views/Northbound/AliCloud/index.vue @@ -151,12 +151,15 @@ import { import type { ActionsType } from '@/components/Table/index.vue'; import { getImage } from '@/utils/comm'; import { message } from 'ant-design-vue'; +import { useMenuStore } from 'store/menu' const router = useRouter(); const instanceRef = ref>({}); const params = ref>({}); const current = ref>({}); +const menuStory = useMenuStore() + const statusMap = new Map(); statusMap.set('enabled', 'success'); statusMap.set('disabled', 'error'); @@ -209,19 +212,14 @@ const columns = [ * 新增 */ const handleAdd = () => { - router.push('/iot/northbound/AliCloud/detail/:id'); + menuStory.jumpPage('Northbound/AliCloud/Detail', { id: ':id'}) }; /** * 查看 */ const handleView = (id: string) => { - router.push({ - path: '/iot/northbound/AliCloud/detail/' + id, - query: { - type: 'view' - } - }); + menuStory.jumpPage('Northbound/AliCloud/Detail', { id }, { type: 'view'}) }; const getActions = ( @@ -249,12 +247,7 @@ const getActions = ( }, icon: 'EditOutlined', onClick: () => { - router.push({ - path: '/iot/northbound/AliCloud/detail/' + data.id, - query: { - type: 'edit' - } - }); + menuStory.jumpPage('Northbound/AliCloud/Detail', { id: data.id }, { type: 'edit'}) }, }, { diff --git a/src/views/Northbound/DuerOS/index.vue b/src/views/Northbound/DuerOS/index.vue index b1079742..e485aff5 100644 --- a/src/views/Northbound/DuerOS/index.vue +++ b/src/views/Northbound/DuerOS/index.vue @@ -147,11 +147,13 @@ import { query, _undeploy, _deploy, _delete, queryProductList, queryTypes } from import type { ActionsType } from '@/components/Table/index.vue'; import { getImage } from '@/utils/comm'; import { message } from 'ant-design-vue'; +import { useMenuStore } from 'store/menu' const router = useRouter(); const instanceRef = ref>({}); const params = ref>({}); const current = ref>({}); +const menuStory = useMenuStore() const statusMap = new Map(); statusMap.set('enabled', 'success'); @@ -236,20 +238,14 @@ const columns = [ * 新增 */ const handleAdd = () => { - router.push('/iot/northbound/DuerOS/detail/:id'); + menuStory.jumpPage('Northbound/DuerOS/Detail', { id: ':id'}) }; /** * 查看 */ const handleView = (id: string) => { - // router.push('/iot/northbound/DuerOS/detail/' + id); - router.push({ - path: '/iot/northbound/DuerOS/detail/' + id, - query: { - type: 'view', - }, - }); + menuStory.jumpPage('Northbound/DuerOS/Detail', { id }, { type: 'view' }) }; const getActions = ( @@ -277,12 +273,7 @@ const getActions = ( }, icon: 'EditOutlined', onClick: () => { - router.push({ - path: '/iot/northbound/DuerOS/detail/' + data.id, - query: { - type: 'edit', - }, - }); + menuStory.jumpPage('Northbound/DuerOS/Detail', { id: data.id }, { type: 'edit' }) }, }, {