fun.js 2.8 KB

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