index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // 将 Epic 游戏数据转换为文章格式
  26. const epicArticles = computed(() => {
  27. if (!epicData.value || !epicData.value.data) return []
  28. return epicData.value.data
  29. .filter(game => !game.title.includes('神秘游戏'))
  30. .map(game => ({
  31. id: game.id,
  32. title: game.title,
  33. briefContent: `${game.free_start}到${game.free_end}的EPIC免费游戏为${game.title}`,
  34. coverImage: game.cover
  35. }))
  36. })
  37. // 合并文章数据
  38. const articles = computed(() => {
  39. const original = originalArticles.value || []
  40. const epic = epicArticles.value || []
  41. return [...epic, ...original]
  42. })
  43. </script>
  44. <style lang="stylus">
  45. .post
  46. padding: 20px 0
  47. display: flex
  48. align-items: center
  49. justify-content: space-between
  50. border-bottom: 1px dashed var(--border-gray-color)
  51. &__title
  52. font-size: 16px
  53. color: #333333
  54. margin: 0 0 15px 0
  55. &__link
  56. display: block
  57. &__brief
  58. font-size: 14px
  59. line-height: 1.6
  60. color: var(--text-secondary-color)
  61. &__cover
  62. flex: 0 0 auto
  63. width: 100px
  64. margin-left: 10px
  65. line-height: 0
  66. img
  67. width: 100px
  68. max-width: 100%
  69. &__info
  70. flex: 0 1 auto
  71. </style>