Bläddra i källkod

Merge branch 'master' of http://59.110.91.129:3000/zhangmengying/AIClass into wanzi

丸子 6 månader sedan
förälder
incheckning
33f11aefb3
1 ändrade filer med 20 tillägg och 14 borttagningar
  1. 20 14
      src/views/block/Blockly2.vue

+ 20 - 14
src/views/block/Blockly2.vue

@@ -839,26 +839,27 @@ const aiService = {
   controlCurtain: withErrorHandling('控制窗帘状态', async function(isOn) {
     // 根据传入的布尔值决定是打开还是关闭窗帘
     if (isOn) {
-      await this.openCurtain();
+      this.openCurtain();
     } else {
-      await this.closeCurtain();
+      this.closeCurtain();
     }
     return isOn;
   }, '控制窗帘状态失败'),
 
   // 打开窗帘
   openCurtain: withErrorHandling('打开窗帘', async function() {
+
     console.log("打开窗帘");
 
-    if (!state.showCurtainLeft && !state.showCurtainRight) {
+    if (state.showCurtainLeft && state.showCurtainRight) {
       console.log("窗帘已经是打开的状态");
       return true;
     }
 
     try {
       // 重置窗帘状态
-      state.showCurtainLeft = true;
-      state.showCurtainRight = true;
+      // state.showCurtainLeft = true;
+      // state.showCurtainRight = true;
       state.animateCurtainLeft = false;
       state.animateCurtainRight = false;
 
@@ -897,15 +898,15 @@ const aiService = {
   // 关闭窗帘
   closeCurtain: withErrorHandling('关闭窗帘', async function() {
     console.log("关闭窗帘");
-    if (state.showCurtainLeft && state.showCurtainRight) {
+    if (!state.showCurtainLeft && !state.showCurtainRight) {
       console.log("窗帘已经是关闭的状态");
       return true;
     }
 
     try {
       // 重置窗帘状态
-      state.showCurtainLeft = false;
-      state.showCurtainRight = false;
+      // state.showCurtainLeft = false;
+      // state.showCurtainRight = false;
       state.animateCurtainLeft = false;
       state.animateCurtainRight = false;
 
@@ -944,12 +945,17 @@ const aiService = {
     for (const pair of commandPairs) {
       const [device, action] = pair.split('=');
       if (!device || !action) continue;
+
+      const actionBool = action === 'true' || action === '1' || action === 'on' ? true :
+          action === 'false' || action === '0' || action === 'off' ? false :
+              Boolean(action);
+
       if (device === 'light') {
-        await this.controlTopLamp(action)
+        await this.controlTopLamp(actionBool)
       } else if (device === 'curtain') {
-        await this.controlCurtain(action)
+        await this.controlCurtain(actionBool)
       } else if (device === 'tv') {
-        await this.controlTv(action)
+        await this.controlTv(actionBool)
       }
     }
 
@@ -959,9 +965,9 @@ const aiService = {
   // 智能音箱命令处理 - 多参数版本
   controlSmartSpeakers: withErrorHandling('智能音箱命令处理(多参数)', async function(lightStatus, curtainStatus, tvStatus) {
     console.log(`智能音箱执行命令: light=${lightStatus}, curtain=${curtainStatus}, tv=${tvStatus}`);
-    await this.controlTopLamp(lightStatus)
-    await this.controlCurtain(curtainStatus)
-    await this.controlTv(tvStatus)
+    this.controlTopLamp(lightStatus)
+    this.controlCurtain(curtainStatus)
+    this.controlTv(tvStatus)
 
     return "命令执行完成";
   }, '智能音箱命令执行失败'),