【更新】IM页面逻辑完善
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<view class="container">
|
||||
<view v-if="$store.state.token != ''">
|
||||
<block v-if="conversations.length < 1">
|
||||
<view class="vertical null-list">
|
||||
@@ -11,24 +11,25 @@
|
||||
</view>
|
||||
</block>
|
||||
<block v-else>
|
||||
<view v-for="(item, index) in conversations" :key="index" class="mssage-box" @click="toDetail(item)">
|
||||
<view class="mssage-action">
|
||||
<block v-if="!friend(item.targetId).portraitUrl">
|
||||
<u-avatar clsss="mssage-action-cover" size="44"
|
||||
:text="friend(item.targetId).name ? friend(item.targetId).name.substring(0,1) : '未'"
|
||||
font-size="14" randomBgColor></u-avatar>
|
||||
</block>
|
||||
<block v-else>
|
||||
<u-avatar clsss="mssage-action-cover" :src="friend(item.targetId).portraitUrl" size="44">
|
||||
</u-avatar>
|
||||
</block>
|
||||
<view class="mssage-action-content">
|
||||
<view class="mssage-header">
|
||||
<view class="header-name">{{ friend(item.targetId).name || '未知用户' }}</view>
|
||||
<view class="header-time">{{ item.sentTime|timeCustomCN }}</view>
|
||||
</view>
|
||||
<view class="mssage-msg">{{ item.latestMessage.content }}</view>
|
||||
<u-alert type="warning" v-if="connection != 0" description="网络似乎断开了" :show-icon="true"></u-alert>
|
||||
|
||||
<view v-for="(item, index) in conversations" :key="index" class="message" @click="toDetail(item)">
|
||||
<view class="avatar">
|
||||
<u-badge numberType="ellipsis" max="99" shape="horn" absolute :offset="[-5, -5]"
|
||||
:value="item.unreadMessageCount" />
|
||||
<u-avatar size="44" v-if="!friend(item.targetId).portraitUrl"
|
||||
:text="friend(item.targetId).name ? friend(item.targetId).name.substring(0,1) : '未'"
|
||||
font-size="14" randomBgColor></u-avatar>
|
||||
<u-avatar v-else :src="friend(item.targetId).portraitUrl" size="44">
|
||||
</u-avatar>
|
||||
</view>
|
||||
|
||||
<view class="content">
|
||||
<view class="header">
|
||||
<view class="name">{{ friend(item.targetId).name || '未知用户' }}</view>
|
||||
<view class="time">{{ item.targetId }} | {{ item.sentTime|timeCustomCN }}</view>
|
||||
</view>
|
||||
<view class="preview">{{ item.latestMessage.content || ' ' }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
@@ -58,6 +59,7 @@
|
||||
isShown: true, // 当前页面显示状态
|
||||
conversations: [], // 会话列表
|
||||
isImToken: '', // 是否已鉴权
|
||||
connection: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -75,7 +77,7 @@
|
||||
this.isImToken = res.token
|
||||
this.getConversationList()
|
||||
})
|
||||
}
|
||||
}
|
||||
this.getConversationList()
|
||||
this.isShown = true
|
||||
}
|
||||
@@ -90,19 +92,22 @@
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
if (e.index == 1) {
|
||||
if(this.toLogin()){
|
||||
this.$Router.push({
|
||||
name: 'imFriends'
|
||||
})
|
||||
}
|
||||
if (e.index == 1) {
|
||||
if (this.toLogin()) {
|
||||
this.$Router.push({
|
||||
name: 'imFriends'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'$store.getters.newMessage': function(n, o) {
|
||||
'$store.getters.newMessage': function(n, o) {
|
||||
if (this.isShown) {
|
||||
this.getConversationList()
|
||||
}
|
||||
},
|
||||
'$store.getters.connection': function(n, o) {
|
||||
this.connection = n
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -123,7 +128,8 @@
|
||||
const timestamp = 0 // 会话的时间戳(获取这个时间戳之前的会话列表,0 表示从最新开始获取)会话类型
|
||||
RongIMLib.getConversationList(undefined, count, timestamp, (res) => {
|
||||
if (res.code === 0 && res.conversations.length > 0) {
|
||||
this.conversations = res.conversations
|
||||
this.conversations = res.conversations
|
||||
console.log(this.conversations);
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -139,9 +145,10 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.content {
|
||||
.container {
|
||||
background-color: $window-color;
|
||||
min-height: 100vh;
|
||||
padding-bottom: 200px;
|
||||
|
||||
.null-list {
|
||||
height: 100vh;
|
||||
@@ -159,64 +166,128 @@
|
||||
}
|
||||
}
|
||||
|
||||
.mssage-box {
|
||||
.message {
|
||||
position: relative;
|
||||
display: flex;
|
||||
background: white;
|
||||
padding: 24rpx 24rpx 20rpx 24rpx;
|
||||
|
||||
.mssage-action {
|
||||
.avatar {
|
||||
position: relative;
|
||||
padding: 20rpx $padding;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
left: $padding + 108;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
content: " ";
|
||||
height: 1rpx;
|
||||
background: $border-color;
|
||||
}
|
||||
|
||||
&-content {
|
||||
position: absolute;
|
||||
top: 20rpx;
|
||||
height: 44px;
|
||||
left: $padding + 108;
|
||||
right: $margin;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
.mssage-header {
|
||||
display: flex;
|
||||
font-size: $title-size;
|
||||
line-height: 40rpx;
|
||||
justify-content: space-between;
|
||||
|
||||
.header-name {
|
||||
flex: 1;
|
||||
@extend .nowrap;
|
||||
}
|
||||
|
||||
.header-time {
|
||||
padding-left: $padding;
|
||||
font-size: $title-size-sm - 2;
|
||||
color: $text-gray;
|
||||
}
|
||||
}
|
||||
|
||||
.mssage-msg {
|
||||
font-size: $title-size-sm - 2;
|
||||
color: $text-gray;
|
||||
@extend .nowrap;
|
||||
}
|
||||
.u-badge {
|
||||
z-index: 999;
|
||||
}
|
||||
}
|
||||
|
||||
&-item:last-child {
|
||||
.mssage-action::after {
|
||||
display: none;
|
||||
.content {
|
||||
margin-left: 16rpx;
|
||||
flex: 1;
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
.name {
|
||||
font-size: 36rpx
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 24rpx;
|
||||
color: $text-gray;
|
||||
}
|
||||
}
|
||||
|
||||
.preview {
|
||||
width: 520rpx;
|
||||
word-break: break-all;
|
||||
color: $text-gray;
|
||||
font-size: 26rpx;
|
||||
@extend .nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.message:not(:last-child) {
|
||||
&::after {
|
||||
position: absolute;
|
||||
left: $padding + 108;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
content: " ";
|
||||
height: 1rpx;
|
||||
background: $border-color;
|
||||
}
|
||||
}
|
||||
|
||||
// .message-box:not(:last-child) {
|
||||
|
||||
// .message-action {
|
||||
// &::after {
|
||||
// position: absolute;
|
||||
// left: $padding + 108;
|
||||
// right: 0;
|
||||
// bottom: 0;
|
||||
// content: " ";
|
||||
// height: 1rpx;
|
||||
// background: $border-color;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// .message-box {
|
||||
// background: white;
|
||||
|
||||
// .message-action {
|
||||
// position: relative;
|
||||
// padding: 20rpx $padding;
|
||||
|
||||
// .message-avatar {
|
||||
// position: relative;
|
||||
// background: red;
|
||||
// }
|
||||
|
||||
// &-content {
|
||||
// position: absolute;
|
||||
// top: 20rpx;
|
||||
// height: 44px;
|
||||
// left: $padding + 108;
|
||||
// right: $margin;
|
||||
// display: flex;
|
||||
// flex-direction: column;
|
||||
// justify-content: center;
|
||||
|
||||
// .message-header {
|
||||
// display: flex;
|
||||
// font-size: $title-size;
|
||||
// line-height: 40rpx;
|
||||
// justify-content: space-between;
|
||||
|
||||
// .header-name {
|
||||
// flex: 1;
|
||||
// @extend .nowrap;
|
||||
// }
|
||||
|
||||
// .header-time {
|
||||
// padding-left: $padding;
|
||||
// font-size: $title-size-sm - 2;
|
||||
// color: $text-gray;
|
||||
// }
|
||||
// }
|
||||
|
||||
// .message-msg {
|
||||
// font-size: $title-size-sm - 2;
|
||||
// color: $text-gray;
|
||||
// @extend .nowrap;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// &-item:last-child {
|
||||
// .message-action::after {
|
||||
// display: none;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user