From 7eeecab824bbe88c640d8186bc7aa139629e9bd7 Mon Sep 17 00:00:00 2001 From: chenghuan Date: Wed, 20 May 2026 13:43:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=80=83=E8=AF=95=E6=A8=A1=E5=9D=97):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A2=98=E5=BA=93=E6=B7=BB=E5=8A=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=8F=8A=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对表格引用的检查,避免空引用错误 - 优化选择行的逻辑,确保正确处理单选和多选情况 - 引入行键获取和比较功能,提升行数据的处理准确性 - 清理冗余代码,增强代码可读性和维护性 --- .../course/examination/questionBank/add.vue | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/src/views/modules/course/examination/questionBank/add.vue b/src/views/modules/course/examination/questionBank/add.vue index 21714cc..f416f06 100644 --- a/src/views/modules/course/examination/questionBank/add.vue +++ b/src/views/modules/course/examination/questionBank/add.vue @@ -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; },