修改分组页面,新增名称重复校验以及查询的bug

This commit is contained in:
wyt
2025-09-03 10:35:39 +08:00
parent fc40d2e408
commit 981da72495
2 changed files with 129 additions and 96 deletions

View File

@@ -1,6 +1,6 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px" @submit.prevent>
<el-form-item label="分组名称" prop="groupName">
<el-input
v-model="queryParams.groupName"
@@ -20,7 +20,7 @@
</el-radio-group>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button type="primary" icon="Search" @click="handleQuery" native-type="button"> 搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
@@ -256,38 +256,71 @@ async function handleUpdate(row) {
})
}
/** 提交按钮 */
// function submitForm() {
// proxy.$refs["group_managementRef"].validate(valid => {
// if (valid) {
// // 新增:计算祖先路径
// if (form.value.parentId === 0) {
// form.value.ancestors = "0"
// } else {
// const parentNode = findNode(group_managementOptions.value, form.value.parentId)
// if (parentNode) {
// form.value.ancestors = `${parentNode.ancestors},${parentNode.groupId}`
// } else {
// // 找不到父节点时使用默认值
// form.value.ancestors = "0"
// }
// }
// if (form.value.groupId != null) {
// updateGroup_management(form.value).then(response => {
// proxy.$modal.msgSuccess("修改成功")
// open.value = false
// getList()
// })
// } else {
// addGroup_management(form.value).then(response => {
// proxy.$modal.msgSuccess("新增成功")
// open.value = false
// getList()
// })
// }
// }
// })
// }
/** 提交按钮 */
function submitForm() {
proxy.$refs["group_managementRef"].validate(valid => {
if (valid) {
// 新增:计算祖先路径
if (form.value.parentId === 0) {
form.value.ancestors = "0"
} else {
const parentNode = findNode(group_managementOptions.value, form.value.parentId)
if (parentNode) {
form.value.ancestors = `${parentNode.ancestors},${parentNode.groupId}`
} else {
// 找不到父节点时使用默认值
form.value.ancestors = "0"
}
}
if (!valid) return;
if (form.value.groupId != null) {
updateGroup_management(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功")
open.value = false
getList()
})
} else {
addGroup_management(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功")
open.value = false
getList()
})
}
// 计算祖先路径
if (form.value.parentId === 0) {
form.value.ancestors = "0";
} else {
const parentNode = findNode(group_managementOptions.value, form.value.parentId);
form.value.ancestors = parentNode
? `${parentNode.ancestors},${parentNode.groupId}`
: "0";
}
})
const request = form.value.groupId != null
? updateGroup_management(form.value)
: addGroup_management(form.value);
request
.then(() => {
proxy.$modal.msgSuccess(form.value.groupId ? "修改成功" : "新增成功");
open.value = false;
getList();
})
.catch(error => {
// ✅ 后端返回的错误信息
const msg = error?.response?.data?.msg || "操作失败";
proxy.$modal.msgError(msg);
});
});
}
/** 删除按钮操作 */