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