waterfall.uvue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <cl-page back-top>
  3. <view class="py-2">
  4. <cl-waterfall ref="waterfallRef" :column="2" :gutter="16">
  5. <template #item="{ item, index }">
  6. <view class="bg-white mb-3 rounded-xl dark:!bg-gray-800 relative">
  7. <image
  8. :src="item['image']"
  9. mode="widthFix"
  10. class="w-full rounded-xl"
  11. ></image>
  12. <template v-if="item['isAd']">
  13. <cl-tag :pt="{ className: 'absolute left-1 top-1 scale-75' }"
  14. >广告</cl-tag
  15. >
  16. <cl-icon
  17. color="white"
  18. name="close-line"
  19. :pt="{ className: 'absolute right-2 top-2' }"
  20. @tap="del(item['id'] as number)"
  21. ></cl-icon>
  22. </template>
  23. <view class="p-3" v-else>
  24. <cl-text>{{ item["title"] }}</cl-text>
  25. <cl-row class="mt-2" :pt="{ className: 'justify-end items-center' }">
  26. <cl-icon name="heart-line"></cl-icon>
  27. <cl-text :pt="{ className: 'text-sm ml-1' }">{{
  28. item["likeCount"]
  29. }}</cl-text>
  30. </cl-row>
  31. </view>
  32. </view>
  33. </template>
  34. </cl-waterfall>
  35. <cl-loadmore :loading="true" safe-area-bottom></cl-loadmore>
  36. </view>
  37. </cl-page>
  38. </template>
  39. <script lang="ts" setup>
  40. import { random } from "@/cool";
  41. import { onMounted, ref } from "vue";
  42. const waterfallRef = ref<ClWaterfallComponentPublicInstance | null>(null);
  43. const loading = ref(false);
  44. let id = 0;
  45. function refresh() {
  46. const items = [
  47. {
  48. id: id++,
  49. likeCount: random(100, 1000),
  50. title: "春日樱花盛开时节,粉色花瓣如诗如画般飘洒",
  51. image: "https://unix.cool-js.com/images/demo/1.jpg"
  52. },
  53. {
  54. id: id++,
  55. likeCount: random(100, 1000),
  56. title: "夕阳西下的海滩边,金色阳光温柔地洒在波光粼粼的海面上,构成令人心旷神怡的日落美景",
  57. image: "https://unix.cool-js.com/images/demo/2.jpg"
  58. },
  59. {
  60. id: id++,
  61. likeCount: random(100, 1000),
  62. title: "寒冬腊月时分,洁白雪花纷纷扬扬地覆盖着整个世界,感受冬日的宁静与美好",
  63. image: "https://unix.cool-js.com/images/demo/3.jpg"
  64. },
  65. {
  66. id: id++,
  67. image: "https://unix.cool-js.com/images/demo/4.jpg",
  68. isAd: true
  69. },
  70. {
  71. id: id++,
  72. likeCount: random(100, 1000),
  73. title: "都市夜景霓虹闪烁,五彩斑斓光芒照亮城市营造梦幻般景象",
  74. image: "https://unix.cool-js.com/images/demo/5.jpg"
  75. },
  76. {
  77. id: id++,
  78. likeCount: random(100, 1000),
  79. title: "云雾缭绕的山间风光如诗如画让人心旷神怡,微风轻抚树梢带来阵阵清香,鸟儿在林间自由歌唱",
  80. image: "https://unix.cool-js.com/images/demo/6.jpg"
  81. },
  82. {
  83. id: id++,
  84. likeCount: random(100, 1000),
  85. title: "古老建筑与现代摩天大楼交相辉映,传统与现代完美融合创造独特城市景观",
  86. image: "https://unix.cool-js.com/images/demo/7.jpg"
  87. },
  88. {
  89. id: id++,
  90. likeCount: random(100, 1000),
  91. title: "广袤田野绿意盎然风光无限,金黄麦浪在微风中轻柔摇曳,农家炊烟袅袅升起",
  92. image: "https://unix.cool-js.com/images/demo/8.jpg"
  93. },
  94. {
  95. id: id++,
  96. likeCount: random(100, 1000),
  97. title: "璀璨星空下银河横跨天际,繁星闪烁神秘光芒营造浪漫夜空美景",
  98. image: "https://unix.cool-js.com/images/demo/9.jpg"
  99. },
  100. {
  101. id: id++,
  102. likeCount: random(100, 1000),
  103. title: "雄伟瀑布从高耸悬崖飞流直下激起千层浪花,彩虹在水雾中若隐若现如梦如幻",
  104. image: "https://unix.cool-js.com/images/demo/10.jpg"
  105. }
  106. ];
  107. waterfallRef.value!.append(items);
  108. }
  109. function del(id: number) {
  110. waterfallRef.value!.remove(id);
  111. }
  112. onReachBottom(() => {
  113. if (loading.value) return;
  114. loading.value = true;
  115. setTimeout(() => {
  116. refresh();
  117. loading.value = false;
  118. }, 1000);
  119. });
  120. onMounted(() => {
  121. refresh();
  122. });
  123. </script>