Blame view

apps/pages/article/components/detail/zan-bar.vue 1.05 KB
htoooth authored
1 2 3
<template>
  <div class="flex">
    <WidgetAvatarGroup :avatars="praiseHeadIco"></WidgetAvatarGroup>
TaoHuang authored
4
    <span class="v-center" v-if="praiseCount">{{praiseCount}}人喜欢</span>
htoooth authored
5 6 7 8 9
    <span class="time v-center text-right">{{publish_time | formatTime}}</span>
  </div>
</template>

<script>
htoooth authored
10 11 12

import dayjs from 'dayjs';
htoooth authored
13 14 15 16 17
export default {
  name: 'ZanBar',
  props: ['praiseHeadIco', 'praiseCount', 'publish_time'],
  filters: {
    formatTime(str) {
htoooth authored
18 19 20 21
      if (!str) {
        return '';
      }
htoooth authored
22 23 24 25 26 27 28 29 30 31
      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');
      }
htoooth authored
32 33 34 35 36
    }
  }
};
</script>
陈峰 authored
37
<style scoped lang="scss">
htoooth authored
38 39 40 41 42 43
.flex {
  display: flex;
}

.v-center {
  align-self: center;
TaoHuang authored
44
  font-size: 20px;
htoooth authored
45 46 47 48 49 50 51 52 53 54 55
}

.time {
  flex: 1;
}

.text-right {
  text-align: right;
}

</style>