Fix handover expand toggle

This commit is contained in:
caoqianming 2026-07-28 15:39:54 +08:00
parent ac3dc576c2
commit e990c4e150
1 changed files with 7 additions and 4 deletions

View File

@ -13,7 +13,7 @@
<el-table v-bind="$attrs" :data="tableData" :row-key="rowKey || undefined" :key="toggleIndex" ref="scTable" <el-table v-bind="$attrs" :data="tableData" :row-key="rowKey || undefined" :key="toggleIndex" ref="scTable"
:height="height == 'auto' ? null : '100%'" :size="config.size" :border="config.border" :stripe="config.stripe" :height="height == 'auto' ? null : '100%'" :size="config.size" :border="config.border" :stripe="config.stripe"
:summary-method="remoteSummary ? remoteSummaryMethod : summaryMethod" :expand-row-keys="rowKey ? expandRowKeys : undefined" @sort-change="sortChange" :summary-method="remoteSummary ? remoteSummaryMethod : summaryMethod" :expand-row-keys="rowKey ? expandRowKeys : undefined" @sort-change="sortChange"
@filter-change="filterChange" @selection-change="selectionChange"> @filter-change="filterChange" @selection-change="selectionChange" @expand-change="handleExpandChange">
<slot></slot> <slot></slot>
<template v-for="(item, index) in userColumn" :key="index"> <template v-for="(item, index) in userColumn" :key="index">
<el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop" <el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop"
@ -562,16 +562,19 @@ export default {
}, },
// / // /
toggleExpandAll() { toggleExpandAll() {
const isExpandAll = this.expandRowKeys.length === this.$refs.scTable.data.length; const rows = this.tableData || [];
const key = this.rowKey || "id";
const isExpandAll = rows.length > 0 && rows.every(item => this.expandRowKeys.includes(item[key]));
if (isExpandAll) { if (isExpandAll) {
this.expandRowKeys = []; // this.expandRowKeys = []; //
} else { } else {
this.expandRowKeys = this.$refs.scTable.data.map(item => item.id); // this.expandRowKeys = rows.map(item => item[key]); //
} }
}, },
// expandRowKeys // expandRowKeys
handleExpandChange(row, expandedRows) { handleExpandChange(row, expandedRows) {
this.expandRowKeys = expandedRows.map(row => row.is); // const key = this.rowKey || "id";
this.expandRowKeys = expandedRows.map(item => item[key]); //
} }
}, },
}; };