fix:路径图和项目编辑时原名字显示冲突问题

This commit is contained in:
wyx
2023-03-08 01:11:33 +08:00
parent 32601f080b
commit d78f47d795
3 changed files with 34 additions and 5 deletions

View File

@@ -5,12 +5,12 @@
:show-count="showCount" :show-count="showCount"
:maxlength="maxlength" :maxlength="maxlength"
/> />
<div style="color: red; font-size: 10px" v-if="modelV.value && validated===0"> <div style="color: red; font-size: 10px" v-if="modelV.value && validated===0 && isExistName">
名称重复请重新输入 名称重复请重新输入
</div> </div>
</template> </template>
<script setup> <script setup>
import {defineProps, defineEmits, watch, ref} from "vue"; import {defineProps, defineEmits, watch, ref, onMounted} from "vue";
import {validateName} from "@/api/index1"; import {validateName} from "@/api/index1";
import {Form} from "ant-design-vue"; import {Form} from "ant-design-vue";
@@ -39,7 +39,10 @@ const props = defineProps({
validated: { validated: {
type: Number, type: Number,
default: 0, default: 0,
} },
onceName: {
type: String,
},
}); });
const emit = defineEmits(["update:value",'update:validated']); const emit = defineEmits(["update:value",'update:validated']);
@@ -48,6 +51,8 @@ const modelV = ref({
value: props.value value: props.value
}); });
const isExistName = ref(true);
const rulesRef = ref({ const rulesRef = ref({
value: [{ value: [{
required: true, required: true,
@@ -60,7 +65,20 @@ const rulesRef = ref({
Form.useForm(modelV, rulesRef, { debounce: { wait: 800 } }); Form.useForm(modelV, rulesRef, { debounce: { wait: 800 } });
onMounted(() => {
if(props.onceName==modelV.value.value){
isExistName.value = false;
}else{
isExistName.value = true;
}
})
watch(props, () => { watch(props, () => {
if(props.onceName==modelV.value.value){
isExistName.value = false;
}else{
isExistName.value = true;
}
modelV.value.value = props.value; modelV.value.value = props.value;
}); });
@@ -74,7 +92,7 @@ async function validateValue() {
return Promise.reject("请输入名称"); return Promise.reject("请输入名称");
} }
return validateName({ name: modelV.value.value, type: props.type, id: props.id }).then(res => { return validateName({ name: modelV.value.value, type: props.type, id: props.id }).then(res => {
if (res.data.data === 1) { if (res.data.data === 1 && isExistName.value) {
emit("update:validated", 0); emit("update:validated", 0);
return Promise.reject("名称重复"); return Promise.reject("名称重复");
} }

View File

@@ -335,6 +335,7 @@
v-model:validated="validated" v-model:validated="validated"
:maxlength="20" :maxlength="20"
show-count show-count
:onceName="onceName"
:type="3" :type="3"
:id="editPathId" :id="editPathId"
></NameInput> ></NameInput>
@@ -824,6 +825,7 @@ export default {
// //
//创建、编辑------------------------- //创建、编辑-------------------------
pathName: "", //创建/编辑路径图名称 pathName: "", //创建/编辑路径图名称
onceName: "",
organizationList: [ organizationList: [
// { // {
// id: 1, // id: 1,
@@ -903,6 +905,7 @@ export default {
// console.log("打开创建路径弹窗"); // console.log("打开创建路径弹窗");
state.confirmLoading = false; state.confirmLoading = false;
state.pathName = ""; state.pathName = "";
state.onceName = "";
state.pathBg = ""; state.pathBg = "";
state.pathBgId = ""; state.pathBgId = "";
state.pathIntro = ""; state.pathIntro = "";
@@ -914,6 +917,7 @@ export default {
}; };
const handleOut1 = () => { const handleOut1 = () => {
state.pathName = ""; state.pathName = "";
state.onceName = "";
state.pathBg = ""; state.pathBg = "";
state.pathBgId = 1; state.pathBgId = 1;
state.organizationSelectName = null; state.organizationSelectName = null;
@@ -1532,6 +1536,7 @@ export default {
console.log("获取学习路径详情成功", res.data.data); console.log("获取学习路径详情成功", res.data.data);
let detail = res.data.data.routerInfo; let detail = res.data.data.routerInfo;
state.pathName = detail.name; state.pathName = detail.name;
state.onceName = detail.name;
state.pathBg = detail.picUrl; state.pathBg = detail.picUrl;
state.mobilePicUrl = detail.mobilePicUrl; state.mobilePicUrl = detail.mobilePicUrl;
state.pathBgId = ""; state.pathBgId = "";

View File

@@ -308,6 +308,7 @@
:type="1" :type="1"
:maxlength="30" :maxlength="30"
show-count show-count
:onceName="onceName"
:id="projectInfo.projectId" :id="projectInfo.projectId"
></NameInput> ></NameInput>
</div> </div>
@@ -1029,6 +1030,7 @@ export default {
currentPage1: 1, //项目经理分页 currentPage1: 1, //项目经理分页
pageSize1: 10, pageSize1: 10,
projectInfo: {}, projectInfo: {},
onceName:"",
projectClass: [], projectClass: [],
managerList: [], managerList: [],
managerLoading: false, managerLoading: false,
@@ -1102,7 +1104,7 @@ export default {
message.warning("项目名称重复,请修改名称!"); message.warning("项目名称重复,请修改名称!");
return; return;
} */ } */
const offName = await validateName({ const offName = state.projectInfo.name == state.onceName ? false : await validateName({
name: state.projectInfo.name, name: state.projectInfo.name,
type: 1, type: 1,
id: state.projectInfo.projectId, id: state.projectInfo.projectId,
@@ -1126,6 +1128,7 @@ export default {
// 取消按钮 清空输入的数据 // 取消按钮 清空输入的数据
const closeModal2 = () => { const closeModal2 = () => {
state.projectInfo = {}; state.projectInfo = {};
state.onceName = "";
// value1.value = ""; // value1.value = "";
// type = ""; // type = "";
// manager = ""; // manager = "";
@@ -1565,6 +1568,7 @@ export default {
if (record.type === 1 || record.type === 2) { if (record.type === 1 || record.type === 2) {
state.doublepro = true; state.doublepro = true;
state.projectInfo = record; state.projectInfo = record;
state.onceName = record.name;
} else { } else {
router.push({ router.push({
path: "/projectadd", path: "/projectadd",
@@ -1591,6 +1595,7 @@ export default {
}; };
const showModal1 = () => { const showModal1 = () => {
state.projectInfo = {}; state.projectInfo = {};
state.onceName = "";
state.estabish = true; state.estabish = true;
}; };
const closeModal1 = () => { const closeModal1 = () => {
@@ -1692,6 +1697,7 @@ export default {
systemId: record.systemId, systemId: record.systemId,
type: 2, type: 2,
}; };
state.onceName = "";
state.estabish = true; state.estabish = true;
} }