chat.html 8.3 KB

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