index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="posts">
  3. <div class="post" v-for="article in articles">
  4. <div class="post__info">
  5. <h2 class="post__title">
  6. <nuxt-link class="post__link" :to="`/posts/${article.id}`">
  7. {{ article.title }}
  8. </nuxt-link>
  9. </h2>
  10. <div class="post__brief">
  11. {{ article.briefContent }}
  12. </div>
  13. </div>
  14. <div class="post__cover" v-if="article.coverImage">
  15. <img :src="article.coverImage" :alt="article.title" />
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script setup>
  21. // 获取原有文章数据
  22. const { data: originalArticles } = await useFetch('/api/articles')
  23. // 调用 Epic 免费游戏 API
  24. const { data: epicData } = await useFetch('https://uapis.cn/api/v1/game/epic-free')
  25. // 获取本地图片 manifest(通过 API 读取)
  26. const { data: imageManifest } = await useFetch('/api/epic-manifest', {
  27. default: () => ({})
  28. })
  29. // 将 Epic 游戏数据转换为文章格式
  30. const epicArticles = computed(() => {
  31. if (!epicData.value || !epicData.value.data) return []
  32. const manifest = imageManifest.value || {}
  33. return epicData.value.data
  34. .filter(game => !game.title.includes('神秘游戏'))
  35. .map(game => ({
  36. id: game.id,
  37. title: game.title,
  38. briefContent: `${game.free_start}到${game.free_end}的EPIC免费游戏为${game.title}`,
  39. // 优先使用本地缓存图片,如果没有则使用原始 URL
  40. coverImage: manifest[game.id] || game.cover
  41. }))
  42. })
  43. // 合并文章数据
  44. const articles = computed(() => {
  45. const original = originalArticles.value || []
  46. const epic = epicArticles.value || []
  47. return [...epic, ...original]
  48. })
  49. </script>
  50. <style lang="stylus">
  51. .post
  52. padding: 20px 0
  53. display: flex
  54. align-items: center
  55. justify-content: space-between
  56. border-bottom: 1px dashed var(--border-gray-color)
  57. &__title
  58. font-size: 16px
  59. color: #333333
  60. margin: 0 0 15px 0
  61. &__link
  62. display: block
  63. &__brief
  64. font-size: 14px
  65. line-height: 1.6
  66. color: var(--text-secondary-color)
  67. &__cover
  68. flex: 0 0 auto
  69. width: 100px
  70. margin-left: 10px
  71. line-height: 0
  72. img
  73. width: 100px
  74. max-width: 100%
  75. &__info
  76. flex: 0 1 auto
  77. </style>