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

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