sessionList.html 5.7 KB

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