feat/ 温湿度传感器阈值配置优化
This commit is contained in:
parent
3c5cd8016a
commit
5e02fb66c3
|
|
@ -148,8 +148,31 @@ export default {
|
|||
|
||||
// activeTab == 86 的情况
|
||||
if (tabTypeId == 86 || tabTypeId == 84 || tabTypeId == 81) {
|
||||
const numValue = Number(value)
|
||||
return numValue === 0 ? 0 : numValue.toFixed(1)
|
||||
// 如果 value 是字符串,需要先提取数值部分(可能包含单位)
|
||||
let numValue
|
||||
if (typeof value === 'string') {
|
||||
// 使用正则表达式提取数值部分(包括小数点和负号)
|
||||
const numMatch = value.match(/^-?[\d.]+/)
|
||||
if (numMatch) {
|
||||
numValue = Number(numMatch[0])
|
||||
} else {
|
||||
// 如果无法提取数值,返回原值
|
||||
return value
|
||||
}
|
||||
} else {
|
||||
numValue = Number(value)
|
||||
}
|
||||
|
||||
// 检查是否为有效数字
|
||||
if (isNaN(numValue)) {
|
||||
return value
|
||||
}
|
||||
|
||||
// 提取单位部分(如果有)
|
||||
const unit = typeof value === 'string' ? value.replace(/^-?[\d.]+/, '') : ''
|
||||
|
||||
const formattedValue = numValue === 0 ? 0 : numValue.toFixed(1)
|
||||
return unit ? `${formattedValue}${unit}` : formattedValue
|
||||
}
|
||||
|
||||
// activeTab == 71 的情况(水库液位)
|
||||
|
|
@ -162,7 +185,16 @@ export default {
|
|||
// 解析每一行:提取 point_name 和 status
|
||||
const colonIndex = line.indexOf(':')
|
||||
if (colonIndex === -1) {
|
||||
// 如果没有冒号,可能是单个数值
|
||||
// 如果没有冒号,可能是单个数值(可能带单位)
|
||||
// 提取数值部分
|
||||
const numMatch = line.match(/^([\d.]+)/)
|
||||
if (numMatch) {
|
||||
const numValue = numMatch[1]
|
||||
const calculatedValue = calculateWaterLevel(numValue)
|
||||
// 保留单位(如果有)
|
||||
const unit = line.replace(/^[\d.]+/, '')
|
||||
return unit ? `${calculatedValue}${unit}` : calculatedValue
|
||||
}
|
||||
return calculateWaterLevel(line)
|
||||
}
|
||||
const pointName = line.substring(0, colonIndex)
|
||||
|
|
@ -180,7 +212,19 @@ export default {
|
|||
})
|
||||
return formattedLines.join('\n')
|
||||
} else {
|
||||
// 单行数据:直接计算
|
||||
// 单行数据:可能带单位,需要先提取数值部分
|
||||
if (typeof value === 'string') {
|
||||
// 提取数值部分
|
||||
const numMatch = value.match(/^([\d.]+)/)
|
||||
if (numMatch) {
|
||||
const numValue = numMatch[1]
|
||||
const calculatedValue = calculateWaterLevel(numValue)
|
||||
// 保留单位(如果有)
|
||||
const unit = value.replace(/^[\d.]+/, '')
|
||||
return unit ? `${calculatedValue}${unit}` : calculatedValue
|
||||
}
|
||||
}
|
||||
// 如果不是字符串或无法提取数值,直接计算
|
||||
return calculateWaterLevel(value)
|
||||
}
|
||||
}
|
||||
|
|
@ -439,8 +483,6 @@ export default {
|
|||
tableData: typeGroup.devices
|
||||
}))
|
||||
|
||||
console.log(tabs.value, "===> tabs.value");
|
||||
|
||||
|
||||
// 只在首次加载时设置默认激活的选项卡,轮询时保持当前选项卡状态
|
||||
if (isFirstLoad && tabs.value.length > 0) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<!-- 页面标题 -->
|
||||
<div class="page-header">
|
||||
<h2>传感器报警阈值配置</h2>
|
||||
<p class="page-description">配置传感器上下限报警阈值</p>
|
||||
<p class="page-description">配置传感器上报警阈值</p>
|
||||
</div>
|
||||
|
||||
<!-- 传感器列表 -->
|
||||
|
|
@ -22,9 +22,99 @@
|
|||
:model="sensor"
|
||||
:rules="thresholdRules"
|
||||
ref="formRefs"
|
||||
label-width="80px"
|
||||
:label-width="sensor.model_id == 86 ? '120px' : '80px'"
|
||||
class="threshold-form"
|
||||
>
|
||||
<template v-if="sensor.model_id == 86">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
label="温度限值一"
|
||||
prop="upper_threshold"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="sensor.upper_threshold"
|
||||
:min="0"
|
||||
:max="1000"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
label="温度限值二"
|
||||
prop="lower_threshold"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="sensor.lower_threshold"
|
||||
:min="0"
|
||||
:max="1000"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
label="湿度限值一"
|
||||
prop="upper_threshold"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="sensor.upper_threshold_2"
|
||||
:min="0"
|
||||
:max="1000"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
label="湿度限值二"
|
||||
prop="lower_threshold"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="sensor.lower_threshold_2"
|
||||
:min="0"
|
||||
:max="1000"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
label="采集频率(分钟)"
|
||||
prop="lower_threshold"
|
||||
class="sp sp-label"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="sensor.history_data_frequency"
|
||||
:min="1"
|
||||
:max="1000"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入采集频率`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="7">
|
||||
<el-form-item
|
||||
|
|
@ -38,7 +128,7 @@
|
|||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入上限阈值${sensor.unit}`"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
|
@ -54,7 +144,7 @@
|
|||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
:placeholder="`请输入下限阈值${sensor.unit}`"
|
||||
:placeholder="`请输入阈值${sensor.unit}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
|
@ -76,6 +166,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-form-item>
|
||||
<el-button
|
||||
|
|
@ -153,7 +244,7 @@ const saveThresholds = async (sensor) => {
|
|||
|
||||
// 验证阈值逻辑
|
||||
// if (sensor.upper_threshold <= sensor.lower_threshold) {
|
||||
// ElMessage.error("上限阈值必须大于下限阈值");
|
||||
// ElMessage.error("阈值必须大于阈值");
|
||||
// return;
|
||||
// }
|
||||
saving.value = true;
|
||||
|
|
@ -325,4 +416,5 @@ onMounted(() => {
|
|||
::v-deep .sp-label .el-form-item__label {
|
||||
width: 120px !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue