武汉四维h5程序,基于达闼设备,单独分开
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

433 lignes
14 KiB

  1. <template>
  2. <div id="app" class="no-scrollbar" style="width: 100%;">
  3. <!-- <div
  4. v-show="(this.ws && this.ws.readyState == 1) || !this.ws"
  5. style="position: absolute;background: orangered;width: 2vw;height: 2vh;right: 0"
  6. ></div>-->
  7. <div v-if="debug" class="record-wrapper" style="position: absolute;top: 0;z-index: 999;">
  8. <div class="msg msg-right" style="display: contents;">
  9. <div
  10. :key="this.consoleList.index"
  11. class="message-wrapper-right"
  12. style="width:90%;display: flex;background-color: rgba(220,220,220,0.7) !important;border-radius: 2px !important;"
  13. >
  14. <div class="message" style="font-size: 5px !important;text-align: left !important;">
  15. {{ this.consoleList && this.consoleList.time ? this.consoleList.time + ":" : "" }}:{{
  16. (this.consoleList ? this.consoleList.message : "") +
  17. "(pg:" +
  18. this.lastProgress +
  19. ";sleep:" +
  20. this.sleep +
  21. ";speak:" +
  22. this.isSpeaking +
  23. ";state:" +
  24. this.stateVal +
  25. ";npl:" +
  26. this.lastNplText +
  27. ";tts:" +
  28. this.lastTtsText +
  29. ";q:" +
  30. this.lastQText +
  31. ";locked:" +
  32. this.execLocked +
  33. ";qHandle:" +
  34. this.qHandleType +
  35. ")" +
  36. this.otherLog +
  37. JSON.stringify(this.lastPerson) +
  38. this.reqResult +
  39. "noDetectedFace:" +
  40. this.noDetectedFace() +
  41. "noPersonHere:" +
  42. this.noPersonHere()
  43. }}
  44. </div>
  45. <button class="btn" style="position: absolute;top:12vh;" @click="sendMsg(1)">
  46. TEST
  47. </button>
  48. </div>
  49. </div>
  50. </div>
  51. <navigation>
  52. <router-view :style="content"> </router-view>
  53. </navigation>
  54. </div>
  55. </template>
  56. <script>
  57. import Cloudia from "./api/cloudia-sdk-v1.4.1";
  58. import { handleFaceType } from "./utils/handleTts";
  59. import moment from "moment";
  60. import { mapMutations, mapState } from "vuex";
  61. var initTimer2 = 0;
  62. export default {
  63. name: "App",
  64. data() {
  65. return {
  66. isRouterAlive: true,
  67. interactive: "",
  68. content: "",
  69. retryLoadClientType: 0,
  70. lastDetectTs: 0,
  71. lastPersonTs: 0,
  72. lastPerson: {},
  73. sockData: {},
  74. lastNplText: "",
  75. lastTtsText: "",
  76. lastMsDetectTs: 0,
  77. lastMsNlpTimes: 0,
  78. lastDetectObj: {},
  79. lastQText: "",
  80. lastQTs: 0,
  81. execLocked: "",
  82. qHandleType: "",
  83. reqResult: "",
  84. otherLog: "",
  85. otherLog2: "",
  86. sleep: false,
  87. isSpeaking: false,
  88. cameraMode: "level",
  89. jsHandleStateEnabled: false,
  90. jsPlayTtsEnabled: true,
  91. stateVal: "",
  92. ws: null,
  93. times: 0,
  94. timeoutObj: null,
  95. serverTimeoutObj: null,
  96. timeout: 10000,
  97. qData: {},
  98. nlpData: {},
  99. rMsg: {},
  100. heartCheck: {
  101. reset: this.reset,
  102. start: this.start
  103. },
  104. consoleList: {},
  105. debug: this.$cmdList.debug,
  106. connectTimer: null,
  107. strangerDetectTimes: 0
  108. };
  109. },
  110. computed: {
  111. ...mapState({
  112. lastProgress: "lastReq",
  113. padInfo: "pad",
  114. lPerson: "lastPerson",
  115. localDev: "localDevInfo",
  116. debugFlag: "debug"
  117. })
  118. },
  119. watch: {
  120. padInfo: {
  121. handler: function(val, oldVal) {
  122. let that = this;
  123. if (val && that.$cmdList.detectedFaceEnable) {
  124. that.wsInit();
  125. }
  126. },
  127. deep: true
  128. }
  129. },
  130. mounted() {
  131. window._ = _;
  132. window.globalVue = this.$children[0];
  133. window.timer = undefined;
  134. window.intimer = undefined;
  135. window.socketTimer = undefined;
  136. window.closeTimer = undefined;
  137. window.Cloudia = Cloudia;
  138. window.$ = $;
  139. },
  140. destroyed() {
  141. // console.log("=========app destroyed====");
  142. },
  143. methods: {
  144. ...mapMutations([
  145. "setLastPerson",
  146. "setLastReq",
  147. "setProgressPerson",
  148. "setLocalDevInfo",
  149. "setRobotMsg",
  150. "setWs"
  151. ]),
  152. reset: function() {
  153. this.timeoutObj && clearTimeout(this.timeoutObj);
  154. this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
  155. return this;
  156. },
  157. start: function() {
  158. let self = this;
  159. this.timeoutObj = setTimeout(function() {
  160. self.ws.send("ping");
  161. self.serverTimeoutObj = setTimeout(function() {
  162. self.ws.close();
  163. }, self.timeout);
  164. }, this.timeout);
  165. },
  166. consoleLog(text) {
  167. let ts = new Date().getTime();
  168. this.consoleList = {
  169. index: ts,
  170. message: text,
  171. time: moment(ts).format("mm:ss.SSS")
  172. };
  173. },
  174. setProgressCode(key) {
  175. this.setLastReq(key);
  176. },
  177. sendMsg(type) {
  178. var that = this;
  179. that.setLastReq("dhys");
  180. },
  181. returnAdPage() {
  182. // this.sleep = true;
  183. this.sleep = false;
  184. this.setLastReq("");
  185. this.isSpeaking = false;
  186. this.meetingDateStr = "";
  187. this.meetingTitle = "";
  188. // this.lastMsNlpTimes = 0;
  189. // this.lastMsDetectTs = 0;
  190. this.strangerDetectTimes = 0;
  191. this.msgList = [
  192. {
  193. from: 2,
  194. message: "您好,我是小酷。"
  195. }
  196. ];
  197. },
  198. leaveAdPage() {
  199. this.sleep = false;
  200. // window.Cloudia && window.Cloudia.setClothes("suit_blue");
  201. },
  202. wsInit() {
  203. var that = this;
  204. if (this.padInfo && this.padInfo.ipAddr) {
  205. // let wsUrl = "ws://127.0.0.1:9090";
  206. let wsUrl = "ws://" + this.padInfo.ipAddr + ":9090";
  207. //先判断浏览器是否支持WebSocket
  208. if (typeof WebSocket === "undefined") {
  209. that.$alert("您的浏览器不支持socket");
  210. } else {
  211. // 判断 WebSocket是否已经建立连接,避免重复连接
  212. // this.ws && this.ws.close();
  213. // 新增一个websocket实例,并且建立连接
  214. this.ws = new WebSocket(wsUrl);
  215. // 连接成功后的回调函数
  216. this.ws.onopen = this.handleWsOpen;
  217. // 收到服务器数据后的回调函数
  218. this.ws.onmessage = this.handleWsMessage;
  219. // 连接关闭后的回调函数
  220. this.ws.onclose = this.handleReconnectWs;
  221. // 报错时的回调函数(网络断开,网络不稳定, 用户电脑休眠)
  222. this.ws.onerror = this.handleReconnectWs;
  223. this.setWs(this.ws);
  224. }
  225. } else {
  226. that.handleReconnectWs();
  227. }
  228. },
  229. // ws建立连接
  230. handleWsOpen() {
  231. this.consoleLog("websocket已连接,初始化成功");
  232. this.heartCheck.reset().start();
  233. },
  234. // ws拿到服务器(后端接口)或者客户端(心跳监测或者自测)发送的数据
  235. handleWsMessage(msg) {
  236. this.heartCheck.reset().start();
  237. // 拿到的数据
  238. let result = msg.data;
  239. let that = this;
  240. if (result == "tong") {
  241. return;
  242. }
  243. that.lastDetectTs = new Date().getTime();
  244. that.sockData = JSON.parse(result);
  245. that.consoleLog(JSON.stringify(that.sockData));
  246. if (!that.isSpeaking && (that.lastProgress == "" || that.lastProgress == "moshengren")) {
  247. that.handleDetectedFace(that.sockData);
  248. }
  249. },
  250. // 重连ws
  251. handleReconnectWs() {
  252. this.connectTimer && clearTimeout(this.connectTimer);
  253. let that = this;
  254. that.consoleLog("socket断开链接");
  255. that.times++;
  256. this.connectTimer = setTimeout(() => {
  257. if (that.ws) {
  258. that.consoleLog("重连" + that.times + "次", that.ws.readyState);
  259. // 接已经关闭,或者打开连接失败
  260. if (that.ws.readyState === 3) {
  261. that.wsInit();
  262. }
  263. } else {
  264. that.consoleLog("重连" + that.times + "次");
  265. that.wsInit();
  266. }
  267. }, 3000);
  268. },
  269. handleDetectedFace(obj) {
  270. let that = this;
  271. let str = "";
  272. if (obj && (obj.id == undefined || obj.id == -1)) {
  273. //识别到脸,不是系统里的合法人脸
  274. // let currentTs = new Date().getTime();
  275. // that.lastDetectTs = currentTs; //识别到脸的时间戳
  276. // that.lastMsDetectTs = that.lastMsDetectTs == 0 ? currentTs : that.lastMsDetectTs; //陌生人识别时间戳
  277. that.leaveAdPage();
  278. //陌生人识别3秒,只提示一次
  279. if (that.strangerDetectTimes > 5) {
  280. // that.$alert("moshengren");
  281. // that.strangerDetectTimes = 0;
  282. that.lastDetectObj = obj;
  283. that.lastPerson = {};
  284. that.setLastPerson({});
  285. // that.lastMsDetectTs = 0;
  286. str += handleFaceType(that, obj);
  287. that.sleep = false;
  288. that.rMsg = { text: str, ts: new Date().getTime() };
  289. that.setRobotMsg(that.rMsg);
  290. // that.lastMsNlpTimes++;
  291. } else {
  292. that.strangerDetectTimes++;
  293. }
  294. } else if (obj && (obj.id.length > 6 || obj.id > 0)) {
  295. that.strangerDetectTimes = 0;
  296. //识别到认识的人
  297. // that.lastMsDetectTs = 0;
  298. let currentTs = new Date().getTime();
  299. that.lastDetectTs = currentTs;
  300. that.lastDetectObj = obj;
  301. //识别到人
  302. /*if (obj.name != "") {
  303. if (that.lastProgress == "moshengren") {
  304. // that.setLastReq("");
  305. }
  306. }*/
  307. /*if (that.lastProgress == "moshengren") {
  308. return;
  309. }*/
  310. if (that.lastDetectObj.id === that.lastPerson.id) {
  311. that.lastPerson.name = that.lastDetectObj.name;
  312. that.lastPerson.tag = that.lastDetectObj.tag;
  313. }
  314. //1分钟识别到同一人只执行一次
  315. if (
  316. (obj.id == that.lastPerson.id && (currentTs - that.lastPersonTs >= 60000 || that.sleep)) ||
  317. obj.id != that.lastPerson.id
  318. ) {
  319. // that.lastMsNlpTimes = 0;
  320. that.lastPerson = obj;
  321. that.setLastPerson(obj);
  322. that.lastPersonTs = currentTs;
  323. str += handleFaceType(that, obj);
  324. that.rMsg = { text: str, ts: new Date().getTime() };
  325. if (that.lastProgress == "") {
  326. that.setRobotMsg(that.rMsg);
  327. }
  328. that.sleep = false;
  329. that.addMsgList(2, str);
  330. } else {
  331. that.consoleLog("repeat person:" + obj.id);
  332. }
  333. }
  334. },
  335. noDetectedFace() {
  336. let currentTs = new Date().getTime();
  337. if (currentTs - this.lastDetectTs > this.$cmdList.judgeDetectedNoPerson) {
  338. //5秒内没识别
  339. return true;
  340. }
  341. return false;
  342. },
  343. noPersonHere() {
  344. let currentTs = new Date().getTime();
  345. if (currentTs - this.lastQTs > this.$cmdList.judgeNoPerson) {
  346. //15秒钟不说话
  347. return this.noDetectedFace();
  348. }
  349. return false;
  350. },
  351. setIsSpeaking(speak) {
  352. this.isSpeaking = speak;
  353. }
  354. }
  355. };
  356. </script>
  357. <style lang="scss">
  358. * {
  359. margin: 0;
  360. padding: 0;
  361. }
  362. html,
  363. body {
  364. width: 100%;
  365. height: 100%;
  366. overflow-x: hidden;
  367. overflow-y: hidden;
  368. }
  369. .record-wrapper {
  370. margin: 4px;
  371. padding: 4px;
  372. width: 90vw;
  373. }
  374. #app {
  375. width: 100%;
  376. height: 100%;
  377. font-family: Avenir, Helvetica, Arial, sans-serif;
  378. -webkit-font-smoothing: antialiased;
  379. -moz-osx-font-smoothing: grayscale;
  380. text-align: center;
  381. color: #2c3e50;
  382. }
  383. // 隐藏滚轮
  384. .no-scrollbar {
  385. -ms-overflow-style: none;
  386. overflow: -moz-scrollbars-none;
  387. /*background-color: black;*/
  388. -webkit-touch-callout: none;
  389. -webkit-user-select: none;
  390. -khtml-user-select: none;
  391. -moz-user-select: none;
  392. -ms-user-select: none;
  393. user-select: none;
  394. }
  395. .no-scrollbar::-webkit-scrollbar {
  396. width: 0 !important;
  397. }
  398. img {
  399. width: auto;
  400. height: auto;
  401. max-width: 100%;
  402. max-height: 100%;
  403. }
  404. img[lazy="loading"] {
  405. background-color: white;
  406. }
  407. .single-line-text {
  408. overflow: hidden;
  409. text-overflow: ellipsis;
  410. white-space: nowrap;
  411. display: block !important;
  412. text-align: left;
  413. -webkit-line-clamp: 1;
  414. -webkit-box-orient: vertical;
  415. }
  416. </style>