fun.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /** 将15寸和32寸共同用到的 函数内容,封装成一个js文件 */
  2. import {
  3. nextTick,
  4. reactive,
  5. watch
  6. } from 'vue';
  7. import {
  8. getDataList
  9. } from '../api/ChatApp';
  10. import ttsUtils from './tts/ttsUtils';
  11. // 发送消息
  12. const handleSend = async (msgList) => {
  13. const data = {
  14. AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
  15. AId: 'TK1234',
  16. content: ''
  17. }
  18. if (msgList.chatMsg != '') {
  19. msgList.demoVideo1 = false
  20. msgList.demoVideo.play()
  21. msgList.isloading[msgList.len] = true
  22. msgList.len++
  23. let obj = {
  24. otherContent: '',
  25. userContent: '',
  26. image: ""
  27. }
  28. data.content = msgList.chatMsg
  29. obj.userContent = msgList.chatMsg
  30. msgList.chatList.push(obj)
  31. obj.otherContent = await GetNewsList(msgList, data)
  32. console.log(obj.otherContent)
  33. // await sleep(16000);
  34. getChatContent(msgList, obj.otherContent, msgList.len)
  35. ttsUtils.toSpeak(obj.otherContent)
  36. }
  37. msgList.isClick = !msgList.isClick
  38. msgList.otherContent = ''
  39. }
  40. // 调用数据接口
  41. const GetNewsList = async (msgList, data) => {
  42. msgList.chatMsg = ''
  43. var res = await getDataList(data)
  44. console.log(res)
  45. return res
  46. }
  47. // 逐字显示内容
  48. const getChatContent = ((msgList, text, index) => {
  49. if (text == undefined) return
  50. msgList.timer = setInterval(() => {
  51. msgList.textCount++;
  52. if (msgList.textCount == text.length + 1) {
  53. msgList.otherChatList[index - 1] = text;
  54. clearInterval(msgList.timer);
  55. } else {
  56. // 取字符串子串
  57. let nowStr = text.substring(0, msgList.textCount);
  58. msgList.otherChatList[index - 1] = nowStr;
  59. }
  60. }, 50);
  61. console.log(msgList.timer)
  62. msgList.textCount = 0
  63. msgList.isloading[index - 1] = false
  64. msgList.isClick = !msgList.isClick
  65. // logo视频静止
  66. msgList.demoVideo.seek(0)
  67. msgList.demoVideo.pause()
  68. })
  69. // 滚动条回到最底部
  70. const scrollToBottom = ((msgList) => {
  71. nextTick(() => {
  72. const query = uni.createSelectorQuery();
  73. query.select("#content-box").boundingClientRect()
  74. query.select("#content-overflow").boundingClientRect()
  75. query.exec(res => {
  76. const scrollViewHeight = res[0].height
  77. const scrollContentHeight = res[1].height
  78. if (scrollViewHeight < scrollContentHeight) {
  79. const scrollTop = scrollContentHeight - scrollViewHeight
  80. msgList.scrollTop = scrollTop
  81. }
  82. })
  83. })
  84. })
  85. // 背景颜色变换
  86. const styleChange = ((styleData) => {
  87. styleData.value = !styleData.value
  88. if (styleData.value == true) {
  89. styleData.color = "black"
  90. styleData.fontColor = "#fff"
  91. styleData.btnColor = "#ccc"
  92. styleData.contentColor = "rgba(0,0,0,0.5)"
  93. styleData.labelColor = "rgb(105,105,105)"
  94. styleData.borderColor = "rgb(105,105,105)"
  95. styleData.videoSrc = '../../static/video/video.mp4'
  96. } else {
  97. styleData.color = "#fff"
  98. styleData.fontColor = "black"
  99. styleData.btnColor = "rgb(30,144,255)"
  100. styleData.contentColor = "#f5f5f5"
  101. styleData.labelColor = "#f5f5f5"
  102. styleData.borderColor = "rgb(30,144,255)"
  103. styleData.videoSrc = '../../static/video/whiteVideo.mp4'
  104. }
  105. })
  106. //快捷键输入
  107. const shortcuts = ((msgList, item) => {
  108. msgList.chatMsg = item
  109. handleSend(msgList)
  110. })
  111. export {
  112. handleSend,
  113. styleChange,
  114. scrollToBottom,
  115. shortcuts
  116. }