This commit is contained in:
2022-02-23 15:32:31 +08:00
23 changed files with 213 additions and 171 deletions

View File

@@ -12,7 +12,7 @@
// 获取系统版本号 // 获取系统版本号
getVersions({ getVersions({
platform: plus.os.name, platform: plus.os.name,
version: plus.runtime.versionCode version: plus.runtime.version
}).then(res => { }).then(res => {
if (res.update) { if (res.update) {
uni.showModal({ uni.showModal({

View File

@@ -2,7 +2,7 @@
"name" : "ZH-HEALTH", "name" : "ZH-HEALTH",
"appid" : "__UNI__C29473D", "appid" : "__UNI__C29473D",
"description" : "ZH-HEALTH您手上的健康管理专家", "description" : "ZH-HEALTH您手上的健康管理专家",
"versionName" : "1.0.13", "versionName" : "1.0.15",
"versionCode" : 113, "versionCode" : 113,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */

View File

@@ -70,7 +70,9 @@
clearMessages() { clearMessages() {
RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId) RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId)
this.$emit('success') this.$emit('success')
uni.$emit('onContactNotification') uni.$emit('onNewContactConversation', message)
uni.$emit('onNewContactFriends', message)
uni.$emit('onNewContactPendings', message)
} }
} }
} }

View File

@@ -55,7 +55,7 @@
users: [], users: [],
isOwner: false, isOwner: false,
isAdmin: false, isAdmin: false,
canInvite:false,// 是否可以开启邀请 canInvite: false, // 是否可以开启邀请
adminUid: 0, adminUid: 0,
members: 0, members: 0,
actionShow: false, actionShow: false,
@@ -83,7 +83,6 @@
mounted() { mounted() {
this.initGroupInfo() this.initGroupInfo()
getGroupUsers(this.targetId, this.count).then(res => { getGroupUsers(this.targetId, this.count).then(res => {
console.log("res..",res)
this.users = res this.users = res
res.map(item => { res.map(item => {
this.$store.dispatch('updateContact', item) this.$store.dispatch('updateContact', item)

View File

@@ -6,8 +6,10 @@
</view> </view>
<view class="content"> <view class="content">
<view class="header"> <view class="header">
<view class="name">{{ contact(item.targetId).name }} <text v-if="item.conversationType === 3" <view class="name">
class='qun'>[]</text></view> {{ contact(item.targetId).name }}
<text v-if="item.conversationType === 3" class='group'>[]</text>
</view>
<view class="time">{{ item.sentTime|timeCustomCN }}</view> <view class="time">{{ item.sentTime|timeCustomCN }}</view>
</view> </view>
<message-preview class="preview" :msg="item.latestMessage" :draft="item.draft" <message-preview class="preview" :msg="item.latestMessage" :draft="item.draft"
@@ -80,10 +82,8 @@
.name { .name {
font-size: $title-size + 2; font-size: $title-size + 2;
color: #454545; color: #454545;
display: flex;
align-items: center;
.qun { .group {
color: $main-color; color: $main-color;
font-size: $title-size-m - 4; font-size: $title-size-m - 4;
margin-left: 4px; margin-left: 4px;

View File

@@ -46,43 +46,27 @@
} }
}, },
methods: { methods: {
showImage(path) {
uni.previewImage({
urls: [
path
]
})
},
previewImage() { previewImage() {
if (this.content.local) { if (this.content.local && this.content.local.indexOf('///data/user/') < 0) {
uni.previewImage({ this.showImage(this.content.local)
urls: [
this.content.local
],
success: (e) => {
console.log(e);
},
fail: (er) => {
console.log(er);
}
})
} else { } else {
RongIMLib.downloadMediaMessage(this.messageId, { RongIMLib.downloadMediaMessage(this.message.messageId, {
success: (path) => { success: (path) => {
this.content.local = path this.content.local = path
uni.previewImage({ this.showImage(path)
urls: [
path
],
success: (e) => {
console.log(e);
},
fail: (er) => {
console.log(er);
}
})
},
progress: (progress, messageId) => {
console.log('progress', progress);
},
cancel: (messageId) => {
console.log('cancel', messageId);
}, },
error: (errorCode, messageId) => { error: (errorCode, messageId) => {
console.log('errorCode', errorCode); uni.showToast({
icon: 'none',
title: errorCode
})
} }
}) })
} }

View File

@@ -75,11 +75,6 @@
} }
}) })
}, },
created() {
console.log(this.message.messageId)
},
methods: { methods: {
// 播放语音消息 // 播放语音消息
startPlay() { startPlay() {

View File

@@ -113,7 +113,6 @@
onLoad(e) { onLoad(e) {
this.targetId = e.targetId this.targetId = e.targetId
getFriendInfo(e.targetId).then(res => { getFriendInfo(e.targetId).then(res => {
console.log(res, "获取朋友的信息")
this.userInfo = res this.userInfo = res
// 获取到用户信息之后,去检查一下要不要更新 // 获取到用户信息之后,去检查一下要不要更新
this.$store.dispatch('updateContact', res) this.$store.dispatch('updateContact', res)
@@ -148,7 +147,7 @@
}) })
}, },
toPrivate() { toPrivate() {
uni.redirectTo({ uni.navigateTo({
url: '/pages/im/private/chat?targetId=' + this.targetId url: '/pages/im/private/chat?targetId=' + this.targetId
}); });
}, },
@@ -228,8 +227,9 @@
}) })
}, },
singleCall(e) { singleCall(e) {
uni.redirectTo({ uni.navigateTo({
url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type + '&isCall=true' url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type +
'&isCall=true'
}) })
} }
} }

View File

@@ -35,7 +35,10 @@
}, },
onShow() { onShow() {
this.getPendingList() this.getPendingList()
uni.$on('onContactNotification', this.getPendingList) uni.$on('onNewContactPendings', this.getPendingList)
},
onUnload() {
uni.$off('onNewContactPendings')
}, },
methods: { methods: {
getPendingList() { getPendingList() {

View File

@@ -16,8 +16,12 @@
createGroupAnnouncement, createGroupAnnouncement,
getGroupAnnouncement getGroupAnnouncement
} from '@/apis/interfaces/im.js' } from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
targetId: '', targetId: '',

View File

@@ -35,8 +35,12 @@
deleteGroupAnnouncement, deleteGroupAnnouncement,
topGroupAnnouncement topGroupAnnouncement
} from '@/apis/interfaces/im.js' } from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
targetId: '', targetId: '',
@@ -55,7 +59,7 @@
disabled: false disabled: false
}], }],
actionTitle: '请选择操作', actionTitle: '请选择操作',
bg:'#fff' bg: '#fff'
} }
}, },
onLoad(e) { onLoad(e) {
@@ -85,9 +89,9 @@
// 获取公告信息 // 获取公告信息
initData() { initData() {
getGroupAnnouncements(this.targetId).then(res => { getGroupAnnouncements(this.targetId).then(res => {
if(res.length>0){ if (res.length > 0) {
this.bg = '#f9f9f9' this.bg = '#f9f9f9'
}else{ } else {
this.bg = '#fff' this.bg = '#fff'
} }
this.announcements = res this.announcements = res
@@ -215,7 +219,7 @@
-webkit-line-clamp: 3; -webkit-line-clamp: 3;
overflow: hidden; overflow: hidden;
line-height: 1.5; line-height: 1.5;
border-bottom: solid 1rpx #F9F9F9; border-bottom: solid 1rpx #F9F9F9;
padding-bottom: 20rpx; padding-bottom: 20rpx;
span { span {

View File

@@ -20,8 +20,12 @@
joinGroupPre, joinGroupPre,
joinGroup joinGroup
} from '@/apis/interfaces/im.js' } from '@/apis/interfaces/im.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
targetId: '', targetId: '',

View File

@@ -21,8 +21,12 @@
import sentMessageBar from '../components/sentMessageBar' import sentMessageBar from '../components/sentMessageBar'
import showMessageCell from '../components/showMessageCell' import showMessageCell from '../components/showMessageCell'
import utils from '@/utils/index.js' import utils from '@/utils/index.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
components: { components: {
sentMessageBar, sentMessageBar,
showMessageCell showMessageCell
@@ -59,11 +63,9 @@
}) })
// 获取历史消息列表 // 获取历史消息列表
this.getMessageList() this.getMessageList()
// 监听收到本群的消息,追加消息 // 监听消息
uni.$on('onReceiveMessage', (msg) => { uni.$on('onReceiveMessage_' + this.targetId, (message) => {
if (msg.targetId == this.targetId) { this.getNewMessage()
this.getNewMessage()
}
}) })
uni.$on('onReceiptRequest', (msg) => { uni.$on('onReceiptRequest', (msg) => {
if (msg.targetId == this.targetId) { if (msg.targetId == this.targetId) {
@@ -101,6 +103,7 @@
}) })
}, },
onUnload() { onUnload() {
uni.$off('onReceiveMessage_' + this.targetId)
uni.$off('onRecallMessage') uni.$off('onRecallMessage')
uni.$off('onReceiptRequest') uni.$off('onReceiptRequest')
uni.$off('onReceiptResponse') uni.$off('onReceiptResponse')
@@ -164,7 +167,7 @@
}, },
onHide() { onHide() {
// console.log(JSON.stringify(this.$refs)) // console.log(JSON.stringify(this.$refs))
this.$refs.voice.stopPlay() // this.$refs.voice.stopPlay()
} }
} }
</script> </script>

View File

@@ -65,11 +65,15 @@
} from '@/apis/interfaces/uploading' } from '@/apis/interfaces/uploading'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import groupUserList from '../components/groupUserList' import groupUserList from '../components/groupUserList'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
components: { components: {
groupUserList groupUserList
}, },
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
targetId: '', targetId: '',
@@ -133,7 +137,6 @@
return item.key == res.join_type return item.key == res.join_type
})[0].name })[0].name
}).catch(err => { }).catch(err => {
console.log('getGroupInfo ERR', err);
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '群不存在' title: '群不存在'

View File

@@ -8,8 +8,9 @@
<u-index-list :index-list="indexs" inactiveColor="#666" activeColor="#34CE98"> <u-index-list :index-list="indexs" inactiveColor="#666" activeColor="#34CE98">
<u-checkbox-group v-if="friends.length > 0" v-model="checkboxValue" placement="column"> <u-checkbox-group v-if="friends.length > 0" v-model="checkboxValue" placement="column">
<u-index-item v-for="(item, fkey) in friends" :key="fkey"> <u-index-item v-for="(item, fkey) in friends" :key="fkey">
<u-index-anchor :text="indexs[fkey]" v-if="indexs[fkey]" bgColor="#f9f9f9f" height="20" size="12" <u-index-anchor :text="indexs[fkey]" v-if="indexs[fkey]" bgColor="#f9f9f9f" height="20"
color="#666" style="border:none !important;padding: 10rpx 30rpx;background-color: #f9f9f9 !important;" /> size="12" color="#666"
style="border:none !important;padding: 10rpx 30rpx;background-color: #f9f9f9 !important;" />
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex" <view v-for="(friendItem, index) in item" :key="index" class="friend-flex"
@click="addContact(friendItem.targetId)"> @click="addContact(friendItem.targetId)">
<u-checkbox :name="friendItem.targetId" shape="circle" activeColor="#34ce98" <u-checkbox :name="friendItem.targetId" shape="circle" activeColor="#34ce98"
@@ -44,10 +45,13 @@
getGroupUsers getGroupUsers
} from '@/apis/interfaces/im'; } from '@/apis/interfaces/im';
import utils from '@/utils/index.js' import utils from '@/utils/index.js'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default { export default {
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
searchTxt: '', searchTxt: '',
@@ -123,16 +127,16 @@
}, },
onInvite() { onInvite() {
console.log(this.checkboxValue,'userIds.....') console.log(this.checkboxValue, 'userIds.....')
console.log(this.selectValue,'userIds.....') console.log(this.selectValue, 'userIds.....')
let userIds = [] let userIds = []
this.checkboxValue.filter(item=>{ this.checkboxValue.filter(item => {
if(!utils.inArray(item, this.selectValue)){ if (!utils.inArray(item, this.selectValue)) {
userIds.push(item) userIds.push(item)
} }
}) })
// console.log(userIds) // console.log(userIds)
inviteGroupUser(this.targetId, this.checkboxValue,userIds).then(res => { inviteGroupUser(this.targetId, this.checkboxValue, userIds).then(res => {
uni.navigateBack({ uni.navigateBack({
delta: 1, delta: 1,
animationType: 'pop-out', animationType: 'pop-out',

View File

@@ -3,7 +3,7 @@
<view class="reviewed"> <view class="reviewed">
<block v-if="pendings.length > 0"> <block v-if="pendings.length > 0">
<view class="reviewed-item" v-for="(item, index) in pendings" :key="index"> <view class="reviewed-item" v-for="(item, index) in pendings" :key="index">
<u-avatar class="avatar" <u-avatar class="avatar"
:src="JSON.parse(item.content.extra).portraitUrl || require('@/static/user/cover.png')" :src="JSON.parse(item.content.extra).portraitUrl || require('@/static/user/cover.png')"
shape="square" size="46" /> shape="square" size="46" />
<view style="flex:1;" v-if="item.content.operation == 'GroupPending'"> <view style="flex:1;" v-if="item.content.operation == 'GroupPending'">
@@ -34,9 +34,12 @@
} from "@/apis/interfaces/im.js" } from "@/apis/interfaces/im.js"
import im from '@/utils/im/message.js' import im from '@/utils/im/message.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
data() { data() {
return { return {
targetId: '', targetId: '',
@@ -93,7 +96,7 @@
console.log('code', code) console.log('code', code)
if (code == 0) { if (code == 0) {
uni.showToast({ uni.showToast({
title:err.message, title: err.message,
icon: 'none', icon: 'none',
mask: true, mask: true,
duration: 2000 duration: 2000
@@ -153,6 +156,7 @@
} }
} }
.no-lists { .no-lists {
padding-top: $padding * 5; padding-top: $padding * 5;
display: flex; display: flex;

View File

@@ -4,7 +4,12 @@
<script> <script>
import groupUserList from '../components/groupUserList' import groupUserList from '../components/groupUserList'
import onGroupDismiss from '@/utils/im/onGroupDismiss.js'
export default { export default {
mixins: [
onGroupDismiss
],
components: { components: {
groupUserList groupUserList
}, },

View File

@@ -57,24 +57,28 @@
// 好友申请数量 // 好友申请数量
this.checkNewFriendPending() this.checkNewFriendPending()
// 监听新的好友申请 // 监听新的好友申请
uni.$on('onContactNotification', () => { uni.$on('onNewContactConversation', this.checkNewFriendPending)
this.checkNewFriendPending()
})
}, },
onShow() { onShow() {
if (this.$store.state.token !== '') { if (this.$store.state.token !== '') {
this.getConversationList() this.getConversationList()
} }
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
})
// 监听新消息 // 监听新消息
uni.$on('onReceiveMessage', (msg) => { uni.$on('onReceiveMessage', (msg) => {
this.getConversationList() this.getConversationList()
}) })
// 监听网络状态变化
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
if (status == 0) {
this.getConversationList()
}
})
}, },
onHide() { onHide() {
// 页面隐藏的时候,不监听了,性能可能会好一点
uni.$off('onReceiveMessage') uni.$off('onReceiveMessage')
uni.$off('onConnectionStatusChange')
}, },
methods: { methods: {
checkNewFriendPending() { checkNewFriendPending() {

View File

@@ -150,7 +150,7 @@
} else { } else {
IMLib.insertIncomingMessage(1, targetId, targetId, sentStatus, messageContent, sentTime) IMLib.insertIncomingMessage(1, targetId, targetId, sentStatus, messageContent, sentTime)
} }
uni.$emit('onReceiveMessage', { uni.$emit('onReceiveMessage_' + this.targetId, {
targetId: this.targetId targetId: this.targetId
}) })
}, },

View File

@@ -60,6 +60,10 @@
}) })
// 获取消息列表 // 获取消息列表
this.getMessageList() this.getMessageList()
// 监听新消息
uni.$on('onReceiveMessage_' + this.targetId, (message) => {
this.getNewMessage()
})
// 监听消息已读状态 // 监听消息已读状态
uni.$on('onReadReceiptReceived', (data) => { uni.$on('onReadReceiptReceived', (data) => {
if (data.targetId == this.targetId) { if (data.targetId == this.targetId) {
@@ -72,12 +76,6 @@
}) })
} }
}) })
// 监听收到新消息,判断是否是当前会话,更新会话内容
uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) {
this.getNewMessage()
}
})
uni.$on('onRecallMessage', (res) => { uni.$on('onRecallMessage', (res) => {
if (res.targetId == this.targetId) { if (res.targetId == this.targetId) {
this.messages = this.messages.map(item => { this.messages = this.messages.map(item => {
@@ -91,6 +89,7 @@
}) })
}, },
onUnload() { onUnload() {
uni.$off('onReceiveMessage_' + this.targetId)
uni.$off('onRecallMessage') uni.$off('onRecallMessage')
uni.$off('onReadReceiptReceived') uni.$off('onReadReceiptReceived')
}, },

View File

@@ -20,7 +20,28 @@ const onReceiveMessage = (message) => {
} }
}) })
im.setNotifyBadge() im.setNotifyBadge()
// 发布全局事件,有新消息,刷新会话列表
uni.$emit('onReceiveMessage', message) uni.$emit('onReceiveMessage', message)
// 这个是为了更新消息列表页的
uni.$emit('onReceiveMessage_' + message.targetId, message)
}
// 检测联系人信息,不存在的时候,从服务端获取
const checkContactExists = (message) => {
if (!store.getters.contactIsExist(message.targetId)) {
getUserInfo(message.targetId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.error('getUserInfo ERR', err)
})
}
if (!store.getters.contactIsExist(message.senderUserId)) {
getUserInfo(message.senderUserId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.error('getUserInfo ERR', err)
})
}
} }
// 允许通知的消息类型,触发更新消息列表操作,提示音 // 允许通知的消息类型,触发更新消息列表操作,提示音
@@ -32,10 +53,7 @@ const notifyMsgTypes = [
IMLib.ObjectName.Location, IMLib.ObjectName.Location,
IMLib.ObjectName.Voice, IMLib.ObjectName.Voice,
IMLib.ObjectName.HQVoice, IMLib.ObjectName.HQVoice,
IMLib.ObjectName.Sight, IMLib.ObjectName.Sight
IMLib.ObjectName.Text,
IMLib.ObjectName.Text,
IMLib.ObjectName.Text
] ]
const imLibListeners = () => { const imLibListeners = () => {
@@ -48,31 +66,19 @@ const imLibListeners = () => {
IMLib.addReceiveMessageListener((res) => { IMLib.addReceiveMessageListener((res) => {
const message = res.data.message const message = res.data.message
console.error('[收到消息]', message) console.error('[收到消息]', message)
checkContactExists(message)
if (utils.inArray(message.objectName, notifyMsgTypes)) { if (utils.inArray(message.objectName, notifyMsgTypes)) {
if (!store.getters.contactIsExist(message.targetId)) {
getUserInfo(message.targetId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.error('getUserInfo ERR', err)
})
}
if (!store.getters.contactIsExist(message.senderUserId)) {
getUserInfo(message.senderUserId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.error('getUserInfo ERR', err)
})
}
onReceiveMessage(message) onReceiveMessage(message)
} else if (message.objectName === IMLib.ObjectName.ProfileNotification) { } else if (message.objectName === IMLib.ObjectName.ProfileNotification) {
// 更新会话信息 // 更新联系人信息
store.dispatch('updateContact', JSON.parse(message.content.data)) store.dispatch('updateContact', JSON.parse(message.content.data))
// 调用完更新之后,删除这条消息 // 调用完更新之后,删除这条消息
IMLib.deleteMessagesByIds([message.messageId]) IMLib.deleteMessagesByIds([message.messageId])
} else if (message.objectName === IMLib.ObjectName.ContactNotification) { } else if (message.objectName === IMLib.ObjectName.ContactNotification) {
console.error('触发一个新好友的通知事件', message); // 触发一个新好友的通知事件,【会话列表,通讯录,新朋友】页面
// 触发一个新好友的通知事件 uni.$emit('onNewContactConversation', message)
uni.$emit('onContactNotification', message) uni.$emit('onNewContactFriends', message)
uni.$emit('onNewContactPendings', message)
} else if (message.objectName === IMLib.ObjectName.GroupNotification) { } else if (message.objectName === IMLib.ObjectName.GroupNotification) {
// 解散群 // 解散群
if (message.content.operation === 'Dismiss') { if (message.content.operation === 'Dismiss') {
@@ -80,8 +86,11 @@ const imLibListeners = () => {
false) false)
// 解散了就删了吧 // 解散了就删了吧
IMLib.removeConversation(message.conversationType, message.targetId) IMLib.removeConversation(message.conversationType, message.targetId)
uni.$emit('onGroupDismiss', message.targetId) // 发布群解散的消息
uni.$emit('onGroupDismiss')
uni.$emit('onGroupDismiss_' + message.targetId)
} }
// 触发刷新会话列表
uni.$emit('onReceiveMessage', message) uni.$emit('onReceiveMessage', message)
} }
}) })

View File

@@ -0,0 +1,16 @@
// 监听群解散的消息,直接跳转到会话列表页面
const onGroupDismiss = {
onLoad(e) {
uni.$once('onGroupDismiss_' + e.targetId, () => {
uni.showToast({
icon: 'none',
title: '当前群已解散'
})
uni.switchTab({
url: '/pages/im/index'
})
})
}
}
export default onGroupDismiss