fix: 批量删除问题修复

This commit is contained in:
haoxr 2023-03-13 23:08:24 +08:00
parent abc0fb7efc
commit 81be6da082
6 changed files with 40 additions and 34 deletions

View File

@ -20,7 +20,7 @@ const queryFormRef = ref(ElForm);
const deptFormRef = ref(ElForm);
const loading = ref(false);
let ids = reactive([]);
const ids = ref<number[]>([]);
const dialog = reactive<DialogOption>({
visible: false
});
@ -65,7 +65,7 @@ function resetQuery() {
* 行复选框选中记录选中ID集合
*/
function handleSelectionChange(selection: any) {
ids = selection.map((item: any) => item.id);
ids.value = selection.map((item: any) => item.id);
}
/**
@ -133,10 +133,11 @@ function handleSubmit() {
}
/**
* 删除
* 删除部门
*/
function handleDelete(row: any) {
const deptIds = [row.id || ids].join(',');
function handleDelete(deptId?: number) {
const deptIds = [deptId || ids.value].join(',');
if (!deptIds) {
ElMessage.warning('请勾选删除项');
return;
@ -146,18 +147,12 @@ function handleDelete(row: any) {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteDept(deptIds)
.then(() => {
handleQuery();
ElMessage.success('删除成功');
})
.catch(() => {
ElMessage.error('删除失败');
});
})
.catch(() => ElMessage.warning('已取消删除'));
}).then(() => {
deleteDept(deptIds).then(() => {
ElMessage.success('删除成功');
resetQuery();
});
});
}
/**
@ -218,14 +213,13 @@ onMounted(() => {
</div>
<el-card>
<!--toolbar-->
<template #header>
<el-button type="success" @click="openDialog(0, undefined)"
><i-ep-plus />新增</el-button
>
<el-button
type="danger"
@click="handleDelete"
@click="handleDelete()"
:disabled="ids.length === 0"
><i-ep-delete />删除
</el-button>

View File

@ -162,13 +162,18 @@ function resetForm() {
/**
* 删除字典
*/
function handleDelete(dictId: number) {
function handleDelete(dictId?: number) {
const dictIds = [dictId || ids.value].join(',');
if (!dictIds) {
ElMessage.warning('请勾选删除项');
return;
}
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const dictIds = [dictId || ids.value].join(',');
deleteDict(dictIds).then(() => {
ElMessage.success('删除成功');
resetQuery();
@ -209,7 +214,7 @@ onMounted(() => {
<el-button
type="danger"
:disabled="ids.length === 0"
@click="handleDelete"
@click="handleDelete()"
><i-ep-delete />删除</el-button
>
</template>

View File

@ -71,8 +71,6 @@ function resetQuery() {
/**
* 行checkbox change事件
*
* @param selection
*/
function handleSelectionChange(selection: any) {
ids.value = selection.map((item: any) => item.id);
@ -146,13 +144,18 @@ function resetForm() {
/**
* 删除字典类型
*/
function handleDelete(dictTypeId: number) {
function handleDelete(dictTypeId?: number) {
const dictTypeIds = [dictTypeId || ids.value].join(',');
if (!dictTypeIds) {
ElMessage.warning('请勾选删除项');
return;
}
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const dictTypeIds = [dictTypeId || ids.value].join(',');
deleteDictTypes(dictTypeIds).then(() => {
ElMessage.success('删除成功');
resetQuery();
@ -219,7 +222,7 @@ onMounted(() => {
<el-button
type="danger"
:disabled="ids.length === 0"
@click="handleDelete"
@click="handleDelete()"
><i-ep-delete />删除</el-button
>
</template>

View File

@ -104,7 +104,6 @@ function openDialog(parentId?: number, menuId?: number) {
.then(() => {
dialog.visible = true;
if (menuId) {
//
dialog.title = '编辑菜单';
getMenuForm(menuId).then(({ data }) => {
Object.assign(formData, data);
@ -112,7 +111,6 @@ function openDialog(parentId?: number, menuId?: number) {
menuCacheData.path = data.path ?? '';
});
} else {
//
dialog.title = '新增菜单';
formData.parentId = parentId;
}
@ -160,6 +158,7 @@ function submitForm() {
*/
function handleDelete(menuId: number) {
if (!menuId) {
ElMessage.warning('请勾选删除项');
return false;
}

View File

@ -160,13 +160,18 @@ function resetForm() {
/**
* 删除
*/
function handleDelete(roleId: number) {
function handleDelete(roleId?: number) {
const roleIds = [roleId || ids.value].join(',');
if (!roleIds) {
ElMessage.warning('请勾选删除项');
return;
}
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const roleIds = [roleId || ids.value].join(',');
loading.value = true;
deleteRoles(roleIds)
.then(() => {

View File

@ -258,8 +258,8 @@ function handleSubmit() {
/**
* 删除用户
*/
function handleDelete(id: number) {
const userIds = ([id] || ids.value).join(',');
function handleDelete(id?: number) {
const userIds = [id || ids.value].join(',');
if (!userIds) {
ElMessage.warning('请勾选删除项');
return;
@ -459,7 +459,7 @@ onMounted(() => {
<el-button
type="danger"
:disabled="ids.length === 0"
@click="handleDelete"
@click="handleDelete()"
v-hasPerm="['sys:user:delete']"
><i-ep-delete />删除</el-button
>