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

View File

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