zan-bar.vue 1.05 KB
<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>