@peng_kai/kit 0.0.15 → 0.1.0

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 (90) 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 +12 -9
  4. package/admin/{filter → components/filter/src}/FilterParam.vue +15 -15
  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 +9 -9
  10. package/admin/components/text/index.ts +6 -6
  11. package/admin/components/text/src/Amount.vue +22 -19
  12. package/admin/components/text/src/Datetime.vue +12 -12
  13. package/admin/components/text/src/Duration.vue +13 -13
  14. package/admin/components/text/src/Hash.vue +13 -11
  15. package/admin/components/text/src/createTagGetter.ts +7 -7
  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 +48 -48
  31. package/admin/hooks/usePage.ts +67 -65
  32. package/admin/hooks/usePageTab.ts +17 -17
  33. package/admin/layout/large/Breadcrumb.vue +15 -16
  34. package/admin/layout/large/Content.vue +4 -4
  35. package/admin/layout/large/Menu.vue +20 -19
  36. package/admin/layout/large/PageTab.vue +4 -4
  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/types/assist.ts +10 -0
  46. package/admin/unocss/index.ts +1 -1
  47. package/antd/components/InputNumberRange.vue +21 -15
  48. package/antd/directives/formLabelAlign.ts +28 -23
  49. package/antd/hooks/createAntdModal.ts +29 -29
  50. package/antd/hooks/useAntdDrawer.ts +31 -31
  51. package/antd/hooks/useAntdForm.helpers.ts +18 -18
  52. package/antd/hooks/useAntdForm.ts +38 -37
  53. package/antd/hooks/useAntdModal.ts +25 -25
  54. package/antd/hooks/useAntdTable.ts +22 -22
  55. package/antd/hooks/useAntdTheme.ts +86 -0
  56. package/antd/index.ts +8 -7
  57. package/eslint.config.js +50 -0
  58. package/kitDependencies.ts +21 -7
  59. package/package.json +28 -22
  60. package/pnpm-lock.yaml +2244 -153
  61. package/request/helpers.ts +30 -13
  62. package/request/index.ts +2 -2
  63. package/request/interceptors/checkCode.ts +8 -8
  64. package/request/interceptors/filterEmptyValue.ts +9 -9
  65. package/request/interceptors/formatPaging.ts +12 -12
  66. package/request/interceptors/index.ts +7 -6
  67. package/request/interceptors/popupMessage.ts +35 -35
  68. package/request/interceptors/returnResultType.ts +19 -19
  69. package/request/interceptors/toLogin.ts +13 -0
  70. package/request/interceptors/unitizeAxiosError.ts +7 -7
  71. package/request/queryClient.ts +42 -0
  72. package/request/request.ts +21 -21
  73. package/request/type.d.ts +18 -18
  74. package/tsconfig.json +41 -12
  75. package/utils/index.ts +59 -31
  76. package/vue/components/index.ts +1 -0
  77. package/{components → vue/components}/infinite-query/index.ts +1 -1
  78. package/{components → vue/components}/infinite-query/src/InfiniteQuery.vue +29 -29
  79. package/{components → vue/components}/infinite-query/src/useCreateTrigger.ts +13 -13
  80. package/vue/hooks/useComponentRef.ts +12 -12
  81. package/vue/hooks/useIsMounted.ts +4 -4
  82. package/vue/hooks/useTeleportTarget.ts +7 -7
  83. package/vue/index.ts +4 -3
  84. package/admin/defines/definePage.ts +0 -14
  85. package/admin/defines/defineRoute.helpers.ts +0 -37
  86. package/admin/defines/defineRoute.ts +0 -161
  87. package/admin/defines/defineRouteGuard.ts +0 -56
  88. package/admin/defines/defineStartup.ts +0 -41
  89. package/admin/filter/index.ts +0 -5
  90. package/admin/hooks/usePermission.ts +0 -5
@@ -1,27 +1,27 @@
1
- import { computed } from 'vue'
2
- import type { UseQueryReturnType } from '@tanstack/vue-query'
3
- import type { Table, TableProps } from 'ant-design-vue'
4
- import type { ColumnType } from 'ant-design-vue/es/table/interface'
5
- import type { ComponentProps } from 'vue-component-type-helpers'
1
+ import { computed } from 'vue';
2
+ import type { UseQueryReturnType } from '@tanstack/vue-query';
3
+ import type { Table, TableProps } from 'ant-design-vue';
4
+ import type { ColumnType } from 'ant-design-vue/es/table/interface';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
6
 
7
7
  export function useAntdTable<
8
8
  UQRR extends UseQueryReturnType<any, any>,
