refactor: ♻️ 删除优化 loading 和取消删除

This commit is contained in:
hxr
2024-06-25 22:02:57 +08:00
parent f023808450
commit 1dcd4ab0cd
5 changed files with 73 additions and 39 deletions

View File

@@ -283,12 +283,20 @@ function handleDelete(deptId?: number) {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
DeptAPI.deleteByIds(deptIds).then(() => {
ElMessage.success("删除成功");
handleResetQuery();
});
});
}).then(
() => {
loading.value = true;
DeptAPI.deleteByIds(deptIds)
.then(() => {
ElMessage.success("删除成功");
handleResetQuery();
})
.finally(() => (loading.value = false));
},
() => {
ElMessage.info("已取消删除");
}
);
}
/** 关闭弹窗 */

View File

@@ -30,7 +30,7 @@
<el-button
type="danger"
:disabled="ids.length === 0"
@click="handleDeleteClick()"
@click="handleDelete()"
><i-ep-delete />删除</el-button
>
</div>
@@ -75,7 +75,7 @@
type="danger"
link
size="small"
@click.stop="handleDeleteClick(scope.row.id)"
@click.stop="handleDelete(scope.row.id)"
><i-ep-delete />删除</el-button
>
</template>
@@ -333,7 +333,7 @@ function handleCloseDialog() {
*
* @param id 字典ID
*/
function handleDeleteClick(id?: number) {
function handleDelete(id?: number) {
const attrGroupIds = [id || ids.value].join(",");
if (!attrGroupIds) {
ElMessage.warning("请勾选删除项");
@@ -343,12 +343,17 @@ function handleDeleteClick(id?: number) {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
DictAPI.deleteByIds(attrGroupIds).then(() => {
ElMessage.success("删除成功");
handleResetClick();
});
});
}).then(
() => {
DictAPI.deleteByIds(attrGroupIds).then(() => {
ElMessage.success("删除成功");
handleResetClick();
});
},
() => {
ElMessage.info("已取消删除");
}
);
}
// 新增字典

View File

@@ -592,14 +592,22 @@ function handleDelete(menuId: number) {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
MenuAPI.deleteById(menuId).then(() => {
ElMessage.success("删除成功");
handleQuery();
});
})
.catch(() => ElMessage.info("已取消删除"));
}).then(
() => {
loading.value = true;
MenuAPI.deleteById(menuId)
.then(() => {
ElMessage.success("删除成功");
handleQuery();
})
.finally(() => {
loading.value = false;
});
},
() => {
ElMessage.info("已取消删除");
}
);
}
// 关闭弹窗

View File

@@ -363,15 +363,20 @@ function handleDelete(roleId?: number) {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
loading.value = true;
RoleAPI.deleteByIds(roleIds)
.then(() => {
ElMessage.success("删除成功");
handleResetQuery();
})
.finally(() => (loading.value = false));
});
}).then(
() => {
loading.value = true;
RoleAPI.deleteByIds(roleIds)
.then(() => {
ElMessage.success("删除成功");
handleResetQuery();
})
.finally(() => (loading.value = false));
},
() => {
ElMessage.info("已取消删除");
}
);
}
/** 打开分配菜单权限弹窗 */

View File

@@ -375,7 +375,7 @@ function handleResetQuery() {
handleQuery();
}
/** 行选中 */
/** 行复选框选中记录选中ID集合 */
function handleSelectionChange(selection: any) {
removeIds.value = selection.map((item: any) => item.id);
}
@@ -472,12 +472,20 @@ function handleDelete(id?: number) {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(function () {
UserAPI.deleteByIds(userIds).then(() => {
ElMessage.success("删除成功");
handleResetQuery();
});
});
}).then(
function () {
loading.value = true;
UserAPI.deleteByIds(userIds)
.then(() => {
ElMessage.success("删除成功");
handleResetQuery();
})
.finally(() => (loading.value = false));
},
function () {
ElMessage.info("已取消删除");
}
);
}
/** 打开导入弹窗 */
function handleOpenImportDialog() {