mp:实现 wx-msg 的消息列表的适配

This commit is contained in:
YunaiV 2023-01-08 23:20:07 +08:00
parent df5e6161aa
commit 2b477a4dfb
2 changed files with 96 additions and 204 deletions

View File

@ -5,66 +5,84 @@
<template> <template>
<div class="msg-main" v-loading="mainLoading"> <div class="msg-main" v-loading="mainLoading">
<div class="msg-div" :id="'msg-div'+nowStr"> <div class="msg-div" :id="'msg-div'+nowStr">
<!-- 加载更多 -->
<div v-loading="tableLoading"></div> <div v-loading="tableLoading"></div>
<div v-if="!tableLoading"> <div v-if="!tableLoading">
<div class="el-table__empty-block" v-if="loadMore" @click="loadingMore"><span class="el-table__empty-text">点击加载更多</span></div> <div class="el-table__empty-block" v-if="loadMore" @click="loadingMore"><span class="el-table__empty-text">点击加载更多</span></div>
<div class="el-table__empty-block" v-if="!loadMore"><span class="el-table__empty-text">没有更多了</span></div> <div class="el-table__empty-block" v-if="!loadMore"><span class="el-table__empty-text">没有更多了</span></div>
</div> </div>
<!-- 消息列表 -->
<div class="execution" v-for="item in tableData" :key='item.id'> <div class="execution" v-for="item in tableData" :key='item.id'>
<div class="avue-comment" :class="item.type == '2' ? 'avue-comment--reverse' : ''"> <div class="avue-comment" :class="item.sendFrom == '2' ? 'avue-comment--reverse' : ''">
<div class="avatar-div"> <div class="avatar-div">
<img :src="item.type == '1' ? item.headimgUrl : item.appLogo" class="avue-comment__avatar"> <img :src="item.sendFrom == '1' ? item.headimgUrl : item.appLogo" class="avue-comment__avatar">
<div class="avue-comment__author">{{item.type == '1' ? item.nickName : item.appName}}</div> <div class="avue-comment__author">{{item.sendFrom == '1' ? item.nickName : item.appName}}</div>
</div> </div>
<div class="avue-comment__main"> <div class="avue-comment__main">
<div class="avue-comment__header"> <div class="avue-comment__header">
<div class="avue-comment__create_time">{{item.createTime}}</div> <div class="avue-comment__create_time">{{ parseTime(item.createTime) }}</div>
</div> </div>
<div class="avue-comment__body" :style="item.type == '2' ? 'background: #6BED72;' : ''"> <div class="avue-comment__body" :style="item.sendFrom == '2' ? 'background: #6BED72;' : ''">
<div v-if="item.repType == 'event' && item.repEvent == 'subscribe'"><el-tag type="success" size="mini">关注</el-tag></div> <!-- 事件区域 -->
<div v-if="item.repType == 'event' && item.repEvent == 'unsubscribe'"><el-tag type="danger" size="mini">取消关注</el-tag></div> <div v-if="item.type === 'event' && item.event === 'subscribe'">
<div v-if="item.repType == 'event' && item.repEvent == 'CLICK'"><el-tag size="mini">点击菜单</el-tag>{{item.repName}}</div> <el-tag type="success" size="mini">关注</el-tag>
<div v-if="item.repType == 'event' && item.repEvent == 'VIEW'"><el-tag size="mini">点击菜单链接</el-tag>{{item.repUrl}}</div>
<div v-if="item.repType == 'event' && item.repEvent == 'scancode_waitmsg'"><el-tag size="mini">扫码结果</el-tag>{{item.repContent}}</div>
<div v-if="item.repType == 'text'">{{item.repContent}}</div>
<div v-if="item.repType == 'image'">
<a target="_blank" :href="item.repUrl"><img :src="item.repUrl" style="width: 100px"></a>
</div> </div>
<div v-if="item.repType == 'voice'"> <div v-else-if="item.type === 'event' && item.event === 'unsubscribe'">
<WxVoicePlayer :objData="item"></WxVoicePlayer> <el-tag type="danger" size="mini">取消关注</el-tag>
</div> </div>
<div v-if="item.repType == 'video'" style="text-align: center"> <div v-else-if="item.type === 'event' && item.event === 'CLICK'">
<WxVideoPlayer :objData="item"></WxVideoPlayer> <el-tag size="mini">点击菜单</el-tag>{{ item.eventKey }}
</div> </div>
<div v-if="item.repType == 'shortvideo'" style="text-align: center"> <div v-else-if="item.type === 'event' && item.event === 'VIEW'">
<WxVideoPlayer :objData="item"></WxVideoPlayer> <el-tag size="mini">点击菜单链接</el-tag>{{ item.eventKey }}
</div> </div>
<div v-if="item.repType == 'location'"> <div v-else-if="item.type === 'event' && item.event === 'scancode_waitmsg'"> <!-- TODO 芋艿需要测试下 -->
<el-link type="primary" target="_blank" :href="'https://map.qq.com/?type=marker&isopeninfowin=1&markertype=1&pointx='+item.repLocationY+'&pointy='+item.repLocationX+'&name='+item.repContent+'&ref=joolun'"> <el-tag size="mini">扫码结果</el-tag>{{ item.eventKey }}
<img :src="'https://apis.map.qq.com/ws/staticmap/v2/?zoom=10&markers=color:blue|label:A|'+item.repLocationX+','+item.repLocationY+'&key='+qqMapKey+'&size=250*180'"> </div>
<p/><i class="el-icon-map-location"></i>{{item.repContent}} <div v-else-if="item.type === 'event'">
</el-link> <el-tag type="danger" size="mini">未知事件类型</el-tag>
</div> </div>
<div v-if="item.repType == 'link'" class="avue-card__detail"> <!-- 消息区域 -->
<el-link type="success" :underline="false" target="_blank" :href="item.repUrl"> <div v-else-if="item.type === 'text'">{{ item.content }}</div>
<div class="avue-card__title"><i class="el-icon-link"></i>{{item.repName}}</div> <div v-else-if="item.type === 'voice'">
</el-link> <wx-voice-player :url="item.mediaUrl" :content="item.recognition" />
<div class="avue-card__info" style="height: unset">{{item.repDesc}}</div> </div>
</div> <div v-else-if="item.type === 'image'">
<div v-if="item.repType == 'news'" style="width: 300px"> <a target="_blank" :href="item.mediaUrl">
<WxNews :objData="item.content.articles"></WxNews> <img :src="item.mediaUrl" style="width: 100px">
</div> </a>
<div v-if="item.repType == 'music'"> </div>
<el-link type="success" :underline="false" target="_blank" :href="item.repUrl"> <div v-else-if="item.type === 'video' || item.type === 'shortvideo'" style="text-align: center">
<div class="avue-card__body" style="padding:10px;background-color: #fff;border-radius: 5px"> <wx-video-player :url="item.mediaUrl" />
<div class="avue-card__avatar"><img :src="item.repThumbUrl" alt=""></div> </div>
<div class="avue-card__detail"> <div v-if="item.type === 'link'" class="avue-card__detail">
<div class="avue-card__title" style="margin-bottom:unset">{{item.repName}}</div> <el-link type="success" :underline="false" target="_blank" :href="item.url">
<div class="avue-card__info" style="height: unset">{{item.repDesc}}</div> <div class="avue-card__title"><i class="el-icon-link"></i>{{ item.title }}</div>
</div>
</div>
</el-link> </el-link>
<div class="avue-card__info" style="height: unset">{{item.description}}</div>
</div> </div>
<!-- <div v-if="item.repType == 'location'">-->
<!-- <el-link type="primary" target="_blank" :href="'https://map.qq.com/?type=marker&isopeninfowin=1&markertype=1&pointx='+item.repLocationY+'&pointy='+item.repLocationX+'&name='+item.repContent+'&ref=joolun'">-->
<!-- <img :src="'https://apis.map.qq.com/ws/staticmap/v2/?zoom=10&markers=color:blue|label:A|'+item.repLocationX+','+item.repLocationY+'&key='+qqMapKey+'&size=250*180'">-->
<!-- <p/><i class="el-icon-map-location"></i>{{item.repContent}}-->
<!-- </el-link>-->
<!-- </div>-->
<!-- <div v-if="item.repType == 'news'" style="width: 300px">-->
<!-- <WxNews :objData="item.content.articles"></WxNews>-->
<!-- </div>-->
<!-- <div v-if="item.repType == 'music'">-->
<!-- <el-link type="success" :underline="false" target="_blank" :href="item.repUrl">-->
<!-- <div class="avue-card__body" style="padding:10px;background-color: #fff;border-radius: 5px">-->
<!-- <div class="avue-card__avatar"><img :src="item.repThumbUrl" alt=""></div>-->
<!-- <div class="avue-card__detail">-->
<!-- <div class="avue-card__title" style="margin-bottom:unset">{{item.repName}}</div>-->
<!-- <div class="avue-card__info" style="height: unset">{{item.repDesc}}</div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </el-link>-->
<!-- </div>-->
</div> </div>
</div> </div>
</div> </div>
@ -78,26 +96,24 @@
</template> </template>
<script> <script>
import { getPage, addObj, putObj } from '@/api/wxmp/wxmsg' // import { getMessagePage, addObj } from '@/api/mp/message'
import SockJS from 'sockjs-client'; import { getMessagePage } from '@/api/mp/message'
import Stomp from 'stompjs'; // import WxReplySelect from '@/components/wx-reply/main.vue'
import { getToken } from '@/utils/auth' // import WxNews from '@/components/wx-news/main.vue'
import WxReplySelect from '@/components/wx-reply/main.vue' import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
import WxNews from '@/components/wx-news/main.vue' import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
import WxVideoPlayer from '@/components/wx-video-play/main.vue'
import WxVoicePlayer from '@/components/wx-voice-play/main.vue'
export default { export default {
name: "wxMsg", name: "wxMsg",
components: { components: {
WxReplySelect, // WxReplySelect,
WxNews, // WxNews,
WxVideoPlayer, WxVideoPlayer,
WxVoicePlayer WxVoicePlayer
}, },
props: { props: {
wxUserId:{ wxUserId: {
type:String type: String
} }
}, },
data() { data() {
@ -110,10 +126,10 @@
sendLoading:false, sendLoading:false,
tableLoading:false, tableLoading:false,
loadMore: true, loadMore: true,
tableData: [], tableData: [], //
page: { page: {
total: 0, // total: 0, //
currentPage: 1, // pageNo: 1, //
pageSize: 14, // pageSize: 14, //
ascs:[],// ascs:[],//
descs:'create_time'// descs:'create_time'//
@ -129,70 +145,8 @@
}, },
created() { created() {
this.refreshChange() this.refreshChange()
},
destroyed: function() {
this.disconnect()
},
mounted(){
//websocket
// this.initWebSocket()
},
beforeDestroy() {
// ,
this.disconnect();
clearInterval(this.timer);
},
computed: {
}, },
methods:{ methods:{
initWebSocket() {
this.connection();
let self = this;
//,,
this.timer = setInterval(() => {
try {
self.stompClient.send("test");
} catch (err) {
console.log("断线了: " + err);
self.connection();
}
}, 5000);
},
connection() {
let token = getToken()
let headers = {
'Authorization': 'Bearer ' + token
}
//
this.socket = new SockJS('/weixin/ws');//广
// STOMP
this.stompClient = Stomp.over(this.socket);
// websocket
this.stompClient.connect(headers, () => {
this.stompClient.subscribe('/weixin/wx_msg'+this.wxUserId, (msg) => { // topic;
let data = JSON.parse(msg.body)
this.tableData = [...this.tableData , ...[data]]//
this.scrollToBottom()
//
if(data.type == '1'){
putObj({
id: data.id,
readFlag: '0'
}).then(data => {})
}
});
}, (err) => {
});
},
disconnect() {
if (this.stompClient != null) {
this.stompClient.disconnect();
console.log("Disconnected");
}
},
sendMsg(){ sendMsg(){
if(this.objData){ if(this.objData){
if(this.objData.repType == 'news'){ if(this.objData.repType == 'news'){
@ -226,14 +180,14 @@
}) })
}, },
loadingMore(){ loadingMore(){
this.page.currentPage++ this.page.pageNo++
this.getPage(this.page) this.getPage(this.page)
}, },
getPage(page, params) { getPage(page, params) {
this.tableLoading = true this.tableLoading = true
getPage(Object.assign({ getMessagePage(Object.assign({
current: page.currentPage, pageNo: page.pageNo,
size: page.pageSize, pageSize: page.pageSize,
descs:page.descs, descs:page.descs,
ascs: page.ascs, ascs: page.ascs,
wxUserId: this.wxUserId wxUserId: this.wxUserId
@ -243,14 +197,14 @@
if(msgDiv){ if(msgDiv){
scrollHeight = msgDiv.scrollHeight scrollHeight = msgDiv.scrollHeight
} }
let data = response.data.records.reverse() let data = response.data.list.reverse()
this.tableData = [...data , ...this.tableData] this.tableData = [...data , ...this.tableData]
this.page.total = response.data.total this.page.total = response.data.total
this.tableLoading = false this.tableLoading = false
if(data.length < this.page.pageSize || data.length == 0){ if(data.length < this.page.pageSize || data.length === 0){
this.loadMore = false this.loadMore = false
} }
if(this.page.currentPage == 1){// if(this.page.pageNo == 1){//
this.scrollToBottom() this.scrollToBottom()
}else{ }else{
if(data.length != 0){ if(data.length != 0){
@ -261,7 +215,7 @@
}) })
} }
} }
this.page.currentPage = page.currentPage this.page.pageNo = page.pageNo
this.page.pageSize = page.pageSize this.page.pageSize = page.pageSize
}) })
}, },
@ -293,6 +247,12 @@
border-radius: 5px!important; border-radius: 5px!important;
margin: 0 8px!important; margin: 0 8px!important;
} }
.avue-comment--reverse {
-webkit-box-orient: horizontal;
-webkit-box-direction: reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.avue-comment__header{ .avue-comment__header{
border-top-left-radius: 5px; border-top-left-radius: 5px;
border-top-right-radius: 5px; border-top-right-radius: 5px;

View File

@ -29,11 +29,6 @@
<!-- 操作工具栏 --> <!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['mp:message:create']">新增
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -102,68 +97,25 @@
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/> @pagination="getList"/>
<!-- 对话框(添加 / 修改) --> <el-dialog title="用户消息" :visible.sync="open" width="40%">
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <wx-msg wxUserId="1" v-if="true" />
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="用户标识" prop="openid">
<el-input v-model="form.openid" placeholder="请输入用户标识"/>
</el-form-item>
<el-form-item label="昵称" prop="nickname">
<el-input v-model="form.nickname" placeholder="请输入昵称"/>
</el-form-item>
<el-form-item label="头像地址" prop="headimgUrl">
<el-input v-model="form.headimgUrl" placeholder="请输入头像地址"/>
</el-form-item>
<el-form-item label="微信账号ID" prop="wxAccountId">
<el-input v-model="form.wxAccountId" placeholder="请输入微信账号ID"/>
</el-form-item>
<el-form-item label="消息类型" prop="msgType">
<el-select v-model="form.msgType" placeholder="请选择消息类型">
<el-option label="请选择字典生成" value=""/>
</el-select>
</el-form-item>
<el-form-item label="内容">
<editor v-model="form.content" :min-height="192"/>
</el-form-item>
<el-form-item label="最近一条回复内容">
<editor v-model="form.resContent" :min-height="192"/>
</el-form-item>
<el-form-item label="是否已回复" prop="isRes">
<el-input v-model="form.isRes" placeholder="请输入是否已回复"/>
</el-form-item>
<el-form-item label="微信素材ID" prop="mediaId">
<el-input v-model="form.mediaId" placeholder="请输入微信素材ID"/>
</el-form-item>
<el-form-item label="微信图片URL" prop="picUrl">
<el-input v-model="form.picUrl" placeholder="请输入微信图片URL"/>
</el-form-item>
<el-form-item label="本地图片路径" prop="picPath">
<el-input v-model="form.picPath" placeholder="请输入本地图片路径"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { import { getMessagePage } from "@/api/mp/message";
createWxFansMsg,
getMessagePage,
} from "@/api/mp/message";
import Editor from '@/components/Editor/index.vue';
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'; import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'; import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
import WxMsg from '@/views/mp/components/wx-msg/main.vue';
export default { export default {
name: "WxFansMsg", name: "WxFansMsg",
components: { components: {
Editor,
WxVideoPlayer, WxVideoPlayer,
WxVoicePlayer WxVoicePlayer,
WxMsg
}, },
data() { data() {
return { return {
@ -180,9 +132,9 @@ export default {
// //
title: "", title: "",
// //
open: false, open: true,
dateRangeCreateTime: [],
// //
dateRangeCreateTime: [],
queryParams: { queryParams: {
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
@ -258,26 +210,6 @@ export default {
this.resetForm("queryForm"); this.resetForm("queryForm");
this.handleQuery(); this.handleQuery();
}, },
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加粉丝消息表 ";
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
//
createWxFansMsg(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
} }
}; };
</script> </script>