调整聊天界面样式

This commit is contained in:
唐明明
2022-01-19 16:49:29 +08:00
parent 070c6c729e
commit d4d366a357
7 changed files with 330 additions and 243 deletions

View File

@@ -1,43 +1,76 @@
<template>
<div>
<div v-if="$store.state.token != ''">
<div class="container">
<div class="msg-item u-border-bottom" v-for="(item, index) in conversations" @click="toDetail(item)">
<div class="avatar">
<u-badge numberType="ellipsis" max="99" shape="horn" absolute :offset="[-7, -7]"
:value="item.unreadMessageCount" />
<u-avatar shape="square" :src="friend(item.targetId).portraitUrl"></u-avatar>
</div>
<div class="content ">
<div class="name">
<h3>{{ friend(item.targetId).name }}</h3>
<span class="time">{{ item.sentTime|timeCustomCN }}</span>
</div>
<div class="u-line-1">{{ item.latestMessage.content }}</div>
</div>
</div>
</div>
<u-loadmore status="nomore" />
</div>
<div v-else>
<u-button @click="toLogin">去登录</u-button>
</div>
</div>
<template>
<view class="content">
<view v-if="$store.state.token != ''">
<block v-if="conversations.length < 1">
<view class="vertical null-list">
<u-empty
icon="http://cdn.uviewui.com/uview/empty/message.png"
textColor="#999"
text="暂无好友消息"
>
<template>
<view class="null-list-btn">开启聊天</view>
</template>
</u-empty>
</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>
</view>
</view>
</view>
</block>
</view>
<!-- 未登录 -->
<view v-else class="vertical null-list">
<u-empty
icon="http://cdn.uviewui.com/uview/empty/permission.png"
textColor="#999"
text="登录后开启聊天吧~"
>
<template>
<view class="null-list-btn" @click="toLogin">去登录</view>
</template>
</u-empty>
</view>
</view>
</template>
<script>
import * as RongIMLib from '@rongcloud/imlib-uni'
import im from '@/utils/im/index.js'
import userAuth from '@/public/userAuth'
import {
getImToken
} from '@/apis/interfaces/im.js'
import { getImToken } from '@/apis/interfaces/im.js'
export default {
data() {
return {
isShown: true, // 当前页面显示状态
conversations: [] // 会话列表
conversations: [] ,// 会话列表
isImToken: '', // 是否已鉴权
}
},
computed: {
@@ -47,30 +80,32 @@
}
}
},
onLoad() {
getImToken().then(res => {
im.syncFriends()
im.connect(res.token, res.userInfo)
this.getConversationList()
})
},
onShow() {
this.getConversationList()
this.isShown = true
onShow() {
if (this.$store.state.token !== '') {
if(this.isImToken === ''){
getImToken().then(res => {
im.syncFriends()
im.connect(res.token, res.userInfo)
this.isImToken = res.token
this.getConversationList()
})
}
this.getConversationList()
this.isShown = true
}
},
onHide() {
this.isShown = false
},
onNavigationBarButtonTap(e) {
if (e.index == 0) {}
if (e.index == 1) {
uni.navigateTo({
url: '/pages/im/friends/index',
fail: (err) => {
console.log(err);
}
})
if (e.index == 0) {
uni.showToast({
title: '开发中暂未开放,敬请期待',
icon : 'none'
})
}
if (e.index == 1) {
this.$Router.push({name: 'imFriends'})
}
},
watch: {
@@ -96,7 +131,7 @@
getConversationList() {
const count = 1000
const timestamp = 0 // 会话的时间戳获取这个时间戳之前的会话列表0 表示从最新开始获取)会话类型
RongIMLib.getConversationList(undefined, count, timestamp, (res) => {
RongIMLib.getConversationList(undefined, count, timestamp, (res) => {
if (res.code === 0 && res.conversations.length > 0) {
this.conversations = res.conversations
}
@@ -105,51 +140,81 @@
// 进入聊天的详情页面,清理未读消息数量
toDetail(item) {
uni.navigateTo({
url: '/pages/im/private/index?targetId=' + item.targetId +
'&conversationType=' + item.conversationType
url: '/pages/im/private/index?targetId=' + item.targetId + '&conversationType=' + item.conversationType
})
}
}
}
</script>
<style scoped lang="scss">
.container {
padding: 0 $uni-spacing-col-lg $uni-spacing-col-lg $uni-spacing-col-lg;
}
.msg-item {
display: flex;
align-items: center;
padding: $uni-spacing-col-lg 0;
.avatar {
position: relative;
margin-right: $uni-spacing-col-lg;
.u-badge {
z-index: 9;
}
}
.content {
flex: 1;
.name {
display: flex;
justify-content: space-between;
font-size: $uni-font-size-base;
.time {
font-size: $uni-font-size-sm;
color: $uni-text-color-grey;
}
}
.u-line-1 {
color: $u-info;
font-size: $uni-font-size-sm;
}
}
}
<style lang="scss" scoped>
.content{
background-color: $window-color;
min-height: 100vh;
.null-list{
height: 100vh;
text-align: center;
&-btn{
margin-top: $margin * 2;
line-height: 70rpx;
color: $main-color;
border:solid 1rpx $main-color;
padding: 0 ($padding*3);
font-size: $title-size-m;
border-radius: 35rpx;
box-sizing: border-box;
}
}
.mssage-box{
background: white;
.mssage-action{
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;
}
}
}
&-item:last-child{
.mssage-action::after{
display: none;
}
}
}
}
</style>