list-view-refresh.uvue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <cl-page>
  3. <cl-list-view
  4. ref="listViewRef"
  5. :data="data"
  6. :virtual="false"
  7. :pt="{
  8. refresher: {
  9. className: 'pt-3'
  10. }
  11. }"
  12. :refresher-enabled="true"
  13. @pull="onPull"
  14. @bottom="loadMore"
  15. >
  16. <template #item="{ value }">
  17. <goods-item :value="value"></goods-item>
  18. </template>
  19. <template #bottom>
  20. <view class="py-3">
  21. <cl-loadmore :loading="loading" v-if="list.length > 0"></cl-loadmore>
  22. </view>
  23. </template>
  24. </cl-list-view>
  25. </cl-page>
  26. </template>
  27. <script lang="ts" setup>
  28. import { useListView, useUi, type ClListViewItem } from "@/uni_modules/cool-ui";
  29. import { computed, ref } from "vue";
  30. import { usePager } from "@/cool";
  31. import GoodsItem from "../components/goods-item.uvue";
  32. const ui = useUi();
  33. const listViewRef = ref<ClListViewComponentPublicInstance | null>(null);
  34. let id = 0;
  35. const { refresh, list, loading, loadMore } = usePager((params) => {
  36. return new Promise((resolve) => {
  37. setTimeout(() => {
  38. resolve({
  39. list: [
  40. {
  41. id: id++,
  42. title: "春日樱花盛开时节,粉色花瓣如诗如画般飘洒",
  43. image: "https://unix.cool-js.com/images/demo/1.jpg"
  44. },
  45. {
  46. id: id++,
  47. title: "夕阳西下的海滩边,金色阳光温柔地洒在波光粼粼的海面上,构成令人心旷神怡的日落美景",
  48. image: "https://unix.cool-js.com/images/demo/2.jpg"
  49. },
  50. {
  51. id: id++,
  52. title: "寒冬腊月时分,洁白雪花纷纷扬扬地覆盖着整个世界,感受冬日的宁静与美好",
  53. image: "https://unix.cool-js.com/images/demo/3.jpg"
  54. },
  55. {
  56. id: id++,
  57. title: "都市夜景霓虹闪烁,五彩斑斓光芒照亮城市营造梦幻般景象",
  58. image: "https://unix.cool-js.com/images/demo/5.jpg"
  59. },
  60. {
  61. id: id++,
  62. title: "云雾缭绕的山间风光如诗如画让人心旷神怡,微风轻抚树梢带来阵阵清香,鸟儿在林间自由歌唱",
  63. image: "https://unix.cool-js.com/images/demo/6.jpg"
  64. },
  65. {
  66. id: id++,
  67. title: "古老建筑与现代摩天大楼交相辉映,传统与现代完美融合创造独特城市景观",
  68. image: "https://unix.cool-js.com/images/demo/7.jpg"
  69. },
  70. {
  71. id: id++,
  72. title: "广袤田野绿意盎然风光无限,金黄麦浪在微风中轻柔摇曳,农家炊烟袅袅升起",
  73. image: "https://unix.cool-js.com/images/demo/8.jpg"
  74. },
  75. {
  76. id: id++,
  77. title: "璀璨星空下银河横跨天际,繁星闪烁神秘光芒营造浪漫夜空美景",
  78. image: "https://unix.cool-js.com/images/demo/9.jpg"
  79. },
  80. {
  81. id: id++,
  82. title: "雄伟瀑布从高耸悬崖飞流直下激起千层浪花,彩虹在水雾中若隐若现如梦如幻",
  83. image: "https://unix.cool-js.com/images/demo/10.jpg"
  84. }
  85. ],
  86. pagination: {
  87. page: params["page"],
  88. size: params["size"],
  89. total: 100
  90. }
  91. });
  92. ui.hideLoading();
  93. }, 1000);
  94. });
  95. });
  96. const data = computed<ClListViewItem[]>(() => {
  97. return useListView(list.value);
  98. });
  99. async function onPull() {
  100. await refresh({ page: 1 });
  101. listViewRef.value!.stopRefresh();
  102. }
  103. onReady(() => {
  104. ui.showLoading("加载中");
  105. refresh({});
  106. });
  107. </script>