|
@@ -3,6 +3,7 @@ import {defineComponent, h, reactive, resolveComponent, watch} from 'vue';
|
|
|
import {HomeTwo} from '@icon-park/vue-next';
|
|
|
import {useTabStore, storeToRefs} from '@stores';
|
|
|
import {find} from 'lodash-es';
|
|
|
+import {useRoute, useRouter} from 'vue-router';
|
|
|
|
|
|
const MenuIcon = defineComponent({
|
|
|
props: {
|
|
@@ -24,15 +25,21 @@ function renderIcon(icon: string) {
|
|
|
}
|
|
|
|
|
|
export const menuOptions: MenuOption[] = [
|
|
|
- {label: '首页', key: '-1', icon: renderIcon('HomeMenuIcon'), pid: '0'},
|
|
|
+ {
|
|
|
+ label: '首页',
|
|
|
+ key: '-1',
|
|
|
+ icon: renderIcon('HomeMenuIcon'),
|
|
|
+ pid: '0',
|
|
|
+ url: '/',
|
|
|
+ },
|
|
|
{
|
|
|
label: '准入审核',
|
|
|
key: '1',
|
|
|
icon: renderIcon('HomeMenuIcon'),
|
|
|
pid: '0',
|
|
|
children: [
|
|
|
- {label: '审核列表', key: '2', pid: '1'},
|
|
|
- {label: '准入审批', key: '3', pid: '1'},
|
|
|
+ {label: '审核列表', key: '2', pid: '1', url: '/audit'},
|
|
|
+ {label: '准入审批', key: '3', pid: '1', url: '/audit'},
|
|
|
],
|
|
|
},
|
|
|
{
|
|
@@ -40,8 +47,8 @@ export const menuOptions: MenuOption[] = [
|
|
|
key: '4',
|
|
|
icon: renderIcon('HomeMenuIcon'),
|
|
|
children: [
|
|
|
- {label: '物料信息', key: '5', pid: '4'},
|
|
|
- {label: 'BOM管理', key: '6', pid: '4'},
|
|
|
+ {label: '物料信息', key: '5', pid: '4', url: '/audit'},
|
|
|
+ {label: 'BOM管理', key: '6', pid: '4', url: '/audit'},
|
|
|
],
|
|
|
},
|
|
|
];
|
|
@@ -50,6 +57,7 @@ export function useMenu() {
|
|
|
const tabStore = useTabStore();
|
|
|
const {activeKey, tabList} = storeToRefs(tabStore);
|
|
|
const expandKeys = reactive<string[]>([]);
|
|
|
+ const {push} = useRouter();
|
|
|
|
|
|
function onExpandedUpdate(keys: string[] | string) {
|
|
|
expandKeys.length = 0;
|
|
@@ -60,26 +68,30 @@ export function useMenu() {
|
|
|
key: string,
|
|
|
item: MenuOption,
|
|
|
) {
|
|
|
- const {label, pid} = item as (MenuOption & {pid: string, label: string});
|
|
|
+ const {label, pid, url} = item as (MenuOption & {
|
|
|
+ pid: string,
|
|
|
+ label: string,
|
|
|
+ url: string
|
|
|
+ });
|
|
|
|
|
|
tabStore.dispatch({
|
|
|
type: 'ADD',
|
|
|
- payload: {label: label as string, key, url: '/', pid},
|
|
|
+ payload: {label: label as string, key, url, pid},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // activeKey变化后更新菜单的展开菜单的值
|
|
|
+ // activeKey变化后更新菜单的展开菜单的值并跳转到对应的url
|
|
|
watch(activeKey, function(value) {
|
|
|
if (expandKeys[0] === value) return;
|
|
|
|
|
|
- const pid = find(
|
|
|
+ const temp = find(
|
|
|
tabList.value,
|
|
|
val => val.key === value,
|
|
|
- )?.pid;
|
|
|
-
|
|
|
- if (!pid) return;
|
|
|
+ );
|
|
|
|
|
|
- onExpandedUpdate(pid);
|
|
|
+ if (!temp) return;
|
|
|
+ onExpandedUpdate(temp.pid);
|
|
|
+ push(temp.url);
|
|
|
});
|
|
|
|
|
|
return [{activeKey, expandKeys}, {onUpdate, onExpandedUpdate}] as const;
|