邓洁 : 传感器接口对接

This commit is contained in:
dengj
2023-12-13 12:52:59 +08:00
parent 241a031cc5
commit 2d1fbb27ca
4 changed files with 58 additions and 87 deletions

View File

@@ -3,98 +3,78 @@
<div class="fan-speed">
<img src="@/assets/images/airInfo/fan-v-icon.png" alt=""/>
<div class="fan-info">
<div class="input-fan"><span>风速</span><span>进风13m/s</span></div>
<div class="output-fan"><span>出风13m/s</span></div>
<div class="input-fan"><span>风速</span><span>进风{{ windSpeed }}m/s</span></div>
<div class="output-fan"><span>出风{{windSpeed}}m/s</span></div>
</div>
</div>
<item-info
:wp="info"
icon="o2-icon.png"
name="氧气"
unit="%"
/>
<item-info
:wp="info1"
icon="tempture-icon.png"
name="温度"
unit=".c"
/>
<item-info
:wp="info2"
icon="water-icon.png"
name="湿度"
unit="%"
/>
<item-info
:wp="info3"
icon="dust-icon.png"
name="粉尘"
unit="mg/m3"
v-for="item in airList"
:wp="item"
:icon="item.icon"
:name="item.name"
:unit="item.unit"
/>
</div>
</template>
<script setup>
import {ref, reactive} from "vue";
import ItemInfo from "./childComps/ItemInfo.vue";
const props = defineProps({
list: Array,
airData: Array
});
let info = reactive({
// windPId: 0, //编号
// max: 120, //最大值
// value: 70, //测量值
// point: 60, //阈值
});
let info1 = reactive({});
let info2 = reactive({});
let info3 = reactive({});
const windSpeed=ref('')
const airList = ref([])
watch(() => props.list, (now) => {
airList.value.forEach(item=>{
now.forEach(newItem=>{
if(item.equipmentId === newItem.equipmentId){
item.value = newItem.value
}
})
})
}, {deep: true});
watch(() => props.airData, (now) => {
getAirInfo(now.sensorList)
}, {deep: true});
watch(() => props.list, (now, old) => {
console.log('传感器 ', now, old)
now.map(item=>{
getInfo(item)
})
}, {deep: true});
const changeData=(item,flag)=>{
return{
const changeData = (item, flag) => {
return {
equipmentId: item.equipmentId,
icon: changeIcon(item.equipmentType),
name: item.equipmentName.slice(0, 2),
max: 120,
value: flag?flag.value:item.value,
value: flag ? flag.value : item.value,
point: item.valueThreshold,
unit:item.unit
unit: item.unit
}
}
const getInfo=(item)=>{
if(item.equipmentId==info.equipmentId){
// info.value=item.value
changeData(item,info1)
console.log('info',info)
}else if(item.equipmentId==info1.equipmentId){
changeData(item,info1)
}else if(item.equipmentId==info2.equipmentId){
changeData(item,info2)
}else if(item.equipmentId==info3.equipmentId){
changeData(item,info3)
const changeIcon = (type) => {
switch (type) {
case "dust":
return 'dust-icon.png';
case "oxygen":
return 'o2-icon.png';
case "temperature":
return 'tempture-icon.png';
case "humidness":
return 'water-icon.png';
}
}
const getAirInfo = (now) => {
let windPressureObj = {}
let windPressureArr = []
now.map(item => {
if (item.equipmentType === "dust") {//粉尘
info3 = changeData(item)
} else if (item.equipmentType === "oxygen") {//氧气
info = changeData(item)
} else if (item.equipmentType === "temperature") {//温度
info1 = changeData(item)
} else if (item.equipmentType === "humidness") {//湿度
info2 = changeData(item)
if (item.equipmentType === "dust" || item.equipmentType === "oxygen" || item.equipmentType === "temperature" || item.equipmentType === "humidness") {
windPressureObj = changeData(item)
windPressureArr.push(windPressureObj)
}else if(item.equipmentType === "windDirection"){
windSpeed.value = item.value
}
})
windPressureArr.push(windPressureArr.shift())
airList.value = windPressureArr
}
</script>

View File

@@ -2,7 +2,6 @@
<div id="item-info">
<div class="label">
<div :style="{ backgroundImage: 'url(' +getImageUrl(windIcon)+')' }" class="wind-icon"></div>
<!-- <img :src="params.icon" alt="" />-->
<span>{{ params.name }}</span>
</div>
<div class="container" ref="length">
@@ -16,8 +15,6 @@
</template>
<script setup>
import {onMounted, watch, defineProps, computed} from "vue";
const params = defineProps({
wp: Object,
icon: String,
@@ -34,21 +31,19 @@ const windIcon = reactive(params.icon);
const length = ref(null);
const value = ref(null);
const point = ref(null);
// onMounted(handleOnMounted);
//
// function handleOnMounted() {
// // const = length.value.offsetWidth);
// setValue();
// }
onMounted(handleOnMounted);
watch(() => params.wp.value, (val) => {
console.log('xin----', val)
setValue(value);
}, {deep: true});
function handleOnMounted() {
setValue();
}
watch(() => params.wp.value, () => {
setValue();
});
const getImageUrl = (name) => {
return new URL(`../../../../assets/images/airInfo/${name}`, import.meta.url).href
}
const setValue = (val) => {
const setValue = () => {
let width = (params.wp.value * length.value.offsetWidth) / params.wp.max;
value.value.style.width = `${width}px`;
let flag = (params.wp.point * length.value.offsetWidth) / params.wp.max;
@@ -65,7 +60,7 @@ let isWaring = computed(() => {
return params.wp.value >= params.wp.point;
});
const valueAndUnit = computed(() => params.wp.value + params.unit + "");
const valueAndUnit = computed(() => params.wp.value + " "+ params.unit );
</script>
<style lang="scss" scoped>

View File

@@ -15,11 +15,11 @@ const props = defineProps({
winData: Array
});
const wpList = ref([]);
watch(() => props.list, (now, old) => {
watch(() => props.list, (now) => {
wpList.value.forEach(item=>{
now.forEach(item2=>{
if(item.equipmentId === item2.equipmentId){
item.value = item2.value
now.forEach(newItem=>{
if(item.equipmentId === newItem.equipmentId){
item.value = newItem.value
}
})
})

View File

@@ -15,8 +15,6 @@
</template>
<script setup>
import {reactive, onMounted, watch, defineProps, computed} from "vue";
const params = defineProps({
wp: Object,
index: Number,
@@ -27,18 +25,16 @@ const params = defineProps({
// value: 40, //测量值
// point: 60, //阈值
// };
// const wp = reactive(info);
const length = ref(null);
const value = ref(null);
const point = ref(null);
onMounted(handleOnMounted);
function handleOnMounted() {
// const = length.value.offsetWidth);
setValue();
}
watch(() => params.wp.value, (value) => {
watch(() => params.wp.value, () => {
setValue();
});