index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <app-block class="app-article">
  3. <h4 class="app-article__title">{{ title }}</h4>
  4. <section class="app-article__section" v-for="(group, index) in newsList" :key="index">
  5. <dl class="news-list">
  6. <dt class="news-list__date">
  7. <time class="news-list__time">{{ group.time }}</time>
  8. </dt>
  9. <dd class="news-list__item" v-for="(item, index) in group.list" :key="index">
  10. <div class="news-item">
  11. <div class="news-item__content">
  12. <div class="news-item__title">{{ item.title }}</div>
  13. <div class="news-item__meta">
  14. <span class="news-item__time">{{ formatDate(item.publishdate, 'HH:mm') }}</span>
  15. <span class="news-item__author" v-if="item.author">{{ item.author }}</span>
  16. </div>
  17. </div>
  18. <div class="news-item__image" v-if="item.coverimage">
  19. <Image class="news-item__img" fit="cover" :src="item.coverimage" :width="68" :height="60" :radius="4" />
  20. </div>
  21. </div>
  22. </dd>
  23. </dl>
  24. </section>
  25. </app-block>
  26. </template>
  27. <script lang="ts" setup>
  28. import { computed } from 'vue'
  29. import { Image } from 'vant'
  30. import { formatDate } from '@/filters'
  31. import { useRequest } from '@/hooks/request'
  32. import { queryNewTitles } from '@/services/api/news'
  33. defineProps({
  34. title: {
  35. type: String,
  36. default: '新闻资讯'
  37. }
  38. })
  39. const { dataList } = useRequest(queryNewTitles, {
  40. defaultParams: {
  41. pagesize: 20
  42. }
  43. })
  44. const newsList = computed(() => {
  45. const list = dataList.value.reduce<{ time: string; list: Model.NewTitlesRsp[] }[]>((res, item) => {
  46. const date = item.publishdate.split('T')[0]
  47. const group = res.find(group => group.time === date)
  48. if (group) {
  49. group.list.push(item)
  50. } else {
  51. res.push({
  52. time: date,
  53. list: [item]
  54. })
  55. }
  56. return res
  57. }, [])
  58. return list.sort((a, b) => b.time.localeCompare(a.time))
  59. })
  60. </script>
  61. <style lang="less">
  62. @import "./index.less";
  63. </style>