Преглед на файлове

修改智能讲解功能

zxy преди 2 години
родител
ревизия
09a355be0d

+ 2 - 2
smart-xplain/src/main.js

@@ -3,9 +3,9 @@ import App from './App.vue'
 let app = createApp(App)
 
 //挂载websocket地址
-app.config.globalProperties.$wsUrl = 'ws://192.168.0.100:8087/socketServer'
+app.config.globalProperties.$wsUrl = 'ws://23.37.100.80:8087/socketServer'
 //挂载接口前缀
-app.config.globalProperties.$baseUrl = 'http://192.168.0.100:8084/basic'
+app.config.globalProperties.$baseUrl = 'http://23.37.100.80:8084/basic'
 
 import UUID from "vue-uuid";
 app.use(UUID);

+ 61 - 47
smart-xplain/src/view/smartExplain.vue

@@ -34,26 +34,25 @@ export default {
       isAuto: false,
       timer: undefined
     }
-  }
-  ,
+  },
   created() {
     //初始化数据
     this.loadData()
     //初始化websocket
     this.initWebSocket()
+    //轮播手滑切换走马灯
     this.$nextTick(() => {
-      this.slideBanner() /*轮播手滑切换*/
+      this.slideBanner()
     })
-  }
-  ,
+  },
   methods: {
     loadData() {
-      let code = this.getParamByUrl('code');
+      let _this = this;
+      let code = _this.getParamByUrl('code');
       if (!code) {
-        this.$message({message: 'code无效', type: "error",})
+        _this.$message({message: 'code无效', type: "error",})
         return
       }
-      let _this = this;
       axios.get(_this.$baseUrl + '/api/explain/details/findByCode/' + code)
           .then(function (res) {
             let data = res.data.data
@@ -71,7 +70,7 @@ export default {
             console.log(error)
           });
     },
-    //幻灯片切换触发  index:当前幻灯片的index prevIndex上一个幻灯片的index
+    //幻灯片切换触发  index:当前幻灯片的index prevIndex:上一个幻灯片的index
     carouselChange(index, prevIndex) {
       let _this = this
       //如果上一个幻灯片是最后一个,把自动播放标记改为false
@@ -96,12 +95,8 @@ export default {
     playOrPause(index) {
       let _this = this
       //清除定时器
-      if(_this.timer){
-        _this.timer.clearTimeOut()
-        _this.timer = undefined
-      }
-      //计算setTimeOut定时器时间
-      let time = (_this.$refs.audio[index].duration - _this.$refs.audio[index].currentTime) * 1000
+      let interval = undefined;
+      window.clearInterval(interval);
       //播放/暂停 音频
       if (_this.$refs.audio[index].paused) {
         _this.$refs.audio[index].play()
@@ -109,29 +104,46 @@ export default {
         _this.$refs.audio[index].pause()
       }
       //如果当前是视频则播放视频
+      let videoIndex = -1;
       if (_this.carouselDataList[index].explainType == 10) {
         //找到当前下标之前的视频个数 就是当前视频组件的下标
-        let videoIndex = _this.carouselDataList.filter((data, tempIndex) => {
+        videoIndex = _this.carouselDataList.filter((data, tempIndex) => {
           return tempIndex < index && data.explainType == 10;
         }).length
-        //播放/暂停 视频
+      }
+      //播放/暂停 视频
+      if (videoIndex != -1) {
         if (_this.$refs.video[videoIndex].paused) {
           _this.$refs.video[videoIndex].play()
         } else {
           _this.$refs.video[videoIndex].pause()
         }
-        //计算setTimeOut定时器时间
-        if (_this.$refs.video[videoIndex].duration > _this.$refs.audio[index].duration) {
-          time = (_this.$refs.video[videoIndex].duration - _this.$refs.video[videoIndex].currentTime) * 1000
-        }
       }
-      //如果是自动播放并且当前是播放就设置定时器
-      if (_this.isAuto && !_this.$refs.audio[index].paused) {
-        _this.timer = setTimeout(() => {
-          _this.$refs.carousel.next()
-        }, time)
+      if (!_this.isAuto) {
+        return
+      }
+      //设置轮询器 轮询器终止触发时机: 较长的音频/视频结束
+      if (videoIndex != -1 && _this.$refs.video[videoIndex].duration > _this.$refs.audio[index].duration) {
+        if (!interval) {
+          interval = setInterval(() => {
+            if (_this.$refs.video[videoIndex].ended) {
+              _this.$refs.carousel.next()
+              window.clearInterval(interval);
+              interval = undefined
+            }
+          }, 1000)
+        }
+      } else {
+        if (!interval) {
+          interval = setInterval(() => {
+            if (_this.$refs.audio[index].ended) {
+              _this.$refs.carousel.next()
+              window.clearInterval(interval);
+              interval = undefined
+            }
+          }, 1000)
+        }
       }
-
     },
     //消息处理逻辑
     handleMsg(msg) {
@@ -146,8 +158,13 @@ export default {
         //手动触发change事件
         _this.carouselChange(0, _this.carouselDataList.length - 1)
       }
+      //收到切换方案的消息
+      if('replace' === msg.event){
+        console.log('收到重定向消息'+JSON.stringify(msg))
+        location.replace(msg.url)
+      }
     },
-    //走马灯高度返回方法
+    //走马灯高度返回
     calculationHeight() {
       return document.documentElement.clientHeight + 'px';
     },
@@ -155,12 +172,12 @@ export default {
       if (typeof WebSocket === 'undefined')
         return console.log('您的浏览器不支持websocket')
       this.websock = new WebSocket(this.$wsUrl + "/client_" + this.$uuid.v1().replace(/-/g, ""))
-      this.websock.onmessage = this.websocketonmessage
-      this.websock.onopen = this.websocketonopen
-      this.websock.onerror = this.websocketonerror
-      this.websock.onclose = this.websocketclose
+      this.websock.onmessage = this.onMessage
+      this.websock.onopen = this.onOpen
+      this.websock.onerror = this.onError
+      this.websock.onclose = this.onClose
     },
-    websocketonmessage(event) {
+    onMessage(event) {
       let msg = JSON.parse(event.data)
       console.log('收到消息:' + JSON.stringify(msg))
       if (msg.type != 'smartExplain') {
@@ -168,14 +185,14 @@ export default {
       }
       this.handleMsg(msg);
     },
-    websocketonopen() {
+    onOpen() {
       console.log('websocket连接成功')
     },
-    websocketonerror() {
+    onError() {
       console.log('websocket异常')
 
     },
-    websocketclose() {
+    onClose() {
       console.log('websocket关闭成功')
 
     },
@@ -183,8 +200,8 @@ export default {
     getParamByUrl(paramKey) {
       let query = window.location.search.substring(1);
       let vars = query.split("&");
-      for (var i = 0; i < vars.length; i++) {
-        var pair = vars[i].split("=");
+      for (let i = 0; i < vars.length; i++) {
+        let pair = vars[i].split("=");
         if (pair[0] === paramKey) {
           return pair[1];
         }
@@ -205,16 +222,12 @@ export default {
     slideBanner() {
       let that = this
       //选中item的盒子
-      var box = document.querySelector('.el-carousel__container');
-      //手指起点X坐标
-      var startPoint = 0;
-      //手指滑动重点X坐标
-      var stopPoint = 0;
-
+      let box = document.querySelector('.el-carousel__container');
+      //手指起点和终点X坐标
+      let startPoint = 0, stopPoint = 0;
       //重置坐标
-      var resetPoint = function () {
-        startPoint = 0;
-        stopPoint = 0;
+      let resetPoint = function () {
+        startPoint = startPoint = 0;
       }
       //手指按下
       box.addEventListener("touchstart", function (e) {
@@ -252,6 +265,7 @@ export default {
 </script>
 
 <style scoped>
+
 .img-class {
   width: auto;
   height: auto;

+ 1 - 1
spring-cloud/server-basic/src/main/java/com/jd/controller/ExplainDetailsController.java

@@ -52,7 +52,7 @@ public class ExplainDetailsController {
     public Map<String, Object> deleteById(long id) {
         ExplainDetails explainDetails = explainDetailsService.getById(id);
         if (explainDetails != null) {
-            //删除原来的音频文件
+            //删除音频文件
             File file = new File(filePath + explainDetails.getAudioUrl());
             if (file.exists()) {
                 file.delete();

+ 5 - 11
spring-cloud/server-basic/src/main/java/com/jd/service/impl/ExplainDetailsServiceImpl.java

@@ -26,7 +26,7 @@ import java.util.List;
 @Service
 public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper, ExplainDetails> implements ExplainDetailsService {
 
-    private static final String VOCIE_HTTP = "http://23.37.100.80:8093";
+    private static final String VOCIE_HTTP = "http://127.0.0.1:8093";
 
     @Value("${web.file}")
     private String filePath;
@@ -43,11 +43,6 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
     public Boolean saveBean(ExplainDetails explainDetails) {
         //处理语音转换
         explainDetails.setAudioUrl(this.play(explainDetails.getAudioContent()));
-        //删除原来的音频文件
-        File file = new File(filePath + explainDetails.getAudioUrl());
-        if (file.exists()) {
-            file.delete();
-        }
         explainDetails.setCreateTime(DateUtil.now());
         return baseMapper.insert(explainDetails) > 0;
     }
@@ -56,11 +51,6 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
     public Boolean updateBean(ExplainDetails explainDetails) {
         //处理语音转换
         explainDetails.setAudioUrl(this.play(explainDetails.getAudioContent()));
-        //删除原来的音频文件
-        File file = new File(filePath + explainDetails.getAudioUrl());
-        if (file.exists()) {
-            file.delete();
-        }
         explainDetails.setCreateTime(DateUtil.now());
         return baseMapper.updateById(explainDetails) > 0;
     }
@@ -97,6 +87,10 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
             } catch (Exception e) {
                 e.printStackTrace();
             }
+            //删除pcm文件
+            if(file.exists()){
+                file.delete();
+            }
             System.err.println("转换耗时:" + (System.currentTimeMillis() - startTime));
             return path.substring(path.lastIndexOf(filePath) + filePath.length());
         }

+ 8 - 8
spring-cloud/server-basic/src/main/java/com/jd/util/ConvertUtils.java

@@ -1,7 +1,7 @@
 package com.jd.util;
 
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
+import com.jd.util.WaveHeader;
 
 /**
  * @Author: clf
@@ -9,7 +9,7 @@ import java.io.FileOutputStream;
  * @Description: 语音合成工具类
  */
 public class ConvertUtils {
- 
+
     /**
      * 转换音频文件
      * @param src 需要转换的pcm音频路径
@@ -19,7 +19,7 @@ public class ConvertUtils {
     public static void convertPcm2Wav(String src, String target) throws Exception {
         FileInputStream fis = new FileInputStream(src);
         FileOutputStream fos = new FileOutputStream(target);
- 
+
         //计算长度
         byte[] buf = new byte[1024 * 4];
         int size = fis.read(buf);
@@ -29,7 +29,7 @@ public class ConvertUtils {
             size = fis.read(buf);
         }
         fis.close();
- 
+
         //填入参数,比特率等等。这里用的是16位单声道 8000 hz
         WaveHeader header = new WaveHeader();
         //长度字段 = 内容的大小(PCMSize) + 头部字段的大小(不包括前面4字节的标识符RIFF以及fileLength本身的4字节)
@@ -42,9 +42,9 @@ public class ConvertUtils {
         header.BlockAlign = (short)(header.Channels * header.BitsPerSample / 8);
         header.AvgBytesPerSec = header.BlockAlign * header.SamplesPerSec;
         header.DataHdrLeth = PCMSize;
- 
+
         byte[] h = header.getHeader();
- 
+
         assert h.length == 44; //WAV标准,头部应该是44字节
         //write header
         fos.write(h, 0, h.length);
@@ -59,5 +59,5 @@ public class ConvertUtils {
         fos.close();
         System.out.println("Convert OK!");
     }
- 
+
 }

+ 8 - 8
spring-cloud/server-basic/src/main/java/com/jd/util/WaveHeader.java

@@ -2,14 +2,14 @@ package com.jd.util;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
- 
+
 /**
  * @Author: clf
  * @Date: 2020-03-07
  * @Description: wav转换mp3的header
  */
 public class WaveHeader {
- 
+
     public final char fileID[] = {'R', 'I', 'F', 'F'};
     public int fileLength;
     public char wavTag[] = {'W', 'A', 'V', 'E'};;
@@ -23,7 +23,7 @@ public class WaveHeader {
     public short BitsPerSample;
     public char DataHdrID[] = {'d','a','t','a'};
     public int DataHdrLeth;
- 
+
     public byte[] getHeader() throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         WriteChar(bos, fileID);
@@ -44,15 +44,15 @@ public class WaveHeader {
         bos.close();
         return r;
     }
- 
+
     private void WriteShort(ByteArrayOutputStream bos, int s) throws IOException {
         byte[] mybyte = new byte[2];
         mybyte[1] =(byte)( (s << 16) >> 24 );
         mybyte[0] =(byte)( (s << 24) >> 24 );
         bos.write(mybyte);
     }
- 
- 
+
+
     private void WriteInt(ByteArrayOutputStream bos, int n) throws IOException {
         byte[] buf = new byte[4];
         buf[3] =(byte)( n >> 24 );
@@ -61,13 +61,13 @@ public class WaveHeader {
         buf[0] =(byte)( (n << 24) >> 24 );
         bos.write(buf);
     }
- 
+
     private void WriteChar(ByteArrayOutputStream bos, char[] id) {
         for (int i=0; i<id.length; i++) {
             char c = id[i];
             bos.write(c);
         }
     }
- 
+
 }
  

+ 12 - 1
spring-cloud/server-page/src/main/resources/static/ipad/js/basic/index.js

@@ -474,7 +474,7 @@ function clickPlan(planId, sign, name) {
 	// 替换名称
 	$(".def_sch").text(name)
 	layer.close(util.layer.index['planPop'])
-	util.getJSON({
+	util.get({
 		url: FLAT_PATH_BASIC + 'plan/getPlanAreaByPlanId',
 		data: {
 			'planId': planId
@@ -536,6 +536,17 @@ function clickPlan(planId, sign, name) {
 					util.variable['areaObj'].planAreaList[index].signalSourceList = source;
 					initSignSource(source);
 				}
+
+				//通知弧屏区页面切换内容
+				res.data.planAreaList.forEach(t=>{
+					if('hpq'==t.area_code){
+						myWebsocket.websocket.send(JSON.stringify({
+							event: 'replace',
+							url: t.url,
+							type: 'smartExplain'
+						}));
+					}
+				})
 			}
 		}
 	});

+ 2 - 2
spring-cloud/server-page/src/main/resources/static/page/js/basic/explainDetails.js

@@ -29,9 +29,9 @@ layui.config({
                 field: 'explainType',
                 title: '讲解类型',
                 templet: function (d) {
-                    if (d.status == 10) {
+                    if (d.explainType == 10) {
                         return '视频';
-                    } else if (d == 20) {
+                    } else if (d.explainType == 20) {
                         return '图片';
                     } else {
                         return '网页';

+ 1 - 1
spring-cloud/server-page/src/main/resources/static/page/js/constants.js

@@ -2,7 +2,7 @@
  * 配置项目请求接口地址
  */
 // var GATEWAY_URL = "http://23.37.100.80:8084";
- var GATEWAY_URL = "http://23.37.100.87:8084";
+ var GATEWAY_URL = "http://23.37.100.80:8084";
 // var GATEWAY_URL = "http://192.168.101.242:8084";
 var PAGE_URL = "http://23.37.1.104:5500";