This commit is contained in:
sx 2025-02-20 15:39:41 +08:00
commit 4e769f24ed
7 changed files with 515 additions and 503 deletions

View File

@ -208,10 +208,11 @@ export const news = {
})
},
// 群聊发消息
// 消息列表
getMessageList(param) {
return util.request({
url: `/user/chat/getMessageList`,
// url: `/user/chat/getMessageList`,
url: `/user/chat/getMsgListById`,
query: param.query,
data: param.data,
method: 'GET'

View File

@ -15,6 +15,9 @@ import {
reactive,
watch,
} from 'vue'
import {
onLoad,
} from "@dcloudio/uni-app"
//
import util from '@/common/js/util';
const {
@ -149,6 +152,8 @@ onMounted(() => {
//
// proxy.$refs.alert.open()
})
onLoad(()=>{
//
getNoReadNum()
})
@ -182,6 +187,7 @@ function handleMenu(item) {
else uni.navigateTo({
url: `/${item.pagePath}`,
})
getNoReadNum()
return
}
//
@ -221,9 +227,10 @@ function getNoReadNum() {
return
}
// #ifdef APP
const unreadCount = uni.$chat.getTotalUnreadMessageCount();
noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount;
// #endif
}
</script>

View File

@ -43,9 +43,11 @@
})
onBeforeUnmount(() => {
// #ifdef APP
uni.offKeyboardHeightChange(rs => {
console.log('rs', rs)
})
// #endif
})
/**

View File

@ -1,11 +1,11 @@
<script setup>
/**
/**
* 通讯录
*/
import {
import {
useStore,
} from 'vuex'
import {
} from 'vuex'
import {
ref,
computed,
reactive,
@ -13,164 +13,164 @@
onUnmounted,
inject,
getCurrentInstance,
} from 'vue'
//
import util from '@/common/js/util.js'
//
import TencentCloudChat from '@tencentcloud/chat';
// api
import api from '@/api/index.js'
import pinyin from 'js-pinyin'
import {
} from 'vue'
//
import util from '@/common/js/util.js'
//
import TencentCloudChat from '@tencentcloud/chat';
// api
import api from '@/api/index.js'
import pinyin from 'js-pinyin'
import {
forEach
} from 'lodash';
const {
} from 'lodash';
const {
proxy
} = getCurrentInstance();
const store = useStore()
const userinfo = computed(() => {
} = getCurrentInstance();
const store = useStore()
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
const msgType = {}
//
const userList = reactive({
})
const msgType = {}
//
const userList = reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0,
})
//
let user = reactive({})
//
const listKey = ref('')
//
const letterList = [{
})
//
let user = reactive({})
//
const listKey = ref('')
//
const letterList = [{
key: 'other',
name: '#',
},
{
},
{
key: 'a',
name: 'A',
},
{
},
{
key: 'b',
name: 'B',
},
{
},
{
key: 'c',
name: 'C',
},
{
},
{
key: 'd',
name: 'D',
},
{
},
{
key: 'e',
name: 'E',
},
{
},
{
key: 'f',
name: 'F',
},
{
},
{
key: 'g',
name: 'G',
},
{
},
{
key: 'h',
name: 'H',
},
{
},
{
key: 'i',
name: 'I',
},
{
},
{
key: 'j',
name: 'J',
},
{
},
{
key: 'k',
name: 'K',
},
{
},
{
key: 'l',
name: 'L',
},
{
},
{
key: 'm',
name: 'M',
},
{
},
{
key: 'n',
name: 'N',
},
{
},
{
key: 'o',
name: 'O',
},
{
},
{
key: 'p',
name: 'P',
},
{
},
{
key: 'q',
name: 'Q',
},
{
},
{
key: 'r',
name: 'R',
},
{
},
{
key: 's',
name: 'S',
},
{
},
{
key: 't',
name: 'T',
},
{
},
{
key: 'u',
name: 'U',
},
{
},
{
key: 'v',
name: 'V',
},
{
},
{
key: 'w',
name: 'W',
},
{
},
{
key: 'x',
name: 'X',
},
{
},
{
key: 'y',
name: 'Y',
},
{
},
{
key: 'z',
name: 'Z',
},
]
//
const touchmove = ref(false)
// dom
const letterDom = reactive({
},
]
//
const touchmove = ref(false)
// dom
const letterDom = reactive({
itemHeight: 0,
minHeight: 0,
maxHeight: 0,
height: 0,
})
//
const rightOption = [{
})
//
const rightOption = [{
text: '删除',
style: {
backgroundColor: '#F85050'
},
fn: (user) => delFriend(user),
},
},
// {
// text: '',
// style: {
@ -178,9 +178,9 @@
// },
// fn: (user) => setFriendNote(user),
// },
]
]
onMounted(() => {
onMounted(() => {
//
getFriendList()
//
@ -189,42 +189,45 @@
addlistener()
// proxy.$refs.note.open()
})
})
onUnmounted(() => {
onUnmounted(() => {
removelistener()
})
})
const viewData = ref([])
const viewData = ref([])
//
function addlistener() {
//
function addlistener() {
let onFriendListUpdated = (event) => {
console.log('onFriendListUpdated', event.data);
getFriendList()
}
// #ifdef APP
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
}
// #endif
}
//
function removelistener() {
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => {});
}
//
function removelistener() {
// #ifdef APP
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => { });
// #endif
}
//
function getFriendList() {
//
function getFriendList() {
// sdk
let isReady = uni.$chat.isReady();
console.log('getFriendList', isReady)
if (!isReady) {
setTimeout(function() {
setTimeout(function () {
getFriendList()
}, 500);
return
}
console.log('getFriendList')
//
api.news.getFriendList().then(rs => {
@ -239,13 +242,13 @@
showCancel: false,
})
})
}
}
/**
/**
* 用户列表排序
* @param {Object} userList
*/
function handleUserList(userList) {
function handleUserList(userList) {
//
const userArr = []
//
@ -279,11 +282,11 @@
// return surnameA.localeCompare(surnameB);
// });
return userArr;
}
}
//
function getLetterProperty() {
//
function getLetterProperty() {
const query = uni.createSelectorQuery().in(proxy);
query.select(".letterBox").boundingClientRect((data) => {
@ -292,15 +295,15 @@
letterDom.maxHeight = data.bottom
letterDom.itemHeight = data.height / letterList.length
}).exec();
}
}
//
function handleTouchStart(ev) {
//
function handleTouchStart(ev) {
touchmove.value = true
}
}
//
function handleTouchMove(ev) {
//
function handleTouchMove(ev) {
if (!touchmove.value) return
//
let result = ev.touches[0].pageY
@ -313,36 +316,36 @@
//
listKey.value = letterList[index].key
}
}
//
function handleTouchEnd(ev) {
//
function handleTouchEnd(ev) {
touchmove.value = false
}
}
/**
/**
* 点击字母
* @param {Object} item 点击的当前项
*/
function handleLetter(item) {
function handleLetter(item) {
listKey.value = item.key
}
}
/**
/**
* 右滑菜单
* @param {Object} ev 默认事件
* @param {Object} user 用户信息
*/
function handleSwipeAction(ev, user) {
function handleSwipeAction(ev, user) {
ev.content.fn(user)
proxy.$refs.swipeAction.closeAll()
}
}
/**
/**
* 删除好友
* @param {Object} user 需要删除的好友信息
*/
function delFriend(user) {
function delFriend(user) {
new Promise((resolve, reject) => {
util.alert({
content: `确认删除好友${user.remark || user.userNickname}`
@ -367,23 +370,23 @@
})
})
})
}
}
/**
/**
* 设置好友备注
* @param {Object} ev 需要操作的好友信息
*/
function setFriendNote(ev) {
function setFriendNote(ev) {
//
Object.assign(user, ev)
//
setTimeout(() => {
proxy.$refs.note.open()
}, 50)
}
}
//
function handleSaveNote() {
//
function handleSaveNote() {
api.news.setNotes({
query: {
name: user.note || '',
@ -402,29 +405,29 @@
showCancel: false,
})
})
}
}
/**
/**
* 点击用户
* @param {Object} user 当前用户信息
*/
function handleUser(user) {
function handleUser(user) {
util.toChat({
name: user.remark || user.userNickname,
msgId: user.userId,
type: 'C2C',
})
}
}
/**
/**
* 跳转
* @param {Object} url
*/
function link(url) {
function link(url) {
uni.navigateTo({
url,
})
}
}
</script>
<template>
@ -449,10 +452,10 @@
<view class="letter ptb10 plr30 c666 f20">{{ item.letter }}</view>
<view class="child pl30 pr50">
<uni-swipe-action-item :right-options="rightOption" v-for="(user, secIndex) in item.child"
:key="secIndex" @click="handleSwipeAction($event,user)">
:key="secIndex" @click="handleSwipeAction($event, user)">
<view class="item rows ptb20" @click="handleUser(user)">
<image class="wh80 avatar cir" :src="user.avatar" mode="aspectFill" />
<view class="name thd f1 ml20 c333 f32">{{user.remark || user.userNickname}}</view>
<view class="name thd f1 ml20 c333 f32">{{ user.remark || user.userNickname }}</view>
</view>
</uni-swipe-action-item>
</view>
@ -475,7 +478,7 @@
<uni-popup ref="note" type="bottom" mask-background-color="rgba(0,0,0,0)">
<view class="noteAlt popBot plr25 bfff">
<view class="header rows ptb20">
<view class="title c333 f34">设置好友({{user.remark}})备注</view>
<view class="title c333 f34">设置好友({{ user.remark }})备注</view>
<uni-icons type="closeempty" size="40rpx" @click="$refs.note.close()" />
</view>
@ -489,8 +492,8 @@
</template>
<style lang="scss" scoped>
//
.firendBox {
//
.firendBox {
height: 100%;
.scroll {
@ -510,18 +513,18 @@
border-top: 2rpx solid #eee;
}
}
}
}
//
.letterBox {
//
.letterBox {
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
}
}
//
.noteAlt {
//
.noteAlt {
box-shadow: 0 0 20rpx #0003;
.content {
@ -531,5 +534,5 @@
border-radius: 20rpx;
}
}
}
}
</style>

