@peng_kai/kit 0.2.0-beta.3 → 0.2.0-beta.30

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 (64) hide show
  1. package/admin/adminPlugin.ts +11 -1
  2. package/admin/components/filter/src/FilterDrawer.vue +153 -153
  3. package/admin/components/filter/src/FilterParam.vue +1 -1
  4. package/admin/components/filter/src/FilterReset.vue +12 -9
  5. package/admin/components/rich-text/index.ts +1 -1
  6. package/admin/components/rich-text/src/RichText.new.vue +164 -0
  7. package/admin/components/rich-text/src/RichText.vue +3 -6
  8. package/admin/components/rich-text/src/editorConfig.ts +126 -0
  9. package/admin/components/rich-text/src/imageUploader.ts +20 -18
  10. package/admin/components/scroll-nav/index.ts +1 -1
  11. package/admin/components/scroll-nav/src/ScrollNav.vue +1 -1
  12. package/admin/components/settings/index.ts +1 -0
  13. package/admin/components/settings/src/Settings.vue +333 -0
  14. package/admin/components/text/index.ts +13 -13
  15. package/admin/components/text/src/Amount.vue +121 -121
  16. package/admin/components/text/src/Datetime.vue +1 -1
  17. package/admin/components/text/src/Duration.vue +26 -26
  18. package/admin/components/text/src/Hash.vue +51 -51
  19. package/admin/components/text/src/createTagGetter.ts +13 -13
  20. package/admin/components/upload/index.ts +1 -0
  21. package/admin/components/upload/src/PictureCardUpload.vue +1 -1
  22. package/admin/components/upload/src/helpers.ts +37 -0
  23. package/admin/defines/route/defineRoute.ts +2 -4
  24. package/admin/defines/route/getRoutes.ts +4 -4
  25. package/admin/defines/route/index.ts +1 -1
  26. package/admin/defines/route-guard/defineRouteGuard.ts +1 -4
  27. package/admin/defines/route-guard/getRouteGuards.ts +5 -7
  28. package/admin/defines/startup/defineStartup.ts +1 -3
  29. package/admin/defines/startup/runStartup.ts +4 -6
  30. package/admin/layout/large/Breadcrumb.vue +2 -2
  31. package/admin/layout/large/Content.vue +2 -2
  32. package/admin/layout/large/Menu.vue +2 -2
  33. package/admin/layout/large/PageTab.vue +2 -2
  34. package/admin/permission/routerGuard.ts +1 -1
  35. package/admin/permission/vuePlugin.ts +1 -0
  36. package/admin/route-guards/index.ts +3 -3
  37. package/admin/route-guards/pageProgress.ts +27 -27
  38. package/admin/stores/createUsePageStore.ts +1 -3
  39. package/admin/styles/classCover.scss +107 -0
  40. package/admin/styles/globalCover.scss +54 -54
  41. package/admin/styles/index.scss +14 -12
  42. package/antd/components/InputNumberRange.vue +59 -59
  43. package/antd/directives/formLabelAlign.ts +36 -36
  44. package/antd/hooks/useAntdDrawer.ts +73 -73
  45. package/antd/hooks/useAntdForm.ts +1 -1
  46. package/antd/hooks/useAntdModal.ts +4 -1
  47. package/antd/hooks/useAntdTable.ts +2 -1
  48. package/libs/dayjs.ts +7 -0
  49. package/libs/echarts.ts +1 -1
  50. package/libs/vue-i18n.ts +21 -0
  51. package/package.json +36 -35
  52. package/request/helpers.ts +68 -68
  53. package/request/interceptors/returnResultType.ts +3 -3
  54. package/request/interceptors/toLogin.ts +43 -26
  55. package/request/request.ts +0 -3
  56. package/request/type.d.ts +92 -92
  57. package/stylelint.config.cjs +7 -7
  58. package/tsconfig.json +50 -50
  59. package/utils/LocaleManager.ts +125 -0
  60. package/utils/date.ts +1 -9
  61. package/vite/index.mjs +34 -8
  62. package/vue/components/infinite-query/index.ts +1 -1
  63. package/vue/components/infinite-query/src/InfiniteQuery.vue +199 -199
  64. package/vue/components/infinite-query/src/useCreateTrigger.ts +39 -39
