ソースを参照

虚拟实验室-智能家居:
1、窗帘初始状态
2、台灯颜色初始状态

liyanbo 6 ヶ月 前
コミット
8aff379e64
3 ファイル変更22 行追加15 行削除
  1. 0 1
      src/api/blockly/music.js
  2. 14 7
      src/views/block/Blockly.vue
  3. 8 7
      src/views/block/Blockly2.vue

+ 0 - 1
src/api/blockly/music.js

@@ -17,7 +17,6 @@ export const musicTypeConfig = {
     }
 };
 
-// 播放音乐函数 - 修改为接受参数而不是直接使用外部变量
 // 播放音乐函数 - 修改为接受参数而不是直接使用外部变量
 export const playMusic = (musicType, state, musicPlayer) => {
     console.log(`播放音乐类型: ${musicType}`);

+ 14 - 7
src/views/block/Blockly.vue

@@ -454,7 +454,7 @@ const state = reactive({
 
   // 台灯状态
   lamp: {
-    isLightOn: false,// 台灯是否亮着
+    isLightOn: true,// 台灯是否亮着
     brightness: 50, // 默认亮度50%
     color: "#ffffff", // 默认颜色白色
     colorLog: "白", // 默认颜色白色
@@ -899,13 +899,13 @@ const aiService = {
   // 综合控制台灯(参数格式:"颜色, 亮度, 音乐")
   controlLampWithSingleParam: withErrorHandling('智能台灯综合控制', async function(params) {
     // 解析参数字符串
-    let color = ''; // 默认颜色
+    let color = ''; // 默认颜色
     let brightness = 0; // 默认亮度
     let music = ''; // 音乐信息
 
     if (params && typeof params === 'string') {
       // 根据逗号分割参数
-      const paramArray = params.split('').map(p => p.trim());
+      const paramArray = params.split(',').map(p => p.trim());
 
       // 提取颜色(第一个参数)
       if (paramArray.length > 0 && paramArray[0]) {
@@ -921,8 +921,10 @@ const aiService = {
       if (paramArray.length > 2 && paramArray[2]) {
         music = paramArray[2];
 
-        // 调用音乐播放函数
-        await this.playMusic(music);
+        if (music !== '不播放') {
+          // 调用音乐播放函数
+          await this.playMusic(music);
+        }
       }
     }
     // 调用控制台灯方法
@@ -931,11 +933,16 @@ const aiService = {
 
   // 综合控制台灯(参数格式:"颜色, 亮度")
   controlLamp: withErrorHandling('智能台灯控制', async function(brightness, color) {
+
     // 先设置亮度
-    await this.setLampBrightness(brightness);
+    if (brightness !== "-1") {
+      await this.setLampBrightness(brightness);
+    }
 
     // 再设置颜色
-    await this.setLampColor(color);
+    if (color !== '不处理') {
+      await this.setLampColor(color);
+    }
 
     return { brightness: state.lamp.brightness, color: state.lamp.color };
   }, '智能台灯控制失败'),

+ 8 - 7
src/views/block/Blockly2.vue

@@ -383,8 +383,8 @@ const state = reactive({
   },
 
   // 智能家居图片显示控制
-  showCurtainLeft: true,
-  showCurtainRight: true,
+  showCurtainLeft: false,
+  showCurtainRight: false,
   showTelevision: false,
   showLightOpen: false,
   showLightClose: false,
@@ -846,9 +846,9 @@ const aiService = {
   controlCurtain: withErrorHandling('控制窗帘状态', async function(isOn) {
     // 根据传入的布尔值决定是打开还是关闭窗帘
     if (isOn) {
-      this.openCurtain();
-    } else {
       this.closeCurtain();
+    } else {
+      this.openCurtain();
     }
     return isOn;
   }, '控制窗帘状态失败'),
@@ -857,7 +857,7 @@ const aiService = {
   openCurtain: withErrorHandling('打开窗帘', async function() {
 
     if (!state.showCurtainLeft && !state.showCurtainRight) {
-      console.log("窗帘已经是打开的状态");
+      console.log("窗帘已经是打开的状态",state.showCurtainLeft,state.showCurtainRight);
       return true;
     }
 
@@ -903,8 +903,9 @@ const aiService = {
 
   // 关闭窗帘
   closeCurtain: withErrorHandling('关闭窗帘', async function() {
+
     if (state.showCurtainLeft && state.showCurtainRight) {
-      console.log("窗帘已经是关闭的状态");
+      console.log("窗帘已经是关闭的状态",state.showCurtainLeft,state.showCurtainRight);
       return true;
     }
 
@@ -950,7 +951,7 @@ const aiService = {
     const commandPairs = params.split(',');
     for (const pair of commandPairs) {
       const [device, action] = pair.split('=');
-      if (!device || !action) continue;
+      if (!device || !action || action ==='不处理') continue;
 
       const actionBool = action === 'true' || action === '1' || action === 'on' ? true :
           action === 'false' || action === '0' || action === 'off' ? false :