This commit is contained in:
lxz 2024-01-04 19:29:00 +08:00
parent 49bfb7c6c2
commit cec3669a0b
2 changed files with 21 additions and 54 deletions

View File

@ -383,9 +383,7 @@
])
onLoad(() => {
uni.hideTabBar()
// console.log(store.state.userInfo)
if (!store.state.userInfo) {
uni.redirectTo({
url: '/pages/Login/login'
@ -428,17 +426,13 @@
//
let threshold = []
const thresholdFn = (item, min, max) => {
if (item.num < min) {
item.status = (item.num - min).toFixed(1)
}
if (item.num > max) {
item.status = (item.num - max).toFixed(1)
}
}
//
const environmentList = reactive([{
icon: "FS",
@ -499,6 +493,7 @@
])
onShow(() => {
// getlist()
getlist1()
getlist2()
@ -514,13 +509,14 @@
lindexist({
land_id: tdId.value
}).then((res) => {
if (res.code == 1) {
userInfo.value = res.data
scoketData = {
username: userInfo.value.master_phone,
device: 'lihai_lot_walnutpi_dev_' + userInfo.value.device_id
}
openScoket()
// console.log(scoketData)
video_url.value = res.data.video_url
threshold = res.data?.monitor?.threshold || ""
if (Object.keys(res.data).length > 0) {
@ -552,29 +548,15 @@
environmentList[6].num = res.data.monitor.air_monitor_data.rainfall
environmentList[7].num = res.data.monitor.air_monitor_data.light_intensity
thresholdFn(environmentList[0], threshold.wind_speed_min, threshold.wind_speed_max)
// thresholdFn(environmentList[1], threshold.wind_speed_min, threshold.wind_speed_max)
// sdf
thresholdFn(environmentList[2], threshold.air_temp_min, threshold.air_temp_max)
thresholdFn(environmentList[3], threshold.air_mois_min, threshold.air_mois_max)
thresholdFn(environmentList[4], threshold.air_co2_content_min, threshold
.air_co2_content_max)
thresholdFn(environmentList[5], threshold.ambient_air_pressure_min, threshold
.ambient_air_pressure_max)
// sdf
// thresholdFn(environmentList[6], threshold.ambient_air_pressure_min, threshold.ambient_air_pressure_max)
// thresholdFn(environmentList[6], threshold.ambient_air_pressure_min, threshold.ambient_air_pressure_max)
}
}
@ -590,12 +572,6 @@
keyword: ''
}).then((res) => {
if (res.code == 1) {
tdId.value = res.data[0]?.id || ''
getlist()
if (res.data.length > 0) {
@ -739,12 +715,17 @@
const openScoket = () => {
console.log("openScoket")
if (store.state.onScoket) return
store.dispatch('changeScoket')
// console.log("scoket")
// return
uni.connectSocket({
url: 'ws://60.204.152.17:8765'
url: 'ws://iot.lihaink.cn'
});
uni.onSocketOpen(function(res) {
store.dispatch('changeScoket')
uni.sendSocketMessage({
data: JSON.stringify(scoketData)
});
@ -757,30 +738,6 @@
console.log('WebSocket 已关闭!');
});
}
setTimeout(() => {
uni.connectSocket({
url: 'ws://60.204.152.17:8765'
});
uni.onSocketOpen(function(res) {
uni.sendSocketMessage({
data: JSON.stringify(scoketData)
});
});
uni.onSocketError(function(res) {
console.log('WebSocket连接打开失败请检查');
});
uni.onSocketClose(function(res) {
console.log('WebSocket 已关闭!');
});
}, 5000)
onPullDownRefresh(() => {
getlist1()
getlist2()

View File

@ -4,7 +4,8 @@ import {
const store = createStore({
state: {
userInfo: uni.getStorageSync("SY_USER") || null,
tabbrIndex: 0
tabbrIndex: 0,
onScoket: false,
},
@ -15,6 +16,9 @@ const store = createStore({
},
changeTabbar(state, index) {
state.tabbrIndex = index
},
changeScoket(state, index) {
state.onScoket = true
}
},
actions: {
@ -30,6 +34,12 @@ const store = createStore({
}, info) {
commit('changeTabbar', info)
},
changeScoket({
commit
}, info) {
commit('changeScoket')
}
}
})