@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.
Files changed (91) hide show
  1. package/.vscode/settings.json +41 -0
  2. package/admin/components/filter/index.ts +5 -0
  3. package/admin/{filter → components/filter/src}/FilterDrawer.vue +99 -96
  4. package/admin/{filter → components/filter/src}/FilterParam.vue +76 -76
  5. package/admin/{filter → components/filter/src}/FilterReset.vue +7 -4
  6. package/admin/{filter → components/filter/src}/useFilterParams.ts +9 -9
  7. package/admin/{filter → components/filter/src}/useFilterQuery.ts +11 -11
  8. package/admin/components/scroll-nav/index.ts +1 -1
  9. package/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
  10. package/admin/components/text/index.ts +13 -13
  11. package/admin/components/text/src/Amount.vue +117 -114
  12. package/admin/components/text/src/Datetime.vue +44 -44
  13. package/admin/components/text/src/Duration.vue +26 -26
  14. package/admin/components/text/src/Hash.vue +42 -40
  15. package/admin/components/text/src/createTagGetter.ts +13 -13
  16. package/admin/defines/index.ts +4 -5
  17. package/admin/defines/page/definePage.ts +12 -0
  18. package/admin/defines/page/index.ts +1 -0
  19. package/admin/defines/route/defineRoute.ts +14 -0
  20. package/admin/defines/route/getRoutes.ts +84 -0
  21. package/admin/defines/route/helpers.ts +49 -0
  22. package/admin/defines/route/index.ts +73 -0
  23. package/admin/defines/route-guard/defineRouteGuard.ts +18 -0
  24. package/admin/defines/route-guard/getRouteGuards.ts +40 -0
  25. package/admin/defines/route-guard/index.ts +2 -0
  26. package/admin/defines/startup/defineStartup.ts +11 -0
  27. package/admin/defines/startup/getStartups.ts +30 -0
  28. package/admin/defines/startup/index.ts +2 -0
  29. package/admin/hooks/index.ts +5 -6
  30. package/admin/hooks/useMenu.ts +128 -128
  31. package/admin/hooks/usePage.ts +141 -139
  32. package/admin/hooks/usePageTab.ts +35 -35
  33. package/admin/layout/large/Breadcrumb.vue +69 -70
  34. package/admin/layout/large/Content.vue +24 -24
  35. package/admin/layout/large/Menu.vue +69 -68
  36. package/admin/layout/large/PageTab.vue +71 -71
  37. package/admin/layout/large/index.ts +4 -4
  38. package/admin/permission/index.ts +4 -0
  39. package/admin/permission/routerGuard.ts +43 -0
  40. package/admin/permission/usePermission.ts +52 -0
  41. package/admin/permission/vuePlugin.ts +30 -0
  42. package/admin/route-guards/index.ts +2 -0
  43. package/admin/route-guards/pageProgress.ts +16 -0
  44. package/admin/route-guards/pageTitle.ts +24 -0
  45. package/admin/styles/globalCover.scss +43 -43
  46. package/admin/types/assist.ts +10 -0
  47. package/admin/unocss/index.ts +1 -1
  48. package/antd/components/InputNumberRange.vue +53 -47
  49. package/antd/directives/formLabelAlign.ts +36 -31
  50. package/antd/hooks/createAntdModal.ts +29 -29
  51. package/antd/hooks/useAntdDrawer.ts +73 -73
  52. package/antd/hooks/useAntdForm.helpers.ts +18 -18
  53. package/antd/hooks/useAntdForm.ts +38 -37
  54. package/antd/hooks/useAntdModal.ts +25 -25
  55. package/antd/hooks/useAntdTable.ts +70 -70
  56. package/antd/hooks/useAntdTheme.ts +86 -0
  57. package/antd/index.ts +8 -7
  58. package/eslint.config.js +50 -0
  59. package/kitDependencies.ts +21 -7
  60. package/package.json +46 -40
  61. package/pnpm-lock.yaml +2689 -0
  62. package/request/helpers.ts +49 -32
  63. package/request/index.ts +2 -2
  64. package/request/interceptors/checkCode.ts +8 -8
  65. package/request/interceptors/filterEmptyValue.ts +9 -9
  66. package/request/interceptors/formatPaging.ts +12 -12
  67. package/request/interceptors/index.ts +7 -6
  68. package/request/interceptors/popupMessage.ts +35 -35
  69. package/request/interceptors/returnResultType.ts +19 -19
  70. package/request/interceptors/toLogin.ts +13 -0
  71. package/request/interceptors/unitizeAxiosError.ts +7 -7
  72. package/request/queryClient.ts +42 -0
  73. package/request/request.ts +21 -21
  74. package/request/type.d.ts +89 -89
  75. package/tsconfig.json +47 -18
  76. package/utils/index.ts +67 -29
  77. package/vue/components/index.ts +1 -0
  78. package/{components → vue/components}/infinite-query/index.ts +1 -1
  79. package/{components → vue/components}/infinite-query/src/InfiniteQuery.vue +147 -147
  80. package/{components → vue/components}/infinite-query/src/useCreateTrigger.ts +35 -35
  81. package/vue/hooks/useComponentRef.ts +12 -12
  82. package/vue/hooks/useIsMounted.ts +4 -4
  83. package/vue/hooks/useTeleportTarget.ts +7 -7
  84. package/vue/index.ts +4 -3
  85. package/admin/defines/definePage.ts +0 -14
  86. package/admin/defines/defineRoute.helpers.ts +0 -30
  87. package/admin/defines/defineRoute.ts +0 -161
  88. package/admin/defines/defineRouteGuard.ts +0 -56
  89. package/admin/defines/defineStartup.ts +0 -41
  90. package/admin/filter/index.ts +0 -5
  91. 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,2 @@
1
+ export { defineRouteGuard } from './defineRouteGuard';
2
+ export { getRouteGuards } from './getRouteGuards';
@@ -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;
@@ -0,0 +1,2 @@
1
+ export { defineStartup } from './defineStartup';
2
+ export { getStartups } from './getStartups';
@@ -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';
@@ -1,128 +1,128 @@
1
- import { createGlobalState } from '@vueuse/core'
2
- import { reactive, ref, computed, watch } from 'vue'
3
- import type { UnwrapNestedRefs, VNode, Ref } 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) => a.order - b.order)
99
- parentMenu.children = children
100
- }
101
- else {
102
- menus.push(_menu)
103
- menus.sort((a, b) => a.order - b.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
- })
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
+ });