MyListTab.vue 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <ion-page>
  3. <ion-header>
  4. <ion-toolbar>
  5. <ion-title>My List</ion-title>
  6. </ion-toolbar>
  7. </ion-header>
  8. <ion-content>
  9. <div class="p-4">
  10. <div
  11. class="grid grid-cols-2 xs:grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-7 2xl:grid-cols-8 gap-4"
  12. ref="container"
  13. >
  14. <div
  15. v-for="item in collections"
  16. :key="item.id"
  17. @click="detail(item)"
  18. >
  19. <div class="aspect-w-9 aspect-h-16">
  20. <img
  21. class="object-cover rounded md:rounded-md xl:rounded-lg"
  22. :src="item.series.cover"
  23. />
  24. </div>
  25. <div class="text-xs line-clamp-2 mt-1">
  26. {{ item.series.title }}
  27. </div>
  28. </div>
  29. <div
  30. class=""
  31. @click="router.replace({ path: '/tabs/home' })"
  32. >
  33. <div
  34. class="aspect-w-9 aspect-h-16 rounded bg-neutral-800"
  35. >
  36. <div class="grid place-content-center">
  37. <div class="text-neutral-400 leading-none">
  38. <ion-icon class="text-3xl" :icon="add" />
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </ion-content>
  46. </ion-page>
  47. </template>
  48. <script setup lang="ts">
  49. import http from "@/plugins/http";
  50. import {
  51. IonPage,
  52. IonHeader,
  53. IonToolbar,
  54. IonTitle,
  55. IonContent,
  56. onIonViewDidEnter,
  57. IonIcon,
  58. useIonRouter,
  59. } from "@ionic/vue";
  60. import { useWindowSize, useElementSize } from "@vueuse/core";
  61. import { computed, onActivated, onMounted, ref } from "vue";
  62. import SeriesItem from "@/components/SeriesItem.vue";
  63. import { add } from "ionicons/icons";
  64. const router = useIonRouter();
  65. const collections = ref<any[]>([]);
  66. function getData() {
  67. http.get("/collections").then((res) => {
  68. collections.value = [...res.data];
  69. });
  70. }
  71. onIonViewDidEnter(() => {
  72. getData();
  73. });
  74. const { width, height } = useWindowSize();
  75. const container = ref(null);
  76. const { width: containerWidth, height: containerHeight } =
  77. useElementSize(container);
  78. const itemSize = computed(() => {
  79. const itemWidth =
  80. Math.floor(
  81. containerWidth.value / Math.floor(containerWidth.value / 108)
  82. ) - 16;
  83. const itemHeight = (itemWidth * 16) / 9;
  84. return {
  85. width: itemWidth,
  86. height: itemHeight,
  87. };
  88. });
  89. function detail(item: any) {
  90. router.push({ path: `/series/${item.series.id}` });
  91. }
  92. </script>