@aspire-ui/element-component-pro 1.0.1 → 1.0.3
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/README.md +141 -7
- package/dist/ProForm/ApiSelect.vue.d.ts +67 -0
- package/dist/ProForm/ProForm.vue.d.ts +5 -1
- package/dist/ProForm/ProFormItem.vue.d.ts +4 -0
- package/dist/ProForm/TreeSelect.vue.d.ts +64 -0
- package/dist/ProTable/ProTable.vue.d.ts +421 -0
- package/dist/ProTable/TableAction.vue.d.ts +43 -0
- package/dist/ProTable/index.d.ts +8 -0
- package/dist/ProTable/types/index.d.ts +252 -0
- package/dist/ProTable/useProTable.d.ts +14 -0
- package/dist/element-component-pro.es.js +959 -302
- package/dist/element-component-pro.es.js.map +1 -1
- package/dist/element-component-pro.umd.js +2 -2
- package/dist/element-component-pro.umd.js.map +1 -1
- package/dist/index.d.ts +1369 -25
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +13 -51
- package/dist/useComponentSetting.d.ts +12 -0
- package/package.json +7 -5
- package/src/ProForm/ApiSelect.vue +85 -0
- package/src/ProForm/ProForm.vue +13 -3
- package/src/ProForm/ProFormItem.vue +53 -1
- package/src/ProForm/TreeSelect.vue +272 -0
- package/src/ProForm/useForm.ts +0 -1
- package/src/ProTable/ProTable.vue +773 -0
- package/src/ProTable/TableAction.vue +193 -0
- package/src/ProTable/index.ts +20 -0
- package/src/ProTable/types/index.ts +236 -0
- package/src/ProTable/useProTable.ts +79 -0
- package/src/index.ts +13 -10
- package/src/types/index.ts +26 -46
- package/src/useComponentSetting.ts +35 -0
package/README.md
CHANGED
|
@@ -54,12 +54,10 @@ import { ProTable, ProForm } from 'element-component-pro'
|
|
|
54
54
|
```vue
|
|
55
55
|
<template>
|
|
56
56
|
<ProTable
|
|
57
|
-
ref="tableRef"
|
|
58
57
|
:columns="columns"
|
|
59
|
-
:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
show-pagination
|
|
58
|
+
:api="fetchTableData"
|
|
59
|
+
row-key="id"
|
|
60
|
+
:pagination="{ pageSize: 10 }"
|
|
63
61
|
/>
|
|
64
62
|
</template>
|
|
65
63
|
|
|
@@ -81,11 +79,145 @@ const columns: ProColumn[] = [
|
|
|
81
79
|
|
|
82
80
|
const fetchTableData = async (params) => {
|
|
83
81
|
const res = await api.getList(params)
|
|
84
|
-
|
|
82
|
+
// ProTable 约定返回 { list, total },与 VbenAdmin 一致
|
|
83
|
+
return { list: res.list, total: res.total }
|
|
85
84
|
}
|
|
86
85
|
</script>
|
|
87
86
|
```
|
|
88
87
|
|
|
88
|
+
### ProTable + useProTable(tableAction)
|
|
89
|
+
|
|
90
|
+
参考 VbenAdmin 的 `useTable`,ProTable 提供 `useProTable` Hook,对外暴露 `tableAction` 方法。**可选传入 props**:`useProTable(props)` 支持传入 `ProTableProps` 或 `Ref<ProTableProps>`,会在表格 `@register` 时通过 `setProps` 应用,且 props 为响应式时变更会自动同步到表格(类型 `UseProTablePropsReactive`)。
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<ProTable
|
|
95
|
+
@register="registerTable"
|
|
96
|
+
title="用户列表"
|
|
97
|
+
:columns="columns"
|
|
98
|
+
:api="fetchTableData"
|
|
99
|
+
row-key="id"
|
|
100
|
+
:row-selection="{ type: 'checkbox' }"
|
|
101
|
+
/>
|
|
102
|
+
</template>
|
|
103
|
+
|
|
104
|
+
<script setup lang="ts">
|
|
105
|
+
import { ProTable, useProTable } from 'element-component-pro'
|
|
106
|
+
import type { ProColumn, TableActionType } from 'element-component-pro'
|
|
107
|
+
|
|
108
|
+
const columns: ProColumn[] = [
|
|
109
|
+
{ title: 'ID', dataIndex: 'id', width: 80 },
|
|
110
|
+
{ title: '姓名', dataIndex: 'name', width: 120 },
|
|
111
|
+
{ title: '年龄', dataIndex: 'age', width: 80 },
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
const [registerTable, tableAction] = useProTable()
|
|
115
|
+
|
|
116
|
+
const reload = () => {
|
|
117
|
+
// 支持传入 page / pageSize / searchInfo,与 VbenAdmin 对齐
|
|
118
|
+
tableAction.reload({ page: 1 })
|
|
119
|
+
}
|
|
120
|
+
</script>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**TableActionType 常用方法(与 VbenAdmin BasicTable 对齐):**
|
|
124
|
+
|
|
125
|
+
| 方法 | 说明 |
|
|
126
|
+
|------|------|
|
|
127
|
+
| `setProps` | 动态更新 ProTable Props,例如列配置、分页配置等 |
|
|
128
|
+
| `reload(opt?: FetchParams)` | 重新请求数据,支持指定页码、每页条数、搜索参数 |
|
|
129
|
+
| `setLoading(loading: boolean)` | 手动切换表格 loading 状态 |
|
|
130
|
+
| `getDataSource()` / `setTableData(data)` | 获取 / 设置当前表格数据 |
|
|
131
|
+
| `getRawDataSource()` | 获取接口原始返回数据(未经过 afterFetch) |
|
|
132
|
+
| `getColumns()` / `setColumns(cols)` | 获取 / 设置列配置,支持传 `ProColumn[]` 或列 key 数组 |
|
|
133
|
+
| `setPagination(info)` | 设置分页信息(page、pageSize、total) |
|
|
134
|
+
| `getSelectRowKeys()` / `getSelectRows()` | 获取当前选中行的 keys / 行数据 |
|
|
135
|
+
| `getRowSelection()` | 获取当前行选择配置(rowSelection) |
|
|
136
|
+
| `setSelectedRowKeys(keys)` / `clearSelectedRowKeys()` | 设置 / 清空选中行 |
|
|
137
|
+
| `deleteSelectRowByKey(key)` | 取消勾选指定 key 的行 |
|
|
138
|
+
| `updateTableDataRecord(rowKey, record)` | 按 rowKey 更新某一行(局部刷新,不重新请求接口) |
|
|
139
|
+
| `deleteTableDataRecord(rowKey)` | 按 rowKey 删除行(支持单个或数组) |
|
|
140
|
+
| `insertTableDataRecord(record, index?)` | 在指定位置插入一行数据 |
|
|
141
|
+
| `getPaginationRef()` | 获取当前分页信息 `{ page, pageSize, total }` |
|
|
142
|
+
| `getShowPagination()` / `setShowPagination(show)` | 获取 / 设置是否显示分页 |
|
|
143
|
+
| `expandAll()` / `collapseAll()` | 展开 / 折叠树形表格所有行 |
|
|
144
|
+
|
|
145
|
+
### ProTable 操作列 + TableAction 组件
|
|
146
|
+
|
|
147
|
+
参考 VbenAdmin 的 `TableAction`,ProTable 提供了独立的 `TableAction` 组件,用于快速渲染「编辑 / 删除 / 更多」等操作按钮。
|
|
148
|
+
|
|
149
|
+
```vue
|
|
150
|
+
<template>
|
|
151
|
+
<ProTable
|
|
152
|
+
title="操作列示例"
|
|
153
|
+
:columns="columns"
|
|
154
|
+
:data-source="data"
|
|
155
|
+
:action-column="{ title: 'Action', dataIndex: 'action', width: 220, fixed: 'right' }"
|
|
156
|
+
>
|
|
157
|
+
<template #bodyCell="{ column, record }">
|
|
158
|
+
<!-- 只处理 action 列,其它列仍按默认方式渲染(与 Vben bodyCell 行为一致) -->
|
|
159
|
+
<template v-if="column.dataIndex === 'action'">
|
|
160
|
+
<TableAction
|
|
161
|
+
:actions="[
|
|
162
|
+
{
|
|
163
|
+
label: '编辑',
|
|
164
|
+
onClick: () => handleEdit(record),
|
|
165
|
+
},
|
|
166
|
+
]"
|
|
167
|
+
:drop-down-actions="[
|
|
168
|
+
{
|
|
169
|
+
label: '删除',
|
|
170
|
+
color: 'error',
|
|
171
|
+
popConfirm: {
|
|
172
|
+
title: '确认删除该行?',
|
|
173
|
+
confirm: () => handleDelete(record),
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
]"
|
|
177
|
+
/>
|
|
178
|
+
</template>
|
|
179
|
+
</template>
|
|
180
|
+
</ProTable>
|
|
181
|
+
</template>
|
|
182
|
+
|
|
183
|
+
<script setup lang="ts">
|
|
184
|
+
import { ProTable, TableAction } from 'element-component-pro'
|
|
185
|
+
import type { ProColumn } from 'element-component-pro'
|
|
186
|
+
|
|
187
|
+
const columns: ProColumn[] = [
|
|
188
|
+
{ title: '姓名', dataIndex: 'name', width: 120 },
|
|
189
|
+
{ title: '年龄', dataIndex: 'age', width: 80 },
|
|
190
|
+
{ title: '地址', dataIndex: 'address', minWidth: 200 },
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
const data = [
|
|
194
|
+
{ id: 1, name: '张三', age: 28, address: '北京市朝阳区' },
|
|
195
|
+
{ id: 2, name: '李四', age: 32, address: '上海市浦东新区' },
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
const handleEdit = (record: Record<string, unknown>) => {
|
|
199
|
+
console.log('编辑', record)
|
|
200
|
+
}
|
|
201
|
+
const handleDelete = (record: Record<string, unknown>) => {
|
|
202
|
+
console.log('删除', record)
|
|
203
|
+
}
|
|
204
|
+
</script>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**TableActionItem 支持的字段(与 VbenAdmin ActionItem 对齐):**
|
|
208
|
+
|
|
209
|
+
- **label**:按钮文本
|
|
210
|
+
- **icon**:图标 class(可传 Element UI 图标或自定义 iconfont)
|
|
211
|
+
- **color**:`success / error / warning`,内部映射为对应按钮类型
|
|
212
|
+
- **type**:直接透传给 `el-button` 的 `type`
|
|
213
|
+
- **props**:额外的按钮 props
|
|
214
|
+
- **disabled**:是否禁用
|
|
215
|
+
- **divider**:是否在该操作后显示分隔线
|
|
216
|
+
- **ifShow**:是否显示当前操作项(支持函数)
|
|
217
|
+
- **tooltip**:字符串或 Tooltip 配置对象
|
|
218
|
+
- **popConfirm**:气泡确认配置 `{ title, okText, cancelText, confirm, cancel }`
|
|
219
|
+
- **onClick**:点击回调
|
|
220
|
+
|
|
89
221
|
## ProForm
|
|
90
222
|
|
|
91
223
|
参考 [Vben Admin Form](https://doc.vvbin.cn/components/form.html),支持 Schema 驱动、useForm、render/slot、动态显示等。
|
|
@@ -182,8 +314,10 @@ const handleSubmit = (values) => {
|
|
|
182
314
|
|
|
183
315
|
## 示例与文档
|
|
184
316
|
|
|
185
|
-
- **示例**:运行 `npm run dev` 后访问开发预览,包含 ProForm
|
|
317
|
+
- **示例**:运行 `npm run dev` 后访问开发预览,包含 ProTable、ProForm、componentSettings 测试等示例
|
|
318
|
+
- **ProTable 文档**:[docs/ProTable.md](./docs/ProTable.md)
|
|
186
319
|
- **ProForm 文档**:[docs/ProForm.md](./docs/ProForm.md)
|
|
320
|
+
- **组件默认配置**:[docs/ComponentSetting.md](./docs/ComponentSetting.md)(`useComponentSetting`)
|
|
187
321
|
|
|
188
322
|
## 开发
|
|
189
323
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
2
|
+
value?: unknown;
|
|
3
|
+
/** 拉取选项的接口,返回 Promise<Array<{ label, value }>> 或 { list: [] };可接收当前 params 作为参数 */
|
|
4
|
+
api?: (params?: Record<string, unknown>) => Promise<unknown>;
|
|
5
|
+
/** 请求参数,变化时会重新拉取 options */
|
|
6
|
+
params?: Record<string, unknown>;
|
|
7
|
+
/** 是否懒加载:为 true 时在展开下拉时再请求数据,不在挂载时请求 */
|
|
8
|
+
lazy?: boolean;
|
|
9
|
+
/** 接口返回列表中「标签」字段名,默认 'label' */
|
|
10
|
+
labelField?: string;
|
|
11
|
+
/** 接口返回列表中「值」字段名,默认 'value' */
|
|
12
|
+
valueField?: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
clearable?: boolean;
|
|
16
|
+
filterable?: boolean;
|
|
17
|
+
multiple?: boolean;
|
|
18
|
+
}>, {
|
|
19
|
+
labelField: string;
|
|
20
|
+
valueField: string;
|
|
21
|
+
lazy: boolean;
|
|
22
|
+
}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
23
|
+
input: (value: unknown) => void;
|
|
24
|
+
}, string, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
25
|
+
value?: unknown;
|
|
26
|
+
/** 拉取选项的接口,返回 Promise<Array<{ label, value }>> 或 { list: [] };可接收当前 params 作为参数 */
|
|
27
|
+
api?: (params?: Record<string, unknown>) => Promise<unknown>;
|
|
28
|
+
/** 请求参数,变化时会重新拉取 options */
|
|
29
|
+
params?: Record<string, unknown>;
|
|
30
|
+
/** 是否懒加载:为 true 时在展开下拉时再请求数据,不在挂载时请求 */
|
|
31
|
+
lazy?: boolean;
|
|
32
|
+
/** 接口返回列表中「标签」字段名,默认 'label' */
|
|
33
|
+
labelField?: string;
|
|
34
|
+
/** 接口返回列表中「值」字段名,默认 'value' */
|
|
35
|
+
valueField?: string;
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
clearable?: boolean;
|
|
39
|
+
filterable?: boolean;
|
|
40
|
+
multiple?: boolean;
|
|
41
|
+
}>, {
|
|
42
|
+
labelField: string;
|
|
43
|
+
valueField: string;
|
|
44
|
+
lazy: boolean;
|
|
45
|
+
}>>>, {
|
|
46
|
+
lazy: boolean;
|
|
47
|
+
labelField: string;
|
|
48
|
+
valueField: string;
|
|
49
|
+
}>;
|
|
50
|
+
export default _default;
|
|
51
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
52
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
53
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
54
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
55
|
+
} : {
|
|
56
|
+
type: import('vue').PropType<T[K]>;
|
|
57
|
+
required: true;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
type __VLS_WithDefaults<P, D> = {
|
|
61
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
62
|
+
default: D[K];
|
|
63
|
+
}> : P[K];
|
|
64
|
+
};
|
|
65
|
+
type __VLS_Prettify<T> = {
|
|
66
|
+
[K in keyof T]: T[K];
|
|
67
|
+
} & {};
|
|
@@ -5,7 +5,7 @@ declare function __VLS_template(): Partial<Record<string, (_: {
|
|
|
5
5
|
schema: {
|
|
6
6
|
field: string;
|
|
7
7
|
label: string;
|
|
8
|
-
component?:
|
|
8
|
+
component?: (import('..').ProFormBuiltInComponent | import('..').ProFormCustomComponent) | undefined;
|
|
9
9
|
componentProps?: (Record<string, unknown> | ((params: import('..').RenderCallbackParams & {
|
|
10
10
|
formActionType?: FormActionType;
|
|
11
11
|
}) => Record<string, unknown>)) | undefined;
|
|
@@ -72,6 +72,8 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_WithDefaults<
|
|
|
72
72
|
resetFunc?: () => Promise<void>;
|
|
73
73
|
submitOnReset?: boolean;
|
|
74
74
|
formListeners?: FormListeners;
|
|
75
|
+
/** 自定义组件映射(组件名 -> 组件),供 schema.component 使用 */
|
|
76
|
+
components?: Record<string, unknown>;
|
|
75
77
|
}>, {
|
|
76
78
|
labelWidth: string;
|
|
77
79
|
labelPosition: string;
|
|
@@ -146,6 +148,8 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_WithDefaults<
|
|
|
146
148
|
resetFunc?: () => Promise<void>;
|
|
147
149
|
submitOnReset?: boolean;
|
|
148
150
|
formListeners?: FormListeners;
|
|
151
|
+
/** 自定义组件映射(组件名 -> 组件),供 schema.component 使用 */
|
|
152
|
+
components?: Record<string, unknown>;
|
|
149
153
|
}>, {
|
|
150
154
|
labelWidth: string;
|
|
151
155
|
labelPosition: string;
|
|
@@ -14,12 +14,16 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_TypePropsToRu
|
|
|
14
14
|
formDisabled?: boolean;
|
|
15
15
|
autoPlaceholder?: boolean;
|
|
16
16
|
formActionType?: import('../types').FormActionType;
|
|
17
|
+
/** 自定义组件映射(由 ProForm 传入) */
|
|
18
|
+
customComponents?: Record<string, unknown>;
|
|
17
19
|
}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, Readonly<import('vue').ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
18
20
|
schema: ProFormSchema;
|
|
19
21
|
formModel: Record<string, unknown>;
|
|
20
22
|
formDisabled?: boolean;
|
|
21
23
|
autoPlaceholder?: boolean;
|
|
22
24
|
formActionType?: import('../types').FormActionType;
|
|
25
|
+
/** 自定义组件映射(由 ProForm 传入) */
|
|
26
|
+
customComponents?: Record<string, unknown>;
|
|
23
27
|
}>>>, {}>;
|
|
24
28
|
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
25
29
|
export default _default;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
2
|
+
value?: unknown;
|
|
3
|
+
/** 树数据,直接传入时优先使用,不请求 api */
|
|
4
|
+
treeData?: unknown[];
|
|
5
|
+
api?: (params?: Record<string, unknown>) => Promise<unknown>;
|
|
6
|
+
params?: Record<string, unknown>;
|
|
7
|
+
lazy?: boolean;
|
|
8
|
+
labelField?: string;
|
|
9
|
+
valueField?: string;
|
|
10
|
+
childrenField?: string;
|
|
11
|
+
filterable?: boolean;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
clearable?: boolean;
|
|
15
|
+
}>, {
|
|
16
|
+
labelField: string;
|
|
17
|
+
valueField: string;
|
|
18
|
+
childrenField: string;
|
|
19
|
+
lazy: boolean;
|
|
20
|
+
}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
21
|
+
input: (value: unknown) => void;
|
|
22
|
+
}, string, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
23
|
+
value?: unknown;
|
|
24
|
+
/** 树数据,直接传入时优先使用,不请求 api */
|
|
25
|
+
treeData?: unknown[];
|
|
26
|
+
api?: (params?: Record<string, unknown>) => Promise<unknown>;
|
|
27
|
+
params?: Record<string, unknown>;
|
|
28
|
+
lazy?: boolean;
|
|
29
|
+
labelField?: string;
|
|
30
|
+
valueField?: string;
|
|
31
|
+
childrenField?: string;
|
|
32
|
+
filterable?: boolean;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
clearable?: boolean;
|
|
36
|
+
}>, {
|
|
37
|
+
labelField: string;
|
|
38
|
+
valueField: string;
|
|
39
|
+
childrenField: string;
|
|
40
|
+
lazy: boolean;
|
|
41
|
+
}>>>, {
|
|
42
|
+
lazy: boolean;
|
|
43
|
+
labelField: string;
|
|
44
|
+
valueField: string;
|
|
45
|
+
childrenField: string;
|
|
46
|
+
}>;
|
|
47
|
+
export default _default;
|
|
48
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
49
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
50
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
51
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
52
|
+
} : {
|
|
53
|
+
type: import('vue').PropType<T[K]>;
|
|
54
|
+
required: true;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type __VLS_WithDefaults<P, D> = {
|
|
58
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
59
|
+
default: D[K];
|
|
60
|
+
}> : P[K];
|
|
61
|
+
};
|
|
62
|
+
type __VLS_Prettify<T> = {
|
|
63
|
+
[K in keyof T]: T[K];
|
|
64
|
+
} & {};
|