list-view-refresh.uvue 3.1 KB

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