123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>微分机器人</title>
- <!--引入 element-ui 的样式,-->
- <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
- <!-- 必须先引入vue, 后使用element-ui -->
- <script src="./js/vue.js"></script>
- <!-- 引入element 的组件库-->
- <script src="https://unpkg.com/element-ui/lib/index.js"></script>
- <script src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
- <!-- <script>
- var vConsole = new window.VConsole();
- </script> -->
- </head>
- <style>
- body {
- margin: 0;
- padding: 0;
- }
- .box {
- width: 100vw;
- height: 100vh;
- box-sizing: border-box;
- background: #FAFAFA;
- }
- .page5 {
- width: 100vw;
- height: 100vh;
- box-sizing: border-box;
- padding: 0 15px;
- }
- .session_list {
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 1px solid #E2E2E2;
- padding: 15px 0;
- }
- .session_item {
- display: flex;
- align-items: center;
- }
- .session_head {
- width: 48px;
- height: 48px;
- position: relative;
- }
- .head_img {
- width: 48px;
- height: 48px;
- border-radius: 5px;
- }
- .on_line {
- position: absolute;
- right: 0;
- bottom: 0;
- width: 15px;
- height: 15px;
- background: #23E580;
- border: 2px solid #FFFFFF;
- border-radius: 50%;
- }
- .client_name {
- font-weight: 500;
- font-size: 14px;
- color: #222222;
- padding-left: 10px;
- }
- .session_btn {
- font-weight: 500;
- font-size: 14px;
- }
- .online {
- color: #2885FF;
- }
- .offline {
- color: #CCCCCC;
- }
- </style>
- <body>
- <div id="box" class="box">
- <!-- 会话列表 -->
- <div class="page5">
- <div class="session_list" v-for="(item, index) in sessionList" :key="index">
- <div class="session_item">
- <div class="session_head">
- <image class="head_img" :src="item.sessionAvatar"></image>
- <div class="on_line" v-if="item.onlineStatus"></div>
- </div>
- <div class="client_name">{{item.sessionName}}</div>
- </div>
- <div class="session_btn" :class="item.onlineStatus ? 'online' : 'offline'" @click="handlePrize(item)">进入聊天</div>
- </div>
- </div>
- </div>
- </body>
- <script>
- new Vue({
- el: '#box',
- data() {
- return {
- httpUrl: '',
- bId: null,
- env: '',
- memberId: null,
- corpId: null,
- sessionList: [],
- pollInterval: null,
- }
- },
- created() {
- this.bId = this.getQueryParam('bId')
- this.env = this.getQueryParam('env')
- if (!this.env || this.env === 'prod') {
- this.httpUrl = 'https://wlapi.wefanbot.com'
- } else {
- this.httpUrl = 'http://test.wefanbot.com:18993'
- }
- if (this.getQueryParam('memberId')) {
- // 已授权
- this.memberId = this.getQueryParam('memberId')
- this.corpId = this.getQueryParam('corpId')
- this.getSessionList()
- this.startPolling()
- } else {
- // 授权
- this.getAuth()
- }
- },
- beforeDestroy() {
- // 当组件销毁前停止轮询
- this.stopPolling();
- },
- methods: {
- getAuth () {
- fetch(this.httpUrl + `/p/insuite/p/getRedirectUri?env=${this.env}&bId=${this.bId}`)
- .then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- window.location.replace(data)
- } else {
- this.$message({
- message: msg,
- type: 'warning'
- })
- }
- })
- },
- // 截取url中的数据
- getQueryParam (paramName) {
- // 获取当前URL的查询字符串部分
- const queryString = window.location.search;
- // 创建一个URLSearchParams对象
- const urlParams = new URLSearchParams(queryString);
- // 返回指定参数的值,如果不存在则返回null
- return urlParams.get(paramName);
- },
- startPolling() {
- // 这里写你的轮询逻辑,比如发送API请求
- this.intervalId = setInterval(() => {
- this.getSessionList()
- }, 5000); // 每5秒发起一次请求
- },
- getSessionList () {
- fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/sessionListByPage', {
- method: 'post',
- body: JSON.stringify({
- corpId: this.corpId,
- memberId: this.memberId,
- page: 1,
- pageCount: 1000,
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (data) {
- this.sessionList = data.records
- } else {
- this.$message.error(msg)
- }
- })
- },
- handlePrize (item) {
- if (item.onlineStatus) {
- window.location.href = `chat.html?httpUrl=${this.httpUrl}&corpId=${this.corpId}&memberId=${this.memberId}&sessionId=${item.sessionId}`;
- } else {
- return false
- }
- },
- stopPolling() {
- // 清除定时器
- if (this.pollInterval) {
- clearInterval(this.pollInterval);
- this.pollInterval = null;
- }
- },
- }
- })
- </script>
- </html>
|