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