@peng_kai/kit 0.1.17 → 0.2.0-beta.1
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/admin/adminPlugin.ts +47 -0
- package/admin/components/filter/src/FilterDrawer.vue +153 -153
- package/admin/components/filter/src/FilterParam.vue +76 -78
- package/admin/components/filter/src/FilterReset.vue +2 -2
- package/admin/components/filter/src/useFilterParams.ts +75 -25
- package/admin/components/filter/src/useFilterQuery.ts +32 -16
- package/admin/components/rich-text/index.ts +2 -0
- package/admin/components/rich-text/src/RichText.vue +342 -0
- package/admin/components/rich-text/src/imageUploader.ts +34 -0
- package/admin/components/rich-text/src/type.d.ts +7 -0
- 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 +121 -121
- package/admin/components/text/src/Datetime.vue +47 -48
- package/admin/components/text/src/Duration.vue +26 -26
- package/admin/components/text/src/Hash.vue +51 -51
- package/admin/components/text/src/createTagGetter.ts +13 -13
- package/admin/components/upload/index.ts +2 -0
- package/admin/components/upload/src/PictureCardUpload.vue +143 -0
- package/admin/components/upload/src/customRequests.ts +31 -0
- package/admin/defines/index.ts +1 -1
- package/admin/defines/route/helpers.ts +0 -1
- package/admin/defines/startup/defineStartup.ts +8 -1
- package/admin/defines/startup/index.ts +1 -1
- package/admin/defines/startup/{getStartups.ts → runStartup.ts} +16 -7
- package/admin/layout/large/Breadcrumb.vue +68 -69
- package/admin/layout/large/Content.vue +23 -24
- package/admin/layout/large/Menu.vue +68 -69
- package/admin/layout/large/PageTab.vue +70 -71
- package/admin/permission/index.ts +2 -4
- package/admin/permission/routerGuard.ts +41 -43
- package/admin/permission/vuePlugin.ts +46 -30
- package/admin/route-guards/collapseMenu.ts +3 -3
- package/admin/route-guards/index.ts +3 -3
- package/admin/route-guards/pageProgress.ts +27 -27
- package/admin/route-guards/pageTitle.ts +18 -19
- package/admin/{hooks/useMenu.ts → stores/createUseMenuStore.ts} +133 -128
- package/admin/{hooks/usePage.ts → stores/createUsePageStore.ts} +145 -141
- package/admin/stores/createUsePageTabStore.ts +43 -0
- package/admin/{permission/usePermission.ts → stores/createUsePermissionStore.ts} +57 -52
- package/admin/stores/index.ts +8 -0
- package/admin/styles/classCover.scss +8 -0
- package/admin/styles/globalCover.scss +54 -54
- package/antd/components/InputNumberRange.vue +59 -59
- package/antd/directives/formLabelAlign.ts +36 -36
- package/antd/hooks/useAntdDrawer.ts +73 -73
- package/antd/hooks/useAntdForm.helpers.ts +92 -8
- package/antd/hooks/useAntdForm.ts +55 -63
- package/antd/hooks/useAntdTable.ts +127 -115
- package/antd/index.ts +1 -1
- package/libs/a-calc.ts +1 -0
- package/libs/axios.ts +2 -0
- package/libs/bignumber.ts +2 -0
- package/libs/dayjs.ts +5 -0
- package/libs/echarts.ts +5 -0
- package/libs/localstorage-slim.ts +2 -0
- package/libs/lodash-es.ts +1 -0
- package/libs/pinia.ts +1 -0
- package/libs/vue-query.ts +1 -0
- package/libs/vueuse.ts +3 -0
- package/package.json +91 -58
- package/request/helpers.ts +68 -49
- package/request/interceptors/toLogin.ts +26 -26
- package/request/queryClient.ts +34 -21
- package/request/type.d.ts +92 -92
- package/stylelint.config.cjs +7 -7
- package/tsconfig.json +50 -50
- package/utils/upload/AwsS3.ts +68 -0
- package/utils/upload/fileHandlers.ts +27 -0
- package/utils/upload/index.ts +2 -0
- package/vite/index.d.ts +1 -0
- package/vite/index.mjs +27 -0
- package/vue/components/echarts/index.ts +1 -0
- package/vue/components/echarts/src/ECharts.vue +48 -0
- package/vue/components/index.ts +1 -0
- package/vue/components/infinite-query/index.ts +1 -1
- package/vue/components/infinite-query/src/InfiniteQuery.vue +199 -205
- package/vue/components/infinite-query/src/useCreateTrigger.ts +39 -39
- package/vue/components/test/KitTest.vue +9 -0
- package/vue/components/test/testStore.ts +11 -0
- package/admin/hooks/index.ts +0 -5
- package/admin/hooks/usePageTab.ts +0 -35
- package/kitDependencies.ts +0 -43
|
@@ -1,115 +1,127 @@
|
|
|
1
|
-
import { computed, reactive, ref } from 'vue';
|
|
2
|
-
import { pick } from 'lodash-es';
|
|
3
|
-
import type { UseQueryReturnType } from '@tanstack/vue-query';
|
|
4
|
-
import type { Table, TableProps } from 'ant-design-vue';
|
|
5
|
-
import type { ColumnType, FilterValue } from 'ant-design-vue/es/table/interface';
|
|
6
|
-
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
7
|
-
|
|
8
|
-
interface ISorter {
|
|
9
|
-
field?: string
|
|
10
|
-
order?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
1
|
+
import { computed, reactive, ref } from 'vue';
|
|
2
|
+
import { pick } from 'lodash-es';
|
|
3
|
+
import type { UseQueryReturnType } from '@tanstack/vue-query';
|
|
4
|
+
import type { Table, TableProps } from 'ant-design-vue';
|
|
5
|
+
import type { ColumnType, FilterValue } from 'ant-design-vue/es/table/interface';
|
|
6
|
+
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
7
|
+
|
|
8
|
+
interface ISorter {
|
|
9
|
+
field?: string
|
|
10
|
+
order?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultPageSizeOptions = ['10', '20', '50', '100'];
|
|
14
|
+
|
|
15
|
+
export function useAntdTable<
|
|
16
|
+
UQRR extends UseQueryReturnType<any, any>,
|
|
17
|
+
QP extends Partial<{ page?: string | number, page_size?: string | number }>,
|
|
18
|
+
>(uqrt: UQRR, queryParams: QP = ({} as any)) {
|
|
19
|
+
type RecordType = GetRecordType<UQRR>;
|
|
20
|
+
type LocalTableProps = TableProps<RecordType>;
|
|
21
|
+
type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
|
|
22
|
+
type LocalTableRowSelection = NonNullable<LocalTableProps['rowSelection']>;
|
|
23
|
+
|
|
24
|
+
const { data, isFetching, isLoading } = uqrt;
|
|
25
|
+
const filters = ref<Record<string, FilterValue>>();
|
|
26
|
+
const sorter = ref<ISorter>();
|
|
27
|
+
const sorters = ref<ISorter[]>();
|
|
28
|
+
|
|
29
|
+
/* pageSizeOptions 初始化 */
|
|
30
|
+
const pageSizeOptions = [...defaultPageSizeOptions];
|
|
31
|
+
const initPageSize = String(queryParams?.page_size ?? '10');
|
|
32
|
+
|
|
33
|
+
if (!pageSizeOptions.includes(initPageSize)) {
|
|
34
|
+
pageSizeOptions.push(initPageSize);
|
|
35
|
+
pageSizeOptions.sort((p, n) => Number(p) - Number(n));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const onChange: ComponentProps<typeof Table>['onChange'] = (_pagination, _filters, _sorter, extra) => {
|
|
39
|
+
if (extra.action === 'paginate') {
|
|
40
|
+
const page = queryParams.page_size !== _pagination.pageSize ? 1 : _pagination.current;
|
|
41
|
+
Object.assign(queryParams, { page, page_size: _pagination.pageSize ?? 10 });
|
|
42
|
+
}
|
|
43
|
+
else if (extra.action === 'filter') {
|
|
44
|
+
filters.value = _filters;
|
|
45
|
+
}
|
|
46
|
+
else if (extra.action === 'sort') {
|
|
47
|
+
if (Array.isArray(_sorter)) {
|
|
48
|
+
sorter.value = pick(_sorter[0], ['field', 'order']) as any;
|
|
49
|
+
sorters.value = _sorter.map(item => pick(item, ['field', 'order'])) as any;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
sorter.value = pick(_sorter, ['field', 'order']) as any;
|
|
53
|
+
sorters.value = [{ ...sorter.value }];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
|
|
58
|
+
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
|
|
59
|
+
const rowSelection = reactive(rowSelectionGetter());
|
|
60
|
+
|
|
61
|
+
rowSelection.selectedRowKeys ??= [];
|
|
62
|
+
rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
|
|
63
|
+
|
|
64
|
+
return rowSelection;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const tableProps = computed<LocalTableProps>(() => {
|
|
68
|
+
const { list, pagination } = data.value ?? {};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
dataSource: list,
|
|
72
|
+
pagination: {
|
|
73
|
+
disabled: isFetching.value,
|
|
74
|
+
current: Number(queryParams.page ?? 1),
|
|
75
|
+
pageSize: Number(queryParams.page_size ?? 10),
|
|
76
|
+
total: pagination?.total ?? 0,
|
|
77
|
+
showSizeChanger: true,
|
|
78
|
+
showQuickJumper: true,
|
|
79
|
+
pageSizeOptions,
|
|
80
|
+
showTotal: total => `共 ${total} 条`,
|
|
81
|
+
},
|
|
82
|
+
loading: isLoading.value,
|
|
83
|
+
scroll: { x: 'max-content' },
|
|
84
|
+
sticky: true,
|
|
85
|
+
onChange: onChange as any,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
89
|
+
get(_, p) {
|
|
90
|
+
return p;
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const bodyCellType = {} as {
|
|
94
|
+
index: number
|
|
95
|
+
text: any
|
|
96
|
+
value: any
|
|
97
|
+
record: RecordType
|
|
98
|
+
column: ColumnType<RecordType>
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
/** ATable 的预设 Props */
|
|
103
|
+
tableProps,
|
|
104
|
+
/* 过滤的字段 */
|
|
105
|
+
filters,
|
|
106
|
+
/* 排序的字段 */
|
|
107
|
+
sorter,
|
|
108
|
+
/* 多维排序的字段 */
|
|
109
|
+
sorters,
|
|
110
|
+
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
111
|
+
dataIndexs,
|
|
112
|
+
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
113
|
+
bodyCellType,
|
|
114
|
+
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
115
|
+
defineColumns,
|
|
116
|
+
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
117
|
+
defineRowSelection,
|
|
118
|
+
/** 内置的 ATable onChange 事件,默认在 `tableProps` 中 */
|
|
119
|
+
onChange,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
124
|
+
? D extends Api.PageData
|
|
125
|
+
? NonNullable<D['list']>[0]
|
|
126
|
+
: never
|
|
127
|
+
: never;
|
package/antd/index.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { useAntdForm } from './hooks/useAntdForm';
|
|
|
5
5
|
export { useAntdTheme } from './hooks/useAntdTheme';
|
|
6
6
|
export { createAntdModal } from './hooks/createAntdModal';
|
|
7
7
|
export { default as InputNumberRange } from './components/InputNumberRange.vue';
|
|
8
|
-
export type {
|
|
8
|
+
export type { SchemaConfig, ItemSchema } from './hooks/useAntdForm.ts';
|
package/libs/a-calc.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'a-calc';
|
package/libs/axios.ts
ADDED
package/libs/dayjs.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
export { isDayjs, unix, locale, extend } from 'dayjs';
|
|
4
|
+
export type { Dayjs, PluginFunc, UnitType, UnitTypeLong, UnitTypeLongPlural, UnitTypeShort, QUnitType, ConfigType, ConfigTypeMap, OpUnitType, OptionType, ManipulateType } from 'dayjs';
|
|
5
|
+
export default dayjs;
|
package/libs/echarts.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'lodash-es';
|
package/libs/pinia.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'pinia';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/vue-query';
|
package/libs/vueuse.ts
ADDED
package/package.json
CHANGED
|
@@ -1,58 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@peng_kai/kit",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
5
|
-
"description": "",
|
|
6
|
-
"author": "",
|
|
7
|
-
"license": "ISC",
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"main": "index.js",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"dev:js": "tsx ./admin/scripts/deploy.ts",
|
|
12
|
-
"lint": "eslint .",
|
|
13
|
-
"lint:fix": "eslint . --fix"
|
|
14
|
-
},
|
|
15
|
-
"peerDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@peng_kai/kit",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.0-beta.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev:js": "tsx ./admin/scripts/deploy.ts",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"ant-design-vue": "4.1.2",
|
|
17
|
+
"vue": "3.4.19",
|
|
18
|
+
"vue-router": "4.2.5"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aws-sdk/client-s3": "^3.515.0",
|
|
22
|
+
"@aws-sdk/lib-storage": "^3.515.0",
|
|
23
|
+
"@babel/generator": "^7.23.6",
|
|
24
|
+
"@babel/parser": "^7.23.9",
|
|
25
|
+
"@babel/traverse": "^7.23.9",
|
|
26
|
+
"@babel/types": "^7.23.9",
|
|
27
|
+
"@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
|
|
28
|
+
"@ckeditor/ckeditor5-alignment": "^41.1.0",
|
|
29
|
+
"@ckeditor/ckeditor5-autoformat": "^41.1.0",
|
|
30
|
+
"@ckeditor/ckeditor5-basic-styles": "^41.1.0",
|
|
31
|
+
"@ckeditor/ckeditor5-block-quote": "^41.1.0",
|
|
32
|
+
"@ckeditor/ckeditor5-build-classic": "^41.1.0",
|
|
33
|
+
"@ckeditor/ckeditor5-code-block": "^41.1.0",
|
|
34
|
+
"@ckeditor/ckeditor5-document-outline": "^41.1.0",
|
|
35
|
+
"@ckeditor/ckeditor5-editor-classic": "^41.1.0",
|
|
36
|
+
"@ckeditor/ckeditor5-essentials": "^41.1.0",
|
|
37
|
+
"@ckeditor/ckeditor5-font": "^41.1.0",
|
|
38
|
+
"@ckeditor/ckeditor5-heading": "^41.1.0",
|
|
39
|
+
"@ckeditor/ckeditor5-highlight": "^41.1.0",
|
|
40
|
+
"@ckeditor/ckeditor5-horizontal-line": "^41.1.0",
|
|
41
|
+
"@ckeditor/ckeditor5-html-embed": "^41.1.0",
|
|
42
|
+
"@ckeditor/ckeditor5-html-support": "^41.1.0",
|
|
43
|
+
"@ckeditor/ckeditor5-image": "^41.1.0",
|
|
44
|
+
"@ckeditor/ckeditor5-import-word": "^41.1.0",
|
|
45
|
+
"@ckeditor/ckeditor5-indent": "^41.1.0",
|
|
46
|
+
"@ckeditor/ckeditor5-link": "^41.1.0",
|
|
47
|
+
"@ckeditor/ckeditor5-list": "^41.1.0",
|
|
48
|
+
"@ckeditor/ckeditor5-media-embed": "^41.1.0",
|
|
49
|
+
"@ckeditor/ckeditor5-paragraph": "^41.1.0",
|
|
50
|
+
"@ckeditor/ckeditor5-remove-format": "^41.1.0",
|
|
51
|
+
"@ckeditor/ckeditor5-show-blocks": "^41.1.0",
|
|
52
|
+
"@ckeditor/ckeditor5-source-editing": "^41.1.0",
|
|
53
|
+
"@ckeditor/ckeditor5-table": "^41.1.0",
|
|
54
|
+
"@ckeditor/ckeditor5-theme-lark": "^41.1.0",
|
|
55
|
+
"@ckeditor/ckeditor5-typing": "^41.1.0",
|
|
56
|
+
"@ckeditor/ckeditor5-upload": "^41.1.0",
|
|
57
|
+
"@ckeditor/ckeditor5-vue": "^5.1.0",
|
|
58
|
+
"@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
|
+
"@peng_kai/lint": "^0.1.0",
|
|
83
|
+
"@types/archiver": "^6.0.2",
|
|
84
|
+
"@types/lodash-es": "^4.17.12",
|
|
85
|
+
"@types/node": "18.19.15",
|
|
86
|
+
"@types/nprogress": "^0.2.3",
|
|
87
|
+
"type-fest": "^4.10.2",
|
|
88
|
+
"typescript": "^5.3.3",
|
|
89
|
+
"vue-component-type-helpers": "^1.8.27"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/request/helpers.ts
CHANGED
|
@@ -1,49 +1,68 @@
|
|
|
1
|
-
import type { AxiosInstance } from 'axios';
|
|
2
|
-
|
|
3
|
-
export { isTimeout, getServices, 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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,26 +1,26 @@
|
|
|
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
|
+
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
|
+
}
|