zan-bar.vue 1 KB
<template>
  <div class="flex">
    <WidgetAvatarGroup :avatars="praiseHeadIco"></WidgetAvatarGroup>
    <span class="v-center">{{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>
.flex {
  display: flex;
}

.v-center {
  align-self: center;
}

.time {
  flex: 1;
}

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

</style>