ArchivesView.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script setup lang="ts">
  2. import TagCloud from '@/components/TagCloud.vue'
  3. import { api } from '@/utils/axios.ts'
  4. import type { Tag } from '@/models'
  5. import { onMounted, ref } from 'vue'
  6. import { type CateOption, optionOfCate } from '@/utils/cates.ts'
  7. import { router } from '@/router'
  8. const tags = ref<Tag[]>([])
  9. const archiveLabels = ref<CateOption[]>([])
  10. onMounted(() => {
  11. Promise.all([
  12. api.tagList().then((res) => {
  13. tags.value = res.data
  14. }),
  15. api.postCates().then((res) => {
  16. archiveLabels.value = res.data.map(optionOfCate)
  17. }),
  18. ])
  19. });
  20. const handleCateClick = (cate: string) => {
  21. router.push(`/archive?cate=${cate}`)
  22. }
  23. const handleTagClick = (tag: Tag) => {
  24. router.push(`/archive?tag=${tag.name}`)
  25. }
  26. </script>
  27. <template>
  28. <div>
  29. <div class="post-item">
  30. <h1 class="title">话题</h1>
  31. <TagCloud :tags="tags" :on-click="handleTagClick" />
  32. <h2>档案库</h2>
  33. <div class="archive-items-grid">
  34. <div class="archive-item-wrapper" v-for="item in archiveLabels" :key="item.value">
  35. <div class="archive-item" @click="handleCateClick(item.value)">
  36. <div class="prefix-icon" v-html="item.svg.template"/>
  37. <div class="content">{{ item.label }}</div>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <style scoped>
  45. .archive-items-grid {
  46. width: 100%;
  47. }
  48. .archive-item-wrapper {
  49. display: inline-block;
  50. width: 50%;
  51. }
  52. .archive-item .prefix-icon {
  53. width: 32px;
  54. height: 32px;
  55. }
  56. .archive-item {
  57. display: flex;
  58. justify-content: center;
  59. gap: 24px;
  60. background-color: var(--secondary-background-color);
  61. color: var(--text-color);
  62. font-size: larger;
  63. fill: var(--text-color);
  64. padding: 20px 0;
  65. width: calc(100% - 20px);
  66. border-radius: 12px;
  67. align-items: center;
  68. margin: 20px 10px;
  69. cursor: pointer;
  70. transition: all .3s;
  71. }
  72. .archive-item:hover {
  73. box-shadow: var(--secondary-background-color) 0 0 12px;
  74. background-color: var(--text-color);
  75. color: var(--secondary-background-color);
  76. fill: var(--secondary-background-color);
  77. font-weight: bold;
  78. }
  79. </style>