Merge branch 'lr' of http://1.94.221.165:3000/sx/jiuyiUniapp
This commit is contained in:
commit
4e769f24ed
|
@ -208,10 +208,11 @@ export const news = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 群聊发消息
|
// 消息列表
|
||||||
getMessageList(param) {
|
getMessageList(param) {
|
||||||
return util.request({
|
return util.request({
|
||||||
url: `/user/chat/getMessageList`,
|
// url: `/user/chat/getMessageList`,
|
||||||
|
url: `/user/chat/getMsgListById`,
|
||||||
query: param.query,
|
query: param.query,
|
||||||
data: param.data,
|
data: param.data,
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
|
|
|
@ -15,6 +15,9 @@ import {
|
||||||
reactive,
|
reactive,
|
||||||
watch,
|
watch,
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
|
import {
|
||||||
|
onLoad,
|
||||||
|
} from "@dcloudio/uni-app"
|
||||||
// 工具库
|
// 工具库
|
||||||
import util from '@/common/js/util';
|
import util from '@/common/js/util';
|
||||||
const {
|
const {
|
||||||
|
@ -149,6 +152,8 @@ onMounted(() => {
|
||||||
//
|
//
|
||||||
// proxy.$refs.alert.open()
|
// proxy.$refs.alert.open()
|
||||||
|
|
||||||
|
})
|
||||||
|
onLoad(()=>{
|
||||||
// 获取未读消息数量
|
// 获取未读消息数量
|
||||||
getNoReadNum()
|
getNoReadNum()
|
||||||
})
|
})
|
||||||
|
@ -182,6 +187,7 @@ function handleMenu(item) {
|
||||||
else uni.navigateTo({
|
else uni.navigateTo({
|
||||||
url: `/${item.pagePath}`,
|
url: `/${item.pagePath}`,
|
||||||
})
|
})
|
||||||
|
getNoReadNum()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -221,9 +227,10 @@ function getNoReadNum() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
const unreadCount = uni.$chat.getTotalUnreadMessageCount();
|
const unreadCount = uni.$chat.getTotalUnreadMessageCount();
|
||||||
|
|
||||||
noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount;
|
noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount;
|
||||||
|
// #endif
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -43,9 +43,11 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
// #ifdef APP
|
||||||
uni.offKeyboardHeightChange(rs => {
|
uni.offKeyboardHeightChange(rs => {
|
||||||
console.log('rs', rs)
|
console.log('rs', rs)
|
||||||
})
|
})
|
||||||
|
// #endif
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -204,12 +204,16 @@
|
||||||
getFriendList()
|
getFriendList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
|
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除加好友监听
|
// 移除加好友监听
|
||||||
function removelistener() {
|
function removelistener() {
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => { });
|
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => { });
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取朋友列表
|
// 获取朋友列表
|
||||||
|
@ -224,7 +228,6 @@
|
||||||
}, 500);
|
}, 500);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('getFriendList')
|
|
||||||
|
|
||||||
//
|
//
|
||||||
api.news.getFriendList().then(rs => {
|
api.news.getFriendList().then(rs => {
|
||||||
|
|
|
@ -79,7 +79,7 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
// removeListener()
|
removeListener()
|
||||||
})
|
})
|
||||||
|
|
||||||
// 开启监听消息
|
// 开启监听消息
|
||||||
|
@ -93,7 +93,9 @@ function addListener() {
|
||||||
|
|
||||||
// 移除监听
|
// 移除监听
|
||||||
function removeListener() {
|
function removeListener() {
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED);
|
// #ifdef APP
|
||||||
|
uni.$chat.off(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取消息列表
|
// 获取消息列表
|
||||||
|
@ -104,7 +106,8 @@ function getList() {
|
||||||
}
|
}
|
||||||
}).then(rs => {
|
}).then(rs => {
|
||||||
if (rs.code == 200) {
|
if (rs.code == 200) {
|
||||||
list.data = handleList(rs.data);
|
// list.data = handleList(rs.data);
|
||||||
|
list.data = handleList(JSON.parse(rs.msg).SessionItem);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.alert({
|
util.alert({
|
||||||
|
@ -112,17 +115,6 @@ function getList() {
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// // 验证sdk是否准备完毕
|
|
||||||
// let isReady = uni.$chat.isReady();
|
|
||||||
// if (!isReady) {
|
|
||||||
// setTimeout(function () {
|
|
||||||
// getList();
|
|
||||||
// }, 1000);
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uni.$chat.getMessageList({})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,53 +122,37 @@ function getList() {
|
||||||
* @param {Object} item
|
* @param {Object} item
|
||||||
*/
|
*/
|
||||||
function handleList(list) {
|
function handleList(list) {
|
||||||
list.forEach(item => {
|
|
||||||
item.callbackJson = JSON.parse(item.callbackJson);
|
|
||||||
|
|
||||||
if (item.groupId != null) {
|
|
||||||
item.unreadCount = getGroupNoReadNum(item.groupId)
|
|
||||||
}
|
|
||||||
if (item.callbackJson.callback_json.length) {
|
|
||||||
let msgType = item.callbackJson.callback_json[0].MsgType;
|
|
||||||
if (msgType == TencentCloudChat.TYPES.MSG_TEXT) {
|
|
||||||
item.chatText = item.callbackJson.callback_json[0].MsgContent.Text
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_IMAGE) {
|
|
||||||
item.chatText = '[图片]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_AUDIO) {
|
|
||||||
item.chatText = '[语音]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_VIDEO) {
|
|
||||||
item.chatText = '[视频]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_CUSTOM) {
|
|
||||||
if (item.callbackJson.callback_json[0].businessType == 'redPacket') {
|
|
||||||
item.chatText = `[红包] ${item.callbackJson.blessing}`
|
|
||||||
} else if (item.callbackJson.callback_json[0].businessType == '1') {
|
|
||||||
// if (item.callbackJson.callback_json[0].call_type == '1') {
|
|
||||||
// item.chatText = '[语音通话]'
|
|
||||||
// } else if (item.callbackJson.callback_json[0].call_type == '2') {
|
|
||||||
// item.chatText = '[视频通话]'
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询群聊未读数量
|
|
||||||
function getGroupNoReadNum(groupId) {
|
|
||||||
// 验证sdk是否准备完毕
|
// 验证sdk是否准备完毕
|
||||||
let isReady = uni.$chat.isReady();
|
let isReady = uni.$chat.isReady();
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
getGroupNoReadNum(groupId);
|
handleList(list);
|
||||||
}, 800);
|
}, 800);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const unreadCount = uni.$chat.getTotalUnreadMessageCount('GROUP', groupId);
|
list.forEach(item => {
|
||||||
|
item.MsgTime = handleDate(item.MsgTime)
|
||||||
|
|
||||||
return unreadCount;
|
let type = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
|
uni.$chat.getConversationProfile(type).then(rs => {
|
||||||
|
let res = rs.data.conversation;
|
||||||
|
|
||||||
|
item.chatText = res.lastMessage.messageForShow;
|
||||||
|
item.unreadCount = res.unreadCount;
|
||||||
|
if (item.Type == 1) {
|
||||||
|
item.avatar = res.userProfile.avatar;
|
||||||
|
item.name = res.userProfile.nick;
|
||||||
|
} else if (item.Type == 2) {
|
||||||
|
item.avatar = res.groupProfile.avatar;
|
||||||
|
item.name = res.groupProfile.name;
|
||||||
|
item.num = res.groupProfile.memberCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 点击用户
|
// // 点击用户
|
||||||
|
@ -204,14 +180,14 @@ function handleChat(item) {
|
||||||
// 单聊
|
// 单聊
|
||||||
if (item.groupId == null) {
|
if (item.groupId == null) {
|
||||||
param.type = 'C2C'
|
param.type = 'C2C'
|
||||||
param.name = `${item.callbackJson.from_name}`
|
param.name = `${item.name}`
|
||||||
param.msgId = `${item.callbackJson.from_id}`
|
param.msgId = `${item.To_Account}`
|
||||||
} else {
|
} else {
|
||||||
// 群聊
|
// 群聊
|
||||||
param.type = 'GROUP'
|
param.type = 'GROUP'
|
||||||
param.name = `${item.groupChatDTO.name}`
|
param.name = `${item.name}`
|
||||||
param.msgId = `${item.groupId}`
|
param.msgId = `${item.GroupId}`
|
||||||
param.num = `${item.groupChatDTO.memberCount}`
|
param.num = `${item.num}`
|
||||||
}
|
}
|
||||||
|
|
||||||
setRead(item)
|
setRead(item)
|
||||||
|
@ -240,7 +216,7 @@ function delMsg(item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`;
|
let conversationId = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
|
|
||||||
uni.$chat.deleteConversation(conversationId).then(rs => {
|
uni.$chat.deleteConversation(conversationId).then(rs => {
|
||||||
getList()
|
getList()
|
||||||
|
@ -258,7 +234,7 @@ function setRead(item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`;
|
let conversationId = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
uni.$chat.setMessageRead({
|
uni.$chat.setMessageRead({
|
||||||
conversationID: conversationId,
|
conversationID: conversationId,
|
||||||
}).then(rs => {
|
}).then(rs => {
|
||||||
|
@ -266,6 +242,21 @@ function setRead(item) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 时间转换
|
||||||
|
function handleDate(timestamp) {
|
||||||
|
var timestamp = +timestamp * 1000;
|
||||||
|
var date = new Date(timestamp);
|
||||||
|
|
||||||
|
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
|
||||||
|
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
|
||||||
|
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
|
||||||
|
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
|
||||||
|
var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
|
||||||
|
|
||||||
|
var formattedDate = M + D + h + m + s;
|
||||||
|
return formattedDate
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -326,25 +317,28 @@ function setRead(item) {
|
||||||
@click="handleMenu($event, item)">
|
@click="handleMenu($event, item)">
|
||||||
<view class="item rows ptb20 plr30" @click.stop="handleChat(item)">
|
<view class="item rows ptb20 plr30" @click.stop="handleChat(item)">
|
||||||
<view class="image wh90 pr">
|
<view class="image wh90 pr">
|
||||||
<template v-if="item.groupId == null">
|
<!-- <template v-if="item.groupId == null">
|
||||||
<image class="cir wh90" :src="item.callbackJson.from_url" mode="aspectFill" />
|
<image class="cir wh90" :src="item.callbackJson.from_url" mode="aspectFill" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<image class="cir wh90" :src="item.groupChatDTO.groupFaceUrl" mode="aspectFill" />
|
<image class="cir wh90" :src="item.groupChatDTO.groupFaceUrl" mode="aspectFill" />
|
||||||
</template>
|
</template> -->
|
||||||
|
|
||||||
|
<image class="cir wh90" :src="item.avatar" mode="aspectFill" />
|
||||||
<view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount }}
|
<view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="col f1 ml20">
|
<view class="col f1 ml20">
|
||||||
<view class="rows">
|
<view class="rows">
|
||||||
<template v-if="item.groupId == null">
|
<view class="name f1 thd c333 f32">{{ item.name }}</view>
|
||||||
|
<!-- <template v-if="item.groupId == null">
|
||||||
<view class="name f1 thd c333 f32">{{ item.callbackJson.from_name }}</view>
|
<view class="name f1 thd c333 f32">{{ item.callbackJson.from_name }}</view>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
|
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
|
||||||
</template>
|
</template> -->
|
||||||
<view class="datetime c999 f22">
|
<view class="datetime c999 f22">
|
||||||
{{ util.formatTime('MM-dd HH:mm', item.createTime) }}</view>
|
{{ util.formatTime('MM-dd HH:mm', item.MsgTime) }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
|
<view class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
|
@ -155,7 +155,9 @@ function addListener() {
|
||||||
}, 200)
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
|
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听内容滚动
|
// 监听内容滚动
|
||||||
|
@ -210,6 +212,7 @@ function sendMsg(param) {
|
||||||
data: param.data,
|
data: param.data,
|
||||||
}).then((rs) => {
|
}).then((rs) => {
|
||||||
if (rs.code == 200) {
|
if (rs.code == 200) {
|
||||||
|
getHistory()
|
||||||
param.success ? param.success() : ''
|
param.success ? param.success() : ''
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -310,15 +313,15 @@ function getMoreHistroy() {
|
||||||
*/
|
*/
|
||||||
function getHistory(param = {}) {
|
function getHistory(param = {}) {
|
||||||
// 验证sdk是否准备完毕
|
// 验证sdk是否准备完毕
|
||||||
|
// #ifdef APP
|
||||||
let isReady = uni.$chat.isReady();
|
let isReady = uni.$chat.isReady();
|
||||||
//
|
|
||||||
if (!isReady && userinfo.value.id) {
|
if (!isReady && userinfo.value.id) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
getHistory(param)
|
getHistory()
|
||||||
}, 200);
|
}, 200);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//
|
// #endif
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
// 获取单聊聊天记录
|
// 获取单聊聊天记录
|
||||||
|
|
|
@ -94,7 +94,9 @@ function imLoading() {
|
||||||
|
|
||||||
// 移除监听
|
// 移除监听
|
||||||
function removeListener() {
|
function removeListener() {
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.off(TencentCloudChat.EVENT.SDK_READY);
|
uni.$chat.off(TencentCloudChat.EVENT.SDK_READY);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue