screenFront/src/store/moduleSocketMechanics.ts

240 lines
8.8 KiB
TypeScript

/*
* @FilePath: \wwwd:\code\screenFront\src\store\moduleSocketjixie.ts
* @Author: 王路平
* @文件版本: V1.0.0
* @Date: 2023-02-06 15:58:13
* @Description:
*
* 版权信息 : 2023 by ${再登软件}, All Rights Reserved.
*/
import { defineStore } from "pinia";
import { Names } from '@/store/storeName'
import { gettime, clacendTime } from "@/utils/time"
export const useSocketStore = defineStore(Names.socketMechanics, {
// 使用方式
// const Index= useIndexStore()
// 1、Index.{数据}++
// 2、Index.$patch({数据:??})
// 3、Index.$patch((state)=>{ state.数据=??})
// 4、通过action修改
state: () => {
return {
humiture: [
{ "devId": "c6f036c0-33fc-11ed-a7e1-fd42bca6c8c6", "name": "精饰车间", "temp": "33.4", "humidity": "30.9" },
{ "devId": "c651b930-3b15-11ed-b6af-15994988a6b3", "name": "精加车间", "temp": "26.1", "humidity": "47" },
{ "devId": "9c4be1e0-33fb-11ed-a7e1-fd42bca6c8c6", "name": "焊接车间", "temp": "29.3", "humidity": "37.6" },
{ "devId": "0e77f0b0-33fc-11ed-a7e1-fd42bca6c8c6", "name": "大件车间", "temp": "28.6", "humidity": "38.4" },
{ "devId": "91f6d000-33fc-11ed-a7e1-fd42bca6c8c6", "name": "机加车间", "temp": "29.9", "humidity": "36.2" }
],
// humiture:{Humiture:[],bottom:{humidity:null,temp:null,name:null},top:{humidity:null,temp:null,name:null}}, //温湿度
pm: [
{
"devId": "01336fd0-1fa0-11ed-9223-7db1174970a8",
"name": "大件车间中部粉尘",
"pm25": "45",
"pm10": "53"
},
{
"devId": "083e3900-3435-11ed-a7e1-fd42bca6c8c6",
"name": "焊接车间粉尘",
"pm25": "30",
"pm10": "36"
},
{
"devId": "270e1500-eee1-11ed-b2ee-2d727e0cafab",
"name": "精加车间粉尘",
"pm25": "71",
"pm10": "84"
},
{
"devId": "54058c30-eee3-11ed-b2ee-2d727e0cafab",
"name": "机加车间粉尘",
"pm25": "22",
"pm10": "26"
},
{
"devId": "76efb040-eee3-11ed-b2ee-2d727e0cafab",
"name": "大件车间东部粉尘",
"pm25": "53",
"pm10": "60"
},
{
"devId": "a6020310-eee3-11ed-b2ee-2d727e0cafab",
"name": "大件车间西部粉尘",
"pm25": "66",
"pm10": "75"
},
{
"devId": "bcbfb530-88b2-11ed-a926-570995ad0254",
"name": "精饰车间粉尘",
"pm25": "6",
"pm10": "7"
}
],
newVerticalNum: [
{
"type": "TVOC",
"icon": "icon-TVOC-Outlined",
"title": "TVOC检测",
"limit": "0.5",
"unit": "mg/m³",
"value": [
{
"name": "精饰车间TVOC/甲醛监测传感器",
"val": null,
"type": "TVOC_CH2O",
"field": "TVOC"
}
]
},
{
"type": "Smoke",
"icon": "icon-yanwubaojingqi",
"title": "烟雾检测",
"limit": "100",
"unit": null,
"value": [
{
"name": "精饰车间烟雾传感器",
"val": null,
"type": "Smoke",
"field": "Smoke_Reg"
}
]
},
{
"type": "Methane",
"icon": "icon-ranqi",
"title": "燃气检测",
"limit": "0",
"unit": null,
"value": [
{
"name": "精饰车间燃气监测",
"val": null,
"type": "Methane",
"field": "Methane_Reg"
},
{
"name": "食堂燃气监测",
"val": null,
"type": "Methane",
"field": "Methane_Reg"
},
{
"name": "锅炉房燃气监测",
"val": null,
"type": "Methane",
"field": "Methane_Reg"
}
]
},
{
"type": "CH2O",
"icon": "icon-app_icons--",
"title": "甲醛检测",
"limit": "0.08",
"unit": "mg/m³",
"value": [
{
"name": "精饰车间TVOC/甲醛监测传感器",
"val": null,
"type": "TVOC_CH2O",
"field": "CH2O"
}
]
},
{
"type": "FIRE",
"icon": "icon-weibiaoti1",
"title": "明火检测",
"limit": "0",
"unit": null,
"value": [
{
"name": "精饰车间火花传感器",
"val": null,
"type": "FIRE",
"field": "Fire_Reg"
}
]
}
]
}
},
//computed 修改一些值
//需要使用return将数据抛出
//getters内可相互使用计算结果
//使用时可直接放入标签内<div>Index.方法()</div>
getters: {
},
actions: {
//设置新的安全检测数据
setNewVerticalNum(val) {
this.newVerticalNum = val
},
//更新 新的安全检测数据
changeNewVerticalNum(val) {
//{"type":"Smoke","data":{"name":"精饰车间烟雾传感器","val":"100"}}
let pIndex = this.newVerticalNum.findIndex(item => item.type == val.type)
let cIndex = null
if (pIndex != -1) {
cIndex = this.newVerticalNum[pIndex].value.findIndex(item => item.devId == val.data.devId)
}
if (cIndex != -1) {
if (val.data.val > this.newVerticalNum[pIndex].limit) {
let now = new Date().getTime()
if (this.newVerticalNum[pIndex].value[cIndex].date == null) {
this.newVerticalNum[pIndex].value[cIndex].date = gettime()
this.newVerticalNum[pIndex].value[cIndex].time = now
}
let time = this.newVerticalNum[pIndex].value[cIndex].time
this.newVerticalNum[pIndex].value[cIndex].continuous = clacendTime(now, time)
} else {
this.newVerticalNum[pIndex].value[cIndex].date = null
this.newVerticalNum[pIndex].value[cIndex].time = null
}
this.newVerticalNum[pIndex].value[cIndex].val = val.data.val
this.newVerticalNum[pIndex].value[cIndex].status = val.data.hasOwnProperty('status')?val.data.status:true
}
},
/**
* @函数功能:
* @param {*} val 温湿度数据
* @出口参数:
* @函数备注:
*/
changeHumiture(val) {
// console.log(this.humiture.Humiture);
val.Humiture.forEach(res => {
this.humiture.forEach(ele => {
if (res.devId == ele.devId) {
ele.humidity = res.humidity
ele.temp = res.temp
}
})
})
},
/**
* 更新粉尘数据
*/
changeDust(val) {
this.pm.forEach(res => {
if (res.devId == val.devId) {
res.pm25 = val.pm25
res.pm10 = val.pm10
}
})
}
}
})