jiuyiUniapp/jiuyi2/pages/news/chatGroup.vue

153 lines
3.1 KiB
Vue
Raw Normal View History

2025-01-07 21:09:52 +08:00
<script setup>
// 群组列表
import {
reactive,
onMounted,
onUnmounted,
getCurrentInstance,
} from 'vue';
// 工具库
import util from '@/common/js/util.js'
import {
onLoad,
onUnload,
} from '@dcloudio/uni-app'
// 腾讯云聊天
import TencentCloudChat from '@tencentcloud/chat';
//
2025-01-11 03:51:29 +08:00
import api from '@/api/index.js'
//
2025-01-07 21:09:52 +08:00
const {
proxy
} = getCurrentInstance()
// 数据列表
const list = reactive([])
// 右滑菜单
2025-01-12 02:05:25 +08:00
const rightOption = [
// {
// text: '退出群聊',
// style: {
// backgroundColor: '#F85050'
// },
// fn: (item) => quitGroup(item)
// }
]
2025-01-07 21:09:52 +08:00
onLoad(() => {
//
2025-01-12 02:05:25 +08:00
getGroupList()
2025-01-07 21:09:52 +08:00
// 开启监听
addListener()
})
onUnload(() => {
// 移除监听
removeListener()
})
// 开启监听
function addListener() {
let onFriendListUpdated = function(event) {
2025-01-11 03:51:29 +08:00
console.log('onFriendListUpdated')
2025-01-07 21:09:52 +08:00
getGroupList()
}
2025-01-11 03:51:29 +08:00
uni.$chat.on(TencentCloudChat.EVENT.GROUP_LIST_UPDATED, onFriendListUpdated);
2025-01-07 21:09:52 +08:00
}
// 移除监听
function removeListener() {
2025-01-11 03:51:29 +08:00
uni.$chat.off(TencentCloudChat.EVENT.GROUP_LIST_UPDATED);
2025-01-07 21:09:52 +08:00
}
// 获取群组列表
function getGroupList() {
2025-01-12 02:05:25 +08:00
api.news.myGroups().then(rs => {
2025-01-11 03:51:29 +08:00
if (rs.code == 200) {
2025-01-07 21:09:52 +08:00
list.length = 0
2025-01-11 03:51:29 +08:00
list.push(...rs.data)
2025-01-07 21:09:52 +08:00
console.log('group list', list)
2025-01-11 03:51:29 +08:00
return
2025-01-07 21:09:52 +08:00
}
2025-01-11 03:51:29 +08:00
util.alert({
content: rs.msg,
showCancel: false
})
2025-01-07 21:09:52 +08:00
})
}
/**
2025-01-12 02:05:25 +08:00
* 跳转聊天
2025-01-07 21:09:52 +08:00
* @param {Object} item
*/
function handleGroupItem(item) {
console.log('group item', item)
util.toChat({
2025-01-12 02:05:25 +08:00
name: `${item.name}`,
msgId: item.groupId,
2025-01-07 21:09:52 +08:00
type: 'GROUP',
2025-01-12 02:05:25 +08:00
num: item.memberCount,
2025-01-07 21:09:52 +08:00
})
}
/**
* 菜单
* @param {Object} ev 默认事件
* @param {Object} item 单项
*/
function handleMenu(ev, item) {
ev.content.fn(item)
proxy.$refs.swipeAction.closeAll()
}
/**
* 退出群组
* @param {Object} item 详情
*/
function quitGroup(item) {
util.alert({
content: '确认退出群聊?'
}).then(rs => {
if (!rs.confirm) return
uni.$chat.quitGroup({
groupID: item.groupID,
}).then(rs => {
getGroupList()
})
})
}
</script>
<template>
2025-01-12 02:05:25 +08:00
<view class="appbw">
2025-01-07 21:09:52 +08:00
<uni-swipe-action ref="swipeAction">
2025-01-12 02:05:25 +08:00
<view class="list plr30 pb30">
<view class="item" v-for="(item, index) in list" :key="index">
2025-01-07 21:09:52 +08:00
<uni-swipe-action-item :right-options="rightOption" @click="handleMenu($event,item)">
2025-01-12 02:05:25 +08:00
<view class="item rows ptb30" @click="handleGroupItem(item)">
<image class="wh120 fs0 avatar br10" :src="item.groupFaceUrl" mode="aspectFill" />
2025-01-07 21:09:52 +08:00
2025-01-12 02:05:25 +08:00
<view class="f1 oh ml30">
<view class="name thd f1 c333 f34">{{item.name}}</view>
2025-01-07 21:09:52 +08:00
<!-- <view class="content thd mt10 c666 f24">{{item.lastMessage.messageForShow || ''}}</view> -->
</view>
<!-- <view class="time c999 f22" v-if="item.lastMessage.messageForShow || ''">{{util.formatTime('yyyy-MM-dd HH:mm:ss',item.lastMessage.lastTime)}}</view> -->
</view>
</uni-swipe-action-item>
</view>
<view class="mtb20 nomore">到底啦~</view>
</view>
</uni-swipe-action>
</view>
</template>
<style lang="scss">
2025-01-12 02:05:25 +08:00
.list {
.item + .item {
border-top: 2rpx solid #eee;
2025-01-07 21:09:52 +08:00
}
}
</style>