@antdv-vue/pro-table 0.0.0-stage → 2.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/CHANGELOG.md +255 -0
- package/README.md +106 -2
- package/dist/InternalTable.d.ts +360 -0
- package/dist/InternalTable.js +444 -0
- package/dist/RenderTypings.d.ts +33 -0
- package/dist/RenderTypings.js +1 -0
- package/dist/ResizableTableTitle.d.ts +24 -0
- package/dist/ResizableTableTitle.js +89 -0
- package/dist/Store/Provide.d.ts +68 -0
- package/dist/Store/Provide.js +132 -0
- package/dist/Table.d.ts +363 -0
- package/dist/Table.js +151 -0
- package/dist/TableRender.d.ts +54 -0
- package/dist/TableRender.js +295 -0
- package/dist/components/Alert/index.d.ts +45 -0
- package/dist/components/Alert/index.js +94 -0
- package/dist/components/Alert/style/index.d.ts +8 -0
- package/dist/components/Alert/style/index.js +11 -0
- package/dist/components/ColumnSetting/CheckboxList.d.ts +24 -0
- package/dist/components/ColumnSetting/CheckboxList.js +138 -0
- package/dist/components/ColumnSetting/CheckboxListItem.d.ts +17 -0
- package/dist/components/ColumnSetting/CheckboxListItem.js +84 -0
- package/dist/components/ColumnSetting/GroupCheckboxList.d.ts +22 -0
- package/dist/components/ColumnSetting/GroupCheckboxList.js +82 -0
- package/dist/components/ColumnSetting/ToolTipIcon.d.ts +12 -0
- package/dist/components/ColumnSetting/ToolTipIcon.js +47 -0
- package/dist/components/ColumnSetting/index.d.ts +26 -0
- package/dist/components/ColumnSetting/index.js +117 -0
- package/dist/components/ColumnSetting/style/index.d.ts +8 -0
- package/dist/components/ColumnSetting/style/index.js +73 -0
- package/dist/components/DragSortTable/index.d.ts +375 -0
- package/dist/components/DragSortTable/index.js +166 -0
- package/dist/components/DragSortTable/style/index.d.ts +8 -0
- package/dist/components/DragSortTable/style/index.js +25 -0
- package/dist/components/Dropdown/Button.d.ts +20 -0
- package/dist/components/Dropdown/Button.js +155 -0
- package/dist/components/Dropdown/index.d.ts +27 -0
- package/dist/components/Dropdown/index.js +149 -0
- package/dist/components/EditableTable/CellEditorTable.d.ts +63 -0
- package/dist/components/EditableTable/CellEditorTable.js +167 -0
- package/dist/components/EditableTable/EditableTable.d.ts +67 -0
- package/dist/components/EditableTable/EditableTable.js +141 -0
- package/dist/components/EditableTable/InternalEditableTable.d.ts +189 -0
- package/dist/components/EditableTable/InternalEditableTable.js +508 -0
- package/dist/components/EditableTable/RowEditorTable.d.ts +63 -0
- package/dist/components/EditableTable/RowEditorTable.js +147 -0
- package/dist/components/EditableTable/context.d.ts +9 -0
- package/dist/components/EditableTable/context.js +11 -0
- package/dist/components/EditableTable/index.d.ts +5 -0
- package/dist/components/EditableTable/index.js +5 -0
- package/dist/components/Form/FormRender.d.ts +77 -0
- package/dist/components/Form/FormRender.js +198 -0
- package/dist/components/Form/index.d.ts +33 -0
- package/dist/components/Form/index.js +91 -0
- package/dist/components/ToolBar/DensityIcon.d.ts +22 -0
- package/dist/components/ToolBar/DensityIcon.js +71 -0
- package/dist/components/ToolBar/FullScreenIcon.d.ts +6 -0
- package/dist/components/ToolBar/FullScreenIcon.js +30 -0
- package/dist/components/ToolBar/HeaderMenu.d.ts +22 -0
- package/dist/components/ToolBar/HeaderMenu.js +84 -0
- package/dist/components/ToolBar/index.d.ts +102 -0
- package/dist/components/ToolBar/index.js +322 -0
- package/dist/components/ToolBar/style/index.d.ts +8 -0
- package/dist/components/ToolBar/style/index.js +116 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/pro-table.esm.js +3274 -0
- package/dist/style/index.d.ts +11 -0
- package/dist/style/index.js +162 -0
- package/dist/typing.d.ts +409 -0
- package/dist/typing.js +1 -0
- package/dist/useFetchData.d.ts +10 -0
- package/dist/useFetchData.js +243 -0
- package/dist/utils/cellRenderToFromItem.d.ts +52 -0
- package/dist/utils/cellRenderToFromItem.js +163 -0
- package/dist/utils/columnRender.d.ts +54 -0
- package/dist/utils/columnRender.js +148 -0
- package/dist/utils/columnSort.d.ts +7 -0
- package/dist/utils/columnSort.js +17 -0
- package/dist/utils/genProColumnsToColumns.d.ts +69 -0
- package/dist/utils/genProColumnsToColumns.js +197 -0
- package/dist/utils/index.d.ts +122 -0
- package/dist/utils/index.js +227 -0
- package/dist/utils/useDragSort.d.ts +182 -0
- package/dist/utils/useDragSort.js +162 -0
- package/package.json +67 -3
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { useProTableInstanceExpose } from "../../utils/index.js";
|
|
2
|
+
import ProTable from "../../Table.js";
|
|
3
|
+
import { useEditableTableActionContextInject, useEditableTableActionContextProvider } from "./context.js";
|
|
4
|
+
import { Fragment, cloneVNode, computed, createVNode, defineComponent, isVNode, mergeProps, ref, shallowRef, toRef } from "vue";
|
|
5
|
+
import { ProFormDependency } from "@antdv-vue/pro-form";
|
|
6
|
+
import { useIntl } from "@antdv-vue/pro-provider";
|
|
7
|
+
import { childrenToArray, isSpecialNode, runFunction, stringify, transformBooleanProps, useEffect, useMemo } from "@antdv-vue/pro-utils";
|
|
8
|
+
import { get, set, useMergedState } from "@v-c/util";
|
|
9
|
+
import isEqual from "@v-c/util/dist/isEqual";
|
|
10
|
+
import { Button } from "antdv-next";
|
|
11
|
+
import { PlusOutlined } from "@antdv-next/icons";
|
|
12
|
+
//#region src/components/EditableTable/InternalEditableTable.tsx
|
|
13
|
+
/** 可编辑表格的按钮 */
|
|
14
|
+
const RecordCreator = ({ record, position, newRecordType, parentKey }, { slots }) => {
|
|
15
|
+
const actionRef = useEditableTableActionContextInject();
|
|
16
|
+
return childrenToArray(slots.default?.(), true).map((vnode) => {
|
|
17
|
+
if (isVNode(vnode) && !isSpecialNode(vnode)) return cloneVNode(vnode, {
|
|
18
|
+
...vnode.props,
|
|
19
|
+
onClick: async (e) => {
|
|
20
|
+
if (await vnode.props?.onClick?.(e) === false) return;
|
|
21
|
+
if (actionRef) actionRef.value?.addEditRecord?.(record, {
|
|
22
|
+
position,
|
|
23
|
+
newRecordType,
|
|
24
|
+
parentKey
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return vnode;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
RecordCreator.displayName = "RecordCreator";
|
|
32
|
+
RecordCreator.inheritAttrs = false;
|
|
33
|
+
/**
|
|
34
|
+
* 检查是否应该显示创建按钮
|
|
35
|
+
*/
|
|
36
|
+
function shouldShowCreatorButton(maxLength, valueLength, recordCreatorProps) {
|
|
37
|
+
if (typeof maxLength === "number" && maxLength <= valueLength) return false;
|
|
38
|
+
return recordCreatorProps !== false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 创建按钮 DOM
|
|
42
|
+
*/
|
|
43
|
+
function createButtonDom(recordCreatorProps, value, intl) {
|
|
44
|
+
const { record, position, creatorButtonText, newRecordType, parentKey, style, ...restButtonProps } = recordCreatorProps;
|
|
45
|
+
return createVNode(RecordCreator, {
|
|
46
|
+
"record": runFunction(record, value?.length, value) || {},
|
|
47
|
+
"position": position,
|
|
48
|
+
"parentKey": runFunction(parentKey, value?.length, value),
|
|
49
|
+
"newRecordType": newRecordType
|
|
50
|
+
}, { default: () => [createVNode(Button, mergeProps({
|
|
51
|
+
"type": "dashed",
|
|
52
|
+
"style": {
|
|
53
|
+
display: "block",
|
|
54
|
+
margin: "10px 0",
|
|
55
|
+
width: "100%",
|
|
56
|
+
...style
|
|
57
|
+
},
|
|
58
|
+
"icon": createVNode(PlusOutlined, null, null)
|
|
59
|
+
}, restButtonProps), { default: () => [creatorButtonText || intl.getMessage({
|
|
60
|
+
id: "editableTable.action.add",
|
|
61
|
+
defaultMessage: "添加一行数据"
|
|
62
|
+
})] })] });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 创建顶部按钮的渲染属性
|
|
66
|
+
*/
|
|
67
|
+
function createTopButtonProps(creatorButtonDom, columnsLength) {
|
|
68
|
+
const wrapper = (_, { attrs, slots }) => createVNode("thead", { "class": attrs.class }, [slots.default?.(), createVNode("tr", { "style": { position: "relative" } }, [createVNode("td", {
|
|
69
|
+
"col-span": 0,
|
|
70
|
+
"style": { visibility: "hidden" }
|
|
71
|
+
}, [creatorButtonDom]), createVNode("td", {
|
|
72
|
+
"style": {
|
|
73
|
+
position: "absolute",
|
|
74
|
+
left: 0,
|
|
75
|
+
width: "100%"
|
|
76
|
+
},
|
|
77
|
+
"col-span": columnsLength
|
|
78
|
+
}, [creatorButtonDom])])]);
|
|
79
|
+
return { components: { header: { wrapper } } };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 创建底部按钮的渲染属性
|
|
83
|
+
*/
|
|
84
|
+
function createBottomButtonProps(creatorButtonDom, tableViewRender) {
|
|
85
|
+
return { tableViewRender: (_, dom) => createVNode(Fragment, null, [tableViewRender?.(_, dom) ?? dom, creatorButtonDom]) };
|
|
86
|
+
}
|
|
87
|
+
function useCreatorButton({ recordCreatorProps, maxLength, value, intl, columnsLength, tableViewRender }) {
|
|
88
|
+
const creatorButtonDom = computed(() => {
|
|
89
|
+
if (!shouldShowCreatorButton(maxLength.value, value.value?.length || 0, recordCreatorProps.value)) return false;
|
|
90
|
+
if (!recordCreatorProps.value) return false;
|
|
91
|
+
return createButtonDom(recordCreatorProps.value, value.value, intl.value);
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
creatorButtonDom,
|
|
95
|
+
buttonRenderProps: computed(() => {
|
|
96
|
+
if (!recordCreatorProps.value) return {};
|
|
97
|
+
const { position } = recordCreatorProps.value;
|
|
98
|
+
if (!creatorButtonDom) return {};
|
|
99
|
+
return position === "top" ? createTopButtonProps(creatorButtonDom.value, columnsLength.value) : createBottomButtonProps(creatorButtonDom.value, tableViewRender);
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function useEditableProTableInstanceExpose(editableTableRef) {
|
|
104
|
+
return {
|
|
105
|
+
...useProTableInstanceExpose(editableTableRef),
|
|
106
|
+
get nativeElement() {
|
|
107
|
+
return editableTableRef.value?.nativeElement;
|
|
108
|
+
},
|
|
109
|
+
get pageInfo() {
|
|
110
|
+
return editableTableRef.value?.pageInfo;
|
|
111
|
+
},
|
|
112
|
+
get formRef() {
|
|
113
|
+
return editableTableRef.value?.formRef?.nativeElement ? editableTableRef.value?.formRef : null;
|
|
114
|
+
},
|
|
115
|
+
get editableFormRef() {
|
|
116
|
+
return editableTableRef.value?.editableFormRef;
|
|
117
|
+
},
|
|
118
|
+
getRowData: (rowIndex) => editableTableRef.value?.getRowData?.(rowIndex),
|
|
119
|
+
getRowsData: () => editableTableRef.value?.getRowsData?.(),
|
|
120
|
+
setRowData: (rowIndex, data) => editableTableRef.value?.setRowData?.(rowIndex, data)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const InternalEditableProTable = /* @__PURE__ */ defineComponent((props, { slots, expose }) => {
|
|
124
|
+
const intl = useIntl();
|
|
125
|
+
const preData = ref(void 0);
|
|
126
|
+
const tableRef = shallowRef(null);
|
|
127
|
+
const formRef = shallowRef(null);
|
|
128
|
+
const hasHydratedEditableForm = ref(false);
|
|
129
|
+
const booleanProps = transformBooleanProps([
|
|
130
|
+
"manualRequest",
|
|
131
|
+
"showSorterTooltip",
|
|
132
|
+
"showHeader",
|
|
133
|
+
"rowHoverable",
|
|
134
|
+
"revalidateOnFocus",
|
|
135
|
+
"loading",
|
|
136
|
+
"virtual",
|
|
137
|
+
"sticky",
|
|
138
|
+
"tailor",
|
|
139
|
+
"bordered",
|
|
140
|
+
"cardBordered",
|
|
141
|
+
"ghost"
|
|
142
|
+
], props);
|
|
143
|
+
const [value, setValue] = useMergedState(() => props.value || props.defaultValue || [], {
|
|
144
|
+
value: toRef(() => props.value),
|
|
145
|
+
defaultValue: props.defaultValue,
|
|
146
|
+
onChange: (value) => {
|
|
147
|
+
props.onChange?.(value);
|
|
148
|
+
props["onUpdate:value"]?.(value);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const getRowKey = useMemo(() => {
|
|
152
|
+
if (typeof props.rowKey === "function") return props.rowKey;
|
|
153
|
+
return (record, index) => record[props.rowKey] || index;
|
|
154
|
+
}, [() => props.rowKey]);
|
|
155
|
+
/**
|
|
156
|
+
* 根据不同的情况返回不同的 rowKey
|
|
157
|
+
* @param finlayRowKey
|
|
158
|
+
* @returns string | number
|
|
159
|
+
*/
|
|
160
|
+
const coverRowKey = (finlayRowKey) => {
|
|
161
|
+
/**
|
|
162
|
+
* 如果是 prop.name 的模式,就需要把行号转化成具体的rowKey。
|
|
163
|
+
*/
|
|
164
|
+
if (typeof finlayRowKey === "number" && !props.name) {
|
|
165
|
+
if (finlayRowKey >= value.value.length) return finlayRowKey;
|
|
166
|
+
const rowData = value.value && value.value[finlayRowKey];
|
|
167
|
+
return getRowKey.value?.(rowData, finlayRowKey);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 如果是 prop.name 的模式,就直接返回行号
|
|
171
|
+
*/
|
|
172
|
+
if ((typeof finlayRowKey === "string" || finlayRowKey >= value.value.length) && props.name) {
|
|
173
|
+
const rowIndex = value.value.findIndex((item, index) => {
|
|
174
|
+
return getRowKey.value?.(item, index)?.toString() === finlayRowKey?.toString();
|
|
175
|
+
});
|
|
176
|
+
if (rowIndex !== -1) return rowIndex;
|
|
177
|
+
}
|
|
178
|
+
return finlayRowKey;
|
|
179
|
+
};
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!formRef.value || !props.controlled && (props.name || hasHydratedEditableForm.value)) return;
|
|
182
|
+
const formValues = (value.value || []).reduce((result, current, index) => {
|
|
183
|
+
result[String(getRowKey.value(current, index))] = current;
|
|
184
|
+
return result;
|
|
185
|
+
}, {});
|
|
186
|
+
if (Object.keys(formValues).length === 0) return;
|
|
187
|
+
formRef.value.setFieldsValue(formValues);
|
|
188
|
+
hasHydratedEditableForm.value = true;
|
|
189
|
+
}, [
|
|
190
|
+
() => stringify(value.value),
|
|
191
|
+
() => props.controlled,
|
|
192
|
+
() => formRef.value
|
|
193
|
+
]);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (props.name && props?.editable?.form) formRef.value = props?.editable?.form;
|
|
196
|
+
}, [() => props.editable?.form, () => props.name]);
|
|
197
|
+
/**
|
|
198
|
+
* 防止闭包的onchange
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
const handleValuesChange = (record, dataSource) => {
|
|
202
|
+
props.editable?.onValuesChange?.(record, dataSource || []);
|
|
203
|
+
props.onValuesChange?.(dataSource || [], record);
|
|
204
|
+
if (props.controlled && props?.onChange) props.onChange(dataSource);
|
|
205
|
+
};
|
|
206
|
+
useEditableTableActionContextProvider(tableRef);
|
|
207
|
+
/**
|
|
208
|
+
* 获取一行数据的
|
|
209
|
+
* @param rowIndex
|
|
210
|
+
*/
|
|
211
|
+
const getRowData = (rowIndex) => {
|
|
212
|
+
if (rowIndex === void 0) throw new Error("rowIndex is required");
|
|
213
|
+
const finlayRowKey = coverRowKey(rowIndex);
|
|
214
|
+
const rowKeyName = [props.name, finlayRowKey?.toString() ?? ""].flat(1).filter(Boolean);
|
|
215
|
+
return formRef.value?.getFieldValue(rowKeyName);
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* 获取整个 table 的数据
|
|
219
|
+
*/
|
|
220
|
+
const getRowsData = () => {
|
|
221
|
+
const rowKeyName = [props.name].flat(1).filter(Boolean);
|
|
222
|
+
if (Array.isArray(rowKeyName) && rowKeyName.length === 0) {
|
|
223
|
+
const rowData = formRef.value?.getFieldsValue();
|
|
224
|
+
if (Array.isArray(rowData)) return rowData;
|
|
225
|
+
return Object.keys(rowData || {}).map((key) => {
|
|
226
|
+
return rowData?.[key];
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return formRef.value?.getFieldValue(rowKeyName);
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* 设置一行的数据,会将数据进行简单的 merge
|
|
233
|
+
* @param rowIndex
|
|
234
|
+
* @param data
|
|
235
|
+
* @returns void
|
|
236
|
+
*/
|
|
237
|
+
const setRowData = (rowIndex, data) => {
|
|
238
|
+
if (rowIndex === void 0) throw new Error("rowIndex is required");
|
|
239
|
+
const finlayRowKey = coverRowKey(rowIndex);
|
|
240
|
+
const rowKeyName = [props.name, finlayRowKey?.toString() ?? ""].flat(1).filter(Boolean);
|
|
241
|
+
const newRowData = Object.assign({}, {
|
|
242
|
+
...getRowData(rowIndex),
|
|
243
|
+
...data || {}
|
|
244
|
+
});
|
|
245
|
+
if (props.name) {
|
|
246
|
+
const tableName = [props.name].flat(1).filter(Boolean);
|
|
247
|
+
const currentTableData = props.value || formRef.value?.getFieldValue(tableName);
|
|
248
|
+
if (Array.isArray(currentTableData)) {
|
|
249
|
+
const rowIndexToUpdate = typeof finlayRowKey === "number" ? finlayRowKey : currentTableData.findIndex((row, index) => {
|
|
250
|
+
const rowKey = getRowKey.value?.(row, index);
|
|
251
|
+
return rowKey === finlayRowKey || rowKey?.toString() === finlayRowKey?.toString();
|
|
252
|
+
});
|
|
253
|
+
if (rowIndexToUpdate >= 0 && rowIndexToUpdate < currentTableData.length) {
|
|
254
|
+
const updatedTableData = [...currentTableData];
|
|
255
|
+
updatedTableData[rowIndexToUpdate] = newRowData;
|
|
256
|
+
const updateValues = set({}, tableName, updatedTableData);
|
|
257
|
+
formRef.value?.setFieldsValue(updateValues);
|
|
258
|
+
if (props.controlled && props.onChange) props.onChange(updatedTableData);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
const updateValues = set({}, rowKeyName, newRowData);
|
|
262
|
+
formRef.value?.setFieldsValue(updateValues);
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
const updateValues = set({}, rowKeyName, newRowData);
|
|
266
|
+
formRef.value?.setFieldsValue(updateValues);
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
};
|
|
270
|
+
const { buttonRenderProps } = useCreatorButton({
|
|
271
|
+
recordCreatorProps: computed(() => props.recordCreatorProps),
|
|
272
|
+
maxLength: computed(() => props.maxLength),
|
|
273
|
+
value,
|
|
274
|
+
intl,
|
|
275
|
+
columnsLength: computed(() => props.columns?.length),
|
|
276
|
+
tableViewRender: props.tableViewRender
|
|
277
|
+
});
|
|
278
|
+
/**
|
|
279
|
+
* 创建编辑 keys 的 Set,用于快速查找
|
|
280
|
+
*/
|
|
281
|
+
const createEditingKeysSet = (editingKeys) => {
|
|
282
|
+
return new Set((editingKeys || []).map((key) => String(key)));
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* 同步表单值,排除正在编辑的行
|
|
286
|
+
*/
|
|
287
|
+
const syncFormValuesExcludingEditing = (dataSource, editingKeysSet, namePath) => {
|
|
288
|
+
if (!formRef.value) return;
|
|
289
|
+
try {
|
|
290
|
+
if (namePath && namePath.length > 0) {
|
|
291
|
+
const currentList = get(formRef.value.getFieldsValue() || {}, namePath);
|
|
292
|
+
if (currentList && Array.isArray(currentList)) {
|
|
293
|
+
const currentListMap = /* @__PURE__ */ new Map();
|
|
294
|
+
currentList.forEach((item, idx) => {
|
|
295
|
+
const key = getRowKey.value(item, idx);
|
|
296
|
+
currentListMap.set(String(key), item);
|
|
297
|
+
});
|
|
298
|
+
const newValue = set({}, namePath, dataSource.map((item, index) => {
|
|
299
|
+
const key = getRowKey.value(item, index);
|
|
300
|
+
const keyStr = String(key);
|
|
301
|
+
if (editingKeysSet.has(keyStr)) return currentListMap.get(keyStr) || item;
|
|
302
|
+
return item;
|
|
303
|
+
}));
|
|
304
|
+
formRef.value.setFieldsValue(newValue);
|
|
305
|
+
} else {
|
|
306
|
+
const newValue = set({}, namePath, dataSource);
|
|
307
|
+
formRef.value.setFieldsValue(newValue);
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
const formValues = {};
|
|
311
|
+
dataSource.forEach((current, index) => {
|
|
312
|
+
const key = getRowKey.value(current, index);
|
|
313
|
+
const keyStr = String(key);
|
|
314
|
+
if (!editingKeysSet.has(keyStr)) formValues[keyStr] = current;
|
|
315
|
+
});
|
|
316
|
+
if (Object.keys(formValues).length > 0) formRef.value.setFieldsValue(formValues);
|
|
317
|
+
}
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.warn("Failed to sync form values:", error);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
expose({
|
|
323
|
+
...useProTableInstanceExpose(tableRef),
|
|
324
|
+
get nativeElement() {
|
|
325
|
+
return tableRef.value?.nativeElement;
|
|
326
|
+
},
|
|
327
|
+
get pageInfo() {
|
|
328
|
+
return tableRef.value?.pageInfo;
|
|
329
|
+
},
|
|
330
|
+
get formRef() {
|
|
331
|
+
return tableRef.value?.formRef?.nativeElement ? tableRef.value?.formRef : null;
|
|
332
|
+
},
|
|
333
|
+
get editableFormRef() {
|
|
334
|
+
return formRef.value;
|
|
335
|
+
},
|
|
336
|
+
getRowData,
|
|
337
|
+
getRowsData,
|
|
338
|
+
setRowData
|
|
339
|
+
});
|
|
340
|
+
return () => {
|
|
341
|
+
const { onTableChange, maxLength, formItemProps, recordCreatorProps, rowKey, controlled, defaultValue, onChange, onDataSourceChange, ...rest } = props;
|
|
342
|
+
const editableProps = props.name ? {
|
|
343
|
+
...props.editable,
|
|
344
|
+
form: tableRef.value?.formRef
|
|
345
|
+
} : { ...props.editable };
|
|
346
|
+
if (props?.onValuesChange || props.editable?.onValuesChange || props.controlled && props?.onChange) editableProps.onValuesChange = handleValuesChange;
|
|
347
|
+
return createVNode(Fragment, null, [createVNode(ProTable, mergeProps({ "ref": tableRef }, rest, booleanProps, {
|
|
348
|
+
"search": rest.search || false,
|
|
349
|
+
"options": rest.options || false,
|
|
350
|
+
"pagination": rest.pagination || false,
|
|
351
|
+
"rowKey": rowKey,
|
|
352
|
+
"scroll": props.scroll || { x: "max-content" },
|
|
353
|
+
"revalidateOnFocus": rest.revalidateOnFocus || false,
|
|
354
|
+
"tableLayout": props.tableLayout || "fixed"
|
|
355
|
+
}, buttonRenderProps.value, {
|
|
356
|
+
"editable": {
|
|
357
|
+
...editableProps,
|
|
358
|
+
formProps: {
|
|
359
|
+
formRef,
|
|
360
|
+
...editableProps.formProps
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
"dataSource": value.value,
|
|
364
|
+
"onDataSourceChange": (dataSource) => {
|
|
365
|
+
setValue(dataSource);
|
|
366
|
+
/**
|
|
367
|
+
* 如果是 name 模式,需要同步表单值
|
|
368
|
+
* 避免表单值和数据源不一致
|
|
369
|
+
* 注意:不会覆盖正在编辑的行
|
|
370
|
+
*/
|
|
371
|
+
if (props.name && formRef.value) {
|
|
372
|
+
const editingKeys = props.editable?.editableKeys;
|
|
373
|
+
syncFormValuesExcludingEditing(dataSource, createEditingKeysSet(editingKeys), [props.name].flat(1).filter(Boolean));
|
|
374
|
+
}
|
|
375
|
+
if (!props.controlled && props.onChange) props.onChange(dataSource);
|
|
376
|
+
}
|
|
377
|
+
}), slots), props.name ? createVNode(ProFormDependency, { "name": [props.name] }, { default: (changeValue) => {
|
|
378
|
+
if (!preData.value) {
|
|
379
|
+
preData.value = value.value;
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
const list = get(changeValue, [props.name].flat(1));
|
|
383
|
+
if (!list || !Array.isArray(list)) {
|
|
384
|
+
preData.value = value.value;
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const changeIndex = list.findIndex((item, index) => {
|
|
388
|
+
return !isEqual(item, preData.value?.[index]);
|
|
389
|
+
});
|
|
390
|
+
if (changeIndex !== -1) {
|
|
391
|
+
const changeItem = list[changeIndex];
|
|
392
|
+
props?.editable?.onValuesChange?.(changeItem, list);
|
|
393
|
+
}
|
|
394
|
+
preData.value = list;
|
|
395
|
+
return null;
|
|
396
|
+
} }) : null]);
|
|
397
|
+
};
|
|
398
|
+
}, {
|
|
399
|
+
name: "InternalEditableTable",
|
|
400
|
+
inheritAttrs: false,
|
|
401
|
+
props: [
|
|
402
|
+
"beforeSearchSubmit",
|
|
403
|
+
"bodyCell",
|
|
404
|
+
"bordered",
|
|
405
|
+
"caption",
|
|
406
|
+
"cardBordered",
|
|
407
|
+
"cardProps",
|
|
408
|
+
"childrenColumnName",
|
|
409
|
+
"classes",
|
|
410
|
+
"columnEmptyText",
|
|
411
|
+
"columns",
|
|
412
|
+
"columnsState",
|
|
413
|
+
"components",
|
|
414
|
+
"controlled",
|
|
415
|
+
"dataSource",
|
|
416
|
+
"dateFormatter",
|
|
417
|
+
"debounceTime",
|
|
418
|
+
"defaultData",
|
|
419
|
+
"defaultExpandAllRows",
|
|
420
|
+
"defaultExpandedRowKeys",
|
|
421
|
+
"defaultSize",
|
|
422
|
+
"defaultValue",
|
|
423
|
+
"direction",
|
|
424
|
+
"dropdownPrefixCls",
|
|
425
|
+
"editable",
|
|
426
|
+
"errorBoundaryRender",
|
|
427
|
+
"expandIcon",
|
|
428
|
+
"expandIconColumnIndex",
|
|
429
|
+
"expandRowByClick",
|
|
430
|
+
"expandable",
|
|
431
|
+
"expandedRowClassName",
|
|
432
|
+
"expandedRowKeys",
|
|
433
|
+
"expandedRowRender",
|
|
434
|
+
"footer",
|
|
435
|
+
"form",
|
|
436
|
+
"formItemProps",
|
|
437
|
+
"getContainerWidth",
|
|
438
|
+
"getPopupContainer",
|
|
439
|
+
"ghost",
|
|
440
|
+
"headerCell",
|
|
441
|
+
"headerTitle",
|
|
442
|
+
"id",
|
|
443
|
+
"indentSize",
|
|
444
|
+
"loading",
|
|
445
|
+
"locale",
|
|
446
|
+
"manualRequest",
|
|
447
|
+
"maxLength",
|
|
448
|
+
"measureRowRender",
|
|
449
|
+
"name",
|
|
450
|
+
"onChange",
|
|
451
|
+
"onDataSourceChange",
|
|
452
|
+
"onExpand",
|
|
453
|
+
"onExpandedRowsChange",
|
|
454
|
+
"onHeaderRow",
|
|
455
|
+
"onLoad",
|
|
456
|
+
"onLoadingChange",
|
|
457
|
+
"onRequestError",
|
|
458
|
+
"onReset",
|
|
459
|
+
"onRow",
|
|
460
|
+
"onSizeChange",
|
|
461
|
+
"onSubmit",
|
|
462
|
+
"onTableChange",
|
|
463
|
+
"onValuesChange",
|
|
464
|
+
"options",
|
|
465
|
+
"optionsRender",
|
|
466
|
+
"pagination",
|
|
467
|
+
"params",
|
|
468
|
+
"polling",
|
|
469
|
+
"postData",
|
|
470
|
+
"prefixCls",
|
|
471
|
+
"recordCreatorProps",
|
|
472
|
+
"request",
|
|
473
|
+
"revalidateOnFocus",
|
|
474
|
+
"rootClass",
|
|
475
|
+
"rowClassName",
|
|
476
|
+
"rowHoverable",
|
|
477
|
+
"rowKey",
|
|
478
|
+
"rowSelection",
|
|
479
|
+
"scroll",
|
|
480
|
+
"search",
|
|
481
|
+
"searchFormRender",
|
|
482
|
+
"showHeader",
|
|
483
|
+
"showSorterTooltip",
|
|
484
|
+
"size",
|
|
485
|
+
"sortDirections",
|
|
486
|
+
"sticky",
|
|
487
|
+
"styles",
|
|
488
|
+
"summary",
|
|
489
|
+
"tableAlertOptionRender",
|
|
490
|
+
"tableAlertRender",
|
|
491
|
+
"tableClass",
|
|
492
|
+
"tableExtraRender",
|
|
493
|
+
"tableLayout",
|
|
494
|
+
"tableRender",
|
|
495
|
+
"tableStyle",
|
|
496
|
+
"tableViewRender",
|
|
497
|
+
"tailor",
|
|
498
|
+
"title",
|
|
499
|
+
"toolBarRender",
|
|
500
|
+
"toolbar",
|
|
501
|
+
"tooltip",
|
|
502
|
+
"type",
|
|
503
|
+
"value",
|
|
504
|
+
"virtual"
|
|
505
|
+
]
|
|
506
|
+
});
|
|
507
|
+
//#endregion
|
|
508
|
+
export { RecordCreator, InternalEditableProTable as default, useCreatorButton, useEditableProTableInstanceExpose };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { FilterValue, ProTableProps } from "../../typing.js";
|
|
2
|
+
import { RecordCreatorProps } from "./InternalEditableTable.js";
|
|
3
|
+
import * as _$vue from "vue";
|
|
4
|
+
import { ParamsType } from "@antdv-vue/pro-provider";
|
|
5
|
+
import * as _$_antdv_vue_pro_utils0 from "@antdv-vue/pro-utils";
|
|
6
|
+
import { ProFieldValueObjectType, ProFieldValueType } from "@antdv-vue/pro-utils";
|
|
7
|
+
import * as _$antdv_next0 from "antdv-next";
|
|
8
|
+
import * as _$antdv_next_dist_table_interface0 from "antdv-next/dist/table/interface";
|
|
9
|
+
import { VueNode as VueNode$1 } from "@v-c/util/dist/type";
|
|
10
|
+
|
|
11
|
+
//#region src/components/EditableTable/RowEditorTable.d.ts
|
|
12
|
+
declare const RowEditorTable: new <DataType extends Record<string, any>, Params extends ParamsType = ParamsType, ValueType extends (ProFieldValueType | ProFieldValueObjectType) = "text">(props: Omit<ProTableProps<DataType, Params, ValueType>, "onChange"> & {
|
|
13
|
+
defaultValue?: DataType[] | undefined;
|
|
14
|
+
value?: DataType[] | undefined;
|
|
15
|
+
'onUpdate:value'?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
16
|
+
onChange?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
17
|
+
onTableChange?: ((pagination: _$antdv_next0.TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: _$antdv_next0.TableSorterResult<DataType> | _$antdv_next0.TableSorterResult<DataType>[], extra: _$antdv_next_dist_table_interface0.TableCurrentDataSource<DataType>) => void) | undefined;
|
|
18
|
+
recordCreatorProps?: _$_antdv_vue_pro_utils0.WithFalse<RecordCreatorProps<DataType> & _$antdv_next0.ButtonProps & {
|
|
19
|
+
style?: _$vue.CSSProperties;
|
|
20
|
+
creatorButtonText?: VueNode$1;
|
|
21
|
+
}> | undefined;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
onValuesChange?: ((values: DataType[], record: DataType) => void) | undefined;
|
|
24
|
+
controlled?: boolean;
|
|
25
|
+
formItemProps?: Omit<_$_antdv_vue_pro_utils0.FormItemProps, "name">;
|
|
26
|
+
} & {} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps) => _$vue.CreateComponentPublicInstanceWithMixins<Omit<ProTableProps<DataType, Params, ValueType>, "onChange"> & {
|
|
27
|
+
defaultValue?: DataType[] | undefined;
|
|
28
|
+
value?: DataType[] | undefined;
|
|
29
|
+
'onUpdate:value'?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
30
|
+
onChange?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
31
|
+
onTableChange?: ((pagination: _$antdv_next0.TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: _$antdv_next0.TableSorterResult<DataType> | _$antdv_next0.TableSorterResult<DataType>[], extra: _$antdv_next_dist_table_interface0.TableCurrentDataSource<DataType>) => void) | undefined;
|
|
32
|
+
recordCreatorProps?: _$_antdv_vue_pro_utils0.WithFalse<RecordCreatorProps<DataType> & _$antdv_next0.ButtonProps & {
|
|
33
|
+
style?: _$vue.CSSProperties;
|
|
34
|
+
creatorButtonText?: VueNode$1;
|
|
35
|
+
}> | undefined;
|
|
36
|
+
maxLength?: number;
|
|
37
|
+
onValuesChange?: ((values: DataType[], record: DataType) => void) | undefined;
|
|
38
|
+
controlled?: boolean;
|
|
39
|
+
formItemProps?: Omit<_$_antdv_vue_pro_utils0.FormItemProps, "name">;
|
|
40
|
+
} & {}, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, _$vue.PublicProps, {}, false, {}, {}, {}, {}, string, {}, any, _$vue.ComponentProvideOptions, {
|
|
41
|
+
P: {};
|
|
42
|
+
B: {};
|
|
43
|
+
D: {};
|
|
44
|
+
C: {};
|
|
45
|
+
M: {};
|
|
46
|
+
Defaults: {};
|
|
47
|
+
}, Omit<ProTableProps<DataType, Params, ValueType>, "onChange"> & {
|
|
48
|
+
defaultValue?: DataType[] | undefined;
|
|
49
|
+
value?: DataType[] | undefined;
|
|
50
|
+
'onUpdate:value'?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
51
|
+
onChange?: ((value?: DataType[] | undefined) => void) | undefined;
|
|
52
|
+
onTableChange?: ((pagination: _$antdv_next0.TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: _$antdv_next0.TableSorterResult<DataType> | _$antdv_next0.TableSorterResult<DataType>[], extra: _$antdv_next_dist_table_interface0.TableCurrentDataSource<DataType>) => void) | undefined;
|
|
53
|
+
recordCreatorProps?: _$_antdv_vue_pro_utils0.WithFalse<RecordCreatorProps<DataType> & _$antdv_next0.ButtonProps & {
|
|
54
|
+
style?: _$vue.CSSProperties;
|
|
55
|
+
creatorButtonText?: VueNode$1;
|
|
56
|
+
}> | undefined;
|
|
57
|
+
maxLength?: number;
|
|
58
|
+
onValuesChange?: ((values: DataType[], record: DataType) => void) | undefined;
|
|
59
|
+
controlled?: boolean;
|
|
60
|
+
formItemProps?: Omit<_$_antdv_vue_pro_utils0.FormItemProps, "name">;
|
|
61
|
+
} & {}, {}, {}, {}, {}, {}>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { RowEditorTable as default };
|