<template>
  <div @click="$router.push({path: 'NewsDetail', query: { uuid: info.uuid, type: 'news' }})" class=" border-b border-gray-200 py-5">
    <div class=" text-base text-gray-900 font-semibold news-title">{{ info.title }}</div>
    <div class=" text-xs text-gray-800 pt-3 news-info">{{ info.desc }}</div>
    <div
      v-if="showImg"
      class=" h-32 bg-app-blue mt-2 bg-cover bg-center bg-no-repeat"
      :style="{'background-image': `url('${url}')`}"></div>
    <div class=" text-xs text-gray-400 pt-4 tracking-wide">发布时间：{{ $format(info.update_at, 'YYYY-MM-DD') }}</div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { getImageSrcFromFileHash } from '@/service/FileService/index'

export default defineComponent({
  props:{
    showImg:{
      type:Boolean,
      default:true
    },
    info: {
      type: Object
    }
  },
  setup (props) {
    const url = ref('')
    url.value = getImageSrcFromFileHash((props.info as {file_name: string})?.file_name)

    return {
      url
    }
  }
})
</script>

<style scoped>
  .news-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
  }
  .news-info {
    display: -webkit-box;
    overflow: hidden;  
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-all;
  }
</style>