index15.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view id='app' :style="`bottom:${msgList.KeyBoardHeight}px;background-color:${styleData.color}`">
  3. <view class="head" :style="{backgroundColor:styleData.color}">
  4. <text :style="{color:styleData.fontColor}">睿宝AI</text>
  5. <view class="switch">
  6. <switch @change="styleChange(styleData)" />
  7. </view>
  8. </view>
  9. <view class="pageView" :style="{backgroundColor:styleData.color}">
  10. <view class="sidebar-left"></view>
  11. <view class="body">
  12. <view class="list-wrap">
  13. <scroll-view id="content-box" scroll-y="true" class="scrollview" :scroll-top="msgList.scrollTop">
  14. <!-- 聊天主体 -->
  15. <view id="content-overflow">
  16. <view class="scrollview-item" v-for="(item,index) in msgList.chatList" :key='index'>
  17. <!-- user方-聊天内容 -->
  18. <view class="item self" v-if="item.userContent != ''">
  19. <image class="avtar" src="../../static/user-avatar.png" mode="aspectFit"></image>
  20. <view class="content right" disabled
  21. :style="{backgroundColor:styleData.contentColor,color:styleData.fontColor}">
  22. {{ item.userContent }}
  23. </view>
  24. </view>
  25. <!-- ai方-聊天内容 -->
  26. <view class="item other">
  27. <view class="">
  28. <view class="loadingPoint" v-if='msgList.isloading[index]'>
  29. <loadingPointsVue></loadingPointsVue>
  30. </view>
  31. <view class="content left" v-if='!msgList.isloading[index]'
  32. :style="{backgroundColor:styleData.contentColor,color:styleData.fontColor}">
  33. {{ msgList.otherChatList[index] }}
  34. </view>
  35. </view>
  36. <image class="avtar" src="../../static/Ai-avatar.png" mode="aspectFit"></image>
  37. </view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. <view class="chat-bottom">
  43. <view class="uni-label">
  44. <label v-for="(item,index) in labelList" :key="index" @click="shortcuts(msgList,item)"
  45. :style="{backgroundColor:styleData.labelColor,color:styleData.fontColor,borderColor:styleData.borderColor}">{{item}}</label>
  46. </view>
  47. <view class="send-msg">
  48. <view class="uni-textarea" :style="`background-color:${styleData.labelColor};font-color:${styleData.fontColor};`">
  49. <textarea id="input-textarea" type="text" v-model="msgList.chatMsg" placeholder="快来聊天吧"
  50. confirm-type="send" @confirm="handleSend(msgList)" maxlength="300"
  51. @keyboardheightchange="getKeyBoardHeight" :adjust-position="false"
  52. :style="`background-color:${styleData.labelColor};font-color:${styleData.fontColor};`" />
  53. </view>
  54. <view class="uni-button">
  55. <button class="send-btn" @click="handleSend(msgList)" type="primary"
  56. :disabled="msgList.isClick" :style="{backgroundColor:styleData.btnColor}">发送</button>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="sidebar-right">
  62. <!-- <image src="../../static/logo.png" mode="aspectFit"></image> -->
  63. <video class="video" :class="{active:styleData.value}" id="demoVideo" :controls="false" :loop='true' object-fit="cover"
  64. :enable-progress-gesture="false" :show-center-play-btn="false" :src="styleData.videoSrc">
  65. </video>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script setup>
  71. import {
  72. nextTick,
  73. onMounted,
  74. reactive,
  75. ref,
  76. watch
  77. } from 'vue';
  78. import {
  79. getDataList
  80. } from '../../api/ChatApp.js'
  81. import axios from 'axios';
  82. import loadingPointsVue from '../../components/loadingPoints.vue';
  83. import {
  84. styleChange,
  85. handleSend,
  86. scrollToBottom,
  87. shortcuts
  88. } from "../../until/fun.js"
  89. // ----------------------------------------
  90. // 测试代码
  91. const videlSrc = '../../static/video/whiteVideo.mp4'
  92. // let demoVideo = uni.createVideoContext('demoVideo')
  93. // //
  94. // let a = 0
  95. // const aaa = () => {
  96. // if (a++ % 2 == 0) {
  97. // // 停止
  98. // demoVideo.seek(0)
  99. // demoVideo.pause()
  100. // } else {
  101. // // 播放
  102. // demoVideo.play()
  103. // }
  104. // }
  105. // --------------------------------------
  106. const msgList = reactive({
  107. // 输入框
  108. chatMsg: '',
  109. // 聊天数据列表
  110. chatList: [],
  111. // 滚动距离
  112. scrollTop: 0,
  113. // setTimeout的返回值,唯一确定结束对应的setTimeout
  114. timer: 0,
  115. //
  116. textCount: 0,
  117. otherContent: '',
  118. // 处理后的ai数据返回值
  119. otherChatList: [],
  120. // 发送/返回的次数
  121. len: 0,
  122. // 加载符号是否显示
  123. isloading: [],
  124. isClick: false,
  125. KeyBoardHeight: 0,
  126. demoVideo: uni.createVideoContext('demoVideo'),
  127. })
  128. const styleData = reactive({
  129. value: false,
  130. color: '#fff',
  131. fontColor: "black",
  132. btnColor: "rgb(30,144,255)",
  133. contentColor: "#f5f5f5",
  134. labelColor: '#f5f5f5',
  135. borderColor: "rgb(30,144,255)",
  136. videoSrc : '../../static/video/whiteVideo.mp4'
  137. })
  138. const labelList = ref([
  139. "我要加油",
  140. "92号",
  141. "95号",
  142. "98号",
  143. "加油卡",
  144. "易捷加油"
  145. ])
  146. //滚动至聊天底部
  147. watch([msgList.otherChatList, msgList.chatList], (newVal) => {
  148. scrollToBottom(msgList)
  149. })
  150. // 键盘弹起事件
  151. const getKeyBoardHeight = ((event) => {
  152. // 获取键盘高度
  153. msgList.KeyBoardHeight = event.detail.height
  154. })
  155. </script>
  156. <style>
  157. @import url("../../theme/chat15.css");
  158. @import url("../../theme/public.css");
  159. </style>