9
- QP extends Partial<{ page?: string | number; page_size?: string | number }>,
9
+ QP extends Partial<{ page?: string | number, page_size?: string | number }>,
10
10
  >(uqrt: UQRR, queryParams: QP = ({} as any)) {
11
- type RecordType = GetRecordType<UQRR>
12
- type LocalTableProps = TableProps<RecordType>
13
- type LocalColumnsType = NonNullable<LocalTableProps['columns']>
11
+ type RecordType = GetRecordType<UQRR>;
12
+ type LocalTableProps = TableProps<RecordType>;
13
+ type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
14
14
 
15
- const { data, isFetching, isLoading } = uqrt
15
+ const { data, isFetching, isLoading } = uqrt;
16
16
 
17
17
  const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
18
- const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current
19
- Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 })
20
- }
21
- const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn)
18
+ const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current;
19
+ Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 });
20
+ };
21
+ const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn);
22
22
 
23
23
  const tableProps = computed<LocalTableProps>(() => {
24
- const { list, pagination } = data.value ?? {}
24
+ const { list, pagination } = data.value ?? {};
25
25
 
26
26
  return {
27
27
  dataSource: list,
@@ -35,20 +35,20 @@ export function useAntdTable<
35
35
  scroll: { x: 'max-content' },
36
36
  sticky: true,
37
37
  onChange: onPaginationChange as any,
38
- }
39
- })
38
+ };
39
+ });
40
40
  const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
41
41
  get(_, p) {
42
- return p
42
+ return p;
43
43
  },
44
- })
44
+ });
45
45
  const bodyCellType = {} as {
46
46
  index: number
47
47
  text: any
48
48
  value: any
49
49
  record: RecordType
50
50
  column: ColumnType<RecordType>
51
- }
51
+ };
52
52
 
53
53
  return {
54
54
  /** ATable 的预设 Props */
@@ -60,11 +60,11 @@ export function useAntdTable<
60
60
  /** 【类型辅助】用于定义出类型精确的 columns */
61
61
  defineColumns,
62
62
  onPaginationChange,
63
- }
63
+ };
64
64
  }
65
65
 
66
66
  type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
67
67
  ? D extends Api.PageData
68
68
  ? NonNullable<D['list']>[0]
69
69
  : never
