Przeglądaj źródła

AI销售参谋接口调试

zhujindu 1 rok temu
rodzic
commit
d01159bfda
3 zmienionych plików z 37 dodań i 8 usunięć
  1. 1 0
      package.json
  2. BIN
      src/assets/mp3/sample-3s.mp3
  3. 36 8
      src/views/intelligence/index.vue

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
     "@vant/touch-emulator": "^1.4.0",
     "axios": "^0.24.0",
     "axios-jsonp": "^1.0.4",
+    "benz-amr-recorder": "^1.1.5",
     "clipboard": "^2.0.11",
     "coordtransform": "^2.1.2",
     "core-js": "^3.6.5",

BIN
src/assets/mp3/sample-3s.mp3


+ 36 - 8
src/views/intelligence/index.vue

@@ -15,7 +15,7 @@
       :immediate-check="false">
       <div id="snb" ref="snb1">
         <div style="font-size: 14px" v-for="(item, index) in Ggreet" :key="index">
-          <!-- chatRecordFrom 1:发送内容;2:AI回答内容 -->
+          <!-- chatRecordFrom 1:用户发送内容;2:AI回答内容 -->
           <div style="margin: 14px" v-if="item.chatRecordFrom == 'ai' || item.chatRecordFrom == 2">
             <van-row>
               <van-col span="4" @click="clears"
@@ -87,9 +87,9 @@
                     display: inline-block;
                     float: right;
                   ">
-                  <template v-if="item.type == 'audio'">
+                  <template v-if="item.chatRecordFile">
                     <audio>
-                      <source :src="item.audioUrl" type="audio/mpeg" />
+                      <source :src="sample3s" type="audio/mpeg" />
                       <p>
                         Your browser doesn't support HTML5 audio. Here is a
                         <a href="myAudio.mp4">link to download the audio</a> instead.
@@ -432,13 +432,15 @@ import aiselect from '@/assets/Icon/avatar1.png';
 import tabBar from '@/components/tabBar';
 import { getReportInfo } from '@/api';
 import { aiDialogue } from '@/api/inventory';
-import axios from 'axios';
 import { getPosition, getTicketFun } from '@/utils/TXApiFun';
+import BenzAMRRecorder from 'benz-amr-recorder';
+import sample3s from '@/assets/mp3/sample-3s.mp3';
 export default {
   name: 'ai',
   components: { tabBar },
   data() {
     return {
+      sample3s: sample3s,
       loading: false,
       finished: false,
       pageNum: 0,
@@ -490,12 +492,27 @@ export default {
   //   },
   // },
   activated() {
+    this.pageNum = 0;
     this.isNoData = false;
     this.onLoad();
     // 授权
     getTicketFun(['getLocation', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'uploadVoice']);
   },
   methods: {
+    audioPlay(chatRecordFile) {
+      if (!chatRecordFile) {
+        const url = chatRecordFile;
+        this.amr = new BenzAMRRecorder();
+        this.amr.initWithUrl(url).then(() => {
+          this.amr.play();
+        });
+        this.amr.onEnded(() => {
+          // 播放结束重置状态
+        });
+      } else {
+        this.amr.stop();
+      }
+    },
     garbageManager() {
       this.$nextTick(() => {
         this.$refs.snb.scrollTop = this.$refs.snb.scrollHeight;
@@ -596,6 +613,7 @@ export default {
         forbidClick: true,
       });
       this.btnclik = false;
+      // 发送的文本内容添加到对象,减少重新获取接口
       this.Ggreet.push({
         chatRecordText: this.content,
         chatRecordFrom: 1,
@@ -629,6 +647,8 @@ export default {
               this.shows = false;
               this.show = false;
               this.aiDialogueCommon({ type: 2, content: res.serverId }).then((response) => {
+                // 音频内容需要接口传唤格式后添加到对象
+                // this.Ggreet.push(...response.rows);
                 this.Ggreet.push(...response.rows);
                 this.garbageManager();
               });
@@ -651,10 +671,18 @@ export default {
               console.log(res);
               this.shows = false;
               this.show = false;
-              this.aiDialogueCommon({ type: 2, content: res.serverId }).then((response) => {
-                this.Ggreet.push(...response.rows);
-                this.garbageManager();
-              });
+              this.aiDialogueCommon({ type: 2, content: res.serverId })
+                .then((response) => {
+                  this.Ggreet.push(...response.rows);
+                  this.garbageManager();
+                })
+                .catch(() => {
+                  this.Ggreet.push({
+                    chatRecordFile:
+                      'https://cdn-svs-test.nipponpaint.com.cn/%E5%90%B4%E5%BA%B7-20240918152244.amr?Expires=2042176973&OSSAccessKeyId=LTAI5tG1DTJFA16BHkzHVxjz&Signature=BvwZFdxp69wRNy7oOPfqG6lxTww%3D',
+                    chatRecordFrom: 1,
+                  });
+                });
               // aiDialogue({ type: 2, content: res.serverId }).then((response) => {
               //   if (response.code == 200) {
               //     this.Ggreet.push(...response.rows);