fun.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. msgList.demoVideo.play()
  14. msgList.isClick = !msgList.isClick
  15. const data = {
  16. AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
  17. AId: 'TK1234',
  18. content: ''
  19. }
  20. if (msgList.chatMsg != '') {
  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.otherContent = ''
  38. }
  39. // 调用数据接口
  40. const GetNewsList = async (msgList, data) => {
  41. msgList.chatMsg = ''
  42. var res = await getDataList(data)
  43. console.log(res)
  44. return res
  45. }
  46. // 逐字显示内容
  47. const getChatContent = ((msgList, text, index) => {
  48. if (text == undefined) return
  49. msgList.timer = setInterval(() => {
  50. msgList.textCount++;
  51. if (msgList.textCount == text.length + 1) {
  52. msgList.otherChatList[index - 1] = text;
  53. clearInterval(msgList.timer);
  54. } else {
  55. // 取字符串子串
  56. let nowStr = text.substring(0, msgList.textCount);
  57. msgList.otherChatList[index - 1] = nowStr;
  58. }
  59. }, 50);
  60. console.log(msgList.timer)
  61. msgList.textCount = 0
  62. msgList.isloading[index - 1] = false
  63. msgList.isClick = !msgList.isClick
  64. // logo视频静止
  65. msgList.demoVideo.seek(0)
  66. msgList.demoVideo.pause()
  67. })
  68. // 滚动条回到最底部
  69. const scrollToBottom = ((msgList) => {
  70. nextTick(() => {
  71. const query = uni.createSelectorQuery();
  72. query.select("#content-box").boundingClientRect()
  73. query.select("#content-overflow").boundingClientRect()
  74. query.exec(res => {
  75. const scrollViewHeight = res[0].height
  76. const scrollContentHeight = res[1].height
  77. if (scrollViewHeight < scrollContentHeight) {
  78. const scrollTop = scrollContentHeight - scrollViewHeight
  79. msgList.scrollTop = scrollTop
  80. }
  81. })
  82. })
  83. })
  84. // 背景颜色变换
  85. const styleChange = ((styleData) => {
  86. styleData.value = !styleData.value
  87. if (styleData.value == true) {
  88. styleData.color = "black"
  89. styleData.fontColor = "#fff"
  90. styleData.btnColor = "#ccc"
  91. styleData.contentColor = "rgba(0,0,0,0.5)"
  92. styleData.labelColor = "rgb(105,105,105)"
  93. styleData.borderColor = "rgb(105,105,105)"
  94. styleData.videoSrc = '../../static/video/video.mp4'
  95. } else {
  96. styleData.color = "#fff"
  97. styleData.fontColor = "black"
  98. styleData.btnColor = "rgb(30,144,255)"
  99. styleData.contentColor = "#f5f5f5"
  100. styleData.labelColor = "#f5f5f5"
  101. styleData.borderColor = "rgb(30,144,255)"
  102. styleData.videoSrc = '../../static/video/whiteVideo.mp4'
  103. }
  104. })
  105. //快捷键输入
  106. const shortcuts = ((msgList, item) => {
  107. msgList.chatMsg = item
  108. handleSend(msgList)
  109. })
  110. export {
  111. handleSend,
  112. styleChange,
  113. scrollToBottom,
  114. shortcuts
  115. }