70
- : never
70
+ : never;
@@ -0,0 +1,86 @@
1
+ import { reactiveComputed, useStyleTag } from '@vueuse/core';
2
+ import pickBy from 'lodash-es/pickBy';
3
+ import { theme } from 'ant-design-vue';
4
+ import type { ThemeConfig } from 'ant-design-vue/es/config-provider/context';
5
+ import type { Ref } from 'vue';
6
+ import { computed, unref } from 'vue';
7
+
8
+ export function useAntdTheme(mode: Ref<string>, config: Ref<Record<string, any>>) {
9
+ const antdTheme = reactiveComputed<ThemeConfig>(() => {
10
+ const _mode = unref(mode);
11
+ const _config = unref(config);
12
+ const algorithm = ['dark'].includes(_mode) ? theme.darkAlgorithm : theme.defaultAlgorithm;
13
+ const screenXS = Number.parseFloat(_config.breakpoints.mobile);
14
+ const screenSM = Number.parseFloat(_config.breakpoints.mobilel);
15
+ const screenMD = Number.parseFloat(_config.breakpoints.tablet);
16
+ const screenLG = Number.parseFloat(_config.breakpoints.tabletl);
17
+ const screenXL = Number.parseFloat(_config.breakpoints.laptop);
18
+ const screenXXL = Number.parseFloat(_config.breakpoints.desktop);
19
+ const screenXXXL = Number.parseFloat(_config.breakpoints.desktop1k);
20
+ const token: ThemeConfig['token'] = {
21
+ ...algorithm({ ...theme.defaultSeed, colorPrimary: _config.colors.primary.DEFAULT }),
22
+ borderRadius: 2,
23
+ screenXS,
24
+ screenXSMin: screenXS,
25
+ screenXSMax: screenSM - 0.1,
26
+ screenSM,
27
+ screenSMMin: screenSM,
28
+ screenSMMax: screenMD - 0.1,
29
+ screenMD,
30
+ screenMDMin: screenMD,
31
+ screenMDMax: screenLG - 0.1,
32
+ screenLG,
33
+ screenLGMin: screenLG,
34
+ screenLGMax: screenXL - 0.1,
35
+ screenXL,
36
+ screenXLMin: screenXL,
37
+ screenXLMax: screenXXL - 0.1,
38
+ screenXXL,
39
+ screenXXLMin: screenXXL,
40
+ screenXXLMax: screenXXXL - 0.1,
41
+ screenXXXL,
42
+ screenXXXLMin: screenXXXL,
43
+ };
44
+
45
+ if (_mode === 'dark') {
46
+ Object.assign<typeof token, typeof token>(token, {
47
+ colorBgLayout: '#0a0a0a',
48
+ });
49
+ }
50
+
51
+ return { token };
52
+ });
53
+
54
+ const colorER = /.*color.*/;
55
+ const cssVariable = computed(() => {
56
+ return pickBy(antdTheme.token, (_v, k) => {
57
+ if (colorER.test(k))
58
+ return true;
59
+ if (['fontFamily'].includes(k))
60
+ return true;
61
+ return false;
62
+ });
63
+ });
64
+
65
+ useGlobalCssVariable('antd', cssVariable);
66
+
67
+ return antdTheme;
68
+ }
69
+
70
+ function useGlobalCssVariable(prefix: string, vars: Ref<Record<string, any>>) {
71
+ const cssVariable = computed(() => {
72
+ const _vars = unref(vars);
73
+ let wrapper = ':root{ /**/ }';
74
+
75
+ if (_vars) {
76
+ const tokens = Object.entries(_vars)
77
+ .map(([k, v]) => `--${prefix}-${String(k)}: ${String(v)};`)
78
+ .join(' ');
79
+ wrapper = wrapper.replace('/**/', tokens);
80
+ }
81
+
82
+ return wrapper;
83
+ });
84
+
85
+ return useStyleTag(cssVariable);
86
+ }
package/antd/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { useAntdModal } from './hooks/useAntdModal'
2
- export { useAntdDrawer } from './hooks/useAntdDrawer'
3
- export { useAntdTable } from './hooks/useAntdTable'
4
- export { useAntdForm } from './hooks/useAntdForm'
5
- export { createAntdModal } from './hooks/createAntdModal'
6
- export { default as InputNumberRange } from './components/InputNumberRange.vue'
7
- export type { TField, RecordToSchemas } from './hooks/useAntdForm.ts'
1
+ export { useAntdModal } from './hooks/useAntdModal';
2
+ export { useAntdDrawer } from './hooks/useAntdDrawer';
3
+ export { useAntdTable } from './hooks/useAntdTable';
4
+ export { useAntdForm } from './hooks/useAntdForm';
5
+ export { useAntdTheme } from './hooks/useAntdTheme';
6
+ export { createAntdModal } from './hooks/createAntdModal';
7
+ export { default as InputNumberRange } from './components/InputNumberRange.vue';
8
+ export type { TField, RecordToSchemas } from './hooks/useAntdForm.ts';
@@ -0,0 +1,50 @@
1
+ import antfu from '@antfu/eslint-config';
2
+
3
+ export default antfu(
4
+ {
5
+ stylistic: {
6
+ indent: 2,
7
+ quotes: 'single',
8
+ semi: true,
9
+ jsx: true,
10
+ },
11
+ },
12
+ {
13
+ files: ['**/*.ts', '**/*.vue'],
14
+ rules: {
15
+ 'no-console': ['off'],
16
+ 'ts/no-use-before-define': ['off'],
17
+ },
18
+ },
19
+ {
20
+ files: ['**/*.vue'],
21
+ rules: {
22
+ 'vue/attribute-hyphenation': ['error', 'never'],
23
+ 'vue/v-on-event-hyphenation': ['error', 'never', { autofix: true }],
24
+ 'vue/custom-event-name-casing': ['error', 'camelCase'],
25
+ 'vue/prop-name-casing': ['error', 'camelCase'],
26
+ 'vue/component-definition-name-casing': ['error', 'PascalCase'],
27
+ 'vue/component-name-in-template-casing': ['error', 'PascalCase', { registeredComponentsOnly: false }],
28
+ 'vue/max-attributes-per-line': ['error', {
29
+ singleline: { max: 3 },
30
+ multiline: { max: 3 },
31
+ }],
32
+ 'vue/v-slot-style': ['error', {
33
+ atComponent: 'shorthand',
34
+ default: 'shorthand',
35
+ named: 'shorthand',
36
+ }],
37
+ 'vue/block-lang': ['error', {
38
+ script: { lang: 'ts' },
39
+ }],
40
+ 'vue/block-order': ['error', {
41
+ order: ['script:not([setup])', 'script[setup]', 'template', 'style[scoped]', 'style:not([scoped])'],
42
+ }],
43
+ },
44
+ },
45
+ {
46
+ rules: {
47
+ 'eslint-comments/no-unlimited-disable': ['off'],
48
+ },
49
+ },
50
+ );
@@ -1,11 +1,15 @@
1
- import type dayjs from "dayjs";
2
- import type { useMenu, usePage, usePageTab, usePermission } from "./admin/hooks";
3
- import type { useRoute, useRouter } from 'vue-router'
1
+ import type dayjs from 'dayjs';
2
+ import type { useRoute, useRouter } from 'vue-router';
3
+ import type { useMenu, usePage, usePageTab } from './admin/hooks';
4
+ import type { TRole, usePermission } from './admin/permission/usePermission';
4
5
 
