fix(ti): 修复新增触控项目异常
兼容功能字典未加载或字典项缺失的情况,避免读取空对象。 提交失败时保留表单内容,并增加重复提交保护。
This commit is contained in:
parent
a35b8a855c
commit
3d83ad7e47
@ -334,7 +334,7 @@
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
@ -425,6 +425,10 @@ const data = reactive({
|
||||
trademark: null,
|
||||
modelSpec: null,
|
||||
quantity: null,
|
||||
entrustUnit: null,
|
||||
productionUnit: null,
|
||||
sampleDate: null,
|
||||
productionDate: null,
|
||||
},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
@ -522,8 +526,10 @@ function reset() {
|
||||
trademark: null,
|
||||
modelSpec: null,
|
||||
quantity: null,
|
||||
status: null,
|
||||
remark: null,
|
||||
entrustUnit: null,
|
||||
productionUnit: null,
|
||||
sampleDate: null,
|
||||
productionDate: null,
|
||||
createBy: null,
|
||||
createTime: null,
|
||||
updateBy: null,
|
||||
@ -560,32 +566,39 @@ function handleAdd() {
|
||||
|
||||
|
||||
const formRef = ref();
|
||||
const submitForm = () => {
|
||||
if (!formRef.value) return;
|
||||
const submitting = ref(false);
|
||||
const submitForm = async () => {
|
||||
if (!formRef.value || submitting.value) return;
|
||||
|
||||
formRef.value.validate((valid) => {
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
form.value.testFuncIds = JSON.stringify(form.value.testFuncIds)
|
||||
if (isAdd.value) {
|
||||
addProject(form.value).then(res => {
|
||||
if (res.code === 200) {
|
||||
ElMessage.success("添加成功");
|
||||
getList();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
updateProject(form.value).then(res => {
|
||||
if (res.code === 200) {
|
||||
ElMessage.success("修改成功");
|
||||
getList();
|
||||
}
|
||||
})
|
||||
const valid = await formRef.value.validate().catch(() => false);
|
||||
if (!valid) return;
|
||||
|
||||
const testFuncIds = Array.isArray(form.value.testFuncIds)
|
||||
? form.value.testFuncIds
|
||||
: [];
|
||||
const payload = {
|
||||
...form.value,
|
||||
testFuncIds: JSON.stringify(testFuncIds),
|
||||
};
|
||||
|
||||
submitting.value = true;
|
||||
try {
|
||||
const res = isAdd.value
|
||||
? await addProject(payload)
|
||||
: await updateProject(payload);
|
||||
if (res.code !== 200) {
|
||||
ElMessage.error(res.msg || (isAdd.value ? "添加失败" : "修改失败"));
|
||||
return;
|
||||
}
|
||||
ElMessage.success(isAdd.value ? "添加成功" : "修改成功");
|
||||
open.value = false;
|
||||
reset();
|
||||
});
|
||||
getList();
|
||||
} catch (err) {
|
||||
console.error(isAdd.value ? "添加项目异常:" : "修改项目异常:", err);
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdate = (row) => {
|
||||
@ -593,7 +606,7 @@ const handleUpdate = (row) => {
|
||||
open.value = true;
|
||||
isAdd.value = false;
|
||||
title.value = "修改测试项目";
|
||||
form.value = row;
|
||||
form.value = { ...row };
|
||||
let arr = []
|
||||
try {
|
||||
arr = JSON.parse(form.value.testFuncIds);
|
||||
@ -644,24 +657,32 @@ const vehicleConfigChange = (value) => {
|
||||
getFuncList(value)
|
||||
}
|
||||
|
||||
const getFuncList = (value) => {
|
||||
getFunction({
|
||||
const getFuncList = async (value) => {
|
||||
if (!value) return;
|
||||
try {
|
||||
const res = await getFunction({
|
||||
pageNum: 1,
|
||||
pageSize: 10000,
|
||||
vehicleConfigId: value
|
||||
}).then((res) => {
|
||||
if (res.code === 200) {
|
||||
});
|
||||
if (res.code !== 200) {
|
||||
ElMessage.error(res.msg || "加载功能列表失败");
|
||||
return;
|
||||
}
|
||||
const dictItems = ti_function_config.value || [];
|
||||
funcIdOptions.value = (res.rows || []).map(item => {
|
||||
const label = ti_function_config.value.find(func => {
|
||||
return func.value === item.funcKey
|
||||
}).label
|
||||
const dictItem = dictItems.find(func => {
|
||||
return String(func.value) === String(item.funcKey)
|
||||
});
|
||||
return {
|
||||
label: label,
|
||||
label: dictItem?.label || item.funcKey || `功能 ${item.id}`,
|
||||
value: item.id
|
||||
};
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("加载功能列表异常:", err);
|
||||
ElMessage.error("网络异常,加载功能列表失败");
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const executeOpen = ref(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user