Merge branch 'master' of https://git.yuzhankeji.cn/TmOct5/ZhHealth
This commit is contained in:
@@ -117,9 +117,10 @@ const getGroupBase = (groupId) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGroupUsers = (groupId) => {
|
const getGroupUsers = (groupId, limit) => {
|
||||||
|
limit = limit || 0
|
||||||
return request({
|
return request({
|
||||||
url: 'im/groups/' + groupId + '/users'
|
url: 'im/groups/' + groupId + '/users?limit=' + limit
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ const joinGroup = (groupId, message) => {
|
|||||||
|
|
||||||
const quitGroup = (groupId) => {
|
const quitGroup = (groupId) => {
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'DELETE',
|
||||||
url: 'im/groups/' + groupId + '/quit'
|
url: 'im/groups/' + groupId + '/quit'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -210,6 +211,59 @@ const dismissGroup = (groupId) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除群成员
|
||||||
|
*/
|
||||||
|
const removeGroupUser = (groupId, userId) => {
|
||||||
|
return request({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: 'im/groups/' + groupId + '/users/' + userId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请群成员
|
||||||
|
*/
|
||||||
|
const inviteGroupUser = (groupId, userIds) => {
|
||||||
|
return request({
|
||||||
|
method: 'POST',
|
||||||
|
url: 'im/groups/' + groupId + '/invite',
|
||||||
|
data: {
|
||||||
|
userIds
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置群管理
|
||||||
|
*/
|
||||||
|
const setGroupAdmin = (groupId, userId) => {
|
||||||
|
return request({
|
||||||
|
method: 'POST',
|
||||||
|
url: 'im/groups/' + groupId + '/admin/' + userId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除群管理
|
||||||
|
*/
|
||||||
|
const removeGroupAdmin = (groupId, userId) => {
|
||||||
|
return request({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: 'im/groups/' + groupId + '/admin/' + userId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转移群主
|
||||||
|
*/
|
||||||
|
const transferGroupOwner = (groupId, userId) => {
|
||||||
|
return request({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: 'im/groups/' + groupId + '/owner/' + userId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getImToken,
|
getImToken,
|
||||||
deleteFriend,
|
deleteFriend,
|
||||||
@@ -235,5 +289,10 @@ export {
|
|||||||
joinGroupPre,
|
joinGroupPre,
|
||||||
joinGroup,
|
joinGroup,
|
||||||
quitGroup,
|
quitGroup,
|
||||||
dismissGroup
|
dismissGroup,
|
||||||
|
inviteGroupUser,
|
||||||
|
removeGroupUser,
|
||||||
|
setGroupAdmin,
|
||||||
|
removeGroupAdmin,
|
||||||
|
transferGroupOwner
|
||||||
}
|
}
|
||||||
|
|||||||
11
pages.json
11
pages.json
@@ -52,8 +52,8 @@
|
|||||||
"path": "pages/record/foods",
|
"path": "pages/record/foods",
|
||||||
"name": "RecordFoods",
|
"name": "RecordFoods",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "",
|
"navigationBarTitleText": "",
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -482,6 +482,13 @@
|
|||||||
"navigationBarTitleText": "群信息"
|
"navigationBarTitleText": "群信息"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/im/group/invite",
|
||||||
|
"name": "imGroupInvite",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "邀请好友"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/im/group/users",
|
"path": "pages/im/group/users",
|
||||||
"name": "imGroupUsers",
|
"name": "imGroupUsers",
|
||||||
|
|||||||
@@ -39,6 +39,11 @@
|
|||||||
smsAuth
|
smsAuth
|
||||||
} from "@/apis/interfaces/auth";
|
} from "@/apis/interfaces/auth";
|
||||||
import userAuth from "@/public/userAuth";
|
import userAuth from "@/public/userAuth";
|
||||||
|
import {
|
||||||
|
getImToken
|
||||||
|
} from '@/apis/interfaces/im.js'
|
||||||
|
import im from '@/utils/im/index.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -59,6 +64,11 @@
|
|||||||
"setToken",
|
"setToken",
|
||||||
res.token_type + " " + res.access_token
|
res.token_type + " " + res.access_token
|
||||||
);
|
);
|
||||||
|
// 在这里,登录成功,链接IM服务
|
||||||
|
getImToken().then(res => {
|
||||||
|
console.log('在这获取IM-TOKEN', res);
|
||||||
|
im.connect(res.token, res.userInfo, () => {})
|
||||||
|
})
|
||||||
this.$Router.back();
|
this.$Router.back();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
<list class="body" :show-scrollbar="false">
|
<list class="body" :show-scrollbar="false">
|
||||||
<cell class="cell" v-for="(item, index) in messages" :key="index">
|
<cell class="cell" v-for="(item, index) in messages" :key="index">
|
||||||
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
||||||
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square" :src="item.content.userInfo.portraitUrl" />
|
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
|
||||||
|
:src="item.content.userInfo.portraitUrl" />
|
||||||
<view class="msg">
|
<view class="msg">
|
||||||
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
||||||
:msg="item.content" :name="item.content.userInfo.name" />
|
:msg="item.content" :name="item.content.userInfo.name" />
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
</cell>
|
</cell>
|
||||||
<cell class="cell-footer" ref="chatBottom"></cell>
|
<cell class="cell-footer" ref="chatBottom"></cell>
|
||||||
</list>
|
</list>
|
||||||
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" />
|
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -43,13 +44,24 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
targetId: '',
|
targetId: '',
|
||||||
conversationType: 3,
|
conversationType: RongIMLib.ConversationType.GROUP,
|
||||||
messages: [],
|
messages: [],
|
||||||
groupInfo: {
|
groupInfo: {
|
||||||
name: ''
|
name: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
latestMessage() {
|
||||||
|
if (this.messages.length > 1) {
|
||||||
|
return this.messages[this.messages.length - 1]
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
sentTime: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
this.targetId = e.targetId
|
this.targetId = e.targetId
|
||||||
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
|
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
|
||||||
@@ -59,15 +71,11 @@
|
|||||||
this.getMessageList()
|
this.getMessageList()
|
||||||
uni.$on('onReceiveMessage', (msg) => {
|
uni.$on('onReceiveMessage', (msg) => {
|
||||||
if (msg.targetId == this.targetId) {
|
if (msg.targetId == this.targetId) {
|
||||||
this.getMessageList()
|
this.getNewMessage()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
uni.$once('cleanGroupMessage', this.getMessageList)
|
uni.$once('cleanGroupMessage', this.getMessageList)
|
||||||
},
|
},
|
||||||
onBackPress() {
|
|
||||||
uni.$off('onReceiveMessage')
|
|
||||||
console.log('Off onReceiveMessage');
|
|
||||||
},
|
|
||||||
onNavigationBarButtonTap() {
|
onNavigationBarButtonTap() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/group/info?targetId=' + this.targetId
|
url: '/pages/im/group/info?targetId=' + this.targetId
|
||||||
@@ -82,19 +90,31 @@
|
|||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
|
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
|
||||||
})
|
})
|
||||||
} else{
|
} else {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/im/friends/info?targetId=' + item.senderUserId
|
url: '/pages/im/friends/info?targetId=' + item.senderUserId
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getNewMessage() {
|
||||||
|
im.getMessageList(
|
||||||
|
this.conversationType,
|
||||||
|
this.targetId,
|
||||||
|
this.latestMessage.sentTime,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
(messages) => {
|
||||||
|
this.messages = this.messages.concat(messages)
|
||||||
|
this.scrollBottom()
|
||||||
|
})
|
||||||
|
},
|
||||||
// 获取消息列表
|
// 获取消息列表
|
||||||
getMessageList() {
|
getMessageList() {
|
||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
0,
|
||||||
20,
|
100,
|
||||||
true,
|
true,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
this.messages = messages.reverse()
|
this.messages = messages.reverse()
|
||||||
@@ -103,12 +123,15 @@
|
|||||||
},
|
},
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
scrollBottom(type) {
|
scrollBottom(type) {
|
||||||
// 清理当前会话,未读消息数量
|
if (this.latestMessage) {
|
||||||
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
|
// 清理当前会话,未读消息数量
|
||||||
// 发送消息已读状态给对方
|
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
|
||||||
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
.sentTime)
|
||||||
// 更新badge提醒数量
|
// // 发送消息已读状态给对方
|
||||||
im.setNotifyBadge()
|
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
|
||||||
|
// 更新badge提醒数量
|
||||||
|
im.setNotifyBadge()
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let el = this.$refs.chatBottom
|
let el = this.$refs.chatBottom
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<view class="members u-border-bottom">
|
<view class="members u-border-bottom">
|
||||||
<view class="users">
|
<view class="users">
|
||||||
<view class="user" v-for="(item, index) in users" :key="index" @click="toUser(item)">
|
<view :class="['user', {'active': item.targetId == currentUser.targetId}]"
|
||||||
<u-avatar size="44" shape="square" :src="item.portraitUrl"></u-avatar>
|
v-for="(item, index) in users" :key="index" @click="toUser(item)"
|
||||||
|
@longpress="showUserActionSheet(item)">
|
||||||
|
<u-avatar size="44" shape="square" :src="item.portraitUrl">
|
||||||
|
</u-avatar>
|
||||||
<view class="name">{{ item.name }}</view>
|
<view class="name">{{ item.name }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="user" v-if="group.can_invite">
|
<view class="user" v-if="group.can_invite">
|
||||||
@@ -57,6 +60,10 @@
|
|||||||
<u-action-sheet @select="doAction" :actions="joinTypeMap" cancelText="取消" :show="showActions"
|
<u-action-sheet @select="doAction" :actions="joinTypeMap" cancelText="取消" :show="showActions"
|
||||||
@close="showActions=false">
|
@close="showActions=false">
|
||||||
</u-action-sheet>
|
</u-action-sheet>
|
||||||
|
|
||||||
|
<u-action-sheet @select="handleUserAction" :actions="userActionMap" cancelText="取消" :show="showUserAction"
|
||||||
|
@close="hideUserAction">
|
||||||
|
</u-action-sheet>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -65,7 +72,12 @@
|
|||||||
getGroupInfo,
|
getGroupInfo,
|
||||||
updateGroup,
|
updateGroup,
|
||||||
quitGroup,
|
quitGroup,
|
||||||
dismissGroup
|
removeGroupUser,
|
||||||
|
setGroupAdmin,
|
||||||
|
removeGroupAdmin,
|
||||||
|
dismissGroup,
|
||||||
|
transferGroupOwner,
|
||||||
|
getGroupUsers
|
||||||
} from '@/apis/interfaces/im.js'
|
} from '@/apis/interfaces/im.js'
|
||||||
import {
|
import {
|
||||||
uploads
|
uploads
|
||||||
@@ -90,7 +102,24 @@
|
|||||||
qrContent: 'JOINGROUP|',
|
qrContent: 'JOINGROUP|',
|
||||||
joinType: '',
|
joinType: '',
|
||||||
joinTypeMap: [],
|
joinTypeMap: [],
|
||||||
showActions: false
|
showActions: false,
|
||||||
|
showUserAction: false,
|
||||||
|
userActionMap: [{
|
||||||
|
key: 0,
|
||||||
|
name: '移除成员',
|
||||||
|
disabled: false
|
||||||
|
}, {
|
||||||
|
key: 1,
|
||||||
|
name: '设置管理',
|
||||||
|
disabled: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 2,
|
||||||
|
name: '转移群主',
|
||||||
|
disabled: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
currentUser: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
@@ -110,18 +139,23 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.initData()
|
this.initData()
|
||||||
|
this.initUsers()
|
||||||
uni.$on('groupAnnouncementCreated', this.initData)
|
uni.$on('groupAnnouncementCreated', this.initData)
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
uni.$off('groupAnnouncementCreated')
|
uni.$off('groupAnnouncementCreated')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
initUsers() {
|
||||||
|
getGroupUsers(this.targetId, 14).then(res => {
|
||||||
|
this.users = res
|
||||||
|
})
|
||||||
|
},
|
||||||
initData() {
|
initData() {
|
||||||
getGroupInfo(this.targetId).then(res => {
|
getGroupInfo(this.targetId).then(res => {
|
||||||
this.group = res.group
|
this.group = res.group
|
||||||
this.groupName = res.group.name
|
this.groupName = res.group.name
|
||||||
this.announcement = res.announcement
|
this.announcement = res.announcement
|
||||||
this.users = res.users
|
|
||||||
this.members = res.members
|
this.members = res.members
|
||||||
this.loaded = true
|
this.loaded = true
|
||||||
this.joinTypeMap = res.join_type_map.map(item => {
|
this.joinTypeMap = res.join_type_map.map(item => {
|
||||||
@@ -132,6 +166,7 @@
|
|||||||
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: '群不存在'
|
||||||
@@ -167,7 +202,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
inviteUser() {
|
inviteUser() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/im/group/invite?targetId=' + this.targetId
|
||||||
|
})
|
||||||
},
|
},
|
||||||
loadMore() {
|
loadMore() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@@ -209,7 +246,6 @@
|
|||||||
},
|
},
|
||||||
// 修改群头像
|
// 修改群头像
|
||||||
onGroupAvatar() {
|
onGroupAvatar() {
|
||||||
console.log('onGroupAvatar');
|
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
count: 1,
|
count: 1,
|
||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
@@ -325,13 +361,85 @@
|
|||||||
icon: 'none',
|
icon: 'none',
|
||||||
title: '退出群聊成功'
|
title: '退出群聊成功'
|
||||||
})
|
})
|
||||||
|
// 移除指定的会话
|
||||||
|
RongIMLib.removeConversation(this.conversationType, this.targetId)
|
||||||
|
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
url: '/pages/im/index'
|
url: '/pages/im/index'
|
||||||
})
|
})
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
showUserActionSheet(item) {
|
||||||
|
this.currentUser = item
|
||||||
|
// 只有管理员以上才会弹窗
|
||||||
|
if (this.group.is_admin) {
|
||||||
|
if (this.group.is_owner) {
|
||||||
|
this.userActionMap.map((item) => {
|
||||||
|
item.disabled = false
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.showUserAction = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hideUserAction() {
|
||||||
|
this.currentUser = {}
|
||||||
|
this.showUserAction = false
|
||||||
|
},
|
||||||
|
handleUserAction(e) {
|
||||||
|
switch (e.key) {
|
||||||
|
case 0:
|
||||||
|
removeGroupUser(this.targetId, this.currentUser.targetId).then(res => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '成员移除成功'
|
||||||
|
})
|
||||||
|
}).catch(err => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: err.message
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
this.initUsers()
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
setGroupAdmin(this.targetId, this.currentUser.targetId).then(res => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '设置管理成功'
|
||||||
|
})
|
||||||
|
}).catch(err => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: err.message
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
this.initUsers()
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
transferGroupOwner(this.targetId, this.currentUser.targetId).then(res => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '群主转让成功'
|
||||||
|
})
|
||||||
|
}).catch(err => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: err.message
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
this.initUsers()
|
||||||
|
this.initData()
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,6 +475,10 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: $window-color;
|
||||||
|
}
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
color: $text-gray-m;
|
color: $text-gray-m;
|
||||||
width: 126rpx;
|
width: 126rpx;
|
||||||
|
|||||||
21
pages/im/group/invite.vue
Normal file
21
pages/im/group/invite.vue
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<view class="">
|
||||||
|
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
targetId: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLoad(e) {
|
||||||
|
this.targetId = e.targetId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
<text class="text">{{ customCN(item.sentTime) }}</text>
|
<text class="text">{{ customCN(item.sentTime) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
||||||
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)" :src="userInfo.portraitUrl" />
|
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
|
||||||
|
:src="userInfo.portraitUrl" />
|
||||||
<view class="msg">
|
<view class="msg">
|
||||||
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
||||||
:msg="item.content" />
|
:msg="item.content" />
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
</cell>
|
</cell>
|
||||||
<cell class="cell-footer" ref="chatBottom"></cell>
|
<cell class="cell-footer" ref="chatBottom"></cell>
|
||||||
</list>
|
</list>
|
||||||
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" />
|
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -41,6 +42,12 @@
|
|||||||
const ChatList = uni.requireNativePlugin('dom')
|
const ChatList = uni.requireNativePlugin('dom')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
sentMessageBar,
|
||||||
|
showVoice,
|
||||||
|
showImage,
|
||||||
|
showText
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
targetId: '',
|
targetId: '',
|
||||||
@@ -53,11 +60,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
computed: {
|
||||||
sentMessageBar,
|
latestMessage() {
|
||||||
showVoice,
|
if (this.messages.length > 1) {
|
||||||
showImage,
|
return this.messages[this.messages.length - 1]
|
||||||
showText
|
} else {
|
||||||
|
return {
|
||||||
|
sentTime: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
this.targetId = e.targetId
|
this.targetId = e.targetId
|
||||||
@@ -70,30 +82,48 @@
|
|||||||
// 监听消息已读状态
|
// 监听消息已读状态
|
||||||
uni.$on('onReadReceiptReceived', (data) => {
|
uni.$on('onReadReceiptReceived', (data) => {
|
||||||
if (data.targetId == this.targetId) {
|
if (data.targetId == this.targetId) {
|
||||||
this.getMessageList()
|
this.messages = this.messages.map((item) => {
|
||||||
|
if (item.messageDirection == 1 && item.sentStatus == 30 && item.receivedTime <
|
||||||
|
data.messageTime + 1000) {
|
||||||
|
item.sentStatus = 50
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 监听收到新消息,判断是否是当前会话,更新会话内容
|
// 监听收到新消息,判断是否是当前会话,更新会话内容
|
||||||
uni.$on('onReceiveMessage', (msg) => {
|
uni.$on('onReceiveMessage', (msg) => {
|
||||||
if (msg.targetId == this.targetId) {
|
if (msg.targetId == this.targetId) {
|
||||||
this.getMessageList()
|
this.getNewMessage()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onBackPress() {
|
onUnload() {
|
||||||
uni.$off('onReceiveMessage')
|
uni.$off('onReadReceiptReceived')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
customCN(val) {
|
customCN(val) {
|
||||||
return timeCustomCN(val)
|
return timeCustomCN(val)
|
||||||
},
|
},
|
||||||
|
getNewMessage() {
|
||||||
|
im.getMessageList(
|
||||||
|
this.conversationType,
|
||||||
|
this.targetId,
|
||||||
|
this.latestMessage.sentTime || 0,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
(messages) => {
|
||||||
|
this.messages = this.messages.concat(messages)
|
||||||
|
this.scrollBottom()
|
||||||
|
})
|
||||||
|
},
|
||||||
// 获取消息列表
|
// 获取消息列表
|
||||||
getMessageList() {
|
getMessageList() {
|
||||||
im.getMessageList(
|
im.getMessageList(
|
||||||
this.conversationType,
|
this.conversationType,
|
||||||
this.targetId,
|
this.targetId,
|
||||||
new Date().getTime(),
|
0,
|
||||||
10,
|
100,
|
||||||
true,
|
true,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
this.messages = messages.reverse()
|
this.messages = messages.reverse()
|
||||||
@@ -109,12 +139,15 @@
|
|||||||
},
|
},
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
scrollBottom(type) {
|
scrollBottom(type) {
|
||||||
// 清理当前会话,未读消息数量
|
if (this.latestMessage) {
|
||||||
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
|
// 清理当前会话,未读消息数量
|
||||||
// 发送消息已读状态给对方
|
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
|
||||||
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
|
.sentTime)
|
||||||
// 更新badge提醒数量
|
// // 发送消息已读状态给对方
|
||||||
im.setNotifyBadge()
|
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
|
||||||
|
// 更新badge提醒数量
|
||||||
|
im.setNotifyBadge()
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let el = this.$refs.chatBottom
|
let el = this.$refs.chatBottom
|
||||||
ChatList.scrollToElement(el, {
|
ChatList.scrollToElement(el, {
|
||||||
|
|||||||
@@ -1,87 +1,89 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="setting">
|
<view class="setting">
|
||||||
<!-- 更多管理 -->
|
<!-- 更多管理 -->
|
||||||
<view class="list">
|
<view class="list">
|
||||||
<view class="list-item" @click="updImgs">
|
<view class="list-item" @click="updImgs">
|
||||||
<view class="list-item-left"> <span>修改头像</span> </view>
|
<view class="list-item-left"> <span>修改头像</span> </view>
|
||||||
<view class="avatar" >
|
<view class="avatar">
|
||||||
<image :src="avatar.showPath || require('@/static/user/cover.png')" mode="aspectFill" />
|
<image :src="avatar.showPath || require('@/static/user/cover.png')" mode="aspectFill" />
|
||||||
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="list-item">
|
<view class="list-item">
|
||||||
<view class="list-item-left"> <span>修改昵称</span> </view>
|
<view class="list-item-left"> <span>修改昵称</span> </view>
|
||||||
<view class="input">
|
<view class="input">
|
||||||
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
|
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
|
||||||
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<u-toast ref="uToast" />
|
<u-toast ref="uToast" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
getUserSettingInfo,
|
getUserSettingInfo,
|
||||||
resetUserInfo
|
resetUserInfo
|
||||||
} from '@/apis/interfaces/setting.js'
|
} from '@/apis/interfaces/setting.js'
|
||||||
import {
|
import {
|
||||||
uploads
|
uploads
|
||||||
} from '@/apis/interfaces/uploading'
|
} from '@/apis/interfaces/uploading'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
canLogin: true,
|
canLogin: true,
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: {
|
avatar: {
|
||||||
path: '',
|
path: '',
|
||||||
showPath: ''
|
showPath: ''
|
||||||
},
|
},
|
||||||
is_bind: true
|
is_bind: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.getUserInfo()
|
this.getUserInfo()
|
||||||
},
|
},
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
this.getUserInfo()
|
this.getUserInfo()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 获取当前用户得基本信息
|
// 获取当前用户得基本信息
|
||||||
getUserInfo() {
|
getUserInfo() {
|
||||||
getUserSettingInfo().then(res => {
|
getUserSettingInfo().then(res => {
|
||||||
this.avatar.showPath = res.avatar
|
this.avatar.showPath = res.avatar
|
||||||
this.nickname = res.nickname
|
this.nickname = res.nickname
|
||||||
this.is_bind = res.is_bind
|
this.is_bind = res.is_bind
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.$refs.uToast.show({
|
this.$refs.uToast.show({
|
||||||
title: err.message,
|
title: err.message,
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
duration: 3000
|
duration: 3000
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 上传头像
|
// 上传头像
|
||||||
updImgs(type) {
|
updImgs(type) {
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
crop: {
|
crop: {
|
||||||
width: 80,
|
quality: 100,
|
||||||
height: 80
|
width: 128,
|
||||||
},
|
height: 128,
|
||||||
success: res => {
|
resize: true
|
||||||
let path = res.tempFiles.map((val, index) => {
|
},
|
||||||
return {
|
success: res => {
|
||||||
name: 'uploads' + index,
|
let path = res.tempFiles.map((val, index) => {
|
||||||
uri: val.path
|
return {
|
||||||
}
|
name: 'uploads' + index,
|
||||||
})
|
uri: val.path
|
||||||
uploads(path).then(pathRes => {
|
}
|
||||||
this.avatar.path = pathRes.path[0]
|
})
|
||||||
this.avatar.showPath = pathRes.url[0]
|
uploads(path).then(pathRes => {
|
||||||
this.resetUserInfo('avatar',pathRes.url[0])
|
this.avatar.path = pathRes.path[0]
|
||||||
}).catch(err => {
|
this.avatar.showPath = pathRes.url[0]
|
||||||
|
this.resetUserInfo('avatar', pathRes.url[0])
|
||||||
|
}).catch(err => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: err.message,
|
title: err.message,
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -89,29 +91,29 @@
|
|||||||
mask: true
|
mask: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 修改姓名
|
// 修改姓名
|
||||||
blur(e){
|
blur(e) {
|
||||||
let value = e.detail.value
|
let value = e.detail.value
|
||||||
if(value !== this.nickname){
|
if (value !== this.nickname) {
|
||||||
this.resetUserInfo('nickname',value)
|
this.resetUserInfo('nickname', value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 修改头像或昵称
|
// 修改头像或昵称
|
||||||
resetUserInfo(key, value) {
|
resetUserInfo(key, value) {
|
||||||
let data ={
|
let data = {
|
||||||
key:key,
|
key: key,
|
||||||
value:value
|
value: value
|
||||||
}
|
}
|
||||||
resetUserInfo(data).then(res=>{
|
resetUserInfo(data).then(res => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res,
|
title: res,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
this.getUserInfo()
|
this.getUserInfo()
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: err.message,
|
title: err.message,
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -119,93 +121,93 @@
|
|||||||
mask: true
|
mask: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
page {
|
page {
|
||||||
background-color: #F8F8F8;
|
background-color: #F8F8F8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.setting {
|
.setting {
|
||||||
position: relative;
|
position: relative;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
|
||||||
// 更多管理
|
// 更多管理
|
||||||
.list {
|
.list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: -10rpx;
|
top: -10rpx;
|
||||||
border-radius: 20rpx;
|
border-radius: 20rpx;
|
||||||
margin: 0 $margin;
|
margin: 0 $margin;
|
||||||
padding: 30rpx 0;
|
padding: 30rpx 0;
|
||||||
width: calc(100% - 80rpx);
|
width: calc(100% - 80rpx);
|
||||||
|
|
||||||
.list-item {
|
.list-item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 40rpx 0;
|
padding: 40rpx 0;
|
||||||
border-bottom: solid 1rpx #f9f9f9;
|
border-bottom: solid 1rpx #f9f9f9;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-size: $title-size;
|
font-size: $title-size;
|
||||||
|
|
||||||
.avatar {
|
.avatar {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
|
||||||
image {
|
image {
|
||||||
width: 100rpx;
|
width: 100rpx;
|
||||||
height: 100rpx;
|
height: 100rpx;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
margin-right: 20rpx;
|
margin-right: 20rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
||||||
input {
|
input {
|
||||||
padding-right: $padding - 10;
|
padding-right: $padding - 10;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.list-item-left {
|
.list-item-left {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
image {
|
image {
|
||||||
width: 40rpx;
|
width: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
margin-left: 20rpx;
|
margin-left: 20rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -105,9 +105,11 @@ class userAuth {
|
|||||||
openid: authResult.authResult.openid
|
openid: authResult.authResult.openid
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
uni.closeAuthView()
|
uni.closeAuthView()
|
||||||
store.commit('setToken', res.token_type + ' ' + res.access_token)
|
store.commit('setToken', res.token_type + ' ' + res
|
||||||
|
.access_token)
|
||||||
// 在这里,登录成功,链接IM服务
|
// 在这里,登录成功,链接IM服务
|
||||||
getImToken().then(res => {
|
getImToken().then(res => {
|
||||||
|
console.log('在这获取IM-TOKEN', res);
|
||||||
im.connect(res.token, res.userInfo)
|
im.connect(res.token, res.userInfo)
|
||||||
})
|
})
|
||||||
resolve()
|
resolve()
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import listeners from './listeners.js'
|
|||||||
import {
|
import {
|
||||||
getFriends,
|
getFriends,
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
getImToken
|
getImToken,
|
||||||
|
getMyGroups
|
||||||
} from '@/apis/interfaces/im.js'
|
} from '@/apis/interfaces/im.js'
|
||||||
|
|
||||||
const initIm = (KEY) => {
|
const initIm = (KEY) => {
|
||||||
@@ -58,7 +59,7 @@ const connect = (token, userInfo, callback) => {
|
|||||||
// 设置未读消息数量
|
// 设置未读消息数量
|
||||||
setNotifyBadge()
|
setNotifyBadge()
|
||||||
// 首次运行获取好友列表
|
// 首次运行获取好友列表
|
||||||
const FK = 'IFT_' + userInfo.targetId
|
const FK = 'ZHK_' + userInfo.targetId
|
||||||
|
|
||||||
uni.getStorage({
|
uni.getStorage({
|
||||||
key: FK,
|
key: FK,
|
||||||
@@ -71,10 +72,12 @@ const connect = (token, userInfo, callback) => {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
// 程序是首次运行,初始化加载好友信息
|
// 程序是首次运行,初始化加载好友和群组信息
|
||||||
getFriends().then(res => {
|
Promise.all([getFriends(), getMyGroups()]).then(result => {
|
||||||
res.map(item => {
|
result.map(contacts => {
|
||||||
store.dispatch('initContact', item)
|
contacts.map(item => {
|
||||||
|
store.dispatch('initContact', item)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
uni.setStorageSync(FK, userInfo.targetId)
|
uni.setStorageSync(FK, userInfo.targetId)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
|
|||||||
conversationType,
|
conversationType,
|
||||||
targetId,
|
targetId,
|
||||||
objectNames,
|
objectNames,
|
||||||
timeStamp + 1000,
|
timeStamp,
|
||||||
count,
|
count,
|
||||||
isForward,
|
isForward,
|
||||||
({
|
({
|
||||||
|
|||||||
Reference in New Issue
Block a user