UPDATE: 添加被检设备编辑监测点PT和CT值按照指定规则进行校验
This commit is contained in:
@@ -32,43 +32,27 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="PT变比" required>
|
||||
<el-form-item label="PT变比" required>
|
||||
<div class="ratio-input-group">
|
||||
<el-form-item prop="ptPrimary" class="ratio-form-item">
|
||||
<el-input
|
||||
v-model="ptPrimary"
|
||||
placeholder="一次侧"
|
||||
@input="handlePtInput"
|
||||
/>
|
||||
<el-input v-model="ptPrimary" placeholder="一次侧" @input="handlePtInput" />
|
||||
</el-form-item>
|
||||
<span class="colon">:</span>
|
||||
<el-form-item prop="ptSecondary" class="ratio-form-item">
|
||||
<el-input
|
||||
v-model="ptSecondary"
|
||||
placeholder="二次侧"
|
||||
@input="handlePtInput"
|
||||
/>
|
||||
<el-input v-model="ptSecondary" placeholder="二次侧" @input="handlePtInput" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
<!-- 修改CT变比部分 -->
|
||||
<el-form-item label="CT变比" required>
|
||||
<div class="ratio-input-group">
|
||||
<el-form-item prop="ctPrimary" class="ratio-form-item">
|
||||
<el-input
|
||||
v-model="ctPrimary"
|
||||
placeholder="一次侧"
|
||||
@input="handleCtInput"
|
||||
/>
|
||||
<el-input v-model="ctPrimary" placeholder="一次侧" @input="handleCtInput" />
|
||||
</el-form-item>
|
||||
<span class="colon">:</span>
|
||||
<el-form-item prop="ctSecondary" class="ratio-form-item">
|
||||
<el-input
|
||||
v-model="ctSecondary"
|
||||
placeholder="二次侧"
|
||||
@input="handleCtInput"
|
||||
/>
|
||||
<el-input v-model="ctSecondary" placeholder="二次侧" @input="handleCtInput" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@@ -103,6 +87,12 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-alert
|
||||
show-icon
|
||||
title="注意:PT和CT变比请输入正常值,不可以缩小相同的倍数!"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
></el-alert>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="close()">取消</el-button>
|
||||
@@ -114,12 +104,12 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ElMessage, type FormItemRule } from 'element-plus'
|
||||
import { computed, ref, Ref, watch } from 'vue'
|
||||
import { computed, ref, type Ref } from 'vue'
|
||||
import { type Monitor } from '@/api/device/interface/monitor'
|
||||
import { dialogMiddle } from '@/utils/elementBind'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import { generateUUID } from '@/utils'
|
||||
import { Device } from '@/api/device/interface/device'
|
||||
import { type Device } from '@/api/device/interface/device'
|
||||
|
||||
const dictStore = useDictStore()
|
||||
const lineNum = ref<{ id: number; name: string }[]>([])
|
||||
@@ -211,25 +201,24 @@ const handleCtInput = () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 添加一个用于手动验证的引用
|
||||
const extraFormRules = ref({
|
||||
ptPrimary: [
|
||||
{ required: true, message: 'PT变比一次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
],
|
||||
ptSecondary: [
|
||||
{ required: true, message: 'PT变比二次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
],
|
||||
ctPrimary: [
|
||||
{ required: true, message: 'CT变比一次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
],
|
||||
ctSecondary: [
|
||||
{ required: true, message: 'CT变比二次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
]
|
||||
ptPrimary: [
|
||||
{ required: true, message: 'PT变比一次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
],
|
||||
ptSecondary: [
|
||||
{ required: true, message: 'PT变比二次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^\d+(\.\d+)?$/, message: '请输入数字', trigger: 'blur' }
|
||||
],
|
||||
ctPrimary: [
|
||||
{ required: true, message: 'CT变比一次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
],
|
||||
ctSecondary: [
|
||||
{ required: true, message: 'CT变比二次侧必填!', trigger: 'blur' },
|
||||
{ pattern: /^[1-9]\d*$/, message: '请输入正整数', trigger: 'blur' }
|
||||
]
|
||||
})
|
||||
|
||||
// 保存数据
|
||||
@@ -238,43 +227,91 @@ const save = () => {
|
||||
dialogFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
// 手动验证额外的字段
|
||||
let extraValid = true;
|
||||
const fieldsToValidate = ['ptPrimary', 'ptSecondary', 'ctPrimary', 'ctSecondary'];
|
||||
|
||||
for (const field of fieldsToValidate) {
|
||||
const value = eval(field); // 获取对应字段的值
|
||||
const rules = extraFormRules.value[field];
|
||||
|
||||
for (const rule of rules) {
|
||||
if (rule.required && !value.value) {
|
||||
ElMessage.error({ message: rule.message as string });
|
||||
extraValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rule.pattern && value.value && !rule.pattern.test(value.value)) {
|
||||
ElMessage.error({ message: rule.message as string });
|
||||
extraValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!extraValid) break;
|
||||
}
|
||||
|
||||
if (!extraValid) {
|
||||
return;
|
||||
let extraValid = true
|
||||
const fieldsToValidate = ['ptPrimary', 'ptSecondary', 'ctPrimary', 'ctSecondary']
|
||||
|
||||
for (const field of fieldsToValidate) {
|
||||
const value = eval(field) // 获取对应字段的值
|
||||
const rules = extraFormRules.value[field]
|
||||
|
||||
for (const rule of rules) {
|
||||
if (rule.required && !value.value) {
|
||||
ElMessage.error({ message: rule.message as string })
|
||||
extraValid = false
|
||||
break
|
||||
}
|
||||
|
||||
if (rule.pattern && value.value && !rule.pattern.test(value.value)) {
|
||||
ElMessage.error({ message: rule.message as string })
|
||||
extraValid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!extraValid) break
|
||||
}
|
||||
|
||||
if (!extraValid) {
|
||||
return
|
||||
}
|
||||
|
||||
// 校验名称是否重复
|
||||
const isNameDuplicate = monitorTable.value.some(
|
||||
const isNameDuplicate = monitorTable.value?.some(
|
||||
item => item.name === formContent.value.name && item.id !== formContent.value.id
|
||||
)
|
||||
if (isNameDuplicate) {
|
||||
ElMessage.error({ message: '监测点名称已存在,请重新输入!' })
|
||||
return
|
||||
}
|
||||
// 添加PT CT逻辑
|
||||
// PT 逻辑
|
||||
let ptPrimaryValue = ptPrimary.value
|
||||
let ptSecondaryValue = ptSecondary.value
|
||||
let ptErrorTips = false
|
||||
let ctErrorTips = false
|
||||
const ptFinalValue = ['100', '380']
|
||||
const ptFinalChangeValue = ['57.74', '220']
|
||||
const ctFinalValue = ['1', '5']
|
||||
|
||||
// 若值都为 1, 则改值为 380
|
||||
if (ptPrimaryValue === '1' && ptSecondaryValue === '1') {
|
||||
formContent.value.pt = `${ptFinalValue[1]}:${ptFinalValue[1]}`
|
||||
} else {
|
||||
// 若PT分母值不为 ['100', '380']
|
||||
if (!ptFinalValue.includes(ptSecondaryValue)) {
|
||||
// 若PT分母值不为 ['57.74', '220'],提示
|
||||
if (ptFinalChangeValue.includes(ptSecondaryValue)) {
|
||||
// 判断值为 57.74,则 57.74 => 100
|
||||
if (ptSecondaryValue === ptFinalChangeValue[0]) {
|
||||
ptSecondaryValue = ptFinalValue[0]
|
||||
}
|
||||
// 判断值为 220,则 220 => 380
|
||||
if (ptSecondaryValue === ptFinalChangeValue[1]) {
|
||||
ptSecondaryValue = ptFinalValue[1]
|
||||
}
|
||||
} else {
|
||||
ptErrorTips = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// CT 逻辑, CT 分母是否为 ['1', '5']
|
||||
if (!ctFinalValue.includes(ctSecondary.value)) {
|
||||
ctErrorTips = true
|
||||
}
|
||||
if (ptErrorTips && ctErrorTips) {
|
||||
ElMessage.error({ message: '请确认PT和CT无误!' })
|
||||
return
|
||||
} else {
|
||||
if (ptErrorTips) {
|
||||
ElMessage.error({ message: '请确认PT无误!' })
|
||||
return
|
||||
}
|
||||
if (ctErrorTips) {
|
||||
ElMessage.error({ message: '请确认CT无误!' })
|
||||
return
|
||||
}
|
||||
}
|
||||
formContent.value.pt = `${ptPrimaryValue}:${ptSecondaryValue}`
|
||||
if (titleType.value != 'edit') {
|
||||
formContent.value.id = generateUUID().replaceAll('-', '')
|
||||
}
|
||||
@@ -324,7 +361,7 @@ const open = async (sign: string, data: Monitor.ResPqMon, device: Device.ResPqDe
|
||||
ptPrimary.value = primary
|
||||
ptSecondary.value = secondary
|
||||
}
|
||||
|
||||
|
||||
// 解析CT变比
|
||||
if (data.ct) {
|
||||
const [primary, secondary] = data.ct.split(':')
|
||||
@@ -364,18 +401,22 @@ defineExpose({ open })
|
||||
|
||||
<style scoped>
|
||||
.ratio-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ratio-form-item {
|
||||
flex: 1;
|
||||
margin-bottom: 0 !important;
|
||||
flex: 1;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.colon {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.el-alert {
|
||||
--el-alert-padding: 0px 12px !important;
|
||||
--el-alert-title-font-size: 12px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user