fix: 【antd】修复添加批量删除时产生的副作用

This commit is contained in:
puhui999
2025-06-15 21:09:40 +08:00
parent 2939c2e4f5
commit 0d411310fe
16 changed files with 281 additions and 315 deletions

View File

@@ -2,8 +2,6 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemOAuth2TokenApi } from '#/api/system/oauth2/token';
import { ref } from 'vue';
import { DocAlert, Page } from '@vben/common-ui';
import { message } from 'ant-design-vue';
@@ -11,7 +9,6 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteOAuth2Token,
deleteOAuth2TokenList,
getOAuth2TokenPage,
} from '#/api/system/oauth2/token';
import { $t } from '#/locales';
@@ -41,41 +38,6 @@ async function handleDelete(row: SystemOAuth2TokenApi.OAuth2Token) {
}
}
// 选中的令牌ID
const checkedAccessTokens = ref<string[]>([]);
/** 处理表格选择变化 */
function handleSelectionChange({
selectRecords,
}: {
selectRecords: SystemOAuth2TokenApi.OAuth2Token[];
}) {
checkedAccessTokens.value = selectRecords.map((row) => row.accessToken);
}
/** 批量删除处理 */
async function handleDeleteBatch() {
if (checkedAccessTokens.value.length === 0) {
message.warning('请至少选择一条数据');
return;
}
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', ['令牌']),
key: 'action_key_msg',
});
try {
await deleteOAuth2TokenList(checkedAccessTokens.value);
message.success({
content: $t('ui.actionMessage.deleteSuccess', ['令牌']),
key: 'action_key_msg',
});
checkedAccessTokens.value = [];
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -101,18 +63,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
toolbarConfig: {
refresh: { code: 'query' },
search: true,
slots: {
buttons: 'toolbar_buttons',
},
},
checkboxConfig: {
checkField: 'checked',
trigger: 'row',
highlight: true,
range: true,
},
events: {
checkboxChange: handleSelectionChange,
},
} as VxeTableGridOptions<SystemOAuth2TokenApi.OAuth2Token>,
});
@@ -128,20 +78,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
</template>
<Grid table-title="令牌列表">
<template #toolbar_buttons>
<a-button
v-auth="['system:oauth2-token:delete']"
type="primary"
danger
:disabled="checkedAccessTokens.length === 0"
@click="handleDeleteBatch"
>
<template #icon>
<component :is="ACTION_ICON.DELETE" />
</template>
批量强退
</a-button>
</template>
<template #actions="{ row }">
<TableAction
:actions="[