@@ -1,73 +1,73 @@
1
- import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue';
2
- import { defineComponent, h, isProxy, reactive, toRef, toRefs } from 'vue';
3
- import type { Component } from 'vue';
4
- import type { ButtonProps, DrawerProps } from 'ant-design-vue';
5
- import type { ComponentProps } from 'vue-component-type-helpers';
6
- import type { Writable } from 'type-fest';
7
- import { useComponentRef } from '../../vue';
8
-
9
- const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true, rootClassName: 'antd-cover__basic-drawer' };
10
-
11
- interface IComponentConfig<Comp extends Component> {
12
- is: Comp
13
- props?: Writable<ComponentProps<Comp>>
14
- }
15
-
16
- export function useAntdDrawer<Comp extends Component>(
17
- comp: IComponentConfig<Comp> | Comp,
18
- drawerProps = defaultDrawerProps,
19
- ) {
20
- const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>;
21
- const compProps = reactive(_comp.props);
22
- const compRef = useComponentRef(_comp.is);
23
- const _drawerProps: DrawerProps = reactive({
24
- ...defaultDrawerProps,
25
- ...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
26
- });
27
-
28
- const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
29
- Object.assign(_drawerProps, newAntdModalProps);
30
- Object.assign(compProps, newBodyProps);
31
- _drawerProps.open = true;
32
- };
33
- const close = () => {
34
- _drawerProps.open = false;
35
- };
36
-
37
- const DrawerFooter = defineComponent({
38
- setup() {
39
- const cancelBtnProps: ButtonProps = reactive({ onClick: close });
40
- const confirmBtnProps: ButtonProps = reactive({
41
- type: 'primary',
42
- loading: toRef(() => (compRef as any)?.loading),
43
- onClick: () => (compRef as any)?.confirm?.(),
44
- });
45
-
46
- return { cancelBtnProps, confirmBtnProps };
47
- },
48
- render() {
49
- const { cancelBtnProps, confirmBtnProps } = this;
50
-
51
- return h(ASpace, {}, () => [
52
- h(AButton, cancelBtnProps, () => '取消'),
53
- h(AButton, confirmBtnProps, () => '确定'),
54
- ]);
55
- },
56
- });
57
- const PresetComponent = defineComponent({
58
- render() {
59
- return h(ADrawer, _drawerProps, {
60
- default: () => h(_comp.is, compProps as any),
61
- });
62
- },
63
- });
64
-
65
- _drawerProps.footer = _drawerProps.footer === undefined ? h(DrawerFooter) : _drawerProps.footer;
66
- _drawerProps['onUpdate:open'] = (visiable) => {
67
- _drawerProps.open = visiable;
68
- };
69
- (compProps as any).ref = compRef;
70
- (compProps as any).onClose = close;
71
-
72
- return { PresetComponent, drawerProps: _drawerProps, open, close };
73
- }
1
+ import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue';
2
+ import { defineComponent, h, isProxy, reactive, toRef, toRefs } from 'vue';
3
+ import type { Component } from 'vue';
4
+ import type { ButtonProps, DrawerProps } from 'ant-design-vue';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
+ import type { Writable } from 'type-fest';
7
+ import { useComponentRef } from '../../vue';
8
+
9
+ const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true, rootClassName: 'antd-cover__basic-drawer' };
10
+
11
+ interface IComponentConfig<Comp extends Component> {
12
+ is: Comp
13
+ props?: Writable<ComponentProps<Comp>>
14
+ }
15
+
16
+ export function useAntdDrawer<Comp extends Component>(
17
+ comp: IComponentConfig<Comp> | Comp,
18
+ drawerProps = defaultDrawerProps,
19
+ ) {
20
+ const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>;
21
+ const compProps = reactive(_comp.props);
22
+ const compRef = useComponentRef(_comp.is);
23
+ const _drawerProps: DrawerProps = reactive({
24
+ ...defaultDrawerProps,
25
+ ...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
26
+ });
27
+
28
+ const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
29
+ Object.assign(_drawerProps, newAntdModalProps);
30
+ Object.assign(compProps, newBodyProps);
31
+ _drawerProps.open = true;
32
+ };
33
+ const close = () => {
34
+ _drawerProps.open = false;
35
+ };
36
+
37
+ const DrawerFooter = defineComponent({
38
+ setup() {
39
+ const cancelBtnProps: ButtonProps = reactive({ onClick: close });
40
+ const confirmBtnProps: ButtonProps = reactive({
41
+ type: 'primary',
42
+ loading: toRef(() => (compRef as any)?.loading),
43
+ onClick: () => (compRef as any)?.confirm?.(),
44
+ });
45
+
46
+ return { cancelBtnProps, confirmBtnProps };
47
+ },
48
+ render() {
49
+ const { cancelBtnProps, confirmBtnProps } = this;
50
+
51
+ return h(ASpace, {}, () => [
52
+ h(AButton, cancelBtnProps, () => '取消'),
53
+ h(AButton, confirmBtnProps, () => '确定'),
54
+ ]);
55
+ },
56
+ });
57
+ const PresetComponent = defineComponent({
58
+ render() {
59
+ return h(ADrawer, _drawerProps, {
60
+ default: () => h(_comp.is, compProps as any),
61
+ });
62
+ },
63
+ });
64
+
65
+ _drawerProps.footer = _drawerProps.footer === undefined ? h(DrawerFooter) : _drawerProps.footer;
66
+ _drawerProps['onUpdate:open'] = (visiable) => {
67
+ _drawerProps.open = visiable;
68
+ };
69
+ (compProps as any).ref = compRef;
70
+ (compProps as any).onClose = close;
71
+
72
+ return { PresetComponent, drawerProps: _drawerProps, open, close };
73
+ }
@@ -25,7 +25,7 @@ interface Options<S, TS> {
25
25
  transform?: (state: S) => TS
26
26
  }
