123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <!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: calc(100vh - 63px);
- box-sizing: border-box;
- padding: 18px 15px;
- overflow-y: auto;
- /* overflow-x: unset; */
- }
- .chat_list {
- display: flex;
- align-items: center;
- }
- .custom_msg {
- display: flex;
- align-items: center;
- justify-content: flex-start;
- padding-bottom: 22px;
- box-sizing: border-box;
- width: 100%;
- }
- .my_msg {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- padding-bottom: 22px;
- box-sizing: border-box;
- width: 100%;
- }
- .customchat_box {
- padding: 10px 12px;
- background: #FFFFFF;
- border-radius: 10px;
- font-weight: 400;
- font-size: 14px;
- color: #222222;
- max-width: 227px;
- word-wrap: break-word;
- white-space: normal;
- }
- .mychat_box {
- padding: 10px 12px;
- background: #1677FF;
- border-radius: 10px;
- font-weight: 400;
- font-size: 14px;
- color: #FFFFFF;
- max-width: 227px;
- word-wrap: break-word;
- white-space: normal;
- }
- .chatbox_left {
- width: 6px;
- height: 12px;
- margin-left: 5px;
- }
- .chatbox_right {
- width: 10px;
- height: 12px;
- margin-left: -5px;
- margin-right: 5px;
- }
- .headImg {
- width: 44px;
- height: 44px;
- border-radius: 50%;
- }
- .chat_img {
- max-width: 200px;
- border-radius: 10px;
- }
- .input_style {
- padding: 10px;
- box-sizing: border-box;
- position: relative;
- }
- .el-input__inner {
- border-radius: 22px;
- height: 43px;
- padding-right: 60px;
- }
- .send_btn {
- width: 50px;
- height: 33px;
- position: absolute;
- right: 15px;
- top: 15px;
- }
- </style>
- <body>
- <div id="box" class="box">
- <!-- 聊天页 -->
- <div ref="messageContent" class="page5">
- <div class="chat_list" v-for="(item, index) in chatList" :key="index">
- <div class="my_msg" v-if="item.self">
- <div class="mychat_box" v-if="item.contentType === 0" v-html="item.content"></div>
- <image class="chat_img" mode="aspectFit" v-else-if="item.contentType === 1" :src="item.content"></image>
- <div class="mychat_box" v-else-if="item.contentType === 5" v-html="JSON.parse(item.content).curl"></div>
- <div class="mychat_box" v-else-if="item.contentType === 33">小程序信息(不支持查看)</div>
- <div class="mychat_box" v-else-if="item.contentType === 51">视频号信息(不支持查看)</div>
- <div class="mychat_box" v-else-if="item.contentType === 100">图片已过期(不支持查看)</div>
- <div class="mychat_box" v-else v-html="item.content"></div>
- <image class="chatbox_right" src="./img/chatbox_right.png"></image>
- <image class="headImg" :src="item.sendUrl"></image>
- </div>
- <div class="custom_msg" v-else>
- <image class="headImg" :src="item.sendUrl"></image>
- <image class="chatbox_left" src="./img/chatbox_left.png"></image>
- <div class="customchat_box" v-if="item.contentType === 0" v-html="item.content"></div>
- <image class="chat_img" mode="aspectFit" v-else-if="item.contentType === 1" :src="item.content"></image>
- <div class="customchat_box" v-else-if="item.contentType === 5" v-html="JSON.parse(item.content).curl"></div>
- <div class="customchat_box" v-else-if="item.contentType === 33">小程序信息(不支持查看)</div>
- <div class="customchat_box" v-else-if="item.contentType === 51">视频号信息(不支持查看)</div>
- <div class="customchat_box" v-else-if="item.contentType === 100">图片已过期(不支持查看)</div>
- <div class="customchat_box" v-else v-html="item.content"></div>
- </div>
- </div>
- </div>
- <div class="input_style">
- <el-input
- placeholder="请输入内容"
- v-model="msgData">
- </el-input>
- <image class="send_btn" :src="msgData ? './img/send_btn.png' : './img/no_send_btn.png'" @click="sendMsg"></image>
- </div>
- </div>
- </body>
- <script>
- new Vue({
- el: '#box',
- data() {
- return {
- httpUrl: '',
- memberId: null,
- corpId: null,
- sessionId: null,
- chatList: [],
- msgData: '',
- pollInterval: null,
- }
- },
- created() {
- this.httpUrl = this.getQueryParam('httpUrl')
- this.corpId = this.getQueryParam('corpId')
- this.memberId = this.getQueryParam('memberId')
- this.sessionId = this.getQueryParam('sessionId')
- this.chatData()
- this.startPolling()
- },
- beforeDestroy() {
- // 当组件销毁前停止轮询
- this.stopPolling();
- },
- methods: {
- // 截取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.chatData()
- }, 5000); // 每5秒发起一次请求
- },
- chatData () {
- fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/messageListByPage', {
- method: 'post',
- body: JSON.stringify({
- corpId: this.corpId,
- memberId: this.memberId,
- sessionId: this.sessionId,
- page: 1,
- pageCount: 1000,
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (data) {
- this.chatList = data.records.reverse()
- this.$nextTick(() => {
- this.$refs.messageContent.scrollTop = this.$refs.messageContent.scrollHeight
- })
- } else {
- this.$message.error(msg)
- }
- })
- },
- sendMsg () {
- fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-counselor/p/sendMessage', {
- method: 'post',
- body: JSON.stringify({
- corpId: this.corpId,
- memberId: this.memberId,
- sessionId: this.sessionId,
- text: this.msgData,
- type: 0
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- this.msgData = ''
- this.chatData()
- } else {
- this.$message.error(msg)
- }
- })
- },
- stopPolling() {
- // 清除定时器
- if (this.pollInterval) {
- clearInterval(this.pollInterval);
- this.pollInterval = null;
- }
- },
- }
- })
- </script>
- </html>
|