From 6966cf4c163e90a7d19ecd9b7f9c9943742dbb20 Mon Sep 17 00:00:00 2001 From: maochaoying <925670706@qq.com> Date: Mon, 14 Aug 2023 22:40:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E4=BB=A4=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Setting/components/Device.vue | 29 +++++++++++++++++++++------- src/mock/command.js | 4 ++-- src/pages/Home.vue | 6 +++++- src/store/modules/setting.js | 14 ++++++++++++++ src/store/modules/websocket.js | 24 ++++++++++++----------- 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/components/Setting/components/Device.vue b/src/components/Setting/components/Device.vue index c8f9b59..596a90c 100644 --- a/src/components/Setting/components/Device.vue +++ b/src/components/Setting/components/Device.vue @@ -5,7 +5,7 @@

import { ref } from 'vue' import { showSuccessToast, showFailToast } from 'vant' -import { useSettingStore } from '@/store' +import { useSettingStore, useWebSocketStore } from '@/store' +import { storeToRefs } from 'pinia' +import { setSettingValJSON } from '@/mock/command' + const settingStore = useSettingStore() -const addLiquidVal = ref(settingStore.addLiquidConfigVal) -const sprayLiquidVal = ref(settingStore.sprayLiquidConfigVal) +const webSocketStore = useWebSocketStore() +const { addLiquidConfigVal, sprayLiquidConfigVal } = storeToRefs(settingStore) const formatter = value => { + if (value > 2000) { + return '2000/g' + } if (value != 0) { var newVal = value.replace(/\b(0+)/gi, '') return newVal + '/g' @@ -47,17 +53,26 @@ const formatter = value => { const setAddliquidVal = () => { const val = parseInt( - addLiquidVal.value.substring(0, addLiquidVal.value.length - 2), + addLiquidConfigVal.value.substring(0, addLiquidConfigVal.value.length - 2), ) settingStore.changeAddLiquidConfigVal(val) + webSocketStore.sendCommandMsg( + setSettingValJSON('drainage_pump_speed', addLiquidConfigVal.value), + ) showSuccessToast('设置成功') } const setSprayLiquidVal = () => { const val = parseInt( - sprayLiquidVal.value.substring(0, sprayLiquidVal.value.length - 2), + sprayLiquidConfigVal.value.substring( + 0, + sprayLiquidConfigVal.value.length - 2, + ), ) settingStore.changeSprayLiquidConfigVal(val) + webSocketStore.sendCommandMsg( + setSettingValJSON('injection_pump_speed', sprayLiquidConfigVal.value), + ) showSuccessToast('设置成功') } diff --git a/src/mock/command.js b/src/mock/command.js index b3aaf8c..edaf82f 100644 --- a/src/mock/command.js +++ b/src/mock/command.js @@ -58,7 +58,7 @@ export const getAllUserJSON = { messageId: 'getAllUser', } -export const getAllSetting = { +export const getAllSettingJSON = { command: 'getAllSetting', messageId: 'getAllSetting', } @@ -71,7 +71,7 @@ export const getAllRecords = disinfection_id => { } } -export const setSettingVal = (settingName, settingVal) => { +export const setSettingValJSON = (settingName, settingVal) => { return { command: 'setSettingVal', messageId: 'setSettingVal', diff --git a/src/pages/Home.vue b/src/pages/Home.vue index f678576..5a53274 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -191,7 +191,7 @@ import { useSettingStore, useUserStore, } from '@/store' -import { logoutJSON, getStateJSON } from '@/mock/command' +import { logoutJSON, getStateJSON, getAllSettingJSON } from '@/mock/command' import { useRouter } from 'vue-router' const router = useRouter() @@ -215,6 +215,10 @@ const changeShowOperator = flag => { const changeTab = index => { activeTab.value = index + if (index == 5) { + // getAllSetting + webSocketStore.sendCommandMsg(getAllSettingJSON) + } } const getdateTime = () => { diff --git a/src/store/modules/setting.js b/src/store/modules/setting.js index eb01d21..15c3535 100644 --- a/src/store/modules/setting.js +++ b/src/store/modules/setting.js @@ -14,10 +14,24 @@ export const useSettingStore = defineStore({ sprayLiquidConfigVal: 0, // 首屏初始化 initLoading: true, + // 所有setting的对象数据 + allSettingList: [], } }, // actions actions: { + updateAllSettingList(allSettingList) { + // 对当前数组进行处理 赋予给泵参数 + const addLiquid = allSettingList.filter( + item => item.name == 'drainage_pump_speed', + )[0] + const sprayLiquid = allSettingList.filter( + item => item.name == 'injection_pump_speed', + )[0] + this.addLiquidConfigVal = addLiquid.val + this.sprayLiquidConfigVal = sprayLiquid.val + this.allSettingList = allSettingList + }, updateInitLoading() { this.initLoading = false }, diff --git a/src/store/modules/websocket.js b/src/store/modules/websocket.js index ad49b5c..bdac749 100644 --- a/src/store/modules/websocket.js +++ b/src/store/modules/websocket.js @@ -38,8 +38,6 @@ export const useWebSocketStore = defineStore({ userStore.updateUserList(dbval) break case 'chpasswd': - // const { dbval } = JSON.parse(ev.data) - // userStore.updateUserList(dbval) break case 'startDisinfection': break @@ -47,6 +45,10 @@ export const useWebSocketStore = defineStore({ break case 'login': break + case 'getAllSetting': + const { dbval: allSetting } = JSON.parse(ev.data) + settingStore.updateAllSettingList(allSetting) + break default: break } @@ -63,15 +65,15 @@ export const useWebSocketStore = defineStore({ init.connect() init.ws.onmessage = function (data) { // console.log(data) - const { command } = data - switch (command) { - case 'RealtimeSensorDataReport': - const { sensor_data } = data || {} - // 将sensor_data中的数据更新到store中 - break - default: - break - } + // const { command } = data + // switch (command) { + // case 'RealtimeSensorDataReport': + // const { sensor_data } = data || {} + // // 将sensor_data中的数据更新到store中 + // break + // default: + // break + // } } this.socketEventInstance = init },