27
27
 
28
- function useAntdForm<S extends Record<string, any>, TS = S>(schemas: MaybeRefOrGetter<SchemaConfig<S>>, options?: Options<S, TS>) {
28
+ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRefOrGetter<SchemaConfig<S>>, options?: Options<S, TS>) {
29
29
  const schemasR = toRef(schemas);
30
30
 
31
31
  const state = ref({} as S);
@@ -33,7 +33,10 @@ export function useAntdModal<Comp extends Component>(
33
33
  ...defaultModalProps,
34
34
  ...isProxy(modalProps) ? toRefs(modalProps) : modalProps,
35
35
  confirmLoading: toRef(() => (compRef as any)?.loading),
36
- onOk: () => (compRef as any)?.confirm?.(),
36
+ onOk: (e: MouseEvent) => {
37
+ (compRef as any)?.confirm?.(e);
38
+ modalProps.onOk?.(e);
39
+ },
37
40
  });
38
41
  const modalSlotName = _comp.type === 'body' ? 'default' : 'modalRender';
39
42
 
@@ -55,9 +55,10 @@ export function useAntdTable<
55
55
  }
56
56
  };
57
57
  const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
58
- const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
58
+ const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection = () => ({})) => {
59
59
  const rowSelection = reactive(rowSelectionGetter());
60
60
 
61
+ rowSelection.preserveSelectedRowKeys ??= true;
61
62
  rowSelection.selectedRowKeys ??= [];
62
63
  rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
63
64
 
package/libs/dayjs.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import dayjs from 'dayjs';
2
2
 
3
+ import relativeTime from 'dayjs/plugin/relativeTime';
4
+ import 'dayjs/locale/zh';
5
+ import 'dayjs/locale/en';
6
+
3
7
  export { isDayjs, unix, locale, extend } from 'dayjs';
4
8
  export type { Dayjs, PluginFunc, UnitType, UnitTypeLong, UnitTypeLongPlural, UnitTypeShort, QUnitType, ConfigType, ConfigTypeMap, OpUnitType, OptionType, ManipulateType } from 'dayjs';
5
9
  export default dayjs;
10
+
11
+ dayjs.locale('zh');
12
+ dayjs.extend(relativeTime);
package/libs/echarts.ts CHANGED
@@ -1,4 +1,4 @@
1
- import echarts from 'echarts';
1
+ import * as echarts from 'echarts';
2
2
 
3
3
  export type * from 'echarts/types/dist/echarts';
4
4
 
@@ -0,0 +1,21 @@
1
+ import type { I18nOptions } from 'vue-i18n';
2
+
3
+ export * from 'vue-i18n';
4
+
5
+ export type TDatetimeStyles = Record<
6
+ 'date' | 'time' | 'full' | 'mdhms' | 'mdhm',
7
+ NonNullable<I18nOptions['datetimeFormats']>[string][string]
8
+ >;
9
+
10
+ export const presetDatetimeStyles: TDatetimeStyles = {
11
+ /** 年/月/日 */
12
+ date: { year: 'numeric', month: '2-digit', day: '2-digit' },
13
+ /** 时:分:秒 */
14
+ time: { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false },
15
+ /** 年/月/日 时:分:秒 */
16
+ full: { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false },
17
+ /** 月/日 时:分:秒 */
18
+ mdhms: { month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false },
19
+ /** 月/日 时:分 */
20
+ mdhm: { month: '2-digit', day: '2-digit', hour: 'numeric', minute: 'numeric', hour12: false },
21
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.0-beta.3",
4
+ "version": "0.2.0-beta.30",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -14,16 +14,41 @@
14
14
  },
15
15
  "peerDependencies": {
16
16
  "ant-design-vue": "4.1.2",
17
- "vue": "3.4.19",
18
- "vue-router": "4.2.5"
17
+ "vue": "3.4.21",
18
+ "vue-router": "4.3.0"
19
19
  },
20
20
  "dependencies": {
21
- "@aws-sdk/client-s3": "^3.515.0",
22
- "@aws-sdk/lib-storage": "^3.515.0",
21
+ "@aws-sdk/client-s3": "^3.525.0",
22
+ "@aws-sdk/lib-storage": "^3.525.1",
23
23
  "@babel/generator": "^7.23.6",
24
- "@babel/parser": "^7.23.9",
25
- "@babel/traverse": "^7.23.9",
26
- "@babel/types": "^7.23.9",
24
+ "@babel/parser": "^7.24.0",
25
+ "@babel/traverse": "^7.24.0",
26
+ "@babel/types": "^7.24.0",
27
+ "@ckeditor/ckeditor5-vue": "^5.1.0",
28
+ "@tanstack/vue-query": "^5.25.0",
29
+ "@vueuse/components": "^10.9.0",
30
+ "@vueuse/core": "^10.9.0",
31
+ "@vueuse/router": "^10.9.0",
32
+ "a-calc": "^1.3.11",
33
+ "ant-design-vue": "^4.1.2",
34
+ "archiver": "^6.0.2",
35
+ "axios": "^1.6.7",
36
+ "bignumber.js": "^9.1.2",
37
+ "chokidar": "^3.6.0",
38
+ "dayjs": "^1.11.10",
39
+ "echarts": "^5.4.3",
40
+ "execa": "^8.0.1",
41
+ "fast-glob": "^3.3.2",
42
+ "localstorage-slim": "^2.7.0",
43
+ "lodash-es": "^4.17.21",
44
+ "nprogress": "^0.2.0",
45
+ "pinia": "^2.1.7",
46
+ "tsx": "^4.7.1",
47
+ "vue": "^3.4.21",
48
+ "vue-i18n": "^9.10.1",
49
+ "vue-router": "^4.3.0"
50
+ },
51
+ "devDependencies": {
27
52
  "@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
28
53
  "@ckeditor/ckeditor5-alignment": "^41.1.0",
29
54
  "@ckeditor/ckeditor5-autoformat": "^41.1.0",
@@ -54,38 +79,14 @@
54
79
  "@ckeditor/ckeditor5-theme-lark": "^41.1.0",
55
80
  "@ckeditor/ckeditor5-typing": "^41.1.0",
56
81
  "@ckeditor/ckeditor5-upload": "^41.1.0",
57
- "@ckeditor/ckeditor5-vue": "^5.1.0",
58
82
  "@ckeditor/ckeditor5-word-count": "^41.1.0",
59
- "@tanstack/vue-query": "^5.21.4",
60
- "@vueuse/components": "^10.7.2",
61
- "@vueuse/core": "^10.7.2",
62
- "@vueuse/router": "^10.7.2",
63
- "a-calc": "^1.3.8",
64
- "ant-design-vue": "^4.1.2",
65
- "archiver": "^6.0.1",
66
- "axios": "^1.6.7",
67
- "bignumber.js": "^9.1.2",
68
- "chokidar": "^3.6.0",
69
- "dayjs": "^1.11.10",
70
- "echarts": "^5.4.3",
71
- "execa": "^8.0.1",
72
- "fast-glob": "^3.3.2",
73
- "localstorage-slim": "^2.7.0",
74
- "lodash-es": "^4.17.21",
75
- "nprogress": "^0.2.0",
76
- "pinia": "^2.1.7",
77
- "tsx": "^4.7.1",
78
- "vue": "^3.4.19",
79
- "vue-router": "^4.2.5"
80
- },
81
- "devDependencies": {
82
83
  "@peng_kai/lint": "^0.1.0",
83
84
  "@types/archiver": "^6.0.2",
84
85
  "@types/lodash-es": "^4.17.12",
85
86
  "@types/node": "18.19.15",
86
87
  "@types/nprogress": "^0.2.3",
87
- "type-fest": "^4.10.2",
88
- "typescript": "^5.3.3",
89
- "vue-component-type-helpers": "^1.8.27"
88
+ "type-fest": "^4.11.1",
89
+ "typescript": "^5.4.2",
90
+ "vue-component-type-helpers": "^2.0.6"
90
91
  }
91
92
  }