View File

@ -69,7 +69,7 @@ const list = reactive([])
onMounted(() => {
if (props.type == 0) {
getList()
} else if(props.type == 1) {
} else if (props.type == 1) {
//
} else if (props.type == 2) {
//
@ -79,7 +79,7 @@ onMounted(() => {
})
onUnmounted(() => {
// removeListener()
removeListener()
})
//
@ -93,7 +93,9 @@ function addListener() {
//
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 => {
if (rs.code == 200) {
list.data = handleList(rs.data);
// list.data = handleList(rs.data);
list.data = handleList(JSON.parse(rs.msg).SessionItem);
return
}
util.alert({
@ -112,17 +115,6 @@ function getList() {
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
*/
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
let isReady = uni.$chat.isReady();
if (!isReady) {
setTimeout(function () {
getGroupNoReadNum(groupId);
handleList(list);
}, 800);
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) {
param.type = 'C2C'
param.name = `${item.callbackJson.from_name}`
param.msgId = `${item.callbackJson.from_id}`
param.name = `${item.name}`
param.msgId = `${item.To_Account}`
} else {
//
param.type = 'GROUP'
param.name = `${item.groupChatDTO.name}`
param.msgId = `${item.groupId}`
param.num = `${item.groupChatDTO.memberCount}`
param.name = `${item.name}`
param.msgId = `${item.GroupId}`
param.num = `${item.num}`
}
setRead(item)
@ -240,7 +216,7 @@ function delMsg(item) {
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 => {
getList()
@ -258,7 +234,7 @@ function setRead(item) {
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({
conversationID: conversationId,
}).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>
@ -326,25 +317,28 @@ function setRead(item) {
@click="handleMenu($event, item)">
<view class="item rows ptb20 plr30" @click.stop="handleChat(item)">
<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" />
</template>
<template v-else>
<template v-else>
<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>
</view>
<view class="col f1 ml20">
<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>
</template>
<template v-else>
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
</template>
</template> -->
<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 class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
</view>

View File

@ -155,7 +155,9 @@ function addListener() {
}, 200)
}
// #ifdef APP
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
// #endif
}
//
@ -210,6 +212,7 @@ function sendMsg(param) {
data: param.data,
}).then((rs) => {
if (rs.code == 200) {
getHistory()
param.success ? param.success() : ''
return
}
@ -310,15 +313,15 @@ function getMoreHistroy() {
*/
function getHistory(param = {}) {
// sdk
// #ifdef APP
let isReady = uni.$chat.isReady();
//
if (!isReady && userinfo.value.id) {
setTimeout(function () {
getHistory(param)
getHistory()
}, 200);
return
}
//
// #endif
loading.value = true
//

View File

@ -94,7 +94,9 @@ function imLoading() {
//
function removeListener() {
// #ifdef APP
uni.$chat.off(TencentCloudChat.EVENT.SDK_READY);
// #endif
}
/**