list-view-refresh.uvue 3.1 KB

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