一、删除最后一条数据跳转到上一页
js
/*
paginationOptions: {
currentPage: 1,
pageSize: 10,
total: 0,
},
*/
async function removeDone() {
this.wrapperLoading = true
const { name, uuid } = this.currentRow
const { success } = await removeAccount({ uuid })
this.wrapperLoading = false
if (success) {
this.$notify({
type: 'success',
message: `账号${name}删除成功`,
})
// 方案一: 判断是否为最后一条数据 并且总数据不能小于1
const { total, currentPage } = this.paginationOptions.currentPage
if (this.contactsData.length === 1 && total > 1) {
this.paginationOptions.currentPage = currentPage - 1
}
// 方案二:
/* let { currentPage,pageSize,total} = this.paginationOptions
//求删除后还有几页
let deleteAfterPage = Math.ceil((total - 1) / pageSize)
//若删除后页数小于当前页, 取删除后的页数;否则不变
let curPage = currentPage > deleteAfterPage ? deleteAfterPage : currentPage
//当前页只有一页则为1,否则取计算得到的页
this.paginationOptions.currentPage = curPage < 2 ? 1 : curPage */
this.queryAccount()
}
else {
this.$notify({
type: 'error',
message: `账号${name}删除失败`,
})
}
}