From 5fcacfaa4663e0717c910d6116e18f0ef1b1956c Mon Sep 17 00:00:00 2001 From: luojie <125330818@qq.com> Date: Thu, 5 Mar 2026 16:12:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:[=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86][upd?= =?UTF-8?q?ate]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Template/CustomTable.vue | 109 +++++++++++----- .../business/comps/template/comps/sp/SP00456.vue | 143 +++++++++++---------- 2 files changed, 151 insertions(+), 101 deletions(-) diff --git a/src/components/Template/CustomTable.vue b/src/components/Template/CustomTable.vue index b0f06c0..e3c3a69 100644 --- a/src/components/Template/CustomTable.vue +++ b/src/components/Template/CustomTable.vue @@ -6,9 +6,10 @@
序号
-
+
- +
{{ rowIndex + 1 }}
-
+
- +
+ - +
@@ -296,6 +293,12 @@ export default { type: Boolean, default: true, }, + // 是否显示全选 + showCheckAll: { + type: Boolean, + default: false, + }, + // 是否显示排序 showSort: { type: Boolean, default: false, @@ -311,6 +314,9 @@ export default { oldLocalDataSource: [], uuid: getuuid(), isRegent, + selectedRows: [], // 存储选中的行 + isIndeterminate: false, // 半选状态 + checkAll: false, // 全选状态 } }, watch: { @@ -348,7 +354,6 @@ export default { this.justUpdateFilledFormData(); }, onCheckboxTagChange(rowIndex, colIndex, col, value) { - console.log(value,"vvv") // value 现在是整个数组 this.localDataSource[rowIndex][col.prop] = value; // 根据校验规则判断是否清除错误状态 @@ -836,7 +841,11 @@ export default { updateDataSource(dataSource = []) { this.oldLocalDataSource = JSON.parse(JSON.stringify(this.localDataSource)); // 深拷贝数据以避免直接修改原始数据 - this.localDataSource = JSON.parse(JSON.stringify(dataSource || [])); + this.localDataSource = JSON.parse(JSON.stringify(dataSource || [])).map(row => ({ + ...row, + _checked: false // 初始化选中状态为 false + })); + this.updateCheckStatus(); this.checkCompareToOnDataLoad(); }, // 根据行索引更新数据 autoUpdateRecord 是否自动更新记录 @@ -862,7 +871,7 @@ export default { return true; }, // 只是更新已填写的表单数据,不触发校验 - justUpdateFilledFormData(){ + justUpdateFilledFormData() { const params = { type: "fieldChanged", newRecord: null, @@ -870,6 +879,32 @@ export default { } EventBus.$emit('onModifyRecord', params,) }, + // 处理全选 + handleCheckAllChange(val) { + this.localDataSource.forEach(row => { + row._checked = val; + }); + this.updateCheckStatus(); + this.$emit('selectionChange', this.selectedRows); + }, + // 处理单个 checkbox 变化 + handleCheckChange(row, val) { + row._checked = val; + this.updateCheckStatus(); + this.$emit('selectionChange', this.selectedRows); + }, + // 更新选中状态和半选状态 + updateCheckStatus() { + const totalRows = this.localDataSource.length; + const checkedRows = this.localDataSource.filter(row => row._checked).length; + this.checkAll = checkedRows === totalRows && totalRows > 0; + this.isIndeterminate = checkedRows > 0 && checkedRows < totalRows; + // 记录选中的行数据和对应的行索引 + this.selectedRows = this.localDataSource.map((row, rowIndex) => ({ + ...row, + rowIndex + })).filter(item => item._checked); + }, onAddRow() { if (this.$listeners && this.$listeners['onAddRow']) { this.$emit('onAddRow'); @@ -886,10 +921,18 @@ export default { // 添加行 addRow(row = {}) { - this.localDataSource.push(row); + this.localDataSource.push({ + ...row, + _checked: false // 初始化选中状态为 false + }); + this.updateCheckStatus(); }, addRows(rows = []) { - this.localDataSource.push(...rows); + this.localDataSource.push(...rows.map(row => ({ + ...row, + _checked: false // 初始化选中状态为 false + }))); + this.updateCheckStatus(); }, getDataSource() { return this.localDataSource; @@ -1166,7 +1209,7 @@ export default { .flex-wrap { flex-wrap: wrap; - gap:10px; + gap: 10px; } .row-error-border { @@ -1175,13 +1218,15 @@ export default { border-radius: 4px; border: 1px solid #ff5d5d; } -.checkbox-item{ + +.checkbox-item { /* width: 50px; */ display: flex; align-items: center; justify-content: center; } -.c-cell{ + +.c-cell { width: 50px; } \ No newline at end of file diff --git a/src/views/business/comps/template/comps/sp/SP00456.vue b/src/views/business/comps/template/comps/sp/SP00456.vue index 6b27430..ee2008b 100644 --- a/src/views/business/comps/template/comps/sp/SP00456.vue +++ b/src/views/business/comps/template/comps/sp/SP00456.vue @@ -16,33 +16,36 @@
{{ $t('template.common.xzpxpz') - }} + }} {{ $t('template.common.xzjtpz') - }} + }}
-
+
{{ $t('template.common.jtpz') }}
{{ $t('template.common.deleteBtn') - }} + @click="deleteConfig('ladderConfigs', ladderConfig)">{{ + $t('template.common.deleteBtn') + }}