index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <script setup lang="ts">
  2. import { getList } from "./api";
  3. import error from "./error.png";
  4. import loading from "./loading.png";
  5. import { ElLoading } from "element-plus";
  6. import "vue-waterfall-plugin-next/dist/style.css";
  7. import InfiniteLoading from "v3-infinite-loading";
  8. import { onMounted, reactive, ref, nextTick } from "vue";
  9. import backTop from "@/assets/svg/back_top.svg?component";
  10. import { LazyImg, Waterfall } from "vue-waterfall-plugin-next";
  11. const options = reactive({
  12. // 唯一key值
  13. rowKey: "id",
  14. // 卡片之间的间隙
  15. gutter: 10,
  16. // 是否有周围的gutter
  17. hasAroundGutter: true,
  18. // 卡片在PC上的宽度
  19. width: 320,
  20. // 自定义行显示个数,主要用于对移动端的适配
  21. breakpoints: {
  22. 1200: {
  23. // 当屏幕宽度小于等于1200
  24. rowPerView: 4
  25. },
  26. 800: {
  27. // 当屏幕宽度小于等于800
  28. rowPerView: 3
  29. },
  30. 500: {
  31. // 当屏幕宽度小于等于500
  32. rowPerView: 2
  33. }
  34. },
  35. // 动画效果 https://animate.style/
  36. animationEffect: "animate__zoomInUp",
  37. // 动画时间
  38. animationDuration: 1000,
  39. // 动画延迟
  40. animationDelay: 300,
  41. // 背景色
  42. // backgroundColor: "#2C2E3A",
  43. // 图片字段选择器,如果层级较深,使用 xxx.xxx.xxx 方式
  44. imgSelector: "src.original",
  45. // 加载配置
  46. loadProps: {
  47. loading,
  48. error
  49. },
  50. // 是否懒加载
  51. lazyload: true
  52. });
  53. const page = ref(1);
  54. const list = ref([]);
  55. const pageSize = ref();
  56. const loadingInstance = ref();
  57. /** 加载更多 */
  58. function handleLoadMore() {
  59. loadingInstance.value = ElLoading.service({
  60. target: ".content",
  61. background: "transparent",
  62. text: "加载中"
  63. });
  64. getList({
  65. page: page.value,
  66. pageSize: pageSize.value
  67. }).then(res => {
  68. setTimeout(() => {
  69. list.value.push(...res);
  70. page.value += 1;
  71. nextTick(() => {
  72. loadingInstance.value.close();
  73. });
  74. }, 500);
  75. });
  76. }
  77. function handleDelete(item, index) {
  78. list.value.splice(index, 1);
  79. }
  80. function handleClick(item) {
  81. console.log(item);
  82. }
  83. onMounted(() => {
  84. handleLoadMore();
  85. });
  86. </script>
  87. <template>
  88. <el-scrollbar max-height="calc(100vh - 120px)" class="content">
  89. <Waterfall :list="list" v-bind="options">
  90. <template #item="{ item, url, index }">
  91. <div
  92. class="bg-gray-900 rounded-lg shadow-md overflow-hidden transition-all duration-300 ease-linear hover:shadow-lg hover:shadow-gray-600 group"
  93. @click="handleClick(item)"
  94. >
  95. <div class="overflow-hidden">
  96. <LazyImg
  97. :url="url"
  98. class="cursor-pointer transition-all duration-300 ease-linear group-hover:scale-105"
  99. />
  100. </div>
  101. <div class="px-4 pt-2 pb-4 border-t border-t-gray-800">
  102. <h4 class="pb-4! text-gray-50 group-hover:text-yellow-300">
  103. {{ item.name }}
  104. </h4>
  105. <div
  106. class="pt-3 flex justify-between items-center border-t border-t-gray-600 border-opacity-50"
  107. >
  108. <div class="text-gray-50">$ {{ item.price }}</div>
  109. <div>
  110. <button
  111. class="px-3! rounded-full bg-red-500 text-sm text-white shadow-lg transition-all duration-300 hover:bg-red-600 border-0"
  112. @click.stop="handleDelete(item, index)"
  113. >
  114. 删除
  115. </button>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </template>
  121. </Waterfall>
  122. <!-- <div class="flex justify-center py-10">
  123. <button
  124. class="px-5! py-2! rounded-full bg-gray-700 text-md text-white cursor-pointer hover:bg-gray-800 transition-all duration-300 border-0"
  125. @click="handleLoadMore"
  126. >
  127. 加载更多
  128. </button>
  129. </div> -->
  130. <el-backtop
  131. title="回到顶部"
  132. :right="35"
  133. :bottom="50"
  134. :visibility-height="400"
  135. target=".content .el-scrollbar__wrap"
  136. >
  137. <backTop />
  138. </el-backtop>
  139. <!-- 加载更多 -->
  140. <InfiniteLoading :firstload="false" @infinite="handleLoadMore" />
  141. </el-scrollbar>
  142. </template>
  143. <style lang="scss" scoped>
  144. .main-content {
  145. margin: 0 !important;
  146. }
  147. :deep(.el-loading-spinner .el-loading-text) {
  148. font-size: 24px;
  149. }
  150. </style>