作者 dong

资料管理删除按钮

<template>
<div>
<!--引用表格-->
<BasicTable @register="registerTable" :rowSelection="rowSelection" @change="handleTableChange">
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<!--插槽:table标题-->
<template #tableTitle>
<a-button type="primary" v-auth="'embeddings:embeddings:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
... ... @@ -162,7 +162,7 @@
success: handleSuccess,
},
});
const [registerTable, { reload, setPagination }, { rowSelection, selectedRowKeys }] = tableContext;
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
// 高级查询配置
const superQueryConfig = reactive(superQuerySchema);
... ... @@ -214,43 +214,14 @@
* 删除事件
*/
async function handleDelete(record) {
resetPaginationAfterDelete();
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
resetPaginationAfterDelete();
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
// 新增:删除操作后重置分页状态
function resetPaginationAfterDelete() {
// 获取当前分页状态
const currentPagination = pagination.value;
// 计算删除后总页数
const totalPages = Math.ceil((currentPagination.total - 1) / currentPagination.pageSize);
// 如果当前页码大于总页数,则回到最后一页
if (currentPagination.current > totalPages && totalPages > 0) {
pagination.value = {
...currentPagination,
current: totalPages,
total: currentPagination.total - 1,
};
} else {
// 否则保持当前页,但更新总数
pagination.value = {
...currentPagination,
total: currentPagination.total - 1,
};
}
// 设置表格分页状态
setPagination(pagination.value);
}
/**
* 成功回调
*/
... ...