This commit is contained in:
2022-02-16 13:29:42 +08:00
12 changed files with 573 additions and 301 deletions

View File

@@ -117,9 +117,10 @@ const getGroupBase = (groupId) => {
})
}
const getGroupUsers = (groupId) => {
const getGroupUsers = (groupId, limit) => {
limit = limit || 0
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) => {
return request({
method: 'POST',
method: 'DELETE',
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 {
getImToken,
deleteFriend,
@@ -235,5 +289,10 @@ export {
joinGroupPre,
joinGroup,
quitGroup,
dismissGroup
dismissGroup,
inviteGroupUser,
removeGroupUser,
setGroupAdmin,
removeGroupAdmin,
transferGroupOwner
}

View File

@@ -52,8 +52,8 @@
"path": "pages/record/foods",
"name": "RecordFoods",
"style": {
"navigationBarTitleText": "",
"navigationStyle": "custom"
"navigationBarTitleText": "",
"navigationStyle": "custom"
}
},
{
@@ -467,33 +467,40 @@
}
}
}
},
{
"path": "pages/im/group/apply",
"name": "imGroupApply",
"style": {
"navigationBarTitleText": "申请加群"
}
},
{
"path": "pages/im/group/apply",
"name": "imGroupApply",
"style": {
"navigationBarTitleText": "申请加群"
}
},
{
"path": "pages/im/group/info",
"name": "imGroupInfo",
"style": {
"navigationBarTitleText": "群信息"
"navigationBarTitleText": "群信息"
}
},
{
"path": "pages/im/group/invite",
"name": "imGroupInvite",
"style": {
"navigationBarTitleText": "邀请好友"
}
},
{
"path": "pages/im/group/users",
"name": "imGroupUsers",
"style": {
"navigationBarTitleText": "群成员"
"navigationBarTitleText": "群成员"
}
},
{
"path": "pages/im/group/announcement",
"name": "imGroupAnnouncement",
"style": {
"navigationBarTitleText": "群公告",
"navigationBarTitleText": "群公告",
"app-plus": {
"titleNView": {
"type": "default",
@@ -511,7 +518,7 @@
"path": "pages/im/group/announceCreate",
"name": "imGroupAnnouncementCreate",
"style": {
"navigationBarTitleText": "发布群公告"
"navigationBarTitleText": "发布群公告"
}
},
{

View File

@@ -39,6 +39,11 @@
smsAuth
} from "@/apis/interfaces/auth";
import userAuth from "@/public/userAuth";
import {
getImToken
} from '@/apis/interfaces/im.js'
import im from '@/utils/im/index.js'
export default {
data() {
return {
@@ -59,6 +64,11 @@
"setToken",
res.token_type + " " + res.access_token
);
// 在这里登录成功链接IM服务
getImToken().then(res => {
console.log('在这获取IM-TOKEN', res);
im.connect(res.token, res.userInfo, () => {})
})
this.$Router.back();
}).catch((err) => {
uni.showToast({

View File

@@ -3,7 +3,8 @@
<list class="body" :show-scrollbar="false">
<cell class="cell" v-for="(item, index) in messages" :key="index">
<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">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" :name="item.content.userInfo.name" />
@@ -16,7 +17,7 @@
</cell>
<cell class="cell-footer" ref="chatBottom"></cell>
</list>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" />
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view>
</template>
@@ -43,12 +44,23 @@
data() {
return {
targetId: '',
conversationType: 3,
conversationType: RongIMLib.ConversationType.GROUP,
messages: [],
groupInfo: {
name: ''
}
}
},
computed: {
latestMessage() {
if (this.messages.length > 1) {
return this.messages[this.messages.length - 1]
} else {
return {
sentTime: 0
}
}
}
},
onLoad(e) {
this.targetId = e.targetId
@@ -59,42 +71,50 @@
this.getMessageList()
uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) {
this.getMessageList()
this.getNewMessage()
}
})
uni.$once('cleanGroupMessage', this.getMessageList)
},
onBackPress() {
uni.$off('onReceiveMessage')
console.log('Off onReceiveMessage');
})
uni.$once('cleanGroupMessage', this.getMessageList)
},
onNavigationBarButtonTap() {
uni.navigateTo({
url: '/pages/im/group/info?targetId=' + this.targetId
})
},
methods: {
toUser(item) {
if (item.senderUserId == '__system__') {
return
}
if (item.messageDirection == 1) {
uni.navigateTo({
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
})
} else{
uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + item.senderUserId
})
}
methods: {
toUser(item) {
if (item.senderUserId == '__system__') {
return
}
if (item.messageDirection == 1) {
uni.navigateTo({
url: '/pages/im/friends/mine?targetId=' + item.senderUserId
})
} else {
uni.navigateTo({
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() {
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
20,
0,
100,
true,
(messages) => {
this.messages = messages.reverse()
@@ -103,12 +123,15 @@
},
// 滚动到底部
scrollBottom(type) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
// 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
// 更新badge提醒数量
im.setNotifyBadge()
if (this.latestMessage) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime)
// // 发送消息已读状态给对方
// RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom

View File

@@ -2,8 +2,11 @@
<view class="container">
<view class="members u-border-bottom">
<view class="users">
<view class="user" v-for="(item, index) in users" :key="index" @click="toUser(item)">
<u-avatar size="44" shape="square" :src="item.portraitUrl"></u-avatar>
<view :class="['user', {'active': item.targetId == currentUser.targetId}]"
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>
<view class="user" v-if="group.can_invite">
@@ -57,6 +60,10 @@
<u-action-sheet @select="doAction" :actions="joinTypeMap" cancelText="取消" :show="showActions"
@close="showActions=false">
</u-action-sheet>
<u-action-sheet @select="handleUserAction" :actions="userActionMap" cancelText="取消" :show="showUserAction"
@close="hideUserAction">
</u-action-sheet>
</view>
</template>
@@ -65,7 +72,12 @@
getGroupInfo,
updateGroup,
quitGroup,
dismissGroup
removeGroupUser,
setGroupAdmin,
removeGroupAdmin,
dismissGroup,
transferGroupOwner,
getGroupUsers
} from '@/apis/interfaces/im.js'
import {
uploads
@@ -90,7 +102,24 @@
qrContent: 'JOINGROUP|',
joinType: '',
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) {
@@ -110,18 +139,23 @@
}
})
this.initData()
this.initUsers()
uni.$on('groupAnnouncementCreated', this.initData)
},
onUnload() {
uni.$off('groupAnnouncementCreated')
},
methods: {
initUsers() {
getGroupUsers(this.targetId, 14).then(res => {
this.users = res
})
},
initData() {
getGroupInfo(this.targetId).then(res => {
this.group = res.group
this.groupName = res.group.name
this.announcement = res.announcement
this.users = res.users
this.members = res.members
this.loaded = true
this.joinTypeMap = res.join_type_map.map(item => {
@@ -132,6 +166,7 @@
return item.key == res.join_type
})[0].name
}).catch(err => {
console.log('getGroupInfo ERR', err);
uni.showToast({
icon: 'none',
title: '群不存在'
@@ -167,7 +202,9 @@
}
},
inviteUser() {
uni.navigateTo({
url: '/pages/im/group/invite?targetId=' + this.targetId
})
},
loadMore() {
uni.navigateTo({
@@ -209,7 +246,6 @@
},
// 修改群头像
onGroupAvatar() {
console.log('onGroupAvatar');
uni.chooseImage({
count: 1,
sourceType: ['album'],
@@ -268,7 +304,7 @@
item.disabled = false
}
return item
})
})
this.initData()
this.joinType = e.name
this.showActions = false
@@ -324,14 +360,86 @@
uni.showToast({
icon: 'none',
title: '退出群聊成功'
})
})
// 移除指定的会话
RongIMLib.removeConversation(this.conversationType, this.targetId)
uni.switchTab({
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;
align-items: center;
&.active {
background-color: $window-color;
}
.name {
color: $text-gray-m;
width: 126rpx;

21
pages/im/group/invite.vue Normal file
View 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>

View File

@@ -6,8 +6,9 @@
<view class="time">
<text class="text">{{ customCN(item.sentTime) }}</text>
</view>
<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" />
<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" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
@@ -23,7 +24,7 @@
</cell>
<cell class="cell-footer" ref="chatBottom"></cell>
</list>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getMessageList()" />
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view>
</template>
@@ -41,6 +42,12 @@
const ChatList = uni.requireNativePlugin('dom')
export default {
components: {
sentMessageBar,
showVoice,
showImage,
showText
},
data() {
return {
targetId: '',
@@ -53,11 +60,16 @@
}
}
},
components: {
sentMessageBar,
showVoice,
showImage,
showText
computed: {
latestMessage() {
if (this.messages.length > 1) {
return this.messages[this.messages.length - 1]
} else {
return {
sentTime: 0
}
}
}
},
onLoad(e) {
this.targetId = e.targetId
@@ -70,30 +82,48 @@
// 监听消息已读状态
uni.$on('onReadReceiptReceived', (data) => {
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) => {
if (msg.targetId == this.targetId) {
this.getMessageList()
this.getNewMessage()
}
})
},
onBackPress() {
uni.$off('onReceiveMessage')
onUnload() {
uni.$off('onReadReceiptReceived')
},
methods: {
customCN(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() {
im.getMessageList(
this.conversationType,
this.targetId,
new Date().getTime(),
10,
0,
100,
true,
(messages) => {
this.messages = messages.reverse()
@@ -109,12 +139,15 @@
},
// 滚动到底部
scrollBottom(type) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, new Date().getTime() + 1100)
// 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, new Date().getTime())
// 更新badge提醒数量
im.setNotifyBadge()
if (this.latestMessage) {
// 清理当前会话,未读消息数量
RongIMLib.clearMessagesUnreadStatus(this.conversationType, this.targetId, this.latestMessage
.sentTime)
// // 发送消息已读状态给对方
RongIMLib.sendReadReceiptMessage(this.conversationType, this.targetId, this.latestMessage.sentTime)
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom
ChatList.scrollToElement(el, {

View File

@@ -1,211 +1,213 @@
<template>
<view class="setting">
<!-- 更多管理 -->
<view class="list">
<view class="list-item" @click="updImgs">
<view class="list-item-left"> <span>修改头像</span> </view>
<view class="avatar" >
<image :src="avatar.showPath || require('@/static/user/cover.png')" mode="aspectFill" />
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
</view>
</view>
<view class="list-item">
<view class="list-item-left"> <span>修改昵称</span> </view>
<view class="input">
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
</view>
</view>
</view>
<u-toast ref="uToast" />
</view>
</template>
<script>
import {
getUserSettingInfo,
resetUserInfo
} from '@/apis/interfaces/setting.js'
import {
uploads
} from '@/apis/interfaces/uploading'
export default {
data() {
return {
canLogin: true,
nickname: '',
avatar: {
path: '',
showPath: ''
},
is_bind: true
}
},
onShow() {
this.getUserInfo()
},
onPullDownRefresh() {
this.getUserInfo()
},
methods: {
// 获取当前用户得基本信息
getUserInfo() {
getUserSettingInfo().then(res => {
this.avatar.showPath = res.avatar
this.nickname = res.nickname
this.is_bind = res.is_bind
uni.stopPullDownRefresh()
}).catch(err => {
this.$refs.uToast.show({
title: err.message,
type: 'primary',
duration: 3000
})
})
},
// 上传头像
updImgs(type) {
uni.chooseImage({
crop: {
width: 80,
height: 80
},
success: res => {
let path = res.tempFiles.map((val, index) => {
return {
name: 'uploads' + index,
uri: val.path
}
})
uploads(path).then(pathRes => {
this.avatar.path = pathRes.path[0]
this.avatar.showPath = pathRes.url[0]
this.resetUserInfo('avatar',pathRes.url[0])
}).catch(err => {
uni.showToast({
title: err.message,
icon: "none",
duration: 2000,
mask: true
})
})
}
})
},
// 修改姓名
blur(e){
let value = e.detail.value
if(value !== this.nickname){
this.resetUserInfo('nickname',value)
}
},
// 修改头像或昵称
resetUserInfo(key, value) {
let data ={
key:key,
value:value
}
resetUserInfo(data).then(res=>{
uni.showToast({
title: res,
icon: 'none'
})
this.getUserInfo()
}).catch(err => {
uni.showToast({
title: err.message,
icon: "none",
duration: 2000,
mask: true
})
})
}
}
}
</script>
<style lang="scss" scoped>
page {
background-color: #F8F8F8;
}
.setting {
position: relative;
background-color: #fff;
// 更多管理
.list {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
box-sizing: border-box;
position: relative;
top: -10rpx;
border-radius: 20rpx;
margin: 0 $margin;
padding: 30rpx 0;
width: calc(100% - 80rpx);
.list-item {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 40rpx 0;
border-bottom: solid 1rpx #f9f9f9;
box-sizing: border-box;
font-size: $title-size;
.avatar {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
image {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
margin-right: 20rpx;
}
}
.input {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
text-align: right;
flex: 1;
input {
padding-right: $padding - 10;
width: 100%;
}
}
.list-item-left {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
box-sizing: border-box;
image {
width: 40rpx;
}
span {
margin-left: 20rpx;
}
}
}
}
}
<template>
<view class="setting">
<!-- 更多管理 -->
<view class="list">
<view class="list-item" @click="updImgs">
<view class="list-item-left"> <span>修改头像</span> </view>
<view class="avatar">
<image :src="avatar.showPath || require('@/static/user/cover.png')" mode="aspectFill" />
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
</view>
</view>
<view class="list-item">
<view class="list-item-left"> <span>修改昵称</span> </view>
<view class="input">
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
</view>
</view>
</view>
<u-toast ref="uToast" />
</view>
</template>
<script>
import {
getUserSettingInfo,
resetUserInfo
} from '@/apis/interfaces/setting.js'
import {
uploads
} from '@/apis/interfaces/uploading'
export default {
data() {
return {
canLogin: true,
nickname: '',
avatar: {
path: '',
showPath: ''
},
is_bind: true
}
},
onShow() {
this.getUserInfo()
},
onPullDownRefresh() {
this.getUserInfo()
},
methods: {
// 获取当前用户得基本信息
getUserInfo() {
getUserSettingInfo().then(res => {
this.avatar.showPath = res.avatar
this.nickname = res.nickname
this.is_bind = res.is_bind
uni.stopPullDownRefresh()
}).catch(err => {
this.$refs.uToast.show({
title: err.message,
type: 'primary',
duration: 3000
})
})
},
// 上传头像
updImgs(type) {
uni.chooseImage({
crop: {
quality: 100,
width: 128,
height: 128,
resize: true
},
success: res => {
let path = res.tempFiles.map((val, index) => {
return {
name: 'uploads' + index,
uri: val.path
}
})
uploads(path).then(pathRes => {
this.avatar.path = pathRes.path[0]
this.avatar.showPath = pathRes.url[0]
this.resetUserInfo('avatar', pathRes.url[0])
}).catch(err => {
uni.showToast({
title: err.message,
icon: "none",
duration: 2000,
mask: true
})
})
}
})
},
// 修改姓名
blur(e) {
let value = e.detail.value
if (value !== this.nickname) {
this.resetUserInfo('nickname', value)
}
},
// 修改头像或昵称
resetUserInfo(key, value) {
let data = {
key: key,
value: value
}
resetUserInfo(data).then(res => {
uni.showToast({
title: res,
icon: 'none'
})
this.getUserInfo()
}).catch(err => {
uni.showToast({
title: err.message,
icon: "none",
duration: 2000,
mask: true
})
})
}
}
}
</script>
<style lang="scss" scoped>
page {
background-color: #F8F8F8;
}
.setting {
position: relative;
background-color: #fff;
// 更多管理
.list {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
box-sizing: border-box;
position: relative;
top: -10rpx;
border-radius: 20rpx;
margin: 0 $margin;
padding: 30rpx 0;
width: calc(100% - 80rpx);
.list-item {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 40rpx 0;
border-bottom: solid 1rpx #f9f9f9;
box-sizing: border-box;
font-size: $title-size;
.avatar {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
image {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
margin-right: 20rpx;
}
}
.input {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-sizing: border-box;
text-align: right;
flex: 1;
input {
padding-right: $padding - 10;
width: 100%;
}
}
.list-item-left {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
box-sizing: border-box;
image {
width: 40rpx;
}
span {
margin-left: 20rpx;
}
}
}
}
}
</style>

View File

@@ -105,9 +105,11 @@ class userAuth {
openid: authResult.authResult.openid
}).then(res => {
uni.closeAuthView()
store.commit('setToken', res.token_type + ' ' + res.access_token)
store.commit('setToken', res.token_type + ' ' + res
.access_token)
// 在这里登录成功链接IM服务
getImToken().then(res => {
console.log('在这获取IM-TOKEN', res);
im.connect(res.token, res.userInfo)
})
resolve()

View File

@@ -34,7 +34,7 @@ export default {
}
},
mutations: {
updateContactInfo(state, contactInfo) {
updateContactInfo(state, contactInfo) {
Vue.set(state.contacts, contactInfo.targetId, contactInfo)
},
setSenderInfo(state, contactInfo) {

View File

@@ -6,7 +6,8 @@ import listeners from './listeners.js'
import {
getFriends,
getUserInfo,
getImToken
getImToken,
getMyGroups
} from '@/apis/interfaces/im.js'
const initIm = (KEY) => {
@@ -58,7 +59,7 @@ const connect = (token, userInfo, callback) => {
// 设置未读消息数量
setNotifyBadge()
// 首次运行获取好友列表
const FK = 'IFT_' + userInfo.targetId
const FK = 'ZHK_' + userInfo.targetId
uni.getStorage({
key: FK,
@@ -70,12 +71,14 @@ const connect = (token, userInfo, callback) => {
})
})
},
fail: () => {
// 程序是首次运行,初始化加载好友信息
getFriends().then(res => {
res.map(item => {
store.dispatch('initContact', item)
})
fail: () => {
// 程序是首次运行,初始化加载好友和群组信息
Promise.all([getFriends(), getMyGroups()]).then(result => {
result.map(contacts => {
contacts.map(item => {
store.dispatch('initContact', item)
})
})
uni.setStorageSync(FK, userInfo.targetId)
})
}
@@ -206,8 +209,8 @@ const newMessage = (msg) => {
status
}) => {
if (code === 0) {
if (status) {
uni.vibrateLong()
if (status) {
uni.vibrateLong()
triTone()
}
}

View File

@@ -22,7 +22,7 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
conversationType,
targetId,
objectNames,
timeStamp + 1000,
timeStamp,
count,
isForward,
({