diff --git a/src/components/Operator.vue b/src/components/Operator.vue index 5a412fc..474f08e 100644 --- a/src/components/Operator.vue +++ b/src/components/Operator.vue @@ -117,7 +117,7 @@ const logVal = ref(1) const roomSize = ref(0) watch(() => { - roomSize.value = props.input.match(/\d+/g) + roomSize.value = props.input.match(/\d+/g)[0] }) const changeLogVal = val => { @@ -131,6 +131,7 @@ const startDisinfect = () => { if (roomSize.value == 0) { showFailToast('请调整房间大小设置,不能为0') } else { + console.log(roomSize.value) webSocketStore.sendCommandMsg( startDisinfectionJSON(logVal.value, roomSize.value), ) diff --git a/src/components/Progress.vue b/src/components/Progress.vue index 1f58ef2..dddb416 100644 --- a/src/components/Progress.vue +++ b/src/components/Progress.vue @@ -59,6 +59,7 @@ import { useOperatorStore, useWebSocketStore } from '@/store' import { stopDisinfectionJSON, getStateJSON, + continueDisinfectionJSON, pauseDisinfectionJSON, } from '@/mock/command' import { onMounted, onUnmounted, ref } from 'vue' @@ -66,7 +67,7 @@ import * as echarts from 'echarts' const binOption = ref({ legend: { - data: ['Email', 'Union Ads', 'Video Ads'], + data: ['温度', '湿度', '过氧化氢浓度'], }, grid: { left: '3%', @@ -84,19 +85,19 @@ const binOption = ref({ }, series: [ { - name: 'Email', + name: '温度', type: 'line', stack: 'Total', data: [120, 132, 101, 134, 90, 230, 210], }, { - name: 'Union Ads', + name: '湿度', type: 'line', stack: 'Total', data: [220, 182, 191, 234, 290, 330, 310], }, { - name: 'Video Ads', + name: '过氧化氢浓度', type: 'line', stack: 'Total', data: [150, 232, 201, 154, 190, 330, 410], @@ -104,8 +105,18 @@ const binOption = ref({ ], }) const envir1Option = ref({ + legend: { + data: ['温度', '湿度', '过氧化氢浓度'], + }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true, + }, xAxis: { type: 'category', + boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], }, yAxis: { @@ -113,14 +124,38 @@ const envir1Option = ref({ }, series: [ { - data: [150, 230, 224, 218, 135, 147, 260], + name: '温度', type: 'line', + stack: 'Total', + data: [120, 132, 101, 134, 90, 230, 210], + }, + { + name: '湿度', + type: 'line', + stack: 'Total', + data: [220, 182, 191, 234, 290, 330, 310], + }, + { + name: '过氧化氢浓度', + type: 'line', + stack: 'Total', + data: [150, 232, 201, 154, 190, 330, 410], }, ], }) const envir2Option = ref({ + legend: { + data: ['温度', '湿度', '过氧化氢浓度'], + }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true, + }, xAxis: { type: 'category', + boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], }, yAxis: { @@ -128,8 +163,22 @@ const envir2Option = ref({ }, series: [ { - data: [150, 230, 224, 218, 135, 147, 260], + name: '温度', + type: 'line', + stack: 'Total', + data: [120, 132, 101, 134, 90, 230, 210], + }, + { + name: '湿度', type: 'line', + stack: 'Total', + data: [220, 182, 191, 234, 290, 330, 310], + }, + { + name: '过氧化氢浓度', + type: 'line', + stack: 'Total', + data: [150, 232, 201, 154, 190, 330, 410], }, ], }) @@ -150,12 +199,21 @@ onMounted(() => { timer.value = setInterval(() => { webSocketStore.sendCommandMsg(getStateJSON) }, 1000) - var binCharts = echarts.init(document.getElementById('bin')) - binCharts.setOption(binOption.value) - var envir1Charts = echarts.init(document.getElementById('envir1')) - envir1Charts.setOption(envir1Option.value) - var envir2Charts = echarts.init(document.getElementById('envir2')) - envir2Charts.setOption(envir2Option.value) + let a = echarts.getInstanceByDom(document.getElementById('bin')) + if (a == undefined) { + var binCharts = echarts.init(document.getElementById('bin')) + binCharts.setOption(binOption.value) + } + let b = echarts.getInstanceByDom(document.getElementById('envir1')) + if (b == undefined) { + var envir1Charts = echarts.init(document.getElementById('envir1')) + envir1Charts.setOption(envir1Option.value) + } + let c = echarts.getInstanceByDom(document.getElementById('envir2')) + if (c == undefined) { + var envir2Charts = echarts.init(document.getElementById('envir2')) + envir2Charts.setOption(envir2Option.value) + } }) onUnmounted(() => { timer.value = null @@ -177,6 +235,7 @@ const stopDisinfect = () => { const continueDisinfect = () => { if (!operatorStore.disinfectStatus) { + webSocketStore.sendCommandMsg(continueDisinfectionJSON) operatorStore.updateDisinfectStatus(true) } } diff --git a/src/components/Setting/components/Admin.vue b/src/components/Setting/components/Admin.vue index 1b1941a..43d9853 100644 --- a/src/components/Setting/components/Admin.vue +++ b/src/components/Setting/components/Admin.vue @@ -66,9 +66,13 @@ diff --git a/src/components/Setting/components/User.vue b/src/components/Setting/components/User.vue index df83c58..875ac30 100644 --- a/src/components/Setting/components/User.vue +++ b/src/components/Setting/components/User.vue @@ -133,9 +133,19 @@ const updateUserPassword = () => { return } updateUserInfoTip.value = '' - webSocketStore.sendCommandMsg( - chpasswdJSON(userStore.operUser, updateUserNewPassword.value), + // 从userlist中筛选出当前user + const arr = userStore.allUserList.filter( + item => item.uid == userStore.operUser, ) + if (arr?.length > 0) { + webSocketStore.sendCommandMsg( + chpasswdJSON( + userStore.operUser, + updateUserNewPassword.value, + arr[0]?.passwd, + ), + ) + } } const handleAddPasswordShow = () => { diff --git a/src/mock/command.js b/src/mock/command.js index deb93a2..587a2b5 100644 --- a/src/mock/command.js +++ b/src/mock/command.js @@ -15,11 +15,12 @@ export const logoutJSON = { } // 改密码 -export const chpasswdJSON = (userId, passwd) => { +export const chpasswdJSON = (userId, newpasswd, passwd) => { return { command: 'chpasswd', messageId: 'chpasswd', userId, + newpasswd, passwd, } } @@ -41,6 +42,11 @@ export const startDisinfectionJSON = (loglevel, roomVolume) => { } } +export const continueDisinfectionJSON = { + command: 'continueDisinfection', + messageId: 'continueDisinfection', +} + // 停止消毒 export const stopDisinfectionJSON = { command: 'stopDisinfection', diff --git a/src/pages/Home.vue b/src/pages/Home.vue index f21736a..b03f415 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -120,7 +120,7 @@

设置

- - + /> @@ -242,6 +241,9 @@ const onChange = a => { } const changeTab = index => { + if ([2, 3, 4, 5].includes(index) && operatorStore.disinfectStatus) { + return + } activeTab.value = index if (index == 5) { // getAllSetting diff --git a/src/store/modules/websocket.js b/src/store/modules/websocket.js index d9d2a56..1e38a3a 100644 --- a/src/store/modules/websocket.js +++ b/src/store/modules/websocket.js @@ -5,6 +5,7 @@ import { useUserStore } from './user' import { useOperatorStore } from './operator' import { useDeviceStore } from './device' import { useTestStore } from './test' +import { showSuccessToast, showFailToast } from 'vant' export const useWebSocketStore = defineStore({ id: 'websocket', // id必填,且需要唯一 @@ -32,88 +33,91 @@ export const useWebSocketStore = defineStore({ // console.log(JSON.parse(ev.data)) const { ackcode, messageId } = JSON.parse(ev.data) - if (ackcode == 0) { - switch (messageId) { - case 'getState': - // 初始化完毕 - const { state } = JSON.parse(ev.data) - const { - workState, - estimatedRemainingTimeS, - disinfection_id, - isLogin, - permissionLevel, - sensor_data, - } = state || {} - if (!isLogin) { - window.location.href = '/login' - return - } - const { - h2o2_1, - h2o2_2, - h2o2_3, - humid_1, - humid_2, - humid_3, - temp_1, - temp_2, - temp_3, - airCompressor, - disinfectant_volume, - heatingStrip, - airBlower, - sprinklerPump, - chargingPump, - } = sensor_data - // 将sensor_data中的数据更新到store中 - testStore.updateAirCompressorObj(airCompressor) - testStore.updateAirBlowerObj(airBlower) - testStore.updateHeatingStripObj(heatingStrip) - testStore.updateSprinklerPump(sprinklerPump) - testStore.updateChargingPump(chargingPump) - settingStore.updateDeviceIp('127.0.0.1') - deviceStore.updateDisinfectantCapacity(disinfectant_volume) - deviceStore.updateBinTemperature(temp_1) - deviceStore.updateBinHumidity(humid_1) - deviceStore.updateBinHP(h2o2_1) - deviceStore.updateEnvirTemperature1(temp_2) - deviceStore.updateEnvirHumidity1(humid_2) - deviceStore.updateEnvirHP1(h2o2_2) - deviceStore.updateEnvirTemperature2(temp_3) - deviceStore.updateEnvirHumidity2(humid_3) - deviceStore.updateEnvirHP2(h2o2_3) + switch (messageId) { + case 'getState': + // 初始化完毕 + const { state } = JSON.parse(ev.data) + const { + workState, + estimatedRemainingTimeS, + disinfection_id, + isLogin, + permissionLevel, + sensor_data, + } = state || {} + if (!isLogin) { + window.location.href = '/login' + return + } + const { + h2o2_1, + h2o2_2, + h2o2_3, + humid_1, + humid_2, + humid_3, + temp_1, + temp_2, + temp_3, + airCompressor, + disinfectant_volume, + heatingStrip, + airBlower, + sprinklerPump, + chargingPump, + } = sensor_data + // 将sensor_data中的数据更新到store中 + testStore.updateAirCompressorObj(airCompressor) + testStore.updateAirBlowerObj(airBlower) + testStore.updateHeatingStripObj(heatingStrip) + testStore.updateSprinklerPump(sprinklerPump) + testStore.updateChargingPump(chargingPump) + settingStore.updateDeviceIp('192.168.8.10') + deviceStore.updateDisinfectantCapacity(disinfectant_volume) + deviceStore.updateBinTemperature(temp_1) + deviceStore.updateBinHumidity(humid_1) + deviceStore.updateBinHP(h2o2_1) + deviceStore.updateEnvirTemperature1(temp_2) + deviceStore.updateEnvirHumidity1(humid_2) + deviceStore.updateEnvirHP1(h2o2_2) + deviceStore.updateEnvirTemperature2(temp_3) + deviceStore.updateEnvirHumidity2(humid_3) + deviceStore.updateEnvirHP2(h2o2_3) - userStore.updatePermission(permissionLevel) - settingStore.updateInitLoading() - operatorStore.updateDisinfectStatus(workState) - operatorStore.updateEstimatedRemainingTimeS( - estimatedRemainingTimeS, - ) - operatorStore.updateDisinfectionId(disinfection_id) - // 将sensor_data中的数据更新到store中 - break - case 'getAllUser': - const { dbval } = JSON.parse(ev.data) - userStore.updateUserList(dbval) - break - case 'chpasswd': - break - case 'startDisinfection': - break - case 'stopDisinfection': - break - case 'login': - break - case 'getAllRecords': - break - case 'getAllSetting': - const { dbval: allSetting } = JSON.parse(ev.data) - settingStore.updateAllSettingList(allSetting) - break - default: - break - } + userStore.updatePermission(permissionLevel) + settingStore.updateInitLoading() + operatorStore.updateDisinfectStatus(workState) + operatorStore.updateEstimatedRemainingTimeS(estimatedRemainingTimeS) + operatorStore.updateDisinfectionId(disinfection_id) + // 将sensor_data中的数据更新到store中 + break + case 'getAllUser': + const { dbval } = JSON.parse(ev.data) + userStore.updateUserList(dbval) + break + case 'chpasswd': + console.log(JSON.parse(ev.data)) + if (ackcode != 0) { + // 修改失败 + showFailToast('修改失败') + } else { + showSuccessToast('修改成功') + } + break + case 'startDisinfection': + break + case 'stopDisinfection': + break + case 'login': + break + case 'getAllRecords': + break + case 'getAllSetting': + const { dbval: allSetting } = JSON.parse(ev.data) + settingStore.updateAllSettingList(allSetting) + break + default: + break } } this.socketCommandInstance = init @@ -157,7 +161,7 @@ export const useWebSocketStore = defineStore({ testStore.updateHeatingStripObj(heatingStrip) testStore.updateSprinklerPump(sprinklerPump) testStore.updateChargingPump(chargingPump) - settingStore.updateDeviceIp('127.0.0.1') + settingStore.updateDeviceIp('192.168.8.10') deviceStore.updateDisinfectantCapacity(disinfectant_volume) deviceStore.updateBinTemperature(temp_1) deviceStore.updateBinHumidity(humid_1)