@@ -1,68 +1,68 @@
1
- import type { AxiosInstance } from 'axios';
2
-
3
- export { isTimeout, getServices, getBaseUrlByEnv, ApiCode, ApiError };
4
-
5
- enum ApiCode {
6
- NORMAL = 0, // 正常
7
- UNKNOWN = -1, // 未知错误
8
- TIMEOUT = -2, // 请求超时
9
- }
10
-
11
- function getServices() {
12
- const serversModule = getServices.modules;
13
- const servers: Record<string, { server: AxiosInstance } | undefined> = {};
14
-
15
- for (const [key, module] of Object.entries(serversModule)) {
16
- const name = key.match(/\/([0-9a-zA-Z]+)\.ts$/)?.[1];
17
-
18
- if (name)
19
- servers[`${name}.api`] = module as any;
20
- }
21
-
22
- return servers;
23
- }
24
- getServices.modules = {} as any;
25
-
26
- function isTimeout(error: any) {
27
- return error?.message?.toLowerCase().includes('timeout');
28
- }
29
-
30
- function getBaseUrlByEnv(service: string, env: Record<string, string>) {
31
- let serviceName = '';
32
-
33
- if (/^https?:\/\//.test(service)) {
34
- const fileName = service.split('/').pop();
35
- serviceName = fileName?.split('.').shift() ?? '';
36
- }
37
- else {
38
- serviceName = service;
39
- }
40
-
41
- if (!serviceName)
42
- return '';
43
-
44
- const [prefix, target] = env[`VITE_HTTP_PREFIX_${serviceName}`]?.split(' => ') ?? ['', ''];
45
-
46
- return (prefix && target) ? prefix : '';
47
- }
48
-
49
- class ApiError<TResp = any> extends Error {
50
- public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
51
- return !!error?.isApiError;
52
- }
53
-
54
- /**
55
- * 将HTTP status和Api code统一到一个code里
56
- */
57
- public code: number;
58
- public msg: string;
59
- public data: TResp;
60
- public isApiError = true;
61
-
62
- public constructor(info: { code: number, msg: string, data: TResp }) {
63
- super(info.msg);
64
- this.code = info.code;
65
- this.msg = info.msg;
66
- this.data = info.data;
67
- }
68
- }
1
+ import type { AxiosInstance } from 'axios';
2
+
3
+ export { isTimeout, getServices, getBaseUrlByEnv, ApiCode, ApiError };
4
+
5
+ enum ApiCode {
6
+ NORMAL = 0, // 正常
7
+ UNKNOWN = -1, // 未知错误
8
+ TIMEOUT = -2, // 请求超时
9
+ }
10
+
11
+ function getServices() {
12
+ const serversModule = getServices.modules;
13
+ const servers: Record<string, { server: AxiosInstance } | undefined> = {};
14
+
15
+ for (const [key, module] of Object.entries(serversModule)) {
16
+ const name = key.match(/\/([0-9a-zA-Z]+)\.ts$/)?.[1];
17
+
18
+ if (name)
19
+ servers[`${name}.api`] = module as any;
20
+ }
21
+
22
+ return servers;
23
+ }
24
+ getServices.modules = {} as any;
25
+
26
+ function isTimeout(error: any) {
27
+ return error?.message?.toLowerCase().includes('timeout');
28
+ }
29
+
30
+ function getBaseUrlByEnv(service: string, env: Record<string, string>) {
31
+ let serviceName = '';
32
+
33
+ if (/^https?:\/\//.test(service)) {
34
+ const fileName = service.split('/').pop();
35
+ serviceName = fileName?.split('.').shift() ?? '';
36
+ }
37
+ else {
38
+ serviceName = service;
39
+ }
40
+
41
+ if (!serviceName)
42
+ return '';
43
+
44
+ const [prefix, target] = env[`VITE_HTTP_PREFIX_${serviceName}`]?.split(' => ') ?? ['', ''];
45
+
46
+ return (prefix && target) ? prefix : '';
47
+ }
48
+
49
+ class ApiError<TResp = any> extends Error {
50
+ public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
51
+ return !!error?.isApiError;
52
+ }
53
+
54
+ /**
55
+ * 将HTTP status和Api code统一到一个code里
56
+ */
57
+ public code: number;
58
+ public msg: string;
59
+ public data: TResp;
60
+ public isApiError = true;
61
+
62
+ public constructor(info: { code: number, msg: string, data: TResp }) {
63
+ super(info.msg);
64
+ this.code = info.code;
65
+ this.msg = info.msg;
66
+ this.data = info.data;
67
+ }
68
+ }
@@ -7,15 +7,15 @@ import { ApiCode, ApiError, isTimeout } from '../helpers';
7
7
  export function returnResultType(): Parameters<AxiosInterceptorManager<any>['use']> {
8
8
  return [
9
9
  (resp) => {
10
- const { resultType } = resp?.config;
10
+ const resultType = resp?.config?.resultType;
11
11
 
12
12
  if (resultType === 'api')
13
- return resp.data;
13
+ return resp?.data;
14
14
 
15
15
  else if (resultType === 'axios')
16
16
  return resp;
17
17
 
18
- return resp.data?.data;
18
+ return resp?.data?.data;
19
19
  },
20
20
  (error) => {
21
21
  let code = error?.response?.data?.code || error?.response?.status || ApiCode.UNKNOWN;
@@ -1,26 +1,43 @@
1
- import type { AxiosInterceptorManager } from 'axios';
2
-
3
- const REDIRECT_KEY = 'redirect';
4
-
5
- export function toLogin(authPath = `${window.location.origin}/auth/login`, code = 15001): Parameters<AxiosInterceptorManager<any>['use']> {
6
- return [
7
- undefined,
8
- (err) => {
9
- if (err.code !== code)
10
- throw err;
11
-
12
- const currentURL = new URL(window.location.href);
13
- const targetURL = new URL(authPath);
14
-
15
- if (currentURL.searchParams.has(REDIRECT_KEY))
16
- targetURL.searchParams.set(REDIRECT_KEY, currentURL.searchParams.get(REDIRECT_KEY)!);
17
- else
18
- targetURL.searchParams.set(REDIRECT_KEY, window.location.href);
19
-
20
- if (currentURL.toString() === targetURL.toString())
21
- return;
22
-
23
- window.location.href = targetURL.toString();
24
- },
25
- ];
26
- }
1
+ import type { AxiosInterceptorManager } from 'axios';
2
+
3
+ const REDIRECT_KEY = 'redirect';
4
+
5
+ interface IParams {
6
+ loginPath?: string
7
+ code?: number
8
+ toLogin?: (targetUrl: URL) => void
9
+ }
10
+
11
+ const defaultParams: Required<IParams> = {
12
+ loginPath: `${window.location.origin}/auth/login`,
13
+ code: 15001,
14
+ toLogin(targetUrl: URL) {
15
+ window.history.replaceState(null, '', targetUrl.toString());
16
+ },
17
+ };
18
+
19
+ export function toLogin(params: IParams = defaultParams): Parameters<AxiosInterceptorManager<any>['use']> {
20
+ const _params = { ...defaultParams, ...params };
21
+
22
+ return [
23
+ undefined,
24
+ (err) => {
25
+ if (err.code !== _params.code)
26
+ throw err;
27
+
28
+ const currentUrl = new URL(window.location.href);
29
+ const targetUrl = new URL(_params.loginPath);
30
+
31
+ if (currentUrl.searchParams.has(REDIRECT_KEY))
32
+ targetUrl.searchParams.set(REDIRECT_KEY, currentUrl.searchParams.get(REDIRECT_KEY)!);
33
+ else
34
+ targetUrl.searchParams.set(REDIRECT_KEY, window.location.href);
35
+
36
+ if (currentUrl.toString() === targetUrl.toString())
37
+ throw err;
38
+
39
+ _params.toLogin(targetUrl);
40
+ throw err;
41
+ },
42
+ ];
43
+ }
@@ -17,9 +17,6 @@ function createRequest<Req, OResp, Resp = Api.TransformPageResult<OResp>>(
17
17
  // 返回 API 数据中的 data 字段值,默认
18
18
  async function request(reqData: Req, config?: ReqConfig): Promise<Api.GetDataField<Resp>>;
19
19
  async function request(reqData: Req, config?: ReqConfig): Promise<any> {
20
- // if (isSSR())
21
- // return null;
22
-
23
20
  const params = paramBuilder(reqData);
24
21
  const serviceName = params.headers?.['Service-Name'] ?? '';
25
22
  const service = createRequest.services[serviceName]?.server;