|
|
@@ -17,7 +17,7 @@
|
|
|
</div>
|
|
|
</i>
|
|
|
<!-- 压力 -->
|
|
|
- <div class="pressure_block" v-if="pressureValue >= 0"
|
|
|
+ <div class="pressure_block" v-if="pressureValueRef"
|
|
|
:style="{ width: iconSize * 0.375 + 'px', height: iconSize * 0.375 + 'px' }">
|
|
|
<div ref="chartRef" :style="{ width: iconSize * 0.5 + 'px', height: iconSize * 0.5 + 'px' }"
|
|
|
class="pressure_chart"></div>
|
|
|
@@ -30,8 +30,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed } from 'vue'
|
|
|
-import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
|
|
|
+import { ref, onMounted, onBeforeUnmount, watch, computed, toRef } from 'vue'
|
|
|
import * as echarts from 'echarts'
|
|
|
//图表
|
|
|
|
|
|
@@ -65,7 +64,7 @@ const props = defineProps({
|
|
|
},
|
|
|
pressureValue: {// 压力值
|
|
|
type: Number,
|
|
|
- default: -1,// -1表示未传压力值
|
|
|
+ // default: -1,// -1表示未传压力值
|
|
|
},
|
|
|
weightValue: {// 重量值
|
|
|
type: Number,
|
|
|
@@ -155,7 +154,7 @@ const option = ref({
|
|
|
},
|
|
|
data: [
|
|
|
{
|
|
|
- value: props.pressureValue.toFixed(3),
|
|
|
+ value: props.pressureValue?.toFixed(3),
|
|
|
}
|
|
|
],
|
|
|
}
|
|
|
@@ -180,14 +179,17 @@ const getTempClass = computed(() => {
|
|
|
return 'temp_green'
|
|
|
}
|
|
|
})
|
|
|
-// 监听压力变化
|
|
|
-watch(props?.pressureValue, (newVal) => {
|
|
|
- if (myChart) {
|
|
|
+// 取出 pressureValue 的响应式引用
|
|
|
+const pressureValueRef = toRef(props, 'pressureValue')
|
|
|
+
|
|
|
+// 正确 watch 用法
|
|
|
+watch(pressureValueRef, (newVal) => {
|
|
|
+ if (myChart && typeof newVal === 'number' && newVal >= 0) {
|
|
|
myChart.setOption({
|
|
|
series: [
|
|
|
{
|
|
|
type: 'gauge',
|
|
|
- data: [{ name: '压力数据', value: newVal.toFixed(2) }]
|
|
|
+ data: [{ name: '', value: newVal.toFixed(3) }]
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
@@ -206,30 +208,21 @@ const waterLevelPosClass = computed(() =>
|
|
|
const tempPosClass = computed(() =>
|
|
|
'temp_pos' + props.tankType
|
|
|
)
|
|
|
-//温度计数值显示
|
|
|
-const marks = computed(() => ({
|
|
|
- // 80: '80°C',
|
|
|
- // 75: {
|
|
|
- // style: {
|
|
|
- // color: '#fb8a1c',
|
|
|
- // },
|
|
|
- // label: '75°C',
|
|
|
- // },
|
|
|
- // 120: {
|
|
|
- // style: {
|
|
|
- // color: '#ff0000',
|
|
|
- // // fontWeight: 'bold',
|
|
|
- // },
|
|
|
- // label: '120°C',
|
|
|
- // },
|
|
|
- [temperatureValue.value]: {
|
|
|
- style: {
|
|
|
- color: temperatureValue.value < 75 ? '#4CAF50' : (temperatureValue.value < 120 ? '#FFC107' : '#ff0000'),
|
|
|
- fontWeight: 'bold',
|
|
|
- },
|
|
|
- label: `${temperatureValue.value}°C`
|
|
|
- }
|
|
|
-}))
|
|
|
+//温度
|
|
|
+const marks = computed(() => {
|
|
|
+ const val = parseFloat(temperatureValue.value);
|
|
|
+ const displayVal = val % 1 === 0 ? val.toFixed(0) : val.toFixed(1);
|
|
|
+ return {
|
|
|
+ [temperatureValue.value]: {
|
|
|
+ style: {
|
|
|
+ color: val < 75 ? '#4CAF50' : (val < 120 ? '#FFC107' : '#ff0000'),
|
|
|
+ fontWeight: 'bold',
|
|
|
+ },
|
|
|
+ label: `${displayVal}°C`
|
|
|
+ }
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
|
|
|
|
|
|
// 仅传 waterLevelValue,内部组装 config
|