From 15e2f2216d3d6c81eb495b979cdb1a46e20361c4 Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期三, 15 十一月 2023 15:30:42 +0800
Subject: [PATCH] feat: 添加设备切换弹窗组件, 添加设备切换功能,切换后刷新数据

---
 src/store/index.js |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/store/index.js b/src/store/index.js
index ceffa8e..1a46caf 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -1,16 +1,33 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
+import {getDeviceList} from "@/api/home";
 
 Vue.use(Vuex)
 
 export default new Vuex.Store({
   state: {
+    deviceInfo:null
   },
   getters: {
+    currentDeviceName (state){
+      return  state.deviceInfo?.deviceList?.find((ele) => ele?.deviceID === state.deviceInfo?.currentDeviceID)
+        ?.deviceName ?? ''
+    }
   },
   mutations: {
+    setDeviceInfo(state,deviceInfo){
+      state.deviceInfo = deviceInfo
+    }
   },
   actions: {
+    getDeviceInfo({commit}){
+      return  getDeviceList().then(res=>{
+        commit('setDeviceInfo',res.data)
+      }).catch(err=>{
+        console.error(err)
+        commit('setDeviceInfo',null)
+      })
+    }
   },
   modules: {
   }

--
Gitblit v1.8.0