Jelajahi Sumber

1、代码更新

liyanbo 6 bulan lalu
induk
melakukan
ae9bf8e861
4 mengubah file dengan 85 tambahan dan 57 penghapusan
  1. 4 20
      src/api/blockly/music.js
  2. TEMPAT SAMPAH
      src/assets/music/huankuai.mp3
  3. 0 0
      src/assets/music/shuhuan.mp3
  4. 81 37
      src/views/Blockly.vue

+ 4 - 20
src/api/blockly/music.js

@@ -3,29 +3,13 @@ import { ElMessage } from 'element-plus';
 
 // 音乐类型配置(独立配置,不直接关联颜色)
 export const musicTypeConfig = {
-    '平静': {
-        url: '/src/assets/music/pingjing.mp3',
-        name: '平静音乐'
-    },
-    '欢快': {
-        url: '/src/assets/music/pingjing.mp3',
-        name: '欢快音乐'
+    '热闹': {
+        url: '/src/assets/music/huankuai.mp3',
+        name: '热闹音乐'
     },
     '舒缓': {
-        url: '/src/assets/music/pingjing.mp3',
+        url: '/src/assets/music/shuhuan.mp3',
         name: '舒缓音乐'
-    },
-    '激情': {
-        url: '/src/assets/music/pingjing.mp3',
-        name: '激情音乐'
-    },
-    '冥想': {
-        url: '/src/assets/music/pingjing.mp3',
-        name: '冥想音乐'
-    },
-    '自然': {
-        url: '/src/assets/music/pingjing.mp3',
-        name: '自然音乐'
     }
 };
 

TEMPAT SAMPAH
src/assets/music/huankuai.mp3


+ 0 - 0
src/assets/music/pingjing.mp3 → src/assets/music/shuhuan.mp3


+ 81 - 37
src/views/Blockly.vue

@@ -726,11 +726,34 @@ const aiService = {
       recognition.interimResults = false;
       recognition.maxAlternatives = 1;
 
-      if (promptText) {
-        ElMessage.info(promptText + "\n请开始说话...");
-      } else {
-        ElMessage.info("请开始说话...");
-      }
+      let countdown = 10;
+
+      // 固定的消息提示框
+      const messageText = promptText ? `${promptText}\n请开始说话...(${countdown}秒)` : `请开始说话...(${countdown}秒)`;
+      const messageInstance = ElMessage.info({
+        message: messageText,
+        duration: 0 // 0表示不自动关闭
+      });
+
+      // 隐藏的div来更新倒计时显示
+      const timer = setInterval(() => {
+        countdown--;
+        if (countdown > 0) {
+          // 找到消息提示框中的文本元素并更新
+          const messageElement = document.querySelector('.el-message__content');
+          if (messageElement) {
+            const newText = promptText ? `${promptText}\n请开始说话...(${countdown}秒)` : `请开始说话...(${countdown}秒)`;
+            messageElement.textContent = newText;
+          }
+        } else {
+          clearInterval(timer);
+          // 倒计时结束后关闭提示框
+          if (messageInstance && messageInstance.close) {
+            messageInstance.close();
+          }
+        }
+      }, 1000);
+
 
       recognition.onresult = (event) => {
         const speechResult = event.results[0][0].transcript;
@@ -874,7 +897,7 @@ const aiService = {
   }, '生成视频失败'),
 
   // 文本生成文本(如AI对话)
-  textToText: withErrorHandling('AI文本处理', async function(prompt, model = "default") {
+  textToText: withErrorHandling('AI大模型调用', async function(prompt, model = "default") {
     console.log("AI智能体请求,提示词:", prompt);
 
     // 如果没有活跃的对话ID,创建新对话
@@ -941,13 +964,14 @@ const aiService = {
           throw error;
         },
         () => {
-          console.log(`结束对话!`);
+          // console.log(`结束对话!`);
           this.stopTextToTextStream();
         }
     );
 
     // 确保最终结果被设置
     if (resultText) {
+      console.log("AI大模型调用成功,返回结果:", resultText);
       state.generatedContent.text = resultText;
       state.previewType = "text";
       state.previewContent = resultText;
@@ -957,7 +981,7 @@ const aiService = {
     }
 
     return resultText;
-  }, 'AI文本处理失败'),
+  }, 'AI大模型调用失败'),
 
   // 停止文本生成流
   stopTextToTextStream() {
@@ -984,15 +1008,11 @@ const aiService = {
   setLampColor: withErrorHandling('设置台灯颜色', async function(color) {
     // 预定义的颜色映射
     const colorMap = {
-      '红': '#ff0000',
-      '蓝': '#0000ff',
-      '绿': '#00ff00',
-      '黄': '#ffff00',
-      '青': '#00ffff',
-      '靛': '#4b0082',
-      '紫': '#800080',
+      '紫': '#D886F0',
+      '橙': '#F89E35',
+      '黄': '#F9E67E',
+      '青': '#6BF5E6',
       '白': '#ffffff',
-      '黑': '#000000'
     };
 
     // 获取有效的颜色值
@@ -1179,7 +1199,7 @@ onMounted(async () => {
   // 注册AI文本生成文本积木
   Blockly.Blocks["ai_text_to_text"] = {
     init: function () {
-      this.appendDummyInput().appendField("AI文本处理");
+      this.appendDummyInput().appendField("AI大模型调用");
       this.appendValueInput("PROMPT")
           .setCheck("String")
           .appendField("输入文本:");
@@ -1195,7 +1215,7 @@ onMounted(async () => {
           );
       this.setOutput(true, "String");
       this.setColour(300);
-      this.setTooltip("使用AI处理文本并返回结果");
+      this.setTooltip("使用AI大模型调用并返回结果");
       this.setHelpUrl("");
     },
   };
@@ -1311,25 +1331,49 @@ onMounted(async () => {
   // 恢复并优化初始加载组件逻辑 - 与当前Blockly版本兼容的修复版
   try {
     // 使用字符串拼接定义初始XML内容
-    const initialXml = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
-        '  <block type="ai_smart_lamp_single_param" id="initial_block_1" x="50" y="90">\n' +
-        '    <value name="PARAMS">\n' +
-        '      <block type="ai_text_to_text" id="initial_block_2">\n' +
-        '        <field name="MODEL">default</field>\n' +
-        '        <value name="PROMPT">\n' +
-        '          <block type="ai_voice_input" id="initial_block_3">\n' +
-        '            <field name="LANGUAGE">zh-CN</field>\n' +
-        '            <value name="PROMPT">\n' +
-        '              <block type="text" id="initial_block_4">\n' +
-        '                <field name="TEXT">请说话:</field>\n' +
-        '              </block>\n' +
-        '            </value>\n' +
-        '          </block>\n' +
-        '        </value>\n' +
-        '      </block>\n' +
-        '    </value>\n' +
-        '  </block>\n' +
-        '</xml>';
+    const initialXml = "<xml xmlns=\"https://developers.google.com/blockly/xml\">\n" +
+        "  <variables>\n" +
+        "    <variable id=\"kAVG*zJLw/q)l/(/eIMM\">inputText</variable>\n" +
+        "    <variable id=\"[7F(niLz{.fvWvY.VT/N\">lampConfig</variable>\n" +
+        "  </variables>\n" +
+        "  <block type=\"variables_set\" id=\"XIsa=sV/8ImVP5P3:ol4\" x=\"90\" y=\"90\">\n" +
+        "    <field name=\"VAR\" id=\"kAVG*zJLw/q)l/(/eIMM\">inputText</field>\n" +
+        "    <value name=\"VALUE\">\n" +
+        "      <block type=\"ai_voice_input\" id=\"Ql).^+/uT(P~$aMg2OEA\">\n" +
+        "        <field name=\"LANGUAGE\">zh-CN</field>\n" +
+        "        <value name=\"PROMPT\">\n" +
+        "          <block type=\"text\" id=\"kXjnnUncUu7p$a[zz)da\">\n" +
+        "            <field name=\"TEXT\">请说话:</field>\n" +
+        "          </block>\n" +
+        "        </value>\n" +
+        "      </block>\n" +
+        "    </value>\n" +
+        "    <next>\n" +
+        "      <block type=\"variables_set\" id=\"AP0CO$VPeM0*PS*CKT,V\">\n" +
+        "        <field name=\"VAR\" id=\"[7F(niLz{.fvWvY.VT/N\">lampConfig</field>\n" +
+        "        <value name=\"VALUE\">\n" +
+        "          <block type=\"ai_text_to_text\" id=\"lZTz/FN3b(*_p?1zug7F\">\n" +
+        "            <field name=\"MODEL\">default</field>\n" +
+        "            <value name=\"PROMPT\">\n" +
+        "              <block type=\"variables_get\" id=\"si~IQyn|#1H(BKV4Gq;X\">\n" +
+        "                <field name=\"VAR\" id=\"kAVG*zJLw/q)l/(/eIMM\">inputText</field>\n" +
+        "              </block>\n" +
+        "            </value>\n" +
+        "          </block>\n" +
+        "        </value>\n" +
+        "        <next>\n" +
+        "          <block type=\"ai_smart_lamp_single_param\" id=\"ZTAwt~MMm(t5w:$$Azt`\">\n" +
+        "            <value name=\"PARAMS\">\n" +
+        "              <block type=\"variables_get\" id=\"X):w|X4hYE~ru1r9`W8f\">\n" +
+        "                <field name=\"VAR\" id=\"[7F(niLz{.fvWvY.VT/N\">lampConfig</field>\n" +
+        "              </block>\n" +
+        "            </value>\n" +
+        "          </block>\n" +
+        "        </next>\n" +
+        "      </block>\n" +
+        "    </next>\n" +
+        "  </block>\n" +
+        "</xml>";
 
     // 使用安全的方式解析XML
     const xml = Blockly.utils.xml.textToDom(initialXml);