mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-11 16:57:09 +08:00
fix: 修复清空最后一页数据后列表空白,分页条消失的问题
This commit is contained in:
@@ -65,14 +65,21 @@ export function useTable<T extends U, U = T>(api: Api<T>, options?: Options<T, U
|
|||||||
// 删除
|
// 删除
|
||||||
const handleDelete = async <T>(
|
const handleDelete = async <T>(
|
||||||
deleteApi: () => Promise<ApiRes<T>>,
|
deleteApi: () => Promise<ApiRes<T>>,
|
||||||
options?: { title?: string, content?: string, successTip?: string, showModal?: boolean },
|
options?: { title?: string, content?: string, successTip?: string, showModal?: boolean, multiple?: boolean },
|
||||||
): Promise<boolean | undefined> => {
|
): Promise<boolean | undefined> => {
|
||||||
const onDelete = async () => {
|
const onDelete = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await deleteApi()
|
const res = await deleteApi()
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
|
// 计算新总页数
|
||||||
|
const deleteNum = options?.multiple ? selectedKeys.value.length : 1
|
||||||
|
const totalPage = Math.ceil((pagination.total - deleteNum) / pagination.pageSize)
|
||||||
|
// 修正当前页码
|
||||||
|
if (pagination.current > totalPage) {
|
||||||
|
pagination.current = totalPage > 0 ? totalPage : 1
|
||||||
|
}
|
||||||
|
options?.multiple && (selectedKeys.value = [])
|
||||||
Message.success(options?.successTip || '删除成功')
|
Message.success(options?.successTip || '删除成功')
|
||||||
selectedKeys.value = []
|
|
||||||
await getTableData()
|
await getTableData()
|
||||||
}
|
}
|
||||||
return res.success
|
return res.success
|
||||||
|
@@ -114,7 +114,7 @@ const onDelete = () => {
|
|||||||
if (!selectedKeys.value.length) {
|
if (!selectedKeys.value.length) {
|
||||||
return Message.warning('请选择数据')
|
return Message.warning('请选择数据')
|
||||||
}
|
}
|
||||||
return handleDelete(() => deleteMessage(selectedKeys.value), { showModal: false })
|
return handleDelete(() => deleteMessage(selectedKeys.value), { showModal: false, multiple: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记为已读
|
// 标记为已读
|
||||||
|
Reference in New Issue
Block a user