Files
pqs-9100_client/frontend/src/views/machine/testScript/components/setValueTable.vue

352 lines
9.9 KiB
Vue
Raw Normal View History

2024-12-26 09:28:19 +08:00
<template>
2025-02-24 16:45:39 +08:00
<div class="table-container">
2025-02-27 16:24:13 +08:00
<div class="recalculation">
<el-button type="primary" :icon="Refresh" @click="recalculation">一键重算</el-button>
</div>
2025-02-24 16:45:39 +08:00
<el-table
:data="tableData"
:header-cell-style="{
textAlign: 'center',
2025-03-17 15:55:30 +08:00
backgroundColor: 'var(--el-color-primary)',
2025-02-24 16:45:39 +08:00
color: '#fff'
}"
stripe
:cell-style="{ textAlign: 'center' }"
2025-02-27 16:24:13 +08:00
height="550px"
2025-02-24 16:45:39 +08:00
>
<el-table-column type="index" label="序号" width="60" />
<el-table-column prop="pname" label="参考设定值类型" />
<el-table-column prop="name" label="参考设定值子类型" width="250">
<template #default="{ row }">{{ row.harmNum ? `(${row.harmNum}次)` : '' }} {{ row.name }}</template>
</el-table-column>
2025-02-27 16:24:13 +08:00
<el-table-column prop="dataType" label="值类型">
<template #default="{ row }">
<el-select v-model="row.dataType" v-if="!row.show">
<el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<span v-else>
{{ typeList.find(item => item.value == row.dataType)?.label || row.dataType }}
</span>
</template>
</el-table-column>
2025-02-24 16:45:39 +08:00
<el-table-column prop="phase" label="相别" />
<el-table-column prop="value" label="参考设定值">
<template #default="{ row }">
2025-03-27 18:34:40 +08:00
<span v-if="row.show">{{ parseFloat((row.value - 0).toFixed(4)) }}{{ setUnit(row) || '' }}</span>
2025-02-27 16:24:13 +08:00
<el-input type="number" v-else v-model="row.value" placeholder="请输入值" />
</template>
</el-table-column>
2025-02-24 16:45:39 +08:00
<el-table-column prop="value" label="参与误差比较">
<template #default="{ row }">
{{ row.errorFlag == 0 ? '否' : '是' }}
2024-12-30 14:43:13 +08:00
</template>
2025-02-24 16:45:39 +08:00
</el-table-column>
<el-table-column label="操作">
<template #default="{ row }">
<el-button type="primary" link :icon="EditPen" @click="row.show = !row.show" v-if="row.show">
编辑
</el-button>
<el-button type="primary" link :icon="Check" @click="row.show = !row.show" v-else>保存</el-button>
2024-12-30 14:43:13 +08:00
</template>
2025-02-24 16:45:39 +08:00
</el-table-column>
</el-table>
</div>
2024-12-30 14:43:13 +08:00
2025-02-17 08:39:18 +08:00
<el-dialog :title="dialogTitle" v-model="showForm" @close="close" width="500">
<el-form ref="form" :model="form" label-width="auto">
<el-form-item label="参考设定值类型" prop="name">
<el-input v-model="form.name" />
</el-form-item>
<el-form-item label="参考设定值子类型" prop="standardName">
<el-input v-model="form.standardName" />
</el-form-item>
<el-form-item label="参考设定值" prop="standardTime">
<el-input v-model="form.standardTime" />
</el-form-item>
</el-form>
<template #footer>
<div>
<el-button @click="close()"> </el-button>
<el-button type="primary" @click="save"> </el-button>
</div>
</template>
2024-12-30 14:43:13 +08:00
</el-dialog>
2025-02-17 08:39:18 +08:00
</template>
2024-12-26 09:28:19 +08:00
<script setup lang="ts">
2025-02-27 16:24:13 +08:00
import { Refresh, EditPen, Check, Share } from '@element-plus/icons-vue'
2025-02-17 08:39:18 +08:00
import { reactive, ref } from 'vue'
2025-02-24 08:38:54 +08:00
import { getDictTreeByCode } from '@/api/system/dictionary/dictTree'
2024-12-30 14:43:13 +08:00
import { dialogBig } from '@/utils/elementBind'
2025-02-24 08:38:54 +08:00
import { checkDataList, scriptDtlsCheckDataList } from '@/api/device/testScript/index'
2025-02-17 08:39:18 +08:00
const showForm = ref(false)
2024-12-30 14:43:13 +08:00
const dialogVisible = ref(false)
const dialogTitle = ref('')
2025-02-24 08:38:54 +08:00
const props = defineProps({
activeName: {
type: String,
required: true
2025-02-17 08:39:18 +08:00
},
2025-02-24 08:38:54 +08:00
formContent: {
type: [Object, Array],
required: true
2025-02-17 08:39:18 +08:00
},
2025-02-24 08:38:54 +08:00
form: {
type: [Object, Array],
required: true
2025-03-27 18:34:40 +08:00
},
valueCode: {
type: String,
required: true
2025-02-24 08:38:54 +08:00
}
})
2025-02-27 16:24:13 +08:00
const emit = defineEmits(['recalculation'])
2025-02-24 08:38:54 +08:00
const tableData: any = ref([])
// 表格配置项
2025-02-27 16:24:13 +08:00
const typeList = [
{
label: '实时',
value: 'real'
},
{
label: 'CP95值',
value: 'cp95'
},
{
label: '平均值',
value: 'avg'
},
{
label: '最小值',
value: 'min'
},
{
label: '最大值',
value: 'max'
}
]
2025-02-17 08:39:18 +08:00
const form = ref({
name: 220,
standardName: 0,
standardTime: 0
})
2024-12-30 14:43:13 +08:00
// 打开弹窗,可能是新增,也可能是编辑
2025-02-24 08:38:54 +08:00
const open = async (row: any, copyRowList: any) => {
2025-02-24 08:38:54 +08:00
let treeData: any = []
await getDictTreeByCode({
name: '',
id: '',
pid: '',
pids: '',
code: 'Script_Error',
sort: 0
}).then((res: any) => {
treeData = res.data[0].children
})
2025-02-24 16:45:39 +08:00
let checkDataList: any = []
await row.forEach((item: any) => {
item.children.forEach((k: any) => {
if (k.enable != 0 || k.errorFlag != 0) {
checkDataList.push({
pid: k.pid,
valueType: k.id,
dataType: k.dataType,
enable: k.enable,
errorFlag: k.errorFlag
})
}
})
})
2025-03-04 09:35:41 +08:00
let form = handleHarmData(JSON.parse(JSON.stringify(props.form)))
let retryCompute = isEqual(form, copyRowList)
2025-02-24 08:38:54 +08:00
await scriptDtlsCheckDataList({
...form,
2025-02-24 08:38:54 +08:00
scriptId: props.formContent?.id,
scriptType: props.activeName,
checkDataList: checkDataList,
retryCompute: retryCompute
2025-02-24 08:38:54 +08:00
}).then((res: any) => {
res.data.forEach((item: any) => {
let pList = treeData.filter((i: any) => i.id == item.pid)[0]
item.pname = pList.name
item.name = pList.children.filter((i: any) => i.id == item.valueType)[0].name
item.show = true
2025-02-24 08:38:54 +08:00
})
tableData.value = res.data
})
2025-02-17 08:39:18 +08:00
}
2025-02-27 16:24:13 +08:00
// 重算
const recalculation = () => {
emit('recalculation')
}
// 处理多余数据
2025-02-27 16:24:13 +08:00
const handleHarmData = (row: any) => {
row.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 row
}
// 判断数据是否变化
2025-02-27 16:24:13 +08:00
const isEqual = (obj1: any, obj2: any) => {
// 如果两个对象是同一个引用,直接返回 true
if (obj1 == obj2) return true
// 如果其中一个是 null 或者不是对象,返回 false
if (obj1 === null || typeof obj1 !== 'object' || obj2 === null || typeof obj2 !== 'object') {
return false
}
// 获取两个对象的键
const keys1 = Object.keys(obj1)
const keys2 = Object.keys(obj2)
// 如果键的数量不同,返回 false
if (keys1.length !== keys2.length) return false
// 遍历所有键,递归比较值
for (const key of keys1) {
if (!keys2.includes(key) || !isEqual(obj1[key], obj2[key])) {
return false
}
}
return true
}
2025-03-27 18:34:40 +08:00
const unit = [
{
label: '频率',
unit: 'Hz'
},
{
label: '相电压有效值',
unit: 'V'
},
{
label: '电压偏差',
unit: '%'
},
{
label: '电压相角',
unit: '°'
},
{
label: '基波电压有效值',
unit: ''
},
{
label: '电流有效值',
unit: 'A'
},
{
label: '电流相角',
unit: '°'
},
{
label: '基波电流有效值',
unit: ''
},
{
label: '谐波电压',
unit: '%'
},
{
label: '谐波电流',
unit: '%'
},
{
label: '谐波电流幅值',
unit: 'A'
},
{
label: '谐波有功功率',
unit: 'W'
},
{
label: '间谐波电压',
unit: '%'
},
{
label: '间谐波电流',
unit: '%'
},
{
label: '电压幅值',
unit: '%'
},
{
label: '持续时间',
unit: '周波'
},
{
label: '三相电压不平衡度',
unit: '%'
},
{
label: '三相电流不平衡度',
unit: '%'
},
{
label: '闪变',
unit: ''
},
{
label: '电流',
unit: props.valueCode == 'Absolute' ? 'A' : '%'
},
]
// 参考设定值添加单位
const setUnit = (row: any) => {
console.log('🚀 ~ setUnit ~ row:', row)
let text = ''
if (row.pname == '暂态') {
row.name == '电压幅值' ? (text = '%') : ''
row.name == '持续时间' ? (text = '周波') : ''
} else if (row.pname == '电压') {
let o = props.valueCode == 'Absolute' ? 'V' : '%'
row.name == '相电压有效值' ? (text = o) : ''
row.name == '电压偏差' ? (text = '%') : ''
row.name == '电压相角' ? (text = '°') : ''
}else if (row.pname == '电流') {
let o = props.valueCode == 'Absolute' ? 'A' : '%'
row.name == '电流有效值' ? (text = o) : ''
row.name == '电流相角' ? (text = '°') : ''
} else {
text = unit.filter(item => item.label == row.pname)[0]?.unit
}
return text || ''
}
2025-02-17 08:39:18 +08:00
const save = () => {
dialogVisible.value = false
2024-12-30 14:43:13 +08:00
}
2025-02-24 16:45:39 +08:00
const getTableData = () => {
return tableData.value
}
2024-12-30 14:43:13 +08:00
// 关闭弹窗
const close = () => {
dialogVisible.value = false
}
2025-03-27 18:34:40 +08:00
2025-02-24 16:45:39 +08:00
onMounted(() => {})
2025-02-24 08:38:54 +08:00
2024-12-30 14:43:13 +08:00
// 对外映射
2025-02-24 16:45:39 +08:00
defineExpose({ open, getTableData })
2024-12-26 09:28:19 +08:00
</script>
2025-02-27 16:24:13 +08:00
<style scoped>
.recalculation {
2025-03-10 16:11:08 +08:00
width: 100%;
2025-02-27 16:24:13 +08:00
display: flex;
justify-content: end;
margin-bottom: 10px;
}
</style>