chat.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no, viewport-fit=cover" />
  8. <title>领取奖励</title>
  9. <!--引入 element-ui 的样式,-->
  10. <link rel="stylesheet"
  11. href="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742018383195/element-ui.css">
  12. <!-- 必须先引入vue, 后使用element-ui -->
  13. <script
  14. src="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742017957144/vue.js"></script>
  15. <!-- 引入element 的组件库-->
  16. <script
  17. src="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742017747738/element-ui.js"></script>
  18. <!-- <script src="js/vconsole.min.js"></script>
  19. <script>
  20. var vConsole = new window.VConsole();
  21. </script> -->
  22. </head>
  23. <style>
  24. body {
  25. margin: 0;
  26. padding: 0;
  27. }
  28. .box {
  29. width: 100vw;
  30. height: 100vh;
  31. box-sizing: border-box;
  32. background: #FAFAFA;
  33. }
  34. .page5 {
  35. width: 100vw;
  36. height: calc(100vh - 63px);
  37. box-sizing: border-box;
  38. padding: 18px 15px;
  39. overflow-y: auto;
  40. /* overflow-x: unset; */
  41. }
  42. .chat_list {
  43. display: flex;
  44. align-items: center;
  45. }
  46. .custom_msg {
  47. display: flex;
  48. align-items: center;
  49. justify-content: flex-start;
  50. padding-bottom: 22px;
  51. box-sizing: border-box;
  52. width: 100%;
  53. }
  54. .my_msg {
  55. display: flex;
  56. align-items: center;
  57. justify-content: flex-end;
  58. padding-bottom: 22px;
  59. box-sizing: border-box;
  60. width: 100%;
  61. }
  62. .customchat_box {
  63. padding: 10px 12px;
  64. background: #FFFFFF;
  65. border-radius: 10px;
  66. font-weight: 400;
  67. font-size: 14px;
  68. color: #222222;
  69. max-width: 227px;
  70. word-wrap: break-word;
  71. white-space: normal;
  72. }
  73. .mychat_box {
  74. padding: 10px 12px;
  75. background: #1677FF;
  76. border-radius: 10px;
  77. font-weight: 400;
  78. font-size: 14px;
  79. color: #FFFFFF;
  80. max-width: 227px;
  81. word-wrap: break-word;
  82. white-space: normal;
  83. }
  84. .chatbox_left {
  85. width: 6px;
  86. height: 12px;
  87. margin-left: 5px;
  88. }
  89. .chatbox_right {
  90. width: 10px;
  91. height: 12px;
  92. margin-left: -5px;
  93. margin-right: 5px;
  94. }
  95. .headImg {
  96. width: 44px;
  97. height: 44px;
  98. border-radius: 50%;
  99. }
  100. .chat_img {
  101. max-width: 200px;
  102. border-radius: 10px;
  103. }
  104. .input_style {
  105. padding: 10px;
  106. box-sizing: border-box;
  107. position: relative;
  108. }
  109. .el-input__inner {
  110. border-radius: 22px;
  111. height: 43px;
  112. padding-right: 60px;
  113. }
  114. .send_btn {
  115. width: 50px;
  116. height: 33px;
  117. position: absolute;
  118. right: 15px;
  119. top: 15px;
  120. }
  121. </style>
  122. <body>
  123. <div id="box" class="box">
  124. <!-- 聊天页 -->
  125. <div ref="messageContent" class="page5">
  126. <div class="chat_list" v-for="(item, index) in chatList" :key="index">
  127. <div class="my_msg" v-if="item.self">
  128. <div class="mychat_box" v-if="item.contentType === 0" v-html="item.content.replace(/\n/g,'<br/>')"></div>
  129. <image class="chat_img" mode="aspectFit" v-else-if="item.contentType === 1" :src="item.content"></image>
  130. <div class="mychat_box" v-else-if="item.contentType === 5" v-html="JSON.parse(item.content).curl"
  131. @click="navigateToUrl(JSON.parse(item.content).curl)"></div>
  132. <div class="mychat_box" v-else-if="item.contentType === 33">小程序信息(不支持查看)</div>
  133. <div class="mychat_box" v-else-if="item.contentType === 51">视频号信息(不支持查看)</div>
  134. <div class="mychat_box" v-else-if="item.contentType === 100">图片已过期(不支持查看)</div>
  135. <div class="mychat_box" v-else v-html="item.content"></div>
  136. <image class="chatbox_right" src="./img/chatbox_right.png"></image>
  137. <image class="headImg" :src="item.sendUrl"></image>
  138. </div>
  139. <div class="custom_msg" v-else>
  140. <image class="headImg" :src="item.sendUrl"></image>
  141. <image class="chatbox_left" src="./img/chatbox_left.png"></image>
  142. <div class="customchat_box" v-if="item.contentType === 0" v-html="item.content.replace(/\n/g,'<br/>')"></div>
  143. <image class="chat_img" mode="aspectFit" v-else-if="item.contentType === 1" :src="item.content"></image>
  144. <div class="customchat_box" v-else-if="item.contentType === 5" v-html="JSON.parse(item.content).curl"
  145. @click="navigateToUrl(JSON.parse(item.content).curl)"></div>
  146. <div class="customchat_box" v-else-if="item.contentType === 33">小程序信息(不支持查看)</div>
  147. <div class="customchat_box" v-else-if="item.contentType === 51">视频号信息(不支持查看)</div>
  148. <div class="customchat_box" v-else-if="item.contentType === 100">图片已过期(不支持查看)</div>
  149. <div class="customchat_box" v-else v-html="item.content"></div>
  150. </div>
  151. </div>
  152. </div>
  153. <div class="input_style">
  154. <el-input placeholder="请输入内容吧" v-model="msgData">
  155. </el-input>
  156. <image class="send_btn" :src="msgData ? './img/send_btn.png' : './img/no_send_btn.png'" @click="sendMsg"></image>
  157. </div>
  158. </div>
  159. </body>
  160. <script>
  161. new Vue({
  162. el: '#box',
  163. data () {
  164. return {
  165. httpUrl: '',
  166. memberId: null,
  167. corpId: null,
  168. sessionId: null,
  169. chatList: [],
  170. msgData: '',
  171. pollInterval: null,
  172. }
  173. },
  174. created () {
  175. this.httpUrl = this.getQueryParam('httpUrl')
  176. this.corpId = this.getQueryParam('corpId')
  177. this.memberId = this.getQueryParam('memberId')
  178. this.sessionId = this.getQueryParam('sessionId')
  179. document.title = this.getQueryParam('sessionName')
  180. this.chatData()
  181. this.startPolling()
  182. },
  183. beforeDestroy () {
  184. // 当组件销毁前停止轮询
  185. this.stopPolling();
  186. },
  187. methods: {
  188. // 截取url中的数据
  189. getQueryParam (paramName) {
  190. // 获取当前URL的查询字符串部分
  191. const queryString = window.location.search;
  192. // 创建一个URLSearchParams对象
  193. const urlParams = new URLSearchParams(queryString);
  194. // 返回指定参数的值,如果不存在则返回null
  195. return urlParams.get(paramName);
  196. },
  197. startPolling () {
  198. // 这里写你的轮询逻辑,比如发送API请求
  199. this.intervalId = setInterval(() => {
  200. this.chatData()
  201. }, 5000); // 每5秒发起一次请求
  202. },
  203. chatData () {
  204. fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/messageListByPage', {
  205. method: 'post',
  206. body: JSON.stringify({
  207. corpId: this.corpId,
  208. memberId: this.memberId,
  209. sessionId: this.sessionId,
  210. page: 1,
  211. pageCount: 1000,
  212. }),
  213. headers: {
  214. 'Content-Type': 'application/json'
  215. }
  216. }).then(res => {
  217. return res.json()
  218. }).then(result => {
  219. let { data, code, msg } = result
  220. if (data) {
  221. this.chatList = data.records.reverse()
  222. this.$nextTick(() => {
  223. this.$refs.messageContent.scrollTop = this.$refs.messageContent.scrollHeight
  224. })
  225. } else {
  226. this.$message.error(msg)
  227. }
  228. })
  229. },
  230. sendMsg () {
  231. if (!this.msgData) {
  232. this.$message.error('请输入内容')
  233. return
  234. }
  235. fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/sendMessage', {
  236. method: 'post',
  237. body: JSON.stringify({
  238. corpId: this.corpId,
  239. memberId: this.memberId,
  240. sessionId: this.sessionId,
  241. text: this.msgData,
  242. type: 0
  243. }),
  244. headers: {
  245. 'Content-Type': 'application/json'
  246. }
  247. }).then(res => {
  248. return res.json()
  249. }).then(result => {
  250. let { data, code, msg } = result
  251. if (code === 1) {
  252. this.msgData = ''
  253. this.chatData()
  254. } else {
  255. this.$message.error(msg)
  256. }
  257. })
  258. },
  259. stopPolling () {
  260. // 清除定时器
  261. if (this.pollInterval) {
  262. clearInterval(this.pollInterval);
  263. this.pollInterval = null;
  264. }
  265. },
  266. navigateToUrl (url) {
  267. window.location.href = url;
  268. }
  269. }
  270. })
  271. </script>
  272. </html>