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: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning", type: "warning",
}).then(() => { }).then(
DeptAPI.deleteByIds(deptIds).then(() => { () => {
loading.value = true;
DeptAPI.deleteByIds(deptIds)
.then(() => {
ElMessage.success("删除成功"); ElMessage.success("删除成功");
handleResetQuery(); handleResetQuery();
}); })
}); .finally(() => (loading.value = false));
},
() => {
ElMessage.info("已取消删除");
}
);
} }
/** 关闭弹窗 */ /** 关闭弹窗 */

View File

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

View File

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

View File

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

View File

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