feat(考试模块): 优化题库添加功能及事件处理

- 添加对表格引用的检查,避免空引用错误
- 优化选择行的逻辑,确保正确处理单选和多选情况
- 引入行键获取和比较功能,提升行数据的处理准确性
- 清理冗余代码,增强代码可读性和维护性
This commit is contained in:
2026-05-20 13:43:26 +08:00
parent 3518573db2
commit 7eeecab824

View File

@@ -360,23 +360,29 @@ export default {
this.tableColumn = tableColumn;
var that = this;
this.$nextTick(() => {
if (!this.$refs.xTable) {
return;
}
this.clearRadioRowEevnt();
this.clearCheckboxEevnt();
if (this.tableData.length > 0) {
console.log("this.tableData.length at line 354:", this.tableData);
this.tableData.forEach((e, i) => {
if (e.rightWrong == 1) {
console.log("e.rightWrong at line 356:", e);
setTimeout(() => {
if (!that.$refs.xTable) {
return;
}
if (this.dataForm.type == 1) {
that.$refs.xTable.setCheckboxRow(this.tableData[i], true);
that.selectData = that.$refs.xTable.getCheckboxRecords();
} else {
that.$refs.xTable.setRadioRow(this.tableData[i]);
that.selectRow = this.tableData[i];
}
}, 50);
}
});
}
this.clearRadioRowEevnt();
this.clearCheckboxEevnt();
this.$forceUpdate();
});
},
@@ -406,35 +412,58 @@ export default {
this.selectRow = null;
this.$refs.xTable.clearRadioRow();
},
getRowKey(row) {
if (!row) {
return "";
}
if (row.id !== undefined && row.id !== null && row.id !== "") {
return String(row.id);
}
return (
row._X_ROW_KEY ||
row._XID ||
row._X_ROW_ID ||
""
);
},
isSameOptionRow(rowA, rowB) {
if (!rowA || !rowB) {
return false;
}
if (rowA === rowB) {
return true;
}
const keyA = this.getRowKey(rowA);
const keyB = this.getRowKey(rowB);
return keyA && keyB && keyA === keyB;
},
getRadioEvent1() {
var selectIds = [];
let selectedRows = [];
if (this.dataForm.type == 0) {
var data = this.$refs.xTable.getRadioRecord();
console.log("data at line 402:", data);
if (data && (data.id || data._X_ROW_KEY)) {
selectIds.push(data.id || data._X_ROW_KEY);
console.log("selectIds.push at line 404:", selectIds);
const data =
(this.$refs.xTable && this.$refs.xTable.getRadioRecord()) ||
this.selectRow;
if (data) {
selectedRows = [data];
}
} else {
var data = this.$refs.xTable.getCheckboxRecords();
selectIds = data.map(e => {
return e.id || e._X_ROW_KEY;
});
console.log("selectIds at line 369:", selectIds);
const data =
(this.$refs.xTable && this.$refs.xTable.getCheckboxRecords()) ||
[];
selectedRows = data.length ? data : this.selectData;
}
var list = [...this.tableData];
list.map(e => {
const list = [...this.tableData];
list.forEach(e => {
e.rightWrong = 0;
});
if (selectIds.length > 0) {
list.map(e => {
if (selectIds.includes(e.id || e._X_ROW_KEY)) {
if (selectedRows.length > 0) {
list.forEach(e => {
if (selectedRows.some(row => this.isSameOptionRow(row, e))) {
e.rightWrong = 1;
}
});
}
console.log("list at line 428:", list);
return list;
},