联调检测脚本修改功能

This commit is contained in:
GGJ
2025-02-20 16:39:15 +08:00
parent 629fd174e4
commit 14583d919d
9 changed files with 498 additions and 296 deletions

View File

@@ -5,7 +5,7 @@
<el-tab-pane label="检测">
<!-- 全局设置菜单内容 -->
<div style="height: 295px">
<el-radio-group v-model="subType">
<el-radio-group v-model="form.subType">
<el-radio
v-for="item in tabChildren"
:key="item"
@@ -97,7 +97,12 @@
<div class="form-item-container">
<el-form-item label="频率:" prop="name">
<div class="input-label-container">
<el-input type="number" style="width: 100px" v-model="form.ffreq" />
<el-input
type="number"
@mousewheel.native.prevent
style="width: 100px"
v-model="form.ffreq"
/>
<label>Hz</label>
</div>
</el-form-item>
@@ -134,7 +139,7 @@
<template #footer>
<div>
<el-button @click="close()"> </el-button>
<el-button @click="close"> </el-button>
<el-button type="primary" @click="save">保存</el-button>
</div>
</template>
@@ -153,10 +158,10 @@ import TestScriptInHarmTab from '@/views/machine/testScript/components/testScrip
import TestScriptFlickerTab from '@/views/machine/testScript/components/testScriptFlickerTab.vue'
import TestScriptDipTab from '@/views/machine/testScript/components/testScriptDipTab.vue'
import { useDictStore } from '@/stores/modules/dict'
import { addScriptDtls } from '@/api/device/testScript'
import { addScriptDtls, scriptDtlsCheckDataList } from '@/api/device/testScript'
import scriptForm from './scriptForm'
const emit = defineEmits(['addTab'])
const emit = defineEmits(['addTab', 'close'])
const dictStore = useDictStore()
const props = defineProps({
options: {
@@ -167,6 +172,10 @@ const props = defineProps({
type: String,
required: true
},
childActiveName: {
type: String,
required: true
},
formContent: {
type: [Object, Array],
required: true
@@ -174,7 +183,7 @@ const props = defineProps({
})
const key = ref(0)
// let valueType
const form: any = ref(scriptForm)
const form: any = ref(JSON.parse(JSON.stringify(scriptForm)))
const childForm: any = ref([])
const ScriptValueType = ref('')
const setValueTableRef = ref()
@@ -190,7 +199,7 @@ const tableData = [
{ name: 'L3', frequency: 'Uc', type: 'V', electricity: 0, fphase: 0, sort: 2 },
{ name: 'L3', frequency: 'Ic', type: 'I', electricity: 0, fphase: 0, sort: 2 }
]
const subType = ref('')
const tabChildren: any = ref([])
// 定义 span-method 逻辑
const arraySpanMethod = ({ rowIndex, columnIndex }: { rowIndex: number; columnIndex: number }) => {
@@ -232,62 +241,104 @@ const handleRowClick = async (row: any, column: any) => {
// 关闭弹窗
const close = () => {
dialogVisible.value = false
emit('close')
}
// 保存数据
const save = () => {
// dialogVisible.value = false
form.value.subType = subType.value
form.value.label = tabChildren.value.filter((item: any) => item.code == subType.value)[0].label
let copyForm = JSON.parse(JSON.stringify(form.value))
copyForm.channelList.forEach((channel: any) => {
// 筛选出 famp 和 fphase 不同时为 0 的对象
channel.harmList = channel.harmList.filter((item: any) => item.famp !== 0 || item.fphase !== 0)
channel.inHarmList = channel.inHarmList.filter(
(item: any) => item.inharm !== 0 || item.famp !== 0 || item.fphase !== 0
)
})
console.log('🚀 ~ save ~ form.value:', copyForm)
let copyForm = handleHarmData()
addScriptDtls({ ...copyForm, scriptId: props.formContent.id, scriptType: props.activeName }).then(res => {
if (res.code === 'A0000') {
ElMessage.success({ message: res.message })
ElMessage.success({
message: dialogTitle.value == '新增检测项目信息' ? '添加检测脚本成功!' : '编辑检测脚本成功!',
type: 'success'
})
dialogVisible.value = false
emit('addTab', form.value)
}
})
// emit('addTab', form.value)
}
//处理谐波数据
const handleHarmData = () => {
let copyForm = JSON.parse(JSON.stringify(form.value))
copyForm.channelList.forEach((channel: any) => {
// 筛选出 famp 和 fphase 不同时为 0 的对象
channel.harmList = channel.harmList.filter((item: any) => item.famp !== 0 || item.fphase !== 0)
channel.inharmList = channel.inharmList.filter(
(item: any) => item.inharm !== '' || item.famp !== 0 || item.fphase !== 0
)
})
return copyForm
}
// 打开弹窗,可能是新增,也可能是编辑
const open = (sign: string, row: any) => {
dialogVisible.value = true
dialogTitle.value = sign === 'add' ? '新增检测项目信息' : '编辑检测项目信息'
// 添加选择检测项目
tabChildren.value = props.options.filter(item => item.value == props.activeName)[0].children || []
subType.value = tabChildren.value[0].code || ''
// subType.value = tabChildren.value[0].code || ''
if (sign == 'add') {
form.value.subType = props.childActiveName == '' ? tabChildren.value[0].code || '' : props.childActiveName
} else {
form.value = setharmList(JSON.parse(JSON.stringify(row)))
}
handleRowClick({ name: 'L1', sort: 0 }, { label: '相别' })
dictStore.getDictData('Script_Value_Type')
valueCode.value = dictStore
.getDictData('Script_Value_Type')
.filter(item => item.id == props.formContent.valueType)[0].code
}
// 判断后台没有谐波,简谐波值 用于回显
const setharmList = (row: any) => {
row.channelList.forEach((item: any) => {
let harmList = []
for (let i = 2; i < 51; i++) {
let data = item.harmList.filter((harm: any) => harm.harm == i)
if (data.length > 0) {
harmList.push({ harm: i, famp: data[0].famp, fphase: data[0].fphase })
} else {
harmList.push({ harm: i, famp: 0, fphase: 0 })
}
}
item.harmList = harmList
if (item.inharmList.length == 0) {
item.inharmList.push({ inharm: 0, famp: 0, fphase: 0 })
}
})
return row
}
// 复制
const copyRow = (index: number) => {
scriptForm.channelList[index + 2] = JSON.parse(JSON.stringify(scriptForm.channelList[index]))
scriptForm.channelList[index + 3] = JSON.parse(JSON.stringify(scriptForm.channelList[index + 1]))
scriptForm.channelList[index].channelType == 'Ua'
? (scriptForm.channelList[index + 2].channelType = 'Ub')
: (scriptForm.channelList[index + 2].channelType = 'Uc')
scriptForm.channelList[index + 1].channelType == 'Ia'
? (scriptForm.channelList[index + 3].channelType = 'Ib')
: (scriptForm.channelList[index + 3].channelType = 'Ic')
form.value.channelList[index + 2] = JSON.parse(JSON.stringify(form.value.channelList[index]))
form.value.channelList[index + 3] = JSON.parse(JSON.stringify(form.value.channelList[index + 1]))
form.value.channelList[index].channelType == 'Ua'
? (form.value.channelList[index + 2].channelType = 'Ub')
: (form.value.channelList[index + 2].channelType = 'Uc')
form.value.channelList[index + 1].channelType == 'Ia'
? (form.value.channelList[index + 3].channelType = 'Ib')
: (form.value.channelList[index + 3].channelType = 'Ic')
key.value += 1
ElMessage.success({
message: '复制成功!',
type: 'success'
})
}
// 打开 drawer(新增、编辑)
const openDialog = () => {
setValueTableRef.value?.open()
let copyForm = JSON.parse(JSON.stringify(form.value))
scriptDtlsCheckDataList({ ...copyForm, scriptId: props.formContent?.id, scriptType: props.activeName }).then(
res => {}
)
// setValueTableRef.value?.open()
}
// 对外映射