@peng_kai/kit 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +41 -0
- package/admin/components/filter/index.ts +5 -0
- package/admin/{filter → components/filter/src}/FilterDrawer.vue +99 -96
- package/admin/{filter → components/filter/src}/FilterParam.vue +76 -76
- package/admin/{filter → components/filter/src}/FilterReset.vue +7 -4
- package/admin/{filter → components/filter/src}/useFilterParams.ts +9 -9
- package/admin/{filter → components/filter/src}/useFilterQuery.ts +11 -11
- package/admin/components/scroll-nav/index.ts +1 -1
- package/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
- package/admin/components/text/index.ts +13 -13
- package/admin/components/text/src/Amount.vue +117 -114
- package/admin/components/text/src/Datetime.vue +44 -44
- package/admin/components/text/src/Duration.vue +26 -26
- package/admin/components/text/src/Hash.vue +42 -40
- package/admin/components/text/src/createTagGetter.ts +13 -13
- package/admin/defines/index.ts +4 -5
- package/admin/defines/page/definePage.ts +12 -0
- package/admin/defines/page/index.ts +1 -0
- package/admin/defines/route/defineRoute.ts +14 -0
- package/admin/defines/route/getRoutes.ts +84 -0
- package/admin/defines/route/helpers.ts +49 -0
- package/admin/defines/route/index.ts +73 -0
- package/admin/defines/route-guard/defineRouteGuard.ts +18 -0
- package/admin/defines/route-guard/getRouteGuards.ts +40 -0
- package/admin/defines/route-guard/index.ts +2 -0
- package/admin/defines/startup/defineStartup.ts +11 -0
- package/admin/defines/startup/getStartups.ts +30 -0
- package/admin/defines/startup/index.ts +2 -0
- package/admin/hooks/index.ts +5 -6
- package/admin/hooks/useMenu.ts +128 -128
- package/admin/hooks/usePage.ts +141 -139
- package/admin/hooks/usePageTab.ts +35 -35
- package/admin/layout/large/Breadcrumb.vue +69 -70
- package/admin/layout/large/Content.vue +24 -24
- package/admin/layout/large/Menu.vue +69 -68
- package/admin/layout/large/PageTab.vue +71 -71
- package/admin/layout/large/index.ts +4 -4
- package/admin/permission/index.ts +4 -0
- package/admin/permission/routerGuard.ts +43 -0
- package/admin/permission/usePermission.ts +52 -0
- package/admin/permission/vuePlugin.ts +30 -0
- package/admin/route-guards/index.ts +2 -0
- package/admin/route-guards/pageProgress.ts +16 -0
- package/admin/route-guards/pageTitle.ts +24 -0
- package/admin/styles/globalCover.scss +43 -43
- package/admin/types/assist.ts +10 -0
- package/admin/unocss/index.ts +1 -1
- package/antd/components/InputNumberRange.vue +53 -47
- package/antd/directives/formLabelAlign.ts +36 -31
- package/antd/hooks/createAntdModal.ts +29 -29
- package/antd/hooks/useAntdDrawer.ts +73 -73
- package/antd/hooks/useAntdForm.helpers.ts +18 -18
- package/antd/hooks/useAntdForm.ts +38 -37
- package/antd/hooks/useAntdModal.ts +25 -25
- package/antd/hooks/useAntdTable.ts +70 -70
- package/antd/hooks/useAntdTheme.ts +86 -0
- package/antd/index.ts +8 -7
- package/eslint.config.js +50 -0
- package/kitDependencies.ts +21 -7
- package/package.json +46 -40
- package/pnpm-lock.yaml +2689 -0
- package/request/helpers.ts +49 -32
- package/request/index.ts +2 -2
- package/request/interceptors/checkCode.ts +8 -8
- package/request/interceptors/filterEmptyValue.ts +9 -9
- package/request/interceptors/formatPaging.ts +12 -12
- package/request/interceptors/index.ts +7 -6
- package/request/interceptors/popupMessage.ts +35 -35
- package/request/interceptors/returnResultType.ts +19 -19
- package/request/interceptors/toLogin.ts +13 -0
- package/request/interceptors/unitizeAxiosError.ts +7 -7
- package/request/queryClient.ts +42 -0
- package/request/request.ts +21 -21
- package/request/type.d.ts +89 -89
- package/tsconfig.json +47 -18
- package/utils/index.ts +67 -29
- package/vue/components/index.ts +1 -0
- package/{components → vue/components}/infinite-query/index.ts +1 -1
- package/{components → vue/components}/infinite-query/src/InfiniteQuery.vue +147 -147
- package/{components → vue/components}/infinite-query/src/useCreateTrigger.ts +35 -35
- package/vue/hooks/useComponentRef.ts +12 -12
- package/vue/hooks/useIsMounted.ts +4 -4
- package/vue/hooks/useTeleportTarget.ts +7 -7
- package/vue/index.ts +4 -3
- package/admin/defines/definePage.ts +0 -14
- package/admin/defines/defineRoute.helpers.ts +0 -30
- package/admin/defines/defineRoute.ts +0 -161
- package/admin/defines/defineRouteGuard.ts +0 -56
- package/admin/defines/defineStartup.ts +0 -41
- package/admin/filter/index.ts +0 -5
- package/admin/hooks/usePermission.ts +0 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
export { defineRoute } from './defineRoute';
|
|
4
|
+
export { getRoutes } from './getRoutes';
|
|
5
|
+
export { getTitle, getMenusByRouter, printRounesNameInterface } from './helpers';
|
|
6
|
+
|
|
7
|
+
declare module 'vue-router' {
|
|
8
|
+
interface RouteMeta {
|
|
9
|
+
/**
|
|
10
|
+
* 路由标题
|
|
11
|
+
*
|
|
12
|
+
* @description 可用来作 document.title 和菜单的名称
|
|
13
|
+
*
|
|
14
|
+
* 默认:APP 名称
|
|
15
|
+
*/
|
|
16
|
+
title?: string | (() => string)
|
|
17
|
+
/**
|
|
18
|
+
* 菜单和面包屑对应的图标
|
|
19
|
+
*
|
|
20
|
+
* 默认:`''`
|
|
21
|
+
*/
|
|
22
|
+
icon?: (() => VNode)
|
|
23
|
+
/**
|
|
24
|
+
* 路由添加顺序,仅作用于一级路由
|
|
25
|
+
*
|
|
26
|
+
* 默认:`10`
|
|
27
|
+
*/
|
|
28
|
+
order?: number
|
|
29
|
+
/**
|
|
30
|
+
* 是否需要登录
|
|
31
|
+
*
|
|
32
|
+
* 默认:`false`
|
|
33
|
+
*/
|
|
34
|
+
requireAuth?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* 权限码
|
|
37
|
+
*/
|
|
38
|
+
permissionCode?: string
|
|
39
|
+
/**
|
|
40
|
+
* 缓存页面
|
|
41
|
+
*
|
|
42
|
+
* 默认:`true`
|
|
43
|
+
*/
|
|
44
|
+
keepAlive?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* 菜单排序(越大越前)
|
|
47
|
+
*
|
|
48
|
+
* 格式:[parent]@[order]
|
|
49
|
+
* - `parent`:可选。不填则默认取路由的 name 值,并在作为一级菜单显示
|
|
50
|
+
* - `order`:必选。路由排序,值越小排越前
|
|
51
|
+
*
|
|
52
|
+
* 例子:
|
|
53
|
+
* - `@10`:一级菜单
|
|
54
|
+
* - `..@10`:所在的路由层级的父级菜单,例如父级菜单是 admin,那么`..`就是`admin`
|
|
55
|
+
* - `admin@10`:指定菜单的父级为 `admin`
|
|
56
|
+
*
|
|
57
|
+
* 默认:undefined。不在菜单中显示
|
|
58
|
+
*/
|
|
59
|
+
menuOrder?: string
|
|
60
|
+
/**
|
|
61
|
+
* 是否隐藏标签页
|
|
62
|
+
*
|
|
63
|
+
* 默认:`false`
|
|
64
|
+
*/
|
|
65
|
+
hiddenTab?: boolean
|
|
66
|
+
/**
|
|
67
|
+
* 用于生成页面运行时的 key
|
|
68
|
+
*
|
|
69
|
+
* 默认:取 route 对象中 path 值
|
|
70
|
+
*/
|
|
71
|
+
pageKeyFn?: (route: RouteLocationNormalizedLoaded) => string
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Router } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
export interface IGuardConfig {
|
|
4
|
+
/** 路由守卫添加顺序(升序加载) */
|
|
5
|
+
order?: number
|
|
6
|
+
setup: (router: Router) => void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 路由守卫标识
|
|
10
|
+
export const RouteGuardSymbol = Symbol('app-route-guard');
|
|
11
|
+
|
|
12
|
+
// 定义路由守卫
|
|
13
|
+
export function defineRouteGuard(guard: IGuardConfig) {
|
|
14
|
+
(guard as any)[RouteGuardSymbol] = true;
|
|
15
|
+
guard.order ??= 10;
|
|
16
|
+
|
|
17
|
+
return guard;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ENV } from '../../../utils';
|
|
2
|
+
import { RouteGuardSymbol } from './defineRouteGuard';
|
|
3
|
+
import type { IGuardConfig } from './defineRouteGuard';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取路由守卫
|
|
7
|
+
*/
|
|
8
|
+
export async function getRouteGuards() {
|
|
9
|
+
const routeGuardFileRE = /\/([A-Za-z0-9-]+.)?route-guard\.ts$/;
|
|
10
|
+
const routeGuardFiles = Object.fromEntries(
|
|
11
|
+
Object.entries(getRouteGuards.modules).filter(([n]) => routeGuardFileRE.test(n)),
|
|
12
|
+
) as Record<string, Function>;
|
|
13
|
+
const routeGuards: Array<IGuardConfig> = [];
|
|
14
|
+
const routeGuardRecord: { file: string, order: number }[] = [];
|
|
15
|
+
|
|
16
|
+
for (const name in routeGuardFiles) {
|
|
17
|
+
const module: any = await routeGuardFiles[name]();
|
|
18
|
+
|
|
19
|
+
if (Object.hasOwn(module?.default ?? {}, RouteGuardSymbol)) {
|
|
20
|
+
const guard = module.default;
|
|
21
|
+
|
|
22
|
+
routeGuards.push(guard);
|
|
23
|
+
routeGuardRecord.push({ file: name, order: guard.order });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 处理路由守卫
|
|
28
|
+
routeGuards.sort((g1, g2) => Number(g2.order) - Number(g1.order));
|
|
29
|
+
routeGuardRecord.sort((g1, g2) => Number(g2.order) - Number(g1.order));
|
|
30
|
+
|
|
31
|
+
// 输出路由守卫
|
|
32
|
+
if (!ENV.isProd) {
|
|
33
|
+
console.groupCollapsed('路由守卫');
|
|
34
|
+
console.table(routeGuardRecord, ['order', 'file']);
|
|
35
|
+
console.groupEnd();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return routeGuards;
|
|
39
|
+
}
|
|
40
|
+
getRouteGuards.modules = {} as any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
|
|
3
|
+
export type StartupFn = (app: App) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
export const StartupSymbol = Symbol('app-startup');
|
|
6
|
+
|
|
7
|
+
export function defineStartup(startup: StartupFn) {
|
|
8
|
+
(startup as any)[StartupSymbol] = true;
|
|
9
|
+
|
|
10
|
+
return startup;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ENV } from '../../../utils';
|
|
2
|
+
import { StartupSymbol } from './defineStartup';
|
|
3
|
+
import type { StartupFn } from './defineStartup';
|
|
4
|
+
|
|
5
|
+
export async function getStartups() {
|
|
6
|
+
const moduleLoaders = getStartups.modules as Record<string, Function>;
|
|
7
|
+
const startupPaths: string[] = [];
|
|
8
|
+
const startups: Array<StartupFn> = [];
|
|
9
|
+
|
|
10
|
+
for (const [path, moduleLoader] of Object.entries(moduleLoaders)) {
|
|
11
|
+
const module: any = await moduleLoader();
|
|
12
|
+
const plugin: StartupFn = module?.default ?? {};
|
|
13
|
+
|
|
14
|
+
if (!Object.hasOwn(plugin, StartupSymbol))
|
|
15
|
+
continue;
|
|
16
|
+
|
|
17
|
+
startupPaths.push(path);
|
|
18
|
+
startups.push(plugin);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 输出 App 插件
|
|
22
|
+
if (!ENV.isProd) {
|
|
23
|
+
console.groupCollapsed('启动时');
|
|
24
|
+
console.table(startupPaths.map(path => ({ path })), ['path']);
|
|
25
|
+
console.groupEnd();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return startups;
|
|
29
|
+
}
|
|
30
|
+
getStartups.modules = {} as any;
|
package/admin/hooks/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { usePage } from './usePage'
|
|
2
|
-
export type { TPageState, IBreadcrumb } from './usePage'
|
|
3
|
-
export { useMenu } from './useMenu'
|
|
4
|
-
export type { TMenu } from './useMenu'
|
|
5
|
-
export { usePageTab } from './usePageTab'
|
|
6
|
-
export { usePermission } from './usePermission'
|
|
1
|
+
export { usePage } from './usePage';
|
|
2
|
+
export type { TPageState, IBreadcrumb } from './usePage';
|
|
3
|
+
export { useMenu } from './useMenu';
|
|
4
|
+
export type { TMenu } from './useMenu';
|
|
5
|
+
export { usePageTab } from './usePageTab';
|
package/admin/hooks/useMenu.ts
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import { createGlobalState } from '@vueuse/core'
|
|
2
|
-
import { reactive, ref
|
|
3
|
-
import type { UnwrapNestedRefs, VNode
|
|
4
|
-
|
|
5
|
-
export { useMenu }
|
|
6
|
-
export type { TMenu }
|
|
7
|
-
|
|
8
|
-
interface IMenuConfig {
|
|
9
|
-
key: string
|
|
10
|
-
label: string | (() => string)
|
|
11
|
-
icon?: () => VNode
|
|
12
|
-
order: number
|
|
13
|
-
trigger: () => void
|
|
14
|
-
children?: IMenuConfig[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface IMenuReactive {
|
|
18
|
-
key: string
|
|
19
|
-
label: Ref<string>
|
|
20
|
-
icon: Ref<VNode | null>
|
|
21
|
-
order: number
|
|
22
|
-
trigger: () => void
|
|
23
|
-
children?: IMenuReactive[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type TMenu = UnwrapNestedRefs<IMenuReactive
|
|
27
|
-
|
|
28
|
-
const useMenu = createGlobalState(() => {
|
|
29
|
-
const menus = reactive<TMenu[]>([])
|
|
30
|
-
const collapsed = ref(false)
|
|
31
|
-
|
|
32
|
-
const findMenu = (menus: TMenu[], key: string) => {
|
|
33
|
-
const queue = [...menus]
|
|
34
|
-
|
|
35
|
-
while (queue.length > 0) {
|
|
36
|
-
const menu = queue.shift()
|
|
37
|
-
|
|
38
|
-
if (menu.key === key)
|
|
39
|
-
return menu
|
|
40
|
-
|
|
41
|
-
if (menu.children)
|
|
42
|
-
queue.push(...menu.children)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return undefined
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 获取目标路由的路径
|
|
50
|
-
* @param key 目标路由
|
|
51
|
-
*/
|
|
52
|
-
const getMenuPath = (key: string) => {
|
|
53
|
-
const path: TMenu[] = []
|
|
54
|
-
|
|
55
|
-
const _getMenuPath = (menus: TMenu[], key: string) => {
|
|
56
|
-
for (const menu of menus) {
|
|
57
|
-
if (menu.key === key) {
|
|
58
|
-
path.push(menu)
|
|
59
|
-
return true
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (menu.children) {
|
|
63
|
-
path.push(menu)
|
|
64
|
-
if (_getMenuPath(menu.children, key))
|
|
65
|
-
return true
|
|
66
|
-
path.pop()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
_getMenuPath(menus, key)
|
|
74
|
-
|
|
75
|
-
return path
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const addMenu = (menuConfig: IMenuConfig, parentKey?: string) => {
|
|
79
|
-
const labelGetter = typeof menuConfig.label === 'function' ? menuConfig.label : (() => menuConfig.label) as (() => string)
|
|
80
|
-
const iconGetter = typeof menuConfig.icon === 'function' ? menuConfig.icon : () => null
|
|
81
|
-
|
|
82
|
-
const _menu = reactive<IMenuReactive>({
|
|
83
|
-
key: menuConfig.key,
|
|
84
|
-
label: computed(labelGetter),
|
|
85
|
-
icon: computed(iconGetter),
|
|
86
|
-
trigger: menuConfig.trigger,
|
|
87
|
-
order: menuConfig.order,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
if (parentKey) {
|
|
91
|
-
const parentMenu = findMenu(menus, parentKey)
|
|
92
|
-
|
|
93
|
-
if (!parentMenu)
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
const children = reactive(parentMenu.children ?? [])
|
|
97
|
-
children.push(_menu)
|
|
98
|
-
children.sort((a, b) =>
|
|
99
|
-
parentMenu.children = children
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
menus.push(_menu)
|
|
103
|
-
menus.sort((a, b) =>
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const removeMenu = (key: string) => {
|
|
108
|
-
const _remove = (menus: TMenu[], key: string) => {
|
|
109
|
-
for (let i = 0; i < menus.length; i++) {
|
|
110
|
-
const menu = menus[i]
|
|
111
|
-
if (menu.key === key) {
|
|
112
|
-
menus.splice(i, 1)
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
if (menu.children)
|
|
116
|
-
_remove(menu.children, key)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return _remove(menus, key)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const getMenu = (key: string) => {
|
|
124
|
-
return findMenu(menus, key)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { menus, collapsed, getMenuPath, addMenu, removeMenu, getMenu }
|
|
128
|
-
})
|
|
1
|
+
import { createGlobalState } from '@vueuse/core';
|
|
2
|
+
import { computed, reactive, ref } from 'vue';
|
|
3
|
+
import type { Ref, UnwrapNestedRefs, VNode } from 'vue';
|
|
4
|
+
|
|
5
|
+
export { useMenu };
|
|
6
|
+
export type { TMenu };
|
|
7
|
+
|
|
8
|
+
interface IMenuConfig {
|
|
9
|
+
key: string
|
|
10
|
+
label: string | (() => string)
|
|
11
|
+
icon?: () => VNode
|
|
12
|
+
order: number
|
|
13
|
+
trigger: () => void
|
|
14
|
+
children?: IMenuConfig[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IMenuReactive {
|
|
18
|
+
key: string
|
|
19
|
+
label: Ref<string>
|
|
20
|
+
icon: Ref<VNode | null>
|
|
21
|
+
order: number
|
|
22
|
+
trigger: () => void
|
|
23
|
+
children?: IMenuReactive[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type TMenu = UnwrapNestedRefs<IMenuReactive>;
|
|
27
|
+
|
|
28
|
+
const useMenu = createGlobalState(() => {
|
|
29
|
+
const menus = reactive<TMenu[]>([]);
|
|
30
|
+
const collapsed = ref(false);
|
|
31
|
+
|
|
32
|
+
const findMenu = (menus: TMenu[], key: string) => {
|
|
33
|
+
const queue = [...menus];
|
|
34
|
+
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
const menu = queue.shift()!;
|
|
37
|
+
|
|
38
|
+
if (menu.key === key)
|
|
39
|
+
return menu;
|
|
40
|
+
|
|
41
|
+
if (menu.children)
|
|
42
|
+
queue.push(...menu.children);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 获取目标路由的路径
|
|
50
|
+
* @param key 目标路由
|
|
51
|
+
*/
|
|
52
|
+
const getMenuPath = (key: string) => {
|
|
53
|
+
const path: TMenu[] = [];
|
|
54
|
+
|
|
55
|
+
const _getMenuPath = (menus: TMenu[], key: string) => {
|
|
56
|
+
for (const menu of menus) {
|
|
57
|
+
if (menu.key === key) {
|
|
58
|
+
path.push(menu);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (menu.children) {
|
|
63
|
+
path.push(menu);
|
|
64
|
+
if (_getMenuPath(menu.children, key))
|
|
65
|
+
return true;
|
|
66
|
+
path.pop();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
_getMenuPath(menus, key);
|
|
74
|
+
|
|
75
|
+
return path;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const addMenu = (menuConfig: IMenuConfig, parentKey?: string) => {
|
|
79
|
+
const labelGetter = typeof menuConfig.label === 'function' ? menuConfig.label : (() => menuConfig.label) as (() => string);
|
|
80
|
+
const iconGetter = typeof menuConfig.icon === 'function' ? menuConfig.icon : () => null;
|
|
81
|
+
|
|
82
|
+
const _menu = reactive<IMenuReactive>({
|
|
83
|
+
key: menuConfig.key,
|
|
84
|
+
label: computed(labelGetter),
|
|
85
|
+
icon: computed(iconGetter),
|
|
86
|
+
trigger: menuConfig.trigger,
|
|
87
|
+
order: menuConfig.order,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (parentKey) {
|
|
91
|
+
const parentMenu = findMenu(menus, parentKey);
|
|
92
|
+
|
|
93
|
+
if (!parentMenu)
|
|
94
|
+
return;
|
|
95
|
+
|
|
96
|
+
const children = reactive(parentMenu.children ?? []);
|
|
97
|
+
children.push(_menu);
|
|
98
|
+
children.sort((a, b) => b.order - a.order);
|
|
99
|
+
parentMenu.children = children;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
menus.push(_menu);
|
|
103
|
+
menus.sort((a, b) => b.order - a.order);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const removeMenu = (key: string) => {
|
|
108
|
+
const _remove = (menus: TMenu[], key: string) => {
|
|
109
|
+
for (let i = 0; i < menus.length; i++) {
|
|
110
|
+
const menu = menus[i];
|
|
111
|
+
if (menu.key === key) {
|
|
112
|
+
menus.splice(i, 1);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (menu.children)
|
|
116
|
+
_remove(menu.children, key);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return _remove(menus, key);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const getMenu = (key: string) => {
|
|
124
|
+
return findMenu(menus, key);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return { menus, collapsed, getMenuPath, addMenu, removeMenu, getMenu };
|
|
128
|
+
});
|