Skip to content

Commit 36610cc

Browse files
authored
[Table] set return value of validateRowData and validateTableData to be a Promise ; stopPropagation popup content click bubble to document (#1275)
* feat(table): validateRowData and validateTableData support Promise * fix(table): stopPropagation popup content click bubble to document * feat(table): update api files * fix: lint error * fix(lint error): fix
1 parent a55e0ed commit 36610cc

File tree

7 files changed

+140
-90
lines changed

7 files changed

+140
-90
lines changed

examples/table/demos/editable-row.vue

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,50 +202,69 @@ export default {
202202
const { id } = e.currentTarget.dataset;
203203
this.currentSaveId = id;
204204
// 触发内部校验,而后在 onRowValidate 中接收异步校验结果
205-
this.$refs.tableRef.validateRowData(id);
205+
this.$refs.tableRef.validateRowData(id).then((params) => {
206+
console.log('Event Table Promise Validate:', params);
207+
if (params.result.length) {
208+
const r = params.result[0];
209+
MessagePlugin.error(`${r.col.title} ${r.errorList[0].message}`);
210+
return;
211+
}
212+
// 如果是 table 的父组件主动触发校验
213+
if (params.trigger === 'parent' && !params.result.length) {
214+
const current = this.editMap[this.currentSaveId];
215+
if (current) {
216+
this.data.splice(current.rowIndex, 1, current.editedRow);
217+
MessagePlugin.success('保存成功');
218+
}
219+
this.updateEditState(this.currentSaveId);
220+
}
221+
});
206222
},
207223
208224
// 行校验反馈事件,this.$refs.tableRef.validateRowData 执行结束后触发
209225
onRowValidate(params) {
210-
console.log('row-validate:', params);
211-
if (params.result.length) {
212-
const r = params.result[0];
213-
MessagePlugin.error(`${r.col.title} ${r.errorList[0].message}`);
214-
return;
215-
}
216-
// 如果是 table 的父组件主动触发校验
217-
if (params.trigger === 'parent' && !params.result.length) {
218-
const current = this.editMap[this.currentSaveId];
219-
if (current) {
220-
this.data.splice(current.rowIndex, 1, current.editedRow);
221-
MessagePlugin.success('保存成功');
222-
}
223-
this.updateEditState(this.currentSaveId);
224-
}
226+
console.log('Event Table Row Validate:', params);
225227
},
226228
227229
onValidateTableData() {
228230
// 执行结束后触发事件 validate
229-
this.$refs.tableRef.validateTableData();
231+
this.$refs.tableRef.validateTableData().then((params) => {
232+
console.log('Promise Table Data Validate:', params);
233+
const cellKeys = Object.keys(params.result);
234+
const firstError = params.result[cellKeys[0]];
235+
if (firstError) {
236+
MessagePlugin.warning(firstError[0].message);
237+
}
238+
});
230239
},
231240
232241
// 表格全量数据校验反馈事件,this.$refs.tableRef.validateTableData() 执行结束后触发
233242
onValidate(params) {
234-
console.log('validate:', params);
235-
const cellKeys = Object.keys(params.result);
236-
const firstError = params.result[cellKeys[0]];
237-
if (firstError) {
238-
MessagePlugin.warning(firstError[0].message);
239-
}
243+
console.log('Event Table Data Validate:', params);
240244
},
241245
242246
onRowEdit(params) {
243-
const { row, col, value } = params;
247+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
248+
const {
249+
row,
250+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
251+
rowIndex,
252+
col,
253+
value,
254+
} = params;
244255
const oldRowData = this.editMap[row.key]?.editedRow || row;
256+
const editedRow = { ...oldRowData, [col.colKey]: value };
245257
this.editMap[row.key] = {
246258
...params,
247-
editedRow: { ...oldRowData, [col.colKey]: value },
259+
editedRow,
248260
};
261+
262+
// ⚠️ 重要:以下内容应用于全量数据校验(单独的行校验不需要)
263+
// const newData = [...this.data];
264+
// newData[rowIndex] = editedRow;
265+
// this.data = newData;
266+
// 或者
267+
// this.$set(this.data, rowIndex, editedRow);
249268
},
250269
},
251270
};

0 commit comments

Comments
 (0)