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