Browse Source

修改状态变更

yuhongqi 2 days ago
parent
commit
b5ee28ef12
1 changed files with 21 additions and 7 deletions
  1. 21 7
      src/views/live/liveConfig/goods.vue

+ 21 - 7
src/views/live/liveConfig/goods.vue

@@ -341,25 +341,39 @@ export default {
   methods: {
     handleSwitchClick(row) {
       // 1. 获取「即将切换到的目标状态」(当前状态取反)
-      const targetStatus = !row.isShow
+      const targetStatus = row.isShow;
+      const originalIsShow = !row.isShow
       const goodsList = [row.goodsId];
+      if (this.socket == null) {
+        this.$message.error("请从直播间开启展示状态!");
+
+        this.$nextTick(() => {
+          row.isShow = originalIsShow;
+        });
+        return;
+      }
       handleIsShowChange({"goodsIds":goodsList,"isShow":targetStatus,"liveId":this.liveId}).then(res=>{
         if(res.code == 200){
           row.isShow = res.isShow
           if (res.msg == "目前仅支持单一物品展示") {
             this.$message.error(res.msg)
           }
-          if (this.socket == null) {
-            this.$message.error("请从直播间开启展示状态!");
-          } else {
+          if (this.socket != null) {
             const msg = {
               cmd: 'goods',
               data: {"liveId":this.liveId,"goodsId":goodsList[0],"status":targetStatus ? 1 : 0}
-            }
-            this.$store.state.liveWs[this.liveId].send(JSON.stringify(msg));
+            };
+            this.socket.send(JSON.stringify(msg));
           }
+        } else {
+          row.isShow = originalIsShow;
         }
-      })
+      }).catch(err => {
+        // 网络错误时,同样恢复原始状态
+        row.isShow = originalIsShow;
+        // this.$set(row, 'isShow', originalIsShow); // 响应式修复
+        console.error("状态切换失败:", err);
+      });
     },
     handleShelf(){
       this.handleShelfOrUn(1)