This commit is contained in:
sjl
2024-12-11 20:24:00 +08:00
parent 2459fc1848
commit 47883ce426
3 changed files with 71 additions and 80 deletions

View File

@@ -37,7 +37,7 @@ export namespace Plan {
scriptName: string ;
errorSysName: string;
sourceName: string ;
devIds:string[];
devIds: string[];
}

View File

@@ -92,7 +92,7 @@
const pqSourceList=ref<TestSource.ResTestSource[]>([])//获取指定模式下所有检测源
const pqScriptList=ref<TestScript.ResTestScript[]>([])//获取指定模式下所有检测源
const pqErrSysList=ref<ErrorSystem.ErrorSystemList[]>([])//获取指定模式下所有检测源
const pqDevList=ref<Device.ResPqDev[]>([])//获取指定模式下所有检测源
const pqSourceArray = ref<{ label: string; value: string; }[]>()
const pqScriptArray = ref<{ label: string; value: string; }[]>()
@@ -101,7 +101,7 @@
function useMetaInfo() {
const dialogVisible = ref(false)
const titleType = ref('add')
const formContent = ref<Plan.ReqPlan>({
const formContent = reactive<Plan.ReqPlan>({
id:'',
planId:'',
name: '',
@@ -130,7 +130,8 @@
// 清空formContent
const resetFormContent = () => {
formContent.value = {
Object.assign(
formContent,{
id:'',
planId:'',
name: '',
@@ -152,6 +153,8 @@
sourceIds:[],
datasourceIds:'',
}
)
}
let dialogTitle = computed(() => {
@@ -185,16 +188,16 @@ const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
try {
dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
if (formContent.value.id) {
await updatePlan(formContent.value);
if (formContent.id) {
await updatePlan(formContent);
ElMessage.success({ message: `${dialogTitle.value}成功!` })
} else {
// 新增需要把设备模式转成字典ID
const patternItem = dictStore.getDictData('Pattern').find(item => item.name === formContent.value.pattern);
const patternItem = dictStore.getDictData('Pattern').find(item => item.name === formContent.pattern);
if (patternItem) {
formContent.value.pattern = patternItem.id;
formContent.pattern = patternItem.id;
}
await addPlan(formContent.value);
await addPlan(formContent);
ElMessage.success({ message: `${dialogTitle.value}成功!` })
}
close()
@@ -214,14 +217,12 @@ const open = async (sign: string,
data: Plan.ReqPlan,
currentMode: string,) => {
let pqDevList=ref<Device.ResPqDev[]>([])//获取指定模式下所有检测源
//处理异步调用
const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== currentMode)?.id ?? ''
data.pattern = patternId
mode.value = currentMode
titleType.value = sign
dialogVisible.value = true
const pqSource_Result = await getTestSourceList(data);
pqSourceList.value = pqSource_Result.data as TestSource.ResTestSource[];
@@ -230,6 +231,14 @@ const open = async (sign: string,
const PqErrSys_Result = await getPqErrSysList();
pqErrSysList.value = PqErrSys_Result.data as unknown as ErrorSystem.ErrorSystemList[];
if (data.id) {
Object.assign(formContent,{ ...data })
} else {
resetFormContent()
}
// 重置表单
dialogFormRef.value?.resetFields()
if(sign == 'add')
{
const pqDevList_Result = await getUnboundPqDevList(data);
@@ -242,18 +251,11 @@ const open = async (sign: string,
const unboundData = Array.isArray(unboundPqDevList_Result.data) ? unboundPqDevList_Result.data : [];
pqDevList.value = [...boundData,...unboundData] as Device.ResPqDev[];
formContent.devIds = boundData.map(i => i.id );// 已绑定设备id集合
pqDevArray.value = pqDevList.value.map(i => ({
label: i.name,
value: i.id
})); // 设置已绑定设备为默认选中
formContent.value.devIds = boundData.map(i => i.id)// 已绑定设备id集合
console.log('123',formContent.value.devIds)
Object.assign(formContent,{ ...data })
}
console.log(formContent.value)
const sourceArray1 = Array.isArray(pqSourceList.value) ? pqSourceList.value : []
// 将 pqSource_Result 转换成 { label, value } 数组
@@ -274,23 +276,12 @@ const open = async (sign: string,
value: item.id
}));
// const sourceArray4 = Array.isArray(pqDevList.value) ? pqDevList.value : []
// pqDevArray.value = sourceArray4.map(item => ({
// label: item.name,
// value: item.id
// }))
const sourceArray4 = Array.isArray(pqDevList.value) ? pqDevList.value : []
pqDevArray.value = sourceArray4.map(item => ({
label: item.name,
value: item.id
}))
mode.value = currentMode
titleType.value = sign
dialogVisible.value = true
if (data.id) {
formContent.value = { ...data }
} else {
resetFormContent()
}
// 重置表单
dialogFormRef.value?.resetFields()
}
const dataSourceType = computed(() => {