5
- const KEY = '__PK_KIT_DEPENDENCIES__'
6
+ const KEY = '__PK_KIT_DEPENDENCIES__';
6
7
 
7
8
  interface Dependencies {
8
9
  dayjs: typeof dayjs
10
+ appName: string
11
+ appId: string
12
+ roles: Record<string, TRole>
9
13
  useRoute: typeof useRoute
10
14
  useRouter: typeof useRouter
11
15
  useMenu: typeof useMenu
@@ -15,15 +19,25 @@ interface Dependencies {
15
19
  }
16
20
 
17
21
  export function setDependencies(deps: Partial<Dependencies>) {
18
- window[KEY] = { ...window[KEY], ...deps }
22
+ window[KEY] = { ...window[KEY], ...deps };
19
23
  }
20
24
 
21
25
  export function getDependencies() {
22
- return window[KEY]
26
+ if (window[KEY]) {
27
+ return new Proxy(window[KEY], {
28
+ get(target, prop: keyof Dependencies) {
29
+ if (prop in target)
30
+ return target[prop];
31
+ else
32
+ throw new Error(`未发现 kit 依赖 ${prop}`);
33
+ },
34
+ });
35
+ }
36
+ else { throw new Error('未发现 kit 依赖'); };
23
37
  }
24
38
 
25
39
  declare global {
26
40
  interface Window {
27
41
  [KEY]: Dependencies
28
42
  }
29
- }
43
+ }
package/package.json CHANGED
@@ -1,40 +1,46 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
- "version": "0.0.15",
3
+ "type": "module",
4
+ "version": "0.1.0",
4
5
  "description": "",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "keywords": [],
5
9
  "main": "index.js",
6
10
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix"
13
+ },
14
+ "peerDependencies": {
15
+ "@tanstack/vue-query": "4.37.1",
16
+ "@vueuse/core": "10.6.1",
17
+ "ant-design-vue": "4.0.7",
18
+ "axios": "1.6.2",
19
+ "bignumber.js": "9.1.2",
20
+ "dayjs": "1.11.10",
21
+ "lodash-es": "4.17.21",
22
+ "vue": "3.3.8",
23
+ "vue-router": "4.2.5"
8
24
  },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
25
  "dependencies": {
13
26
  "@tanstack/vue-query": "^4.37.1",
14
- "@vueuse/core": "^10.5.0",
15
- "ant-design-vue": "^4.0.6",
16
- "axios": "^1.6.0",
27
+ "@vueuse/core": "^10.6.1",
28
+ "ant-design-vue": "^4.0.7",
29
+ "axios": "^1.6.2",
17
30
  "bignumber.js": "^9.1.2",
18
31
  "dayjs": "^1.11.10",
19
32
  "lodash-es": "^4.17.21",
20
- "vue": "^3.3.7",
33
+ "nprogress": "^0.2.0",
34
+ "vue": "^3.3.8",
21
35
  "vue-router": "^4.2.5"
22
36
  },
23
37
  "devDependencies": {
24
- "@types/lodash-es": "^4.17.10",
38
+ "@antfu/eslint-config": "^1.2.1",
39
+ "@types/lodash-es": "^4.17.11",
25
40
  "@types/node": "18",
26
- "type-fest": "^4.6.0",
41
+ "@types/nprogress": "^0.2.3",
42
+ "type-fest": "^4.8.1",
43
+ "typescript": "^5.2.2",
27
44
  "vue-component-type-helpers": "^1.8.22"
28
- },
29
- "peerDependencies": {
30
- "@tanstack/vue-query": "4.x",
31
- "@vueuse/core": "10.x",
32
- "ant-design-vue": "4.0.x",
33
- "axios": "1.6.x",
34
- "bignumber.js": "9.x",
35
- "dayjs": "1.x",
36
- "lodash-es": "4.x",
37
- "vue": "3.3.x",
38
- "vue-router": "4.2.x"
39
45
  }
40
46
  }