From d553a4be94d4f6ee162cc353a28b220403909cfc Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期六, 03 十月 2026 00:58:19 +0800
Subject: [PATCH] ai优化

---
 src/store/modules/room.ts |   50 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/store/modules/room.ts b/src/store/modules/room.ts
index f3f771b..74fe57b 100644
--- a/src/store/modules/room.ts
+++ b/src/store/modules/room.ts
@@ -52,13 +52,17 @@
       this.room!.opType = room.opType
       this.isSetRoom = true
 
-      // 鏇存柊 cache
-      const bedInfo = wsCache.get(CACHE_KEY.ROOM)
-      if (bedInfo) {
-        bedInfo.room = room
-        bedInfo.isSetRoom = true
-        wsCache.set(CACHE_KEY.ROOM, bedInfo)
-      }
+      // 銆愪慨澶嶃�戝啓鍏ョ紦瀛橈紙sessionStorage锛夈��
+      //
+      // 鍘熷疄鐜版槸 `const bedInfo = wsCache.get(...); if (bedInfo) { ...; wsCache.set(...) }`
+      // 鈥斺�� **鍙湪缂撳瓨宸插瓨鍦ㄦ椂鎵嶆洿鏂帮紝鑰屽叏椤圭洰娌℃湁浠讳綍鍦版柟棣栨鍐欏叆**锛�
+      // 浜庢槸 ROOM 缂撳瓨浠庢湭琚垱寤猴紝`room` 鍙椿鍦ㄥ唴瀛橀噷锛�
+      //   路 鍒锋柊椤甸潰 / 鏂板紑鏍囩椤� / 浠庝細璇濇仮澶嶅悗锛宍isSetRoom` 鍙堟槸鍒濆鐨� false锛�
+      //   路 鑰屽悇鍖荤敓椤甸潰锛圧outine/index/DevInstall锛夊彧鍦� `isSetRoom === true` 鏃�
+      //     鎵嶅惎鍔ㄥ彇鏁板畾鏃跺櫒 鈬� **椤甸潰涓�鐗囩┖鐧斤紝鐪嬭捣鏉ュ儚"娌″姞杞芥帓闃熺梾浜�"**锛�
+      //   路 瑙掕壊涓� doctor 鐨勭敤鎴疯繕浼氳璺敱瀹堝崼寮瑰洖 /roomselect 閲嶆柊閫夎瘖瀹ゃ��
+      // 杩欓噷鏀逛负**鏃犳潯浠跺啓鍏�**锛涙仮澶嶈鏂囦欢鏈熬鐨� setupRoomStorePersistence()銆�
+      wsCache.set(CACHE_KEY.ROOM, { isSetRoom: true, room: this.room })
     },
     // 鍖荤敓绂诲骇
     async clearRoomInfoAction() {
@@ -73,12 +77,23 @@
 
       this.isSetRoom = false
 
-      // 鏇存柊 cache
-      const roomInfo = wsCache.get(CACHE_KEY.ROOM)
-      if (roomInfo) {
-        roomInfo.room = null
-        roomInfo.isSetRoom = false
-        wsCache.set(CACHE_KEY.ROOM, roomInfo)
+      // 娓呯紦瀛橈紙涓庝笂闈㈢殑鍐欏叆瀵瑰簲锛岄伩鍏嶄笅娆″惎鍔ㄦ妸宸茬搴х殑璇婂鎭㈠鍑烘潵锛�
+      wsCache.delete(CACHE_KEY.ROOM)
+    },
+    /**
+     * 銆愪慨澶嶃�戝簲鐢ㄥ惎鍔ㄦ椂浠� sessionStorage 鎭㈠銆屽尰鐢熷凡閫夎瘖瀹ゃ�嶃��
+     *
+     * 涓轰粈涔堥渶瑕侊細`isSetRoom` 鏄唴瀛樻�侊紝鍒锋柊鍗充涪锛涜�屽悇鍖荤敓椤甸潰閮介潬瀹冨喅瀹氭槸鍚﹀彇鏁般��
+     * 鎭㈠鏃跺悓鏃舵牎楠岃瘖瀹や俊鎭畬鏁达紙roomId + bedNo锛夛紝閬垮厤鑴忕紦瀛樻寚鍚戜笉瀛樺湪鐨勫伐浣嶃��
+     */
+    restoreRoomInfo() {
+      if (this.isSetRoom && this.room?.roomId != null) {
+        return // 鍐呭瓨閲屽凡鏈夛紝鏃犻渶鎭㈠
+      }
+      const cached = wsCache.get(CACHE_KEY.ROOM)
+      if (cached?.isSetRoom && cached?.room?.roomId != null && cached?.room?.bedNo != null) {
+        this.room = { ...this.room, ...cached.room }
+        this.isSetRoom = true
       }
     },
   }
@@ -87,3 +102,12 @@
 export const useRoomStoreWithOut = () => {
   return useRoomStore(store)
 }
+
+/**
+ * 鍦ㄥ簲鐢ㄥ惎鍔ㄩ樁娈佃皟鐢ㄤ竴娆★紙瑙� src/main.ts锛夛紝鎶娿�屽凡閫夎瘖瀹ゃ�嶄粠 sessionStorage 鎭㈠鍒� store銆�
+ *
+ * 蹇呴』鏃╀簬璺敱瀹堝崼涓庡悇鍖荤敓椤甸潰鐨� onMounted锛屽惁鍒欓〉闈細鍥犱负 isSetRoom=false 鑰屽畬鍏ㄤ笉鍙栨暟銆�
+ */
+export const setupRoomStorePersistence = () => {
+  useRoomStoreWithOut().restoreRoomInfo()
+}

--
Gitblit v1.9.3