From 12c76d2bd7939af987360cf847694dfad7c99a77 Mon Sep 17 00:00:00 2001 From: likunming Date: Wed, 31 Jul 2024 18:00:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=91=E8=A1=A8=E6=A0=BC=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=B7=E6=96=B0=E5=90=8E=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E5=B1=95=E5=BC=80=E7=9A=84=E8=8A=82=E7=82=B9=E9=9C=80=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E5=B1=95=E5=BC=80=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/platform/components/grid/WGrid.vue | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue b/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue index 124be5a8..9055db11 100644 --- a/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue +++ b/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue @@ -882,7 +882,7 @@ const buttonObj = reactive({ const expandFun = (arr, treeExpand) => { arr.forEach((item) => { if (props.tree && item.children && item.children.length > 0) { - item.expand = !treeExpand; + item[rowDataExtraPropertyName.expand] = !treeExpand; expandFun(item.children, treeExpand); } }); @@ -1379,7 +1379,7 @@ const rowDbClick = (evt, row, index) => { } else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.clone.name) { clone(row); } else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.expand.name) { - row['expand'] = Tools.isEmpty(row['expand']) ? true : !row['expand']; + row[rowDataExtraPropertyName.expand] = Tools.isEmpty(row[rowDataExtraPropertyName.expand]) ? true : !row[rowDataExtraPropertyName.expand]; } else { view(); } @@ -1505,6 +1505,19 @@ const requestHandler = async (ops) => { }); return resp; }; + +const expandDatas = []; +const extractExpandStatus = (arr) => { + arr.forEach((item) => { + if (item[rowDataExtraPropertyName.expand]) { + expandDatas.push(item[props.primaryKey]); + } + if (item.children?.length > 0) { + extractExpandStatus(item.children); + } + }); +}; + const onRequest = async (ops: any) => { state.loading = true; const resp: any = await requestHandler(ops); @@ -1525,6 +1538,10 @@ const onRequest = async (ops: any) => { table.rows = []; } } else if (resp && resp.data && props.tree) { + if (!table.treeExpand && table.rows.length > 0) { + expandDatas.splice(0, expandDatas.length); + extractExpandStatus(toRaw(table.rows)); + } const responseData = resp.data; if (Array.isArray(responseData)) { state.pagination.rowsNumber = responseData.length; @@ -1579,8 +1596,12 @@ const initRowDataExtraProperty = (rowData) => { rowData[rowDataExtraPropertyName.rowKey] = Tools.uuid(); rowData[rowDataExtraPropertyName.ticked] = rowData[rowDataExtraPropertyName.ticked] || false; rowData[rowDataExtraPropertyName.selected] = rowData[rowDataExtraPropertyName.selected] || false; - if (props.tree && Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) { - rowData[rowDataExtraPropertyName.expand] = false; + if (props.tree) { + if (expandDatas.length > 0 && expandDatas.includes(rowData[props.primaryKey])) { + rowData[rowDataExtraPropertyName.expand] = true; + } else if (Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) { + rowData[rowDataExtraPropertyName.expand] = false; + } } }; /**