diff --git a/frontend/src/api/plan/interface/index.ts b/frontend/src/api/plan/interface/index.ts index 15ccc84..19fe4fd 100644 --- a/frontend/src/api/plan/interface/index.ts +++ b/frontend/src/api/plan/interface/index.ts @@ -37,7 +37,7 @@ export namespace Plan { scriptName: string ; errorSysName: string; sourceName: string ; - devIds:string[]; + devIds: string[]; } diff --git a/frontend/src/views/plan/planList/components/planPopup.vue b/frontend/src/views/plan/planList/components/planPopup.vue index a25b4fd..2237bb0 100644 --- a/frontend/src/views/plan/planList/components/planPopup.vue +++ b/frontend/src/views/plan/planList/components/planPopup.vue @@ -92,7 +92,7 @@ const pqSourceList=ref([])//获取指定模式下所有检测源 const pqScriptList=ref([])//获取指定模式下所有检测源 const pqErrSysList=ref([])//获取指定模式下所有检测源 - + const pqDevList=ref([])//获取指定模式下所有检测源 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({ + const formContent = reactive({ id:'', planId:'', name: '', @@ -130,28 +130,31 @@ // 清空formContent const resetFormContent = () => { - formContent.value = { - id:'', - planId:'', - name: '', - pattern: mode.value, - fatherPlanId: '', - dataSourceId: '', - scriptId: '', - errorSysId: '', - timeCheck:0, - testState: 0, - reportState: 0, - result: 2, - code:1, - state:1, - scriptName:'', - errorSysName:'', - sourceName:'', - devIds:[], - sourceIds:[], - datasourceIds:'', - } + Object.assign( + formContent,{ + id:'', + planId:'', + name: '', + pattern: mode.value, + fatherPlanId: '', + dataSourceId: '', + scriptId: '', + errorSysId: '', + timeCheck:0, + testState: 0, + reportState: 0, + result: 2, + code:1, + state:1, + scriptName:'', + errorSysName:'', + sourceName:'', + devIds:[], + sourceIds:[], + datasourceIds:'', + } + ) + } let dialogTitle = computed(() => { @@ -185,16 +188,16 @@ const rules: Ref>> = 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,15 +217,13 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string,) => { - let pqDevList=ref([])//获取指定模式下所有检测源 - - - - //处理异步调用 + //处理异步调用 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[]; const PqScript_Result = await getPqScriptList(data); @@ -230,7 +231,15 @@ const open = async (sign: string, const PqErrSys_Result = await getPqErrSysList(); pqErrSysList.value = PqErrSys_Result.data as unknown as ErrorSystem.ErrorSystemList[]; - if(sign == 'add') + if (data.id) { + Object.assign(formContent,{ ...data }) + } else { + resetFormContent() + } + // 重置表单 + dialogFormRef.value?.resetFields() + + if(sign == 'add') { const pqDevList_Result = await getUnboundPqDevList(data); pqDevList.value = pqDevList_Result.data as Device.ResPqDev[]; @@ -242,55 +251,37 @@ 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 } 数组 - pqSourceArray.value = sourceArray1.map(item => ({ - label: item.name || '', - value: item.id - })); + + const sourceArray1 = Array.isArray(pqSourceList.value) ? pqSourceList.value : [] + // 将 pqSource_Result 转换成 { label, value } 数组 + pqSourceArray.value = sourceArray1.map(item => ({ + label: item.name || '', + value: item.id + })); - const sourceArray2 = Array.isArray(pqScriptList.value ) ? pqScriptList.value : [] - pqScriptArray.value = sourceArray2.map(item => ({ - label: item.name || '', - value: item.id || '' - })); + const sourceArray2 = Array.isArray(pqScriptList.value ) ? pqScriptList.value : [] + pqScriptArray.value = sourceArray2.map(item => ({ + label: item.name || '', + value: item.id || '' + })); - const sourceArray3 = Array.isArray(pqErrSysList.value) ? pqErrSysList.value : [] - pqErrorArray.value = sourceArray3.map(item => ({ - label: item.name, - value: item.id - })); + const sourceArray3 = Array.isArray(pqErrSysList.value) ? pqErrSysList.value : [] + pqErrorArray.value = sourceArray3.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 - // })) + 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(() => { diff --git a/frontend/src/views/plan/planList/index.vue b/frontend/src/views/plan/planList/index.vue index 665032b..77a3f64 100644 --- a/frontend/src/views/plan/planList/index.vue +++ b/frontend/src/views/plan/planList/index.vue @@ -111,7 +111,7 @@ const columns = reactive[]>([ showTestSource(scope.row.sourceName)}> {scope.row.sourceName} - + ) },