diff --git a/CHANGELOG.md b/CHANGELOG.md index 676a5698..5a34d90a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 1.1.3 +**REFACTOR** + +- 重构: 判断vxe-table的复选框是否选中 + **Bug Fixes** - 节点树在编辑 & 空数组(不勾选)情况 勾选节点会造成watch延迟触发 导致会带上父节点id造成id重复 diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index b4cc88c0..e8735c90 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -107,6 +107,7 @@ export type * from '@vben/plugins/vxe-table'; /** * 通用的表格复选框是否选中事件 + * @deprecated 使用vxeCheckboxChecked代替 * @param checked 是否选中 * @returns function */ @@ -118,3 +119,14 @@ export function tableCheckboxEvent(checked: Ref) { }; return event; } + +/** + * 判断vxe-table的复选框是否选中 + * @param tableApi api + * @returns boolean + */ +export function vxeCheckboxChecked( + tableApi: ReturnType[1], +) { + return tableApi?.grid?.getCheckboxRecords?.()?.length > 0; +} diff --git a/apps/web-antd/src/views/monitor/logininfor/index.vue b/apps/web-antd/src/views/monitor/logininfor/index.vue index ddcd72fe..4923f966 100644 --- a/apps/web-antd/src/views/monitor/logininfor/index.vue +++ b/apps/web-antd/src/views/monitor/logininfor/index.vue @@ -9,8 +9,8 @@ import { getVxePopupContainer } from '@vben/utils'; import { Modal, Popconfirm, Space } from 'ant-design-vue'; import { - tableCheckboxEvent, useVbenVxeGrid, + vxeCheckboxChecked, type VxeGridDefines, type VxeGridProps, } from '#/adapter/vxe-table'; @@ -77,18 +77,15 @@ const gridOptions: VxeGridProps = { id: 'monitor-logininfo-index', }; -const checked = ref(false); const canUnlock = ref(false); const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions, gridEvents: { checkboxChange: (e: VxeGridDefines.CheckboxChangeEventParams) => { - const records = e.$table.getCheckboxRecords(); - checked.value = records.length > 0; + const records = e.$grid.getCheckboxRecords(); canUnlock.value = records.length === 1 && records[0]?.status === '1'; }, - checkboxAll: tableCheckboxEvent(checked), }, }); @@ -125,7 +122,6 @@ function handleMultiDelete() { onOk: async () => { await loginInfoRemove(ids); await tableApi.query(); - checked.value = false; }, }); } @@ -138,7 +134,6 @@ async function handleUnlock() { const { userName } = records[0]; await userUnlock(userName); await tableApi.query(); - checked.value = false; canUnlock.value = false; tableApi.grid.clearCheckboxRow(); } @@ -173,7 +168,7 @@ function handleDownloadExcel() { {{ $t('pages.common.export') }} = { id: 'monitor-operlog-index', }; -const checked = ref(false); const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions, @@ -96,8 +89,6 @@ const [BasicTable, tableApi] = useVbenVxeGrid({ sortChange: () => { tableApi.query(); }, - checkboxChange: tableCheckboxEvent(checked), - checkboxAll: tableCheckboxEvent(checked), }, }); @@ -138,7 +129,6 @@ async function handleDelete() { onOk: async () => { await operLogDelete(ids); await tableApi.query(); - checked.value = false; }, }); } @@ -148,6 +138,11 @@ function handleDownloadExcel() { fieldMappingTime: formOptions.fieldMappingTime, }); } + +function isChecked() { + console.log('触发'); + return tableApi?.grid?.getCheckboxRecords?.()?.length > 0; +}