update 网易云信系统通知处理

This commit is contained in:
zengBin 2024-10-31 18:05:31 +08:00
parent 291c4df6a7
commit 12913617c1
5 changed files with 411 additions and 43 deletions

View File

@ -35,7 +35,7 @@ wepy.app({
}
},
globalData: {
versions: 'v5.5.74', // 版本号
versions: 'v5.5.75', // 版本号
navBarHeight: 0, // 导航栏高度
navRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
navTop: 0, // 胶囊距顶部间距
@ -180,6 +180,7 @@ subPackages: [
'root': 'pages/news',
'pages': [
'chitchat',
'editGroupMembers',
'friendRequest',
'groupChitchat',
'groupChitchatDetail',

View File

@ -0,0 +1,293 @@
<style lang="less" scoped>
@import url(../../styles/theme.less);
page {
background-color: #ffffff;
}
.ui-editGroupMembers{
padding: 30rpx 30rpx 180rpx 30rpx;
}
.ui-search{
width: 100vw;
background: #ffffff;
position: fixed;
top: 0;
left: 0;
z-index: 22;
}
.searchIcon{
width: 27rpx;
height: 27rpx;
margin: 0 20rpx;
}
.ui-placeholder{
width: 100%;
height: 90rpx;
}
.ui-select-icon{
width: 36rpx;
height: 36rpx;
display: block;
}
.ui-user-pic{
width: 90rpx;
height: 90rpx;
border-radius: 50%;
display: block;
margin: 0 20rpx 0 32rpx;
}
.ui-name{
width: 100%;
.ui-name-line{
border-bottom: 2rpx solid #f5f5f5;
position: relative;
bottom: -40rpx;
}
}
.ui-btn{
width: 460rpx;
height: 80rpx;
background: linear-gradient(90deg, #FF5380 0%, #FF85A5 100%);
border-radius: 40rpx;
position: fixed;
bottom: 80rpx;
left: 50%;
transform: translateX(-50%);
}
.ui-no-data-icon{
width: 440rpx;
height: 360rpx;
display: block;
margin: 13vh auto 0 auto;
}
</style>
<template>
<view class="ui-editGroupMembers">
<block v-if="type == 'add'">
<view class="cu-bar ui-search bg-white">
<view class="search-form round">
<image class="searchIcon" src="https://images.ufutx.com/202102/26/4081d59162d4a38736c323ed7fffd3db.png" alt=""></image>
<input type="text" placeholder="搜索用户" v-model="inputVal" confirm-type="search" @confirm="getList" />
</view>
</view>
<view class="ui-placeholder"></view>
</block>
<block v-for="(item,index) in members" :key="index">
<view class="f-fcl ui-pb-40" @tap="changeSelect(item, index)">
<view class="f-fcl">
<image v-if="!item.state" class="ui-select-icon" src="https://image.fulllinkai.com/202410/30/10d344fa2e88c47ea964b3e206d64b51.png" mode="widthFix"></image>
<image v-else class="ui-select-icon" src="https://image.fulllinkai.com/202410/30/8a685728482ce06f1126997e53ad3dfc.png" mode="widthFix"></image>
<image class="ui-user-pic" :src="item.photo" mode="aspectFill"></image>
</view>
<view class="ui-name">
<view class="font_32 color333 blod">{{item.nickname}}</view>
<view class="ui-name-line" v-if="index +1 != members.length"></view>
</view>
</view>
</block>
<block v-if="members.length == 0 && loading">
<image class="ui-no-data-icon" src="https://image.fulllinkai.com/202410/30/f560b1298101b213812c9b08a66e37ed.png" mode="aspectFill"></image>
<view class="font_30 color999 text-center">暂无用户信息</view>
</block>
<view class="font_30 colorF f-fcc ui-btn" @tap="twiceVerify">{{type == 'add' ? '确认添加' :'确认删除'}}</view>
</view>
</template>
<script>
import wepy from '@wepy/core'
import https from '../../mixins/https'
import base from '../../mixins/base'
import {service} from '../../config'
wepy.page({
config: {},
mixins: [https, base],
data: {
navHeight: 0,
StatusBar: 0,
CustomBar: 0,
Custom: 0,
inputVal: '',
timer: null,
id: '',
type: '',
members: [],
selectIds: [],
no_more: false,
loading: false,
page: 1,
list: [] // 列表数据
},
watch: {
inputVal () {
let vm = this
clearTimeout(vm.timer)
vm.timer = setTimeout(() => {
vm.selectIds = []
vm.page = 1
vm.no_more = false
vm.getList()
}, 800)
}
},
methods: {
getDetail() {
let vm = this
vm.$showLoading('')
vm.$get({url: `${service.host}/team/${vm.id}/detail`}).then(({code, data}) => {
if (code === 0) {
if (data.members && data.members.length > 0) {
data.members.forEach((item) => {
item.state = false
})
vm.members = data.members
}
}
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
console.log(err)
})
},
getList() {
let vm = this
let data = {
page: 1
}
vm.$showLoading('加载中...')
vm.$get({url: `${service.host}/other/user/list?keyword=${vm.inputVal}`, data}).then(({code, data}) => {
if (code === 0) {
if (data.data && data.data.length > 0) {
data.data.forEach((item) => {
item.state = false
})
vm.members = data.data
}
}
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
console.log(err)
})
},
twiceVerify () {
let vm = this
let url = ''
if (vm.type == 'add') {
url = `${service.host}/team/${vm.id}/invite/users`
} else {
url = `${service.host}/team/${vm.id}/kick/users`
}
let data = {
user_ids: vm.selectIds
}
if (vm.selectIds.length == 0) {
vm.$showToast('请选择至少一位成员')
return
}
wx.showModal({
title: '温馨提示',
content: `是否确认本次${vm.type == 'add' ? '添加' : '删除'}操作?`,
success: function (res) {
if (res.confirm) {
vm.$post({url: url, data}).then(({code, data}) => {
if (code == 0) {
vm.$showToast(`${vm.type == 'add' ? '添加成功' : '删除成功'}`)
if (vm.type != 'add') {
vm.selectIds.forEach((i) => {
vm.members.forEach((j, index) => {
if (i == j.id) {
vm.members.splice(index, 1)
}
})
})
}
setTimeout(() => {
wx.navigateBack({delta: 1})
}, 1500)
}
wx.hideLoading()
}).catch(() => {
wx.hideLoading()
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
changeSelect(e, index) {
console.log(e, index)
let vm = this
if (!vm.members[index].state) {
vm.members[index].state = true
vm.selectIds.push(e.id)
} else {
vm.members[index].state = false
vm.selectIds = vm.selectIds.filter(item => { return item != e.id })
}
console.log(vm.selectIds, '7777')
},
jump () {
const meetingCode = '948050239' // 会议码
const password = '6666' // 会议密码
const channel = 'ExampleChannel' // 从哪里跳转到腾讯会议小程序的
const nickname = encodeURIComponent('小程序用户') // 入会昵称
wx.navigateToMiniProgram({
appId: 'wx33fd6cdc62520063', // 跳转的目标小程序腾讯会议小程序AppId
path: `pages/index/index?chn=${channel}&code=${meetingCode}&pwd=${password}&nm=${nickname}`, // 跳转到的页面路径
extraData: {
},
envVersion: 'release', // 是指要打开的小程序的版本,默认为'release'
success(res) {
// 打开成功
},
fail(err) {
// 打开失败
console.error(`launch Tencent Meeting Miniprogram failed: ${err.errMsg}`)
}
})
}
},
onShow() {
let vm = this
let app = vm.$app.$options
vm.navHeight = app.globalData.navBarHeight
vm.StatusBar = app.globalData.StatusBar
vm.CustomBar = app.globalData.CustomBar
vm.Custom = app.globalData.Custom
},
onLoad(e) {
let vm = this
vm.id = e.id
vm.type = e.type
wx.setNavigationBarTitle({
title: vm.type == 'add' ? '添加成员' : '删除成员',
success: function () {}
})
if (vm.type != 'add') {
vm.getDetail()
} else {
vm.loading = true
}
}
})
</script>
<config>
{
navigationBarTitleText: '',
backgroundColorTop: '#ffffff',
backgroundColorBottom: '#ffffff',
}
</config>

View File

@ -1000,6 +1000,7 @@ wepy.page({
if (e.to != vm.otherUserId) {
return
}
console.log(e, '777')
// 标记IM消息已读
vm.sendMsgReceipt()
if (e.type == 'text' && /\[[^\]]+\]/.test(e.body)) {
@ -1326,12 +1327,62 @@ wepy.page({
// 群通知消息判断
groupNotification (e) {
let text = ``
if (e.type == '7' && e.attach.type == 'addTeamMembers') {
text = `${e.attach.users[1].nick}邀请${e.attach.users[0].nick}加入群`
// 内部接口判断邀请加入群
if (e.type == '7' && e.body_arr.id == 0) {
if (e.body_arr.data.uinfos.length > 2) {
text = `${e.body_arr.data.uinfos[e.body_arr.data.uinfos.length - 1][3]}邀请${e.body_arr.data.uinfos[0][3]}等${e.body_arr.data.uinfos.length - 1}人加入群`
} else {
text = `${e.body_arr.data.uinfos[1][3]}邀请${e.body_arr.data.uinfos[0][3]}加入群`
}
}
if (e.type == '7' && e.attach.type == 'leaveTeam') {
// 内部接口判断踢出群
if (e.type == '7' && e.body_arr.id == 1) {
if (e.body_arr.data.uinfos.length > 2) {
text = `${e.body_arr.data.uinfos[e.body_arr.data.uinfos.length - 1][3]}将${e.body_arr.data.uinfos[0][3]}等${e.body_arr.data.uinfos.length - 1}人踢出群`
} else {
text = `${e.body_arr.data.uinfos[1][3]}将${e.body_arr.data.uinfos[0][3]}踢出群`
}
}
// 内部接口判断退出群聊
if (e.type == '7' && e.body_arr.id == 2) {
text = `${e.body_arr.data.uinfos[0][3]}退出群`
}
// 内部接口判断将谁设为管理员
if (e.type == '7' && e.body_arr.id == 7) {
text = `${e.body_arr.data.uinfos[1][3]}将${e.body_arr.data.uinfos[0][3]}设为管理员`
}
// 内部接口判断将谁取消管理员
if (e.type == '7' && e.body_arr.id == 8) {
text = `${e.body_arr.data.uinfos[1][3]}取消${e.body_arr.data.uinfos[0][3]}的管理员身份`
}
// 网易云信回调邀请进群
if (e.type == 'notification' && e.attach.type == 'addTeamMembers') {
if (e.attach.users.length > 2) {
text = `${e.attach.users[e.attach.users.length - 1].nick}邀请${e.attach.users[0].nick}等${e.attach.users.length - 1}人加入群`
} else {
text = `${e.attach.users[1].nick}邀请${e.attach.users[0].nick}加入群`
}
}
// 网易云信回调添加管理员身份
if (e.type == 'notification' && e.attach.type == 'addTeamManagers') {
text = `${e.attach.users[1].nick}将${e.attach.users[0].nick}设为管理员`
}
// 网易云信回调删除管理员身份
if (e.type == 'notification' && e.attach.type == 'removeTeamManagers') {
text = `${e.attach.users[1].nick}取消${e.attach.users[0].nick}的管理员身份`
}
// 网易云信回调离开群
if (e.type == 'notification' && e.attach.type == 'leaveTeam') {
text = `${e.attach.users[0].nick}离开群`
}
// 网易云信回调踢出群
if (e.type == 'notification' && e.attach.type == 'removeTeamMembers') {
if (e.attach.users.length > 2) {
text = `${e.attach.users[e.attach.users.length - 1].nick}将${e.attach.users[0].nick}等${e.attach.users.length - 1}人踢出群`
} else {
text = `${e.attach.users[1].nick}将${e.attach.users[0].nick}踢出群`
}
}
return text
},
// 图片大小计算

View File

@ -137,14 +137,24 @@ page {
<template>
<view class="ui-groupChitchatDetail">
<view class="ui-member-data-box">
<view class="ui-member-list">
<view class="ui-member-list" v-if="hidden">
<view class="ui-member-block" v-for="(item,index) in detail.members" :key="index">
<block v-if="hidden">
<view class="ui-member-box">
<image @tap.stop="jumpPath(item)" class="ui-member-pic" :src="item.photo === 'https://image.fulllinkai.com/202207/04/1fa9a906b956efa26852fb685a845fff.png?x-oss-process=style/scale1' ? defaultImg : item.photo" mode="aspectFill"></image>
<view class="ui-member-name color-666 font_22 ellipsis_1">{{item.nickname}}</view>
</view>
</block>
<view class="ui-member-box">
<image @tap.stop="jumpPath(`/pages/home/information?id=${item.id}`)" class="ui-member-pic" :src="item.photo === 'https://image.fulllinkai.com/202207/04/1fa9a906b956efa26852fb685a845fff.png?x-oss-process=style/scale1' ? defaultImg : item.photo" mode="aspectFill"></image>
<view class="ui-member-name color-666 font_22 ellipsis_1">{{item.nickname}}</view>
</view>
</view>
<view class="ui-member-block">
<view class="ui-member-box">
<image @tap.stop="jumpPath(`/pages/news/editGroupMembers?id=${id}&type=add`)" class="ui-member-pic" src="https://image.fulllinkai.com/202410/30/05749286f02a045fe8344f4f2006bcaa.png" mode="aspectFill"></image>
<view class="ui-member-name colorF font_22">--</view>
</view>
</view>
<view class="ui-member-block">
<view class="ui-member-box">
<image @tap.stop="jumpPath(`/pages/news/editGroupMembers?id=${id}&type=delete`)" class="ui-member-pic" src="https://image.fulllinkai.com/202410/30/c0ef2d197961d0435f1e83b254cd9c33.png" mode="aspectFill"></image>
<view class="ui-member-name colorF font_22">--</view>
</view>
</view>
</view>
<block v-if="detail.members.length > 20 && !hidden">
@ -378,7 +388,7 @@ wepy.page({
vm.hidden = !vm.hidden
},
jumpPath(e) {
wx.navigateTo({url: `/pages/home/information?id=${e.id}`})
wx.navigateTo({url: e})
}
},
onLoad(e) {
@ -404,6 +414,10 @@ wepy.page({
vm.getDetail()
},
onShow() {
let vm = this
if (vm.id) {
vm.getDetail()
}
},
created() {
}

View File

@ -100,8 +100,20 @@ const IM = (account, token) => {
}
// 群消息未读数增加逻辑
let teamCount = wx.getStorageSync('teamsSessionsCount') || []
if (e.attach && e.attach.type == 'removeTeamMembers') {
teamCount.map((item, index) => {
if (item.id == e.to) {
teamCount.splice(index, 1)
wx.setStorageSync('teamsSessionsCount', teamCount)
}
})
}
if (e.attach && e.attach.type == 'addTeamMembers') {
teamCount.push({id: e.to, unread: 1})
wx.setStorageSync('teamsSessionsCount', teamCount)
}
let newTeamCount = teamCount.filter(item => { return item.id == e.to })
if (e.attach && (e.attach.type === 'leaveTeam' || e.attach.type === 'dismissTeam' || e.attach.type === 'removeTeamMembers' || e.attach.type === 'addTeamMembers')) {
if (e.attach && (e.attach.type === 'dismissTeam' || e.attach.type === 'addTeamMembers')) {
} else {
if (newTeamCount.length > 0) {
teamCount = teamCount.map(item => {
@ -116,39 +128,36 @@ const IM = (account, token) => {
wx.setStorageSync('teamsSessionsCount', teamCount)
}
}
if (currentPage.route == 'pages/tabBar/home') {
wx.request({
url: `${service.host}/notice/count`,
header: {
'Authorization': 'Bearer ' + wx.getStorageSync('token'),
'X-Requested-With': 'XMLHttpRequest'
},
method: 'get',
success: ({data}) => {
let { notice_count } = data.data
console.log(notice_count, '新的未读数')
let groupCountList = wx.getStorageSync('teamsSessionsCount') || []
let groupCount = 0
if (groupCountList.length > 0) {
for (let i = 0; i < groupCountList.length; i++) {
groupCount += groupCountList[i].unread
}
}
if ((notice_count + groupCount) > 0) {
wx.setTabBarBadge({
index: 2,
text: `${notice_count + groupCount}`
})
} else {
wx.removeTabBarBadge({
index: 2
})
wx.request({
url: `${service.host}/notice/count`,
header: {
'Authorization': 'Bearer ' + wx.getStorageSync('token'),
'X-Requested-With': 'XMLHttpRequest'
},
method: 'get',
success: ({data}) => {
let { notice_count } = data.data
console.log(notice_count, '新的未读数')
let groupCountList = wx.getStorageSync('teamsSessionsCount') || []
let groupCount = 0
if (groupCountList.length > 0) {
for (let i = 0; i < groupCountList.length; i++) {
groupCount += groupCountList[i].unread
}
}
})
}
if ((notice_count + groupCount) > 0) {
wx.setTabBarBadge({
index: 2,
text: `${notice_count + groupCount}`
})
} else {
wx.removeTabBarBadge({
index: 2
})
}
}
})
setTimeout(() => {
console.log(currentPage, '7777777')
if (currentPage.route == 'pages/tabBar/news') {
currentPage.onShow()
}