message-footer.vue
1.78 KB
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
<template>
<div class="base" :class="[ isMine ? 'right' : 'left']">
<!-- <div class="name text-ellipsis">{{ from }}</div> -->
<div class="date">{{ date }}</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import { getFullDate } from '../../utils/date'
export default {
name: 'MessageFooter',
props: {
message: {
type: Object,
required: true
}
},
computed: {
...mapState({
currentConversation: state => state.conversation.currentConversation,
currentUserProfile: state => state.user.currentUserProfile,
currentMemberList: state => state.group.currentMemberList
}),
date() {
return getFullDate(new Date(this.message.time * 1000))
},
from() {
const isC2C = this.currentConversation.type === this.TIM.TYPES.CONV_C2C
// 自己发送的用昵称渲染
if (this.isMine) {
return this.currentUserProfile.nick || this.currentUserProfile.userID
}
// 1. C2C 的消息体中还无 nick / avatar 字段,需从 conversation.userProfile 中获取
if (isC2C) {
return (
this.currentConversation.userProfile.nick ||
this.currentConversation.userProfile.userID
)
}
// 2. 群组消息,用消息体中的 nick 渲染。nameCard暂时支持不完善
return this.message.nick || this.message.from
},
isMine() {
return this.message.flow === 'out'
}
}
}
</script>
<style lang="stylus" scoped>
.right {
display: flex;
flex-direction: row-reverse;
margin-right: 15px;
}
.left {
display: flex;
flex-direction: row;
margin-left: 15px;
}
.base {
color: $secondary;
font-size: 12px;
}
.name {
padding: 0 4px;
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>