# 聊天列表组件开发

# 封装聊天列表组件

<template>
	<view>
		<!-- 时间 -->
		<view v-if="item.gstime" class="user-chat-time u-f-ajc">{{item.gstime}}</view>
		<view class="user-chat-list u-f " :class="{'user-chat-me':item.isme}">
			<image v-if="!item.isme" class="chat-img" :src="item.userpic" mode="widthFix" lazy-load></image>
			<view class="user-chat-list-body">
				<!-- 文字 -->
				<text v-if="item.type==='text'">{{item.data}}</text>
				<!-- 图片 -->
				<image v-if="item.type==='img'" :src="item.data" mode="widthFix" lazy-load></image>
			</view>
			<image v-if="item.isme" class="chat-img" :src="item.userpic" mode="widthFix" lazy-load></image>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: Object,
			index: Number
		}
	}
</script>

<style lang="less" scoped>
	.user-chat-list {
		padding: 20rpx 0;
		.chat-img {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			flex-shrink: 0;
		}
	
		.user-chat-list-body {
			position: relative;
			background-color: #f4f4f4;
			padding: 25rpx;
			margin-left: 20rpx;
			margin-right: 100rpx;
			border-radius: 20rpx;
	
			image {
				max-width: 150rpx;
				max-height: 200rpx;
			}
	
			&:after {
				content: '';
				position: absolute;
				left: -30rpx;
				right: 0;
				top: 30rpx;
				width: 0;
				height: 0;
				border: 16rpx solid #f4f4f4;
				border-color: transparent #f4f4f4 transparent transparent;
			}
		}
	}
	
	.user-chat-me {
		justify-content: flex-end;
	
		.user-chat-list-body {
			margin-right: 20rpx;
			margin-left: 100rpx;
	
			&:after {
				content: '';
				left: auto;
				right: -30rpx;
				border-color: transparent transparent transparent #f4f4f4;
			}
		}
	}
	
	.user-chat-time {
		padding: 20rpx 0;
		color: #a2a2a2;
		font-size: 24rpx;
	}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
上次更新: 2021/2/22 上午10:53:04