@qin-ui/element-plus-pro 1.0.7 → 1.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.
- package/AI-CONTEXT.md +227 -23
- package/LICENSE +9 -0
- package/api.json +44 -27
- package/bin/init-ai.mjs +214 -52
- package/es/component-provider/{index-Bmx9Q9Q-.js → index-BGGIWSkO.js} +2 -1
- package/es/component-provider/index-BGGIWSkO.js.map +1 -0
- package/es/component-provider/index.js +2 -1
- package/es/component-provider/index.js.map +1 -0
- package/es/components/component-provider/components/index.vue.d.ts +27 -0
- package/es/components/component-provider/components/index.vue.d.ts.map +1 -0
- package/es/components/component-provider/constants/index.d.ts +16 -0
- package/es/components/component-provider/constants/index.d.ts.map +1 -0
- package/es/components/component-provider/index.d.ts +4 -0
- package/es/components/component-provider/index.d.ts.map +1 -0
- package/es/components/component-provider/types/index.d.ts +35 -0
- package/es/components/component-provider/types/index.d.ts.map +1 -0
- package/es/components/form/components/BaseField/index.vue.d.ts +13 -0
- package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -0
- package/es/components/form/components/BaseField/utils/index.d.ts +3 -0
- package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts +9 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts +23 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts +31 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts.map +1 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts +24 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ProForm/index.vue.d.ts +36 -0
- package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts +7 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -0
- package/es/components/form/components/index.d.ts +12 -0
- package/es/components/form/components/index.d.ts.map +1 -0
- package/es/components/form/constants/index.d.ts +67 -0
- package/es/components/form/constants/index.d.ts.map +1 -0
- package/es/components/form/hooks/index.d.ts +5 -0
- package/es/components/form/hooks/index.d.ts.map +1 -0
- package/es/components/form/hooks/useFields.d.ts +57 -0
- package/es/components/form/hooks/useFields.d.ts.map +1 -0
- package/es/components/form/hooks/useForm.d.ts +93 -0
- package/es/components/form/hooks/useForm.d.ts.map +1 -0
- package/es/components/form/hooks/useFormRef.d.ts +30 -0
- package/es/components/form/hooks/useFormRef.d.ts.map +1 -0
- package/es/components/form/index.d.ts +7 -0
- package/es/components/form/index.d.ts.map +1 -0
- package/es/components/form/types/index.d.ts +234 -0
- package/es/components/form/types/index.d.ts.map +1 -0
- package/es/components/table/components/ColumnControl.vue.d.ts +9 -0
- package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/ProTable.vue.d.ts +47 -0
- package/es/components/table/components/ProTable.vue.d.ts.map +1 -0
- package/es/components/table/components/SearchForm.vue.d.ts +48 -0
- package/es/components/table/components/SearchForm.vue.d.ts.map +1 -0
- package/es/components/table/components/SizeControl.vue.d.ts +12 -0
- package/es/components/table/components/SizeControl.vue.d.ts.map +1 -0
- package/es/components/table/components/TableColumnRenderer.vue.d.ts +17 -0
- package/es/components/table/components/TableColumnRenderer.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/index.d.ts +5 -0
- package/es/components/table/components/index.d.ts.map +1 -0
- package/es/components/table/index.d.ts +33 -0
- package/es/components/table/index.d.ts.map +1 -0
- package/es/components/table/types/index.d.ts +67 -0
- package/es/components/table/types/index.d.ts.map +1 -0
- package/es/components/table/useTable.d.ts +111 -0
- package/es/components/table/useTable.d.ts.map +1 -0
- package/es/element-plus-pro.css +10 -10
- package/es/form/{index-D8btGgqa.js → index-oI6LGSpA.js} +13 -7
- package/es/form/index-oI6LGSpA.js.map +1 -0
- package/es/form/index.js +4 -3
- package/es/form/index.js.map +1 -0
- package/es/index.d.ts +76 -1472
- package/es/index.d.ts.map +1 -0
- package/es/index.js +14 -23
- package/es/index.js.map +1 -0
- package/es/shared/core/index.d.ts +6 -0
- package/es/shared/core/index.d.ts.map +1 -0
- package/es/shared/ui/index.d.ts +12 -0
- package/es/shared/ui/index.d.ts.map +1 -0
- package/es/table/index.js +10 -10
- package/es/table/index.js.map +1 -0
- package/package.json +10 -11
- package/src/components/component-provider/components/index.vue +67 -0
- package/src/components/component-provider/constants/index.ts +209 -0
- package/src/components/component-provider/index.ts +6 -0
- package/src/components/component-provider/types/index.ts +64 -0
- package/src/components/form/components/BaseField/index.vue +181 -0
- package/src/components/form/components/BaseField/utils/index.ts +15 -0
- package/src/components/form/components/BaseFormItem/index.vue +170 -0
- package/src/components/form/components/ContainerFragment/index.vue +24 -0
- package/src/components/form/components/GroupedFieldAttrs/index.vue +115 -0
- package/src/components/form/components/PathProvider/index.vue +19 -0
- package/src/components/form/components/ProForm/index.vue +106 -0
- package/src/components/form/components/SlotComponent/index.vue +26 -0
- package/src/components/form/components/index.ts +15 -0
- package/src/components/form/constants/index.ts +116 -0
- package/src/components/form/hooks/index.ts +5 -0
- package/src/components/form/hooks/useFields.ts +67 -0
- package/src/components/form/hooks/useForm.ts +110 -0
- package/src/components/form/hooks/useFormRef.ts +35 -0
- package/src/components/form/index.ts +29 -0
- package/src/components/form/types/index.ts +300 -0
- package/src/components/table/components/ColumnControl.vue +136 -0
- package/src/components/table/components/DefaultSearchFormContainer.vue +14 -0
- package/src/components/table/components/DefaultTableContainer.vue +14 -0
- package/src/components/table/components/ProTable.vue +420 -0
- package/src/components/table/components/SearchForm.vue +302 -0
- package/src/components/table/components/SizeControl.vue +55 -0
- package/src/components/table/components/TableColumnRenderer.vue +71 -0
- package/src/components/table/components/icons/ColumnHeightOutlined.vue +4 -0
- package/src/components/table/components/icons/DownOutlined.vue +4 -0
- package/src/components/table/components/icons/FilterOutlined.vue +4 -0
- package/src/components/table/components/index.ts +4 -0
- package/src/components/table/index.ts +38 -0
- package/src/components/table/types/index.ts +77 -0
- package/src/components/table/useTable.ts +144 -0
- package/src/index.ts +81 -0
- package/src/shared/core/index.ts +38 -0
- package/src/shared/ui/index.ts +106 -0
- package/es/core/index-C0Pbv44C.js +0 -360
- package/es/vendor/utils/lodash-es-p6jau26B.js +0 -1120
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import {
|
|
3
|
+
Dropdown,
|
|
4
|
+
DropdownMenu,
|
|
5
|
+
DropdownItem,
|
|
6
|
+
Button,
|
|
7
|
+
type TableProps,
|
|
8
|
+
} from '../../../shared/ui';
|
|
9
|
+
import ColumnHeightOutlined from './icons/ColumnHeightOutlined.vue';
|
|
10
|
+
|
|
11
|
+
type Size = TableProps['size'];
|
|
12
|
+
|
|
13
|
+
const size = defineModel<Size>('size');
|
|
14
|
+
|
|
15
|
+
size.value = size.value ?? 'default';
|
|
16
|
+
|
|
17
|
+
const items: Array<{ label: string; key: NonNullable<Size> }> = [
|
|
18
|
+
{ label: '默认', key: 'default' },
|
|
19
|
+
{ label: '中等', key: 'large' },
|
|
20
|
+
{ label: '紧凑', key: 'small' },
|
|
21
|
+
];
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<Dropdown trigger="click" @command="val => (size = val as any)">
|
|
26
|
+
<Button text class="pro-table_size-control_button">
|
|
27
|
+
<ColumnHeightOutlined />
|
|
28
|
+
</Button>
|
|
29
|
+
<template #dropdown>
|
|
30
|
+
<DropdownMenu>
|
|
31
|
+
<DropdownItem
|
|
32
|
+
v-for="item in items"
|
|
33
|
+
:key="item.key"
|
|
34
|
+
:command="item.key"
|
|
35
|
+
:disabled="item.key === size"
|
|
36
|
+
>
|
|
37
|
+
{{ item.label }}
|
|
38
|
+
</DropdownItem>
|
|
39
|
+
</DropdownMenu>
|
|
40
|
+
</template>
|
|
41
|
+
</Dropdown>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<style scoped lang="less">
|
|
45
|
+
.pro-table_size-control_button {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
padding-right: 12px;
|
|
49
|
+
padding-left: 12px;
|
|
50
|
+
|
|
51
|
+
:deep(svg) {
|
|
52
|
+
transform: scale(1.3);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
setup
|
|
4
|
+
generic="D extends Record<string, any> = Record<string, any>"
|
|
5
|
+
>
|
|
6
|
+
import { get, toPath } from '../../../shared/core';
|
|
7
|
+
import { TableColumn } from '../../../shared/ui';
|
|
8
|
+
import type { Column, Columns } from '../types';
|
|
9
|
+
import { computed } from 'vue';
|
|
10
|
+
|
|
11
|
+
defineOptions({ name: 'TableColumnRenderer' });
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
columns: Columns<D>;
|
|
15
|
+
};
|
|
16
|
+
const { columns } = defineProps<Props>();
|
|
17
|
+
|
|
18
|
+
const getColumnKey = (column: Column<D>, index: number) => {
|
|
19
|
+
const key = column.key ?? column.prop;
|
|
20
|
+
if (key === undefined || key === null) return `__idx_${index}`;
|
|
21
|
+
return Array.isArray(key) ? key.join('.') : String(key);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getCellValue = (row: Record<string, any>, column: Column<D>) => {
|
|
25
|
+
const path = column.prop;
|
|
26
|
+
if (!path) return undefined;
|
|
27
|
+
return get(row, toPath(path));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const normalizedColumns = computed(() => {
|
|
31
|
+
return columns.filter(column => !column.hidden);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const getColumnProps = (column: Column<D>) => {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
const { hidden, render, key, ...rest } = column;
|
|
37
|
+
const prop = Array.isArray(column.prop)
|
|
38
|
+
? column.prop.join('.')
|
|
39
|
+
: column.prop
|
|
40
|
+
? String(column.prop)
|
|
41
|
+
: undefined;
|
|
42
|
+
return {
|
|
43
|
+
...rest,
|
|
44
|
+
prop,
|
|
45
|
+
columnKey: key ? String(key) : prop,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<template
|
|
52
|
+
v-for="(column, index) in normalizedColumns"
|
|
53
|
+
:key="getColumnKey(column, index)"
|
|
54
|
+
>
|
|
55
|
+
<TableColumn v-bind="getColumnProps(column)">
|
|
56
|
+
<template #default="scope">
|
|
57
|
+
<template v-if="typeof column.render === 'function'">
|
|
58
|
+
<component
|
|
59
|
+
:is="
|
|
60
|
+
column.render?.({
|
|
61
|
+
...scope,
|
|
62
|
+
column,
|
|
63
|
+
cellValue: getCellValue(scope.row, column),
|
|
64
|
+
})
|
|
65
|
+
"
|
|
66
|
+
/>
|
|
67
|
+
</template>
|
|
68
|
+
</template>
|
|
69
|
+
</TableColumn>
|
|
70
|
+
</template>
|
|
71
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<svg focusable="false" data-icon="column-height" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M840 836H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm0-724H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zM610.8 378c6 0 9.4-7 5.7-11.7L515.7 238.7a7.14 7.14 0 00-11.3 0L403.6 366.3a7.23 7.23 0 005.7 11.7H476v268h-62.8c-6 0-9.4 7-5.7 11.7l100.8 127.5c2.9 3.7 8.5 3.7 11.3 0l100.8-127.5c3.7-4.7.4-11.7-5.7-11.7H548V378h62.8z"></path></svg>
|
|
4
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<svg focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg>
|
|
4
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- prettier-ignore -->
|
|
3
|
+
<svg focusable="false" data-icon="filter" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M880.1 154H143.9c-24.5 0-39.8 26.7-27.5 48L349 597.4V838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3 31.8-32V597.4L907.7 202c12.2-21.3-3.1-48-27.6-48zM603.4 798H420.6V642h182.9v156zm9.6-236.6l-9.5 16.6h-183l-9.5-16.6L212.7 226h598.6L613 561.4z"></path></svg>
|
|
4
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as DefaultSearchFormContainer } from './DefaultSearchFormContainer.vue';
|
|
2
|
+
export { default as DefaultTableContainer } from './DefaultTableContainer.vue';
|
|
3
|
+
export { default as SizeControl } from './SizeControl.vue';
|
|
4
|
+
export { default as ColumnControl } from './ColumnControl.vue';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ComponentPublicInstance } from 'vue';
|
|
2
|
+
import type { PaginationProps, TableProps } from '../../shared/ui';
|
|
3
|
+
import type { ContainerComponent } from '../form/types';
|
|
4
|
+
import type { Columns } from './types';
|
|
5
|
+
import type { SearchFormProps } from './components/SearchForm.vue';
|
|
6
|
+
import type { Table } from './useTable';
|
|
7
|
+
import ProTable from './components/ProTable.vue';
|
|
8
|
+
|
|
9
|
+
type Control = { sizeControl: boolean; columnControl: boolean };
|
|
10
|
+
type SearchFormConfig = Omit<SearchFormProps, 'form'> & {
|
|
11
|
+
hidden?: boolean;
|
|
12
|
+
container?: ContainerComponent | false;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type ReturnTableRecord<V> = V extends Table<any, infer R> ? R : any;
|
|
16
|
+
|
|
17
|
+
// instance
|
|
18
|
+
export type ProTableProps<T extends Table<any> = Table> = {
|
|
19
|
+
table?: T;
|
|
20
|
+
search?: () => Promise<unknown>;
|
|
21
|
+
addIndexColumn?: boolean;
|
|
22
|
+
immediateSearch?: boolean;
|
|
23
|
+
control?: boolean | Partial<Control>;
|
|
24
|
+
searchFormConfig?: SearchFormConfig;
|
|
25
|
+
tableContainer?: ContainerComponent | false;
|
|
26
|
+
columns?: Columns<ReturnTableRecord<T>>;
|
|
27
|
+
data?: ReturnTableRecord<T>[];
|
|
28
|
+
pagination?: false | Partial<PaginationProps>;
|
|
29
|
+
} & Omit<TableProps, 'data'>;
|
|
30
|
+
export type ProTableInstance = ComponentPublicInstance;
|
|
31
|
+
|
|
32
|
+
// types
|
|
33
|
+
export { type Column, type Columns } from './types';
|
|
34
|
+
|
|
35
|
+
// hooks
|
|
36
|
+
export { useTable, type Table } from './useTable';
|
|
37
|
+
|
|
38
|
+
export default ProTable;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ColumnType } from '../../../shared/ui';
|
|
2
|
+
import {
|
|
3
|
+
Data,
|
|
4
|
+
ExtendWithAny,
|
|
5
|
+
KeyExpandString,
|
|
6
|
+
Paths,
|
|
7
|
+
Path,
|
|
8
|
+
} from '../../../shared/core';
|
|
9
|
+
|
|
10
|
+
type BivariantRender<D extends Data = Data> = {
|
|
11
|
+
bivarianceHack(scope: ColumnScope<D>): any;
|
|
12
|
+
}['bivarianceHack'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Element Plus 表格列作用域
|
|
16
|
+
* @template D - 表格行数据类型
|
|
17
|
+
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type ColumnScope<D extends Data = Data> = {
|
|
21
|
+
/** 当前行数据 */
|
|
22
|
+
row: ExtendWithAny<D>;
|
|
23
|
+
/** 当前列配置 */
|
|
24
|
+
column: Column<D>;
|
|
25
|
+
/** 行索引 */
|
|
26
|
+
$index: number;
|
|
27
|
+
/** 单元格值 */
|
|
28
|
+
cellValue: any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @qin-ui/element-plus-pro 表格列配置类型
|
|
33
|
+
*
|
|
34
|
+
* @description 基于 Element Plus 的 ColumnType 列类型,并添加:
|
|
35
|
+
* - prop 作为主要字段(Element Plus 使用 prop 而非 dataIndex)
|
|
36
|
+
* - key 作为辅助标识
|
|
37
|
+
* - hidden 属性
|
|
38
|
+
* - render 自定义渲染函数
|
|
39
|
+
*
|
|
40
|
+
* @template D - 表格行数据类型
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* interface User { name: string; age: number }
|
|
45
|
+
*
|
|
46
|
+
* const columns: Columns<User> = [
|
|
47
|
+
* { prop: 'name', label: '姓名', width: 120 },
|
|
48
|
+
* { prop: 'age', label: '年龄', width: 80 },
|
|
49
|
+
* ]
|
|
50
|
+
* ```
|
|
51
|
+
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export type Column<D extends Data = Data> = Partial<
|
|
55
|
+
Omit<ColumnType<any>, 'prop' | 'property' | 'children' | 'render'>
|
|
56
|
+
> & {
|
|
57
|
+
/** 列字段标识(辅助字段) */
|
|
58
|
+
key?: Path<D>;
|
|
59
|
+
/**
|
|
60
|
+
* @description 列数据路径(主要字段)
|
|
61
|
+
* Element Plus 使用 prop 而非 dataIndex
|
|
62
|
+
* @example 'name' | 'address.city'
|
|
63
|
+
*/
|
|
64
|
+
prop?: KeyExpandString<Extract<keyof D, string>> | Paths<D>;
|
|
65
|
+
/** 是否隐藏该列 */
|
|
66
|
+
hidden?: boolean;
|
|
67
|
+
/** 自定义渲染函数 */
|
|
68
|
+
render?: BivariantRender<D>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @qin-ui/element-plus-pro 表格列配置数组类型
|
|
73
|
+
* @template D - 表格行数据类型
|
|
74
|
+
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export type Columns<D extends Data = Data> = Array<Column<D>>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTable as coreUseTable,
|
|
3
|
+
type Table as _Table,
|
|
4
|
+
} from '../../shared/core';
|
|
5
|
+
import type {
|
|
6
|
+
Data,
|
|
7
|
+
ExtendWithAny,
|
|
8
|
+
DeepPartial,
|
|
9
|
+
PageParam,
|
|
10
|
+
} from '../../shared/core';
|
|
11
|
+
import { Fields } from '../form/types';
|
|
12
|
+
import type { Column, Columns } from './types';
|
|
13
|
+
import type { Ref } from 'vue';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 表格实例类型
|
|
17
|
+
*
|
|
18
|
+
* @description 在 core Table 类型的基础上,将列类型 C 绑定为本地 Column<T>,
|
|
19
|
+
* 并将 dataSource 重命名为 data(Element Plus 使用 data 而非 dataSource),
|
|
20
|
+
* 使 columns 操作获得 Element Plus 表格列的完整属性类型提示。
|
|
21
|
+
*
|
|
22
|
+
* @template D - 搜索表单数据类型
|
|
23
|
+
* @template T - 表格行数据类型(一行数据的类型)
|
|
24
|
+
*
|
|
25
|
+
* @property columns - 列配置数组(响应式 Ref),用于渲染表格列
|
|
26
|
+
* @property data - 表格数据源(响应式 Ref),对应 Element Plus Table 的 data 属性
|
|
27
|
+
* @property pageParam - 分页参数(响应式 reactive),包含 current、pageSize、total
|
|
28
|
+
* @property searchForm - 搜索表单实例(Form 类型),用于管理搜索区域的字段和数据
|
|
29
|
+
* @property setColumn - 更新列配置,支持合并/覆盖两种模式,用法同 setField
|
|
30
|
+
* @property deleteColumn - 删除列,支持路径或查找函数
|
|
31
|
+
* @property appendColumn - 在指定列后追加新列,传 undefined 在末尾追加
|
|
32
|
+
* @property prependColumn - 在指定列前插入新列,传 undefined 在开头插入
|
|
33
|
+
* @property setPageParam - 设置分页参数,支持部分更新和函数式更新
|
|
34
|
+
* @property resetQueryParams - 重置分页到第一页并恢复搜索条件到初始值
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* interface SearchParams { keyword: string }
|
|
39
|
+
* interface User { name: string; age: number }
|
|
40
|
+
*
|
|
41
|
+
* const table: Table<SearchParams, User> = useTable({
|
|
42
|
+
* columns: [{ prop: 'name', title: '姓名' }],
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* table.columns.value // 访问列配置
|
|
46
|
+
* table.setColumn('name', { width: 150 }) // 更新列
|
|
47
|
+
* table.setPageParam({ current: 2 }) // 切换页码
|
|
48
|
+
* table.searchForm.setFormData('keyword', '搜索词') // 操作搜索表单
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export type Table<
|
|
54
|
+
D extends Data = Data,
|
|
55
|
+
T extends Data = ExtendWithAny<D>,
|
|
56
|
+
> = Omit<_Table<D, T, Column<T>>, 'dataSource'> & {
|
|
57
|
+
/**
|
|
58
|
+
* Element Plus 数据源(与 core 的 dataSource 对应)
|
|
59
|
+
*/
|
|
60
|
+
data: Ref<T[]>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type UseTableParams<
|
|
64
|
+
D extends Data = Data,
|
|
65
|
+
T extends Data = ExtendWithAny<D>,
|
|
66
|
+
> = {
|
|
67
|
+
/** 列配置数组 */
|
|
68
|
+
columns?: Columns<T>;
|
|
69
|
+
/** 数据源数组(Element Plus 使用 data 而非 dataSource) */
|
|
70
|
+
data?: T[];
|
|
71
|
+
/** 初始分页参数 */
|
|
72
|
+
pageParam?: PageParam;
|
|
73
|
+
/** 初始搜索参数 */
|
|
74
|
+
searchParam?: ExtendWithAny<DeepPartial<D>>;
|
|
75
|
+
/** 搜索表单字段配置 */
|
|
76
|
+
searchFields?: Fields<D>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 创建表格实例的 Hook
|
|
81
|
+
*
|
|
82
|
+
* @description 基于 `@qin-ui/pro-components-core` 的 `useTable` 封装,适配 Element Plus 的 API 风格:
|
|
83
|
+
* - 数据源使用 `data` 而非 `dataSource`
|
|
84
|
+
*
|
|
85
|
+
* 是 ProTable 组件的核心 Hook,提供了:
|
|
86
|
+
* - 列配置管理(增删改查)
|
|
87
|
+
* - 数据源管理
|
|
88
|
+
* - 分页管理
|
|
89
|
+
* - 搜索表单集成(内部使用 useForm)
|
|
90
|
+
* - 查询参数重置
|
|
91
|
+
*
|
|
92
|
+
* @template D - 搜索表单数据类型
|
|
93
|
+
* @template T - 表格行数据类型
|
|
94
|
+
*
|
|
95
|
+
* @param {object} params - 表格配置参数
|
|
96
|
+
* @param {Columns<T>} [params.columns] - 初始列配置数组
|
|
97
|
+
* @param {T[]} [params.data] - 初始数据源(Element Plus 风格)
|
|
98
|
+
* @param {PageParam} [params.pageParam] - 初始分页参数,默认 `{ current: 1, pageSize: 10, total: 0 }`
|
|
99
|
+
* @param {ExtendWithAny<DeepPartial<D>>} [params.searchParam] - 初始搜索参数
|
|
100
|
+
* @param {Fields<D>} [params.searchFields] - 搜索表单字段配置
|
|
101
|
+
*
|
|
102
|
+
* @returns {Table<D, T>} 表格实例
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* interface SearchParams { keyword: string }
|
|
107
|
+
* interface User { name: string; age: number; email: string }
|
|
108
|
+
*
|
|
109
|
+
* const table = useTable<SearchParams, User>({
|
|
110
|
+
* columns: [
|
|
111
|
+
* { prop: 'name', title: '姓名', width: 120 },
|
|
112
|
+
* { prop: 'age', title: '年龄', width: 80 },
|
|
113
|
+
* ],
|
|
114
|
+
* data: [],
|
|
115
|
+
* pageParam: { current: 1, pageSize: 20, total: 0 },
|
|
116
|
+
* searchParam: { keyword: '' },
|
|
117
|
+
* searchFields: [
|
|
118
|
+
* { path: 'keyword', label: '关键词', component: 'input' },
|
|
119
|
+
* ],
|
|
120
|
+
* })
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @see {@link coreUseTable} 底层核心实现(来自 @qin-ui/pro-components-core)
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export function useTable<
|
|
128
|
+
D extends Data = Data,
|
|
129
|
+
T extends Data = ExtendWithAny<D>,
|
|
130
|
+
>(params: UseTableParams<D, T> = {}): Table<D, T> {
|
|
131
|
+
const { data, ...rest } = params;
|
|
132
|
+
const coreTable = (coreUseTable as any)({
|
|
133
|
+
...rest,
|
|
134
|
+
dataSource: data,
|
|
135
|
+
}) as _Table<D, T, Column<T>>;
|
|
136
|
+
|
|
137
|
+
const { dataSource, ...tableWithoutDataSource } = coreTable as any;
|
|
138
|
+
const table = {
|
|
139
|
+
...tableWithoutDataSource,
|
|
140
|
+
data: dataSource as Ref<T[]>,
|
|
141
|
+
} as Table<D, T>;
|
|
142
|
+
|
|
143
|
+
return table;
|
|
144
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import ProForm from './components/form';
|
|
3
|
+
import ProTable from './components/table';
|
|
4
|
+
import ProComponentProvider from './components/component-provider';
|
|
5
|
+
|
|
6
|
+
export * from './components/form';
|
|
7
|
+
export * from './components/table';
|
|
8
|
+
export * from './components/component-provider';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Schema 驱动的表单组件,基于 element-plus Form 封装
|
|
12
|
+
*
|
|
13
|
+
* @description 通过声明式 JSON Schema 配置即可快速生成表单,
|
|
14
|
+
* 提供极致的 TypeScript 类型推导与组件库插槽扩展能力。
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```vue
|
|
18
|
+
* <script setup lang="ts">
|
|
19
|
+
* import { ProForm, useForm } from '@qin-ui/element-plus-pro'
|
|
20
|
+
* const form = useForm<User>({ name: '' }, [
|
|
21
|
+
* { path: 'name', label: '姓名', component: 'input' }
|
|
22
|
+
* ])
|
|
23
|
+
* </script>
|
|
24
|
+
* <template>
|
|
25
|
+
* <ProForm :form="form" />
|
|
26
|
+
* </template>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Schema 驱动的表格组件,基于 element-plus Table 封装
|
|
30
|
+
*
|
|
31
|
+
* @description 通过声明式列配置即可生成功能完整的表格,
|
|
32
|
+
* 支持列动态控制、搜索表单集成、分页管理等企业级能力。
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```vue
|
|
36
|
+
* <script setup lang="ts">
|
|
37
|
+
* import { ProTable, useTable } from '@qin-ui/element-plus-pro'
|
|
38
|
+
* const table = useTable<User>({ columns: [{ key: 'name', title: '姓名' }] })
|
|
39
|
+
* </script>
|
|
40
|
+
* <template>
|
|
41
|
+
* <ProTable :table="table" />
|
|
42
|
+
* </template>
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* 组件提供者,用于全局配置 ProForm 和 ProTable 的默认行为
|
|
46
|
+
*
|
|
47
|
+
* @description 通过 `ProComponentProvider` 包裹应用根组件,
|
|
48
|
+
* 可以全局覆盖组件的默认属性(如表单布局、表格尺寸等)。
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```vue
|
|
52
|
+
* <template>
|
|
53
|
+
* <ProComponentProvider :component-props="customProps">
|
|
54
|
+
* <App />
|
|
55
|
+
* </ProComponentProvider>
|
|
56
|
+
* </template>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export { ProForm, ProTable, ProComponentProvider };
|
|
60
|
+
|
|
61
|
+
export default {
|
|
62
|
+
/**
|
|
63
|
+
* @qin-ui/element-plus-pro 安装方法
|
|
64
|
+
* @description 全局注册所有组件(ProForm、ProTable、ProComponentProvider)
|
|
65
|
+
*
|
|
66
|
+
* @param {App} app - Vue 应用实例
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { createApp } from 'vue'
|
|
71
|
+
* import ProComponents from '@qin-ui/element-plus-pro'
|
|
72
|
+
* const app = createApp(App)
|
|
73
|
+
* app.use(ProComponents)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
install(app: App) {
|
|
77
|
+
app.component(ProForm.name, ProForm);
|
|
78
|
+
app.component(ProTable.name, ProTable);
|
|
79
|
+
app.component(ProComponentProvider.name!, ProComponentProvider);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 re-export @qin-ui/pro-components-core,包内所有文件通过此文件引入 core 内容,
|
|
3
|
+
* 避免直接散列依赖 @qin-ui/pro-components-core,便于将来统一维护。
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
// hooks
|
|
7
|
+
useForm,
|
|
8
|
+
useTable,
|
|
9
|
+
useFields,
|
|
10
|
+
useFormData,
|
|
11
|
+
useFormRef,
|
|
12
|
+
// injection keys
|
|
13
|
+
InjectionFormKey,
|
|
14
|
+
InjectionPathKey,
|
|
15
|
+
// utils
|
|
16
|
+
get,
|
|
17
|
+
getObject,
|
|
18
|
+
toPath,
|
|
19
|
+
camelizeProperties,
|
|
20
|
+
cloneDeep,
|
|
21
|
+
omit,
|
|
22
|
+
pick,
|
|
23
|
+
isPlainObject,
|
|
24
|
+
// types
|
|
25
|
+
type Data,
|
|
26
|
+
type Path,
|
|
27
|
+
type Paths,
|
|
28
|
+
type KeyExpandString,
|
|
29
|
+
type ExtendWithAny,
|
|
30
|
+
type DeepPartial,
|
|
31
|
+
type PageParam,
|
|
32
|
+
type Fields,
|
|
33
|
+
type Form,
|
|
34
|
+
type Table,
|
|
35
|
+
type UseFieldsReturn,
|
|
36
|
+
type UseFormDataReturn,
|
|
37
|
+
type UseFormRefReturn,
|
|
38
|
+
} from '@qin-ui/pro-components-core';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ElForm as Form,
|
|
3
|
+
ElFormItem as FormItem,
|
|
4
|
+
ElRow as Grid,
|
|
5
|
+
ElCol as GridItem,
|
|
6
|
+
ElTable as Table,
|
|
7
|
+
ElTableColumn as TableColumn,
|
|
8
|
+
ElSpace as Space,
|
|
9
|
+
ElDropdown as Dropdown,
|
|
10
|
+
ElDropdownMenu as DropdownMenu,
|
|
11
|
+
ElDropdownItem as DropdownItem,
|
|
12
|
+
ElCheckbox as Checkbox,
|
|
13
|
+
ElCheckboxGroup as CheckboxGroup,
|
|
14
|
+
ElButton as Button,
|
|
15
|
+
ElAutocomplete as AutoComplete,
|
|
16
|
+
ElCascader as Cascader,
|
|
17
|
+
ElDatePicker as DatePicker,
|
|
18
|
+
ElInput as Input,
|
|
19
|
+
ElInputNumber as InputNumber,
|
|
20
|
+
ElSelect as Select,
|
|
21
|
+
ElSlider as Slider,
|
|
22
|
+
ElSwitch as Switch,
|
|
23
|
+
ElTransfer as Transfer,
|
|
24
|
+
ElTreeSelect as TreeSelect,
|
|
25
|
+
ElRadioGroup as RadioGroup,
|
|
26
|
+
ElTimePicker as TimePicker,
|
|
27
|
+
ElTimeSelect as TimeSelect,
|
|
28
|
+
ElPagination as Pagination,
|
|
29
|
+
useFormDisabled,
|
|
30
|
+
type FormItemInstance,
|
|
31
|
+
type FormInstance,
|
|
32
|
+
type FormProps,
|
|
33
|
+
type FormItemProps,
|
|
34
|
+
type TableProps as _TableProps,
|
|
35
|
+
type TableColumnCtx as ColumnType,
|
|
36
|
+
type PaginationProps,
|
|
37
|
+
type RowProps as GridProps,
|
|
38
|
+
type ColProps as GridItemProps,
|
|
39
|
+
} from 'element-plus';
|
|
40
|
+
import { type MaybeRefOrGetter, computed, inject, provide, toValue } from 'vue';
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
Form,
|
|
44
|
+
FormItem,
|
|
45
|
+
Grid,
|
|
46
|
+
GridItem,
|
|
47
|
+
Table,
|
|
48
|
+
TableColumn,
|
|
49
|
+
Space,
|
|
50
|
+
Dropdown,
|
|
51
|
+
DropdownMenu,
|
|
52
|
+
DropdownItem,
|
|
53
|
+
Checkbox,
|
|
54
|
+
CheckboxGroup,
|
|
55
|
+
Button,
|
|
56
|
+
AutoComplete,
|
|
57
|
+
Cascader,
|
|
58
|
+
DatePicker,
|
|
59
|
+
Input,
|
|
60
|
+
InputNumber,
|
|
61
|
+
Select,
|
|
62
|
+
Slider,
|
|
63
|
+
Switch,
|
|
64
|
+
Transfer,
|
|
65
|
+
TreeSelect,
|
|
66
|
+
RadioGroup,
|
|
67
|
+
TimePicker,
|
|
68
|
+
TimeSelect,
|
|
69
|
+
Pagination,
|
|
70
|
+
type FormItemInstance,
|
|
71
|
+
type FormInstance,
|
|
72
|
+
type FormProps,
|
|
73
|
+
type FormItemProps,
|
|
74
|
+
type PaginationProps,
|
|
75
|
+
type GridProps,
|
|
76
|
+
type GridItemProps,
|
|
77
|
+
type ColumnType,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type TableProps = _TableProps<any>;
|
|
81
|
+
|
|
82
|
+
export const tableProps = () => (Table as any).props || {};
|
|
83
|
+
export const paginationProps = () => (Pagination as any).props || {};
|
|
84
|
+
export const gridItemProps = () => (GridItem as any).props || {};
|
|
85
|
+
export const formItemProps = () => (FormItem as any).props || {};
|
|
86
|
+
|
|
87
|
+
const DisabledContextKey = Symbol('pro-form-disabled-context');
|
|
88
|
+
|
|
89
|
+
export const useDisabledContext = () => {
|
|
90
|
+
const formDisabled = useFormDisabled();
|
|
91
|
+
return inject(
|
|
92
|
+
DisabledContextKey,
|
|
93
|
+
computed(() => !!formDisabled.value)
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const useDisabledContextProvider = (
|
|
98
|
+
disabled: MaybeRefOrGetter<boolean | undefined>
|
|
99
|
+
) => {
|
|
100
|
+
provide(
|
|
101
|
+
DisabledContextKey,
|
|
102
|
+
computed(() => !!toValue(disabled))
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type NamePath = string | number | (string | number)[];
|