sessionList.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: 100vh;
  37. box-sizing: border-box;
  38. padding: 0 15px;
  39. }
  40. .session_list {
  41. display: flex;
  42. align-items: center;
  43. justify-content: space-between;
  44. border-bottom: 1px solid #E2E2E2;
  45. padding: 15px 0;
  46. }
  47. .session_item {
  48. display: flex;
  49. align-items: center;
  50. }
  51. .session_head {
  52. width: 48px;
  53. height: 48px;
  54. position: relative;
  55. }
  56. .head_img {
  57. width: 48px;
  58. height: 48px;
  59. border-radius: 5px;
  60. }
  61. .on_line {
  62. position: absolute;
  63. right: 0;
  64. bottom: 0;
  65. width: 15px;
  66. height: 15px;
  67. background: #23E580;
  68. border: 2px solid #FFFFFF;
  69. border-radius: 50%;
  70. box-sizing: border-box;
  71. }
  72. .client_name {
  73. font-weight: 500;
  74. font-size: 14px;
  75. color: #222222;
  76. padding-left: 10px;
  77. }
  78. .session_btn {
  79. font-weight: 500;
  80. font-size: 14px;
  81. }
  82. .online {
  83. color: #2885FF;
  84. }
  85. .offline {
  86. color: #CCCCCC;
  87. }
  88. </style>
  89. <body>
  90. <div id="box" class="box">
  91. <!-- 会话列表 -->
  92. <div class="page5">
  93. <div class="session_list" v-for="(item, index) in sessionList" :key="index">
  94. <div class="session_item">
  95. <div class="session_head">
  96. <image class="head_img" :src="item.sessionAvatar"></image>
  97. <div class="on_line" v-if="item.onlineStatus"></div>
  98. </div>
  99. <div class="client_name">{{item.sessionName}}</div>
  100. </div>
  101. <div class="session_btn" :class="item.onlineStatus ? 'online' : 'offline'" @click="handlePrize(item)">进入聊天</div>
  102. </div>
  103. </div>
  104. </div>
  105. </body>
  106. <script>
  107. new Vue({
  108. el: '#box',
  109. data () {
  110. return {
  111. httpUrl: '',
  112. bId: null,
  113. env: '',
  114. memberId: null,
  115. corpId: null,
  116. sessionList: [],
  117. pollInterval: null,
  118. }
  119. },
  120. created () {
  121. this.bId = this.getQueryParam('bId')
  122. this.env = this.getQueryParam('env')
  123. if (!this.env || this.env === 'prod') {
  124. this.httpUrl = 'https://wlapi.wefanbot.com'
  125. } else {
  126. this.httpUrl = 'http://test.wefanbot.com:18993'
  127. }
  128. if (this.getQueryParam('memberId')) {
  129. // 已授权
  130. this.memberId = this.getQueryParam('memberId')
  131. this.corpId = this.getQueryParam('corpId')
  132. this.getSessionList()
  133. this.startPolling()
  134. } else {
  135. // 授权
  136. this.getAuth()
  137. }
  138. },
  139. beforeDestroy () {
  140. // 当组件销毁前停止轮询
  141. this.stopPolling();
  142. },
  143. methods: {
  144. getAuth () {
  145. fetch(this.httpUrl + `/p/insuite/p/getRedirectUri?env=${this.env}&bId=${this.bId}`)
  146. .then(res => {
  147. return res.json()
  148. }).then(result => {
  149. let { data, code, msg } = result
  150. if (code === 1) {
  151. window.location.replace(data)
  152. } else {
  153. this.$message({
  154. message: msg,
  155. type: 'warning'
  156. })
  157. }
  158. })
  159. },
  160. // 截取url中的数据
  161. getQueryParam (paramName) {
  162. // 获取当前URL的查询字符串部分
  163. const queryString = window.location.search;
  164. // 创建一个URLSearchParams对象
  165. const urlParams = new URLSearchParams(queryString);
  166. // 返回指定参数的值,如果不存在则返回null
  167. return urlParams.get(paramName);
  168. },
  169. startPolling () {
  170. // 这里写你的轮询逻辑,比如发送API请求
  171. this.intervalId = setInterval(() => {
  172. this.getSessionList()
  173. }, 5000); // 每5秒发起一次请求
  174. },
  175. getSessionList () {
  176. fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/sessionListByPage', {
  177. method: 'post',
  178. body: JSON.stringify({
  179. corpId: this.corpId,
  180. memberId: this.memberId,
  181. page: 1,
  182. pageCount: 1000,
  183. }),
  184. headers: {
  185. 'Content-Type': 'application/json'
  186. }
  187. }).then(res => {
  188. return res.json()
  189. }).then(result => {
  190. let { data, code, msg } = result
  191. if (data) {
  192. this.sessionList = data.records
  193. } else {
  194. this.$message.error(msg)
  195. }
  196. })
  197. },
  198. handlePrize (item) {
  199. if (item.onlineStatus) {
  200. window.location.href = `chat.html?httpUrl=${this.httpUrl}&corpId=${this.corpId}&memberId=${this.memberId}&sessionId=${item.sessionId}&sessionName=${item.sessionName}`;
  201. } else {
  202. return false
  203. }
  204. },
  205. stopPolling () {
  206. // 清除定时器
  207. if (this.pollInterval) {
  208. clearInterval(this.pollInterval);
  209. this.pollInterval = null;
  210. }
  211. },
  212. }
  213. })
  214. </script>
  215. </html>