gaoluyang
2026-05-14 a8d694d5d987892afee5a1bb8f6c01d612e6b2a3
src/components/PIMTable/PIMTable.vue
@@ -14,6 +14,10 @@
            :expand-row-keys="expandRowKeys"
            :show-summary="isShowSummary"
            :summary-method="summaryMethod"
            :default-expand-all="defaultExpandAll"
            :tree-props="treeProps"
            :lazy="lazy"
            :load="load"
            @row-click="rowClick"
            @current-change="currentChange"
            @selection-change="handleSelectionChange"
@@ -316,6 +320,22 @@
      type: [String, Object],
      default: () => ({ width: "100%" }),
    },
    defaultExpandAll: {
      type: Boolean,
      default: false,
    },
    treeProps: {
      type: Object,
      default: () => ({ children: "children", hasChildren: "hasChildren" }),
    },
    lazy: {
      type: Boolean,
      default: false,
    },
    load: {
      type: Function,
      default: null,
    },
  });
  const mergedHeaderCellStyle = computed(() => ({
@@ -326,6 +346,7 @@
  }));
  // Data
  const multipleTable = ref(null);
  const uploadRefs = ref([]);
  const currentFiles = ref({});
  const uploadKeys = ref({});
@@ -499,6 +520,44 @@
  const handleSelectionChange = newSelection => {
    emit("selection-change", newSelection);
  };
  // 展开/折叠树形节点
  const toggleRowExpansion = (row, expanded) => {
    multipleTable.value?.toggleRowExpansion(row, expanded);
  };
  // 展开所有树形节点
  const expandAll = () => {
    const expandRows = (rows) => {
      rows?.forEach(row => {
        if (row[props.treeProps.children]?.length > 0) {
          multipleTable.value?.toggleRowExpansion(row, true);
          expandRows(row[props.treeProps.children]);
        }
      });
    };
    expandRows(props.tableData);
  };
  // 折叠所有树形节点
  const collapseAll = () => {
    const collapseRows = (rows) => {
      rows?.forEach(row => {
        if (row[props.treeProps.children]?.length > 0) {
          collapseRows(row[props.treeProps.children]);
          multipleTable.value?.toggleRowExpansion(row, false);
        }
      });
    };
    collapseRows(props.tableData);
  };
  defineExpose({
    toggleRowExpansion,
    expandAll,
    collapseAll,
    multipleTable
  });
</script>
<style scoped lang="scss">