zan-bar.vue
1.05 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
<template>
<div class="flex">
<WidgetAvatarGroup :avatars="praiseHeadIco"></WidgetAvatarGroup>
<span class="v-center" v-if="praiseCount">{{praiseCount}}人喜欢</span>
<span class="time v-center text-right">{{publish_time | formatTime}}</span>
</div>
</template>
<script>
import dayjs from 'dayjs';
export default {
name: 'ZanBar',
props: ['praiseHeadIco', 'praiseCount', 'publish_time'],
filters: {
formatTime(str) {
if (!str) {
return '';
}
const now = dayjs();
const pubTime = dayjs(str * 1000);
if (now.year() === pubTime.year() && now.month() === pubTime.month() && now.day() === pubTime.day()) {
return pubTime.format('HH:mm');
} else if (now.year() === pubTime.year()) {
return pubTime.format('MM-DD');
} else {
return pubTime.format('YYYY-MM-DD');
}
}
}
};
</script>
<style scoped lang="scss">
.flex {
display: flex;
}
.v-center {
align-self: center;
font-size: 20px;
}
.time {
flex: 1;
}
.text-right {
text-align: right;
}
</style>