@peng_kai/kit 0.1.5 → 0.1.7
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/components/filter/src/FilterDrawer.vue +153 -153
- package/admin/components/filter/src/FilterParam.vue +78 -76
- 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 -117
- package/admin/components/text/src/Datetime.vue +48 -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/hooks/useMenu.ts +128 -128
- package/admin/hooks/usePage.ts +141 -141
- package/admin/hooks/usePageTab.ts +35 -35
- package/admin/layout/large/Breadcrumb.vue +69 -69
- package/admin/layout/large/Content.vue +24 -24
- package/admin/layout/large/Menu.vue +69 -69
- package/admin/layout/large/PageTab.vue +71 -71
- package/admin/permission/index.ts +4 -4
- package/admin/permission/routerGuard.ts +43 -43
- package/admin/permission/usePermission.ts +52 -52
- package/admin/permission/vuePlugin.ts +30 -30
- package/admin/route-guards/index.ts +3 -3
- package/admin/route-guards/pageProgress.ts +27 -27
- package/admin/route-guards/pageTitle.ts +19 -19
- package/admin/styles/globalCover.scss +54 -54
- package/antd/components/InputNumberRange.vue +53 -53
- package/antd/directives/formLabelAlign.ts +36 -36
- package/antd/hooks/useAntdDrawer.ts +73 -73
- package/antd/hooks/useAntdTable.ts +82 -82
- package/package.json +55 -55
- package/request/helpers.ts +49 -49
- package/request/interceptors/toLogin.ts +15 -15
- package/request/type.d.ts +92 -92
- package/stylelint.config.cjs +7 -7
- package/tsconfig.json +50 -50
- package/vue/components/infinite-query/index.ts +1 -1
- package/vue/components/infinite-query/src/InfiniteQuery.vue +205 -205
- package/vue/components/infinite-query/src/useCreateTrigger.ts +39 -39
- package/pnpm-lock.yaml +0 -5255
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { computed, reactive } 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
|
-
|
|
7
|
-
export function useAntdTable<
|
|
8
|
-
UQRR extends UseQueryReturnType<any, any>,
|
|
9
|
-
QP extends Partial<{ page?: string | number, page_size?: string | number }>,
|
|
10
|
-
>(uqrt: UQRR, queryParams: QP = ({} as any)) {
|
|
11
|
-
type RecordType = GetRecordType<UQRR>;
|
|
12
|
-
type LocalTableProps = TableProps<RecordType>;
|
|
13
|
-
type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
|
|
14
|
-
type LocalTableRowSelection = NonNullable<LocalTableProps['rowSelection']>;
|
|
15
|
-
|
|
16
|
-
const { data, isFetching, isLoading } = uqrt;
|
|
17
|
-
|
|
18
|
-
const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
|
|
19
|
-
const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current;
|
|
20
|
-
Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 });
|
|
21
|
-
};
|
|
22
|
-
const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
|
|
23
|
-
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
|
|
24
|
-
const rowSelection = reactive(rowSelectionGetter());
|
|
25
|
-
|
|
26
|
-
rowSelection.selectedRowKeys ??= [];
|
|
27
|
-
rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
|
|
28
|
-
|
|
29
|
-
return rowSelection;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const tableProps = computed<LocalTableProps>(() => {
|
|
33
|
-
const { list, pagination } = data.value ?? {};
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
dataSource: list,
|
|
37
|
-
pagination: {
|
|
38
|
-
disabled: isFetching.value,
|
|
39
|
-
current: Number(queryParams.page ?? 1),
|
|
40
|
-
pageSize: Number(queryParams.page_size ?? 10),
|
|
41
|
-
total: pagination?.total ?? 0,
|
|
42
|
-
showTotal: total => `共 ${total} 条`,
|
|
43
|
-
},
|
|
44
|
-
loading: isLoading.value,
|
|
45
|
-
scroll: { x: 'max-content' },
|
|
46
|
-
sticky: true,
|
|
47
|
-
onChange: onPaginationChange as any,
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
51
|
-
get(_, p) {
|
|
52
|
-
return p;
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
const bodyCellType = {} as {
|
|
56
|
-
index: number
|
|
57
|
-
text: any
|
|
58
|
-
value: any
|
|
59
|
-
record: RecordType
|
|
60
|
-
column: ColumnType<RecordType>
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
/** ATable 的预设 Props */
|
|
65
|
-
tableProps,
|
|
66
|
-
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
67
|
-
dataIndexs,
|
|
68
|
-
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
69
|
-
bodyCellType,
|
|
70
|
-
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
71
|
-
defineColumns,
|
|
72
|
-
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
73
|
-
defineRowSelection,
|
|
74
|
-
onPaginationChange,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
79
|
-
? D extends Api.PageData
|
|
80
|
-
? NonNullable<D['list']>[0]
|
|
81
|
-
: never
|
|
82
|
-
: never;
|
|
1
|
+
import { computed, reactive } 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
|
+
|
|
7
|
+
export function useAntdTable<
|
|
8
|
+
UQRR extends UseQueryReturnType<any, any>,
|
|
9
|
+
QP extends Partial<{ page?: string | number, page_size?: string | number }>,
|
|
10
|
+
>(uqrt: UQRR, queryParams: QP = ({} as any)) {
|
|
11
|
+
type RecordType = GetRecordType<UQRR>;
|
|
12
|
+
type LocalTableProps = TableProps<RecordType>;
|
|
13
|
+
type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
|
|
14
|
+
type LocalTableRowSelection = NonNullable<LocalTableProps['rowSelection']>;
|
|
15
|
+
|
|
16
|
+
const { data, isFetching, isLoading } = uqrt;
|
|
17
|
+
|
|
18
|
+
const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
|
|
19
|
+
const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current;
|
|
20
|
+
Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 });
|
|
21
|
+
};
|
|
22
|
+
const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
|
|
23
|
+
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
|
|
24
|
+
const rowSelection = reactive(rowSelectionGetter());
|
|
25
|
+
|
|
26
|
+
rowSelection.selectedRowKeys ??= [];
|
|
27
|
+
rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
|
|
28
|
+
|
|
29
|
+
return rowSelection;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const tableProps = computed<LocalTableProps>(() => {
|
|
33
|
+
const { list, pagination } = data.value ?? {};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
dataSource: list,
|
|
37
|
+
pagination: {
|
|
38
|
+
disabled: isFetching.value,
|
|
39
|
+
current: Number(queryParams.page ?? 1),
|
|
40
|
+
pageSize: Number(queryParams.page_size ?? 10),
|
|
41
|
+
total: pagination?.total ?? 0,
|
|
42
|
+
showTotal: total => `共 ${total} 条`,
|
|
43
|
+
},
|
|
44
|
+
loading: isLoading.value,
|
|
45
|
+
scroll: { x: 'max-content' },
|
|
46
|
+
sticky: true,
|
|
47
|
+
onChange: onPaginationChange as any,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
51
|
+
get(_, p) {
|
|
52
|
+
return p;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const bodyCellType = {} as {
|
|
56
|
+
index: number
|
|
57
|
+
text: any
|
|
58
|
+
value: any
|
|
59
|
+
record: RecordType
|
|
60
|
+
column: ColumnType<RecordType>
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
/** ATable 的预设 Props */
|
|
65
|
+
tableProps,
|
|
66
|
+
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
67
|
+
dataIndexs,
|
|
68
|
+
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
69
|
+
bodyCellType,
|
|
70
|
+
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
71
|
+
defineColumns,
|
|
72
|
+
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
73
|
+
defineRowSelection,
|
|
74
|
+
onPaginationChange,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
79
|
+
? D extends Api.PageData
|
|
80
|
+
? NonNullable<D['list']>[0]
|
|
81
|
+
: never
|
|
82
|
+
: never;
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
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
|
-
"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"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@babel/generator": "^7.23.5",
|
|
27
|
-
"@babel/parser": "^7.23.5",
|
|
28
|
-
"@babel/traverse": "^7.23.5",
|
|
29
|
-
"@babel/types": "^7.23.5",
|
|
30
|
-
"@tanstack/vue-query": "^4.37.1",
|
|
31
|
-
"@vueuse/core": "^10.6.1",
|
|
32
|
-
"a-calc": "^1.3.8",
|
|
33
|
-
"ant-design-vue": "^4.0.7",
|
|
34
|
-
"axios": "^1.6.2",
|
|
35
|
-
"bignumber.js": "^9.1.2",
|
|
36
|
-
"chokidar": "^3.5.3",
|
|
37
|
-
"dayjs": "^1.11.10",
|
|
38
|
-
"fast-glob": "^3.3.2",
|
|
39
|
-
"lodash-es": "^4.17.21",
|
|
40
|
-
"nprogress": "^0.2.0",
|
|
41
|
-
"vue": "^3.3.8",
|
|
42
|
-
"vue-router": "^4.2.5"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@antfu/eslint-config": "^1.2.1",
|
|
46
|
-
"@peng_kai/lint": "^0.1.0",
|
|
47
|
-
"@types/lodash-es": "^4.17.11",
|
|
48
|
-
"@types/node": "18",
|
|
49
|
-
"@types/nprogress": "^0.2.3",
|
|
50
|
-
"@unocss/eslint-plugin": "^0.57.7",
|
|
51
|
-
"type-fest": "^4.8.1",
|
|
52
|
-
"typescript": "^5.2.2",
|
|
53
|
-
"vue-component-type-helpers": "^1.8.22"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@peng_kai/kit",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.7",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"scripts": {
|
|
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"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@babel/generator": "^7.23.5",
|
|
27
|
+
"@babel/parser": "^7.23.5",
|
|
28
|
+
"@babel/traverse": "^7.23.5",
|
|
29
|
+
"@babel/types": "^7.23.5",
|
|
30
|
+
"@tanstack/vue-query": "^4.37.1",
|
|
31
|
+
"@vueuse/core": "^10.6.1",
|
|
32
|
+
"a-calc": "^1.3.8",
|
|
33
|
+
"ant-design-vue": "^4.0.7",
|
|
34
|
+
"axios": "^1.6.2",
|
|
35
|
+
"bignumber.js": "^9.1.2",
|
|
36
|
+
"chokidar": "^3.5.3",
|
|
37
|
+
"dayjs": "^1.11.10",
|
|
38
|
+
"fast-glob": "^3.3.2",
|
|
39
|
+
"lodash-es": "^4.17.21",
|
|
40
|
+
"nprogress": "^0.2.0",
|
|
41
|
+
"vue": "^3.3.8",
|
|
42
|
+
"vue-router": "^4.2.5"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@antfu/eslint-config": "^1.2.1",
|
|
46
|
+
"@peng_kai/lint": "^0.1.0",
|
|
47
|
+
"@types/lodash-es": "^4.17.11",
|
|
48
|
+
"@types/node": "18",
|
|
49
|
+
"@types/nprogress": "^0.2.3",
|
|
50
|
+
"@unocss/eslint-plugin": "^0.57.7",
|
|
51
|
+
"type-fest": "^4.8.1",
|
|
52
|
+
"typescript": "^5.2.2",
|
|
53
|
+
"vue-component-type-helpers": "^1.8.22"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/request/helpers.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
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
|
-
class ApiError<TResp = any> extends Error {
|
|
31
|
-
public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
|
|
32
|
-
return !!error?.isApiError;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 将HTTP status和Api code统一到一个code里
|
|
37
|
-
*/
|
|
38
|
-
public code: number;
|
|
39
|
-
public msg: string;
|
|
40
|
-
public data: TResp;
|
|
41
|
-
public isApiError = true;
|
|
42
|
-
|
|
43
|
-
public constructor(info: { code: number, msg: string, data: TResp }) {
|
|
44
|
-
super(info.msg);
|
|
45
|
-
this.code = info.code;
|
|
46
|
-
this.msg = info.msg;
|
|
47
|
-
this.data = info.data;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
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
|
+
class ApiError<TResp = any> extends Error {
|
|
31
|
+
public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
|
|
32
|
+
return !!error?.isApiError;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 将HTTP status和Api code统一到一个code里
|
|
37
|
+
*/
|
|
38
|
+
public code: number;
|
|
39
|
+
public msg: string;
|
|
40
|
+
public data: TResp;
|
|
41
|
+
public isApiError = true;
|
|
42
|
+
|
|
43
|
+
public constructor(info: { code: number, msg: string, data: TResp }) {
|
|
44
|
+
super(info.msg);
|
|
45
|
+
this.code = info.code;
|
|
46
|
+
this.msg = info.msg;
|
|
47
|
+
this.data = info.data;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { AxiosInterceptorManager } from 'axios';
|
|
2
|
-
|
|
3
|
-
export function toLogin(authPath = `${window.location.origin}/auth/login`, code = 15001): Parameters<AxiosInterceptorManager<any>['use']> {
|
|
4
|
-
return [
|
|
5
|
-
undefined,
|
|
6
|
-
(err) => {
|
|
7
|
-
if (err.code !== code)
|
|
8
|
-
throw err;
|
|
9
|
-
|
|
10
|
-
const url = new URL(authPath);
|
|
11
|
-
url.searchParams.set('redirect', window.location.href);
|
|
12
|
-
window.location.href = url.toString();
|
|
13
|
-
},
|
|
14
|
-
];
|
|
15
|
-
}
|
|
1
|
+
import type { AxiosInterceptorManager } from 'axios';
|
|
2
|
+
|
|
3
|
+
export function toLogin(authPath = `${window.location.origin}/auth/login`, code = 15001): Parameters<AxiosInterceptorManager<any>['use']> {
|
|
4
|
+
return [
|
|
5
|
+
undefined,
|
|
6
|
+
(err) => {
|
|
7
|
+
if (err.code !== code)
|
|
8
|
+
throw err;
|
|
9
|
+
|
|
10
|
+
const url = new URL(authPath);
|
|
11
|
+
url.searchParams.set('redirect', window.location.href);
|
|
12
|
+
window.location.href = url.toString();
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
}
|
package/request/type.d.ts
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
declare namespace Api {
|
|
2
|
-
type Request = ((reqData: any, options?: Options) => Promise<any>) & {
|
|
3
|
-
id: string
|
|
4
|
-
setDefaultConfig: (config: Partial<import('axios').AxiosRequestConfig>) => Request
|
|
5
|
-
};
|
|
6
|
-
// type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
|
|
7
|
-
interface PageParam {
|
|
8
|
-
page: number
|
|
9
|
-
page_size: number
|
|
10
|
-
}
|
|
11
|
-
interface PageInfo {
|
|
12
|
-
has_more: boolean
|
|
13
|
-
page: number
|
|
14
|
-
page_size: number
|
|
15
|
-
total: number
|
|
16
|
-
}
|
|
17
|
-
interface PageData<T = any> {
|
|
18
|
-
list: T[] | null
|
|
19
|
-
pagination: PaginationInfo
|
|
20
|
-
[k in string]: any
|
|
21
|
-
}
|
|
22
|
-
interface Result<T = any | PageData<any>> {
|
|
23
|
-
code: number
|
|
24
|
-
msg: string
|
|
25
|
-
data: T
|
|
26
|
-
}
|
|
27
|
-
type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any;
|
|
28
|
-
type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any;
|
|
29
|
-
type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
|
|
30
|
-
? NonNullable<L> extends Array<infer I>
|
|
31
|
-
? I
|
|
32
|
-
: any
|
|
33
|
-
: any;
|
|
34
|
-
type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any, pagination: any } ? D : D) : any;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
|
|
38
|
-
*
|
|
39
|
-
* ```
|
|
40
|
-
* {
|
|
41
|
-
* code: number,
|
|
42
|
-
* msg: string,
|
|
43
|
-
* data: {
|
|
44
|
-
* list: [],
|
|
45
|
-
* pagination: {},
|
|
46
|
-
* ...
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
type TransformPageResult<R> = R extends { pagination: infer P, data: infer D }
|
|
52
|
-
? D extends Record<string, any>
|
|
53
|
-
? D extends { list: any }
|
|
54
|
-
? {
|
|
55
|
-
[Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
|
|
56
|
-
} & {
|
|
57
|
-
data: D & { pagination: P }
|
|
58
|
-
}
|
|
59
|
-
: {
|
|
60
|
-
[Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
|
|
61
|
-
} & {
|
|
62
|
-
data: {
|
|
63
|
-
list: D
|
|
64
|
-
pagination: P
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
: R
|
|
68
|
-
: R;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 测试用例 ----------------------------
|
|
72
|
-
// type DDD1 = Api.TransformPageResult<{
|
|
73
|
-
// code: number
|
|
74
|
-
// msg: string
|
|
75
|
-
// data: {
|
|
76
|
-
// name: string
|
|
77
|
-
// }[]
|
|
78
|
-
// pagination: {
|
|
79
|
-
// page: number
|
|
80
|
-
// }
|
|
81
|
-
// }>
|
|
82
|
-
// type DDD2 = Api.TransformPageResult<{
|
|
83
|
-
// code: number
|
|
84
|
-
// msg: string
|
|
85
|
-
// data: {
|
|
86
|
-
// list: { name: string }[]
|
|
87
|
-
// total: {}
|
|
88
|
-
// }
|
|
89
|
-
// pagination: {
|
|
90
|
-
// page: number
|
|
91
|
-
// }
|
|
92
|
-
// }>
|
|
1
|
+
declare namespace Api {
|
|
2
|
+
type Request = ((reqData: any, options?: Options) => Promise<any>) & {
|
|
3
|
+
id: string
|
|
4
|
+
setDefaultConfig: (config: Partial<import('axios').AxiosRequestConfig>) => Request
|
|
5
|
+
};
|
|
6
|
+
// type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
|
|
7
|
+
interface PageParam {
|
|
8
|
+
page: number
|
|
9
|
+
page_size: number
|
|
10
|
+
}
|
|
11
|
+
interface PageInfo {
|
|
12
|
+
has_more: boolean
|
|
13
|
+
page: number
|
|
14
|
+
page_size: number
|
|
15
|
+
total: number
|
|
16
|
+
}
|
|
17
|
+
interface PageData<T = any> {
|
|
18
|
+
list: T[] | null
|
|
19
|
+
pagination: PaginationInfo
|
|
20
|
+
[k in string]: any
|
|
21
|
+
}
|
|
22
|
+
interface Result<T = any | PageData<any>> {
|
|
23
|
+
code: number
|
|
24
|
+
msg: string
|
|
25
|
+
data: T
|
|
26
|
+
}
|
|
27
|
+
type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any;
|
|
28
|
+
type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any;
|
|
29
|
+
type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
|
|
30
|
+
? NonNullable<L> extends Array<infer I>
|
|
31
|
+
? I
|
|
32
|
+
: any
|
|
33
|
+
: any;
|
|
34
|
+
type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any, pagination: any } ? D : D) : any;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* {
|
|
41
|
+
* code: number,
|
|
42
|
+
* msg: string,
|
|
43
|
+
* data: {
|
|
44
|
+
* list: [],
|
|
45
|
+
* pagination: {},
|
|
46
|
+
* ...
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
type TransformPageResult<R> = R extends { pagination: infer P, data: infer D }
|
|
52
|
+
? D extends Record<string, any>
|
|
53
|
+
? D extends { list: any }
|
|
54
|
+
? {
|
|
55
|
+
[Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
|
|
56
|
+
} & {
|
|
57
|
+
data: D & { pagination: P }
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
[Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
|
|
61
|
+
} & {
|
|
62
|
+
data: {
|
|
63
|
+
list: D
|
|
64
|
+
pagination: P
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
: R
|
|
68
|
+
: R;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 测试用例 ----------------------------
|
|
72
|
+
// type DDD1 = Api.TransformPageResult<{
|
|
73
|
+
// code: number
|
|
74
|
+
// msg: string
|
|
75
|
+
// data: {
|
|
76
|
+
// name: string
|
|
77
|
+
// }[]
|
|
78
|
+
// pagination: {
|
|
79
|
+
// page: number
|
|
80
|
+
// }
|
|
81
|
+
// }>
|
|
82
|
+
// type DDD2 = Api.TransformPageResult<{
|
|
83
|
+
// code: number
|
|
84
|
+
// msg: string
|
|
85
|
+
// data: {
|
|
86
|
+
// list: { name: string }[]
|
|
87
|
+
// total: {}
|
|
88
|
+
// }
|
|
89
|
+
// pagination: {
|
|
90
|
+
// page: number
|
|
91
|
+
// }
|
|
92
|
+
// }>
|
package/stylelint.config.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
// root: true,
|
|
3
|
-
extends: ['@peng_kai/lint/vue/stylelint_v2'],
|
|
4
|
-
rules: {
|
|
5
|
-
'custom-property-pattern': '(antd-([a-z][a-zA-Z0-9]+)*)|(([a-z][a-z0-9]*)(-[a-z0-9]+)*)',
|
|
6
|
-
},
|
|
7
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
// root: true,
|
|
3
|
+
extends: ['@peng_kai/lint/vue/stylelint_v2'],
|
|
4
|
+
rules: {
|
|
5
|
+
'custom-property-pattern': '(antd-([a-z][a-zA-Z0-9]+)*)|(([a-z][a-z0-9]*)(-[a-z0-9]+)*)',
|
|
6
|
+
},
|
|
7
|
+
};
|