From 2af9451b7fabed90f46e3a687573c33849103da1 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Tue, 24 Sep 2024 22:38:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90issues/7217=E3=80=91BasicTable?= =?UTF-8?q?=E6=A0=91=E5=BD=A2=E8=A1=A8=E6=A0=BC=E8=AE=BE=E7=BD=AEcheckStri?= =?UTF-8?q?ctly=E6=97=A0=E6=95=88=20---=20=E3=80=90issues/7200=E3=80=91bas?= =?UTF-8?q?icTable=E9=80=89=E4=B8=AD=E5=90=8E=E6=B2=A1=E6=9C=89=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E6=A0=B7=E5=BC=8F=20---?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Table/src/hooks/useCustomSelection.tsx | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/jeecgboot-vue3/src/components/Table/src/hooks/useCustomSelection.tsx b/jeecgboot-vue3/src/components/Table/src/hooks/useCustomSelection.tsx index dbe04996..e6a996e9 100644 --- a/jeecgboot-vue3/src/components/Table/src/hooks/useCustomSelection.tsx +++ b/jeecgboot-vue3/src/components/Table/src/hooks/useCustomSelection.tsx @@ -43,6 +43,8 @@ export function useCustomSelection( let changeRows: Recordable[] = []; let allSelected: boolean = false; + let timer; + // 扁平化数据,children数据也会放到一起 const flattedData = computed(() => { // update-begin--author:liaozhiyang---date:20231016---for:【QQYUN-6774】解决checkbox禁用后全选仍能勾选问题 @@ -122,7 +124,7 @@ export function useCustomSelection( selectedLength: flattedData.value.filter((data) => selectedKeys.value.includes(getRecordKey(data))).length, // update-begin--author:liaozhiyang---date:20240511---for:【QQYUN-9289】解决表格条数不足pageSize数量时行数全部勾选但是全选框不勾选 // 【TV360X-53】为空时会报错,加强判断 - pageSize: tableData.value?.length ?? 0, + pageSize: flattedData.value?.length ?? 0, // update-end--author:liaozhiyang---date:20240511---for:【QQYUN-9289】解决表格条数不足pageSize数量时行数全部勾选但是全选框不勾选 // 【QQYUN-6774】解决checkbox禁用后全选仍能勾选问题 disabled: flattedData.value.length == 0, @@ -317,6 +319,7 @@ export function useCustomSelection( function onSelect(record, checked) { onSelectChild(record, checked); updateSelected(record, checked); + onSelectParent(record, checked); emitChange(); } @@ -339,6 +342,12 @@ export function useCustomSelection( selectedRows.value.splice(index, 1); } } + // update-begin--author:liaozhiyang---date:20240919---for:【issues/7200】basicTable选中后没有选中样式 + clearTimeout(timer); + timer = setTimeout(() => { + selectedKeys.value = [...selectedKeys.value]; + }, 0); + // update-end--author:liaozhiyang---date:20240919---for:【issues/7200】basicTable选中后没有选中样式 } // 调用用户自定义的onChange事件 @@ -372,7 +381,7 @@ export function useCustomSelection( * @param checked */ function onSelectChild(record, checked) { - if (unref(propsRef)?.isTreeTable && unref(propsRef)?.rowSelection?.checkStrictly && !isRadio.value) { + if (unref(propsRef)?.isTreeTable && unref(propsRef)?.rowSelection?.checkStrictly === false && !isRadio.value) { if (record[childrenColumnName.value] && record[childrenColumnName.value].length > 0) { record[childrenColumnName.value].forEach((children) => { updateSelected(children, checked); @@ -384,6 +393,59 @@ export function useCustomSelection( } } // update-end--author:liusq---date:20240819---for:树形表格设置层级关联不生效 + /** + * 2024-09-24 + * liaozhiyang + * 层级关联时,选中上级数据 + * 【issues/7217】BasicTable树形表格设置checkStrictly无效 + * */ + function onSelectParent(record, checked) { + if (unref(propsRef)?.isTreeTable && unref(propsRef)?.rowSelection?.checkStrictly === false && !isRadio.value) { + let condition = true, + currentRecord = record; + while (condition) { + const parentRecord: any = findParent(tableData.value, currentRecord, childrenColumnName.value); + if (parentRecord) { + const childrenRecordKeys: any = []; + parentRecord[childrenColumnName.value].forEach((item) => { + childrenRecordKeys.push(getRecordKey(item)); + }); + if (checked === true) { + const isSubSet = childrenRecordKeys.every((item) => selectedKeys.value.includes(item)); + isSubSet && updateSelected(parentRecord, checked); + } else if (checked === false) { + updateSelected(parentRecord, checked); + } + if (tableData.value.find((item) => getRecordKey(item) === getRecordKey(parentRecord))) { + // 循环终止 + condition = false; + } else { + currentRecord = parentRecord; + } + } else { + // 循环终止 + condition = false; + } + } + } + function findParent(tree, record, children = 'children') { + let parent = null; + function search(nodes) { + for (let node of nodes) { + if (node[children]?.some((child) => getRecordKey(child) === getRecordKey(record))) { + parent = node; + return true; + } + if (node[children] && search(node[children])) { + return true; + } + } + return false; + } + search(tree); + return parent; + } + } // 用于判断是否是自定义选择列 function isCustomSelection(column: BasicColumn) { return column.key === CUS_SEL_COLUMN_KEY;