custom-layout.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <z-paging ref="paging" :refresherEnabled="refresherEnabled" v-model="tableData" :refresherOnly="refresheronly" @onRefresh="onRefresh" @scroll="onScroll" @query="onQuery">
  3. <template #top>
  4. <custom-nav-bar :background-color="backgroundColor" :back="back" :backgroundImageShow="true" :topHeight="topHeight" ref="navbar" :title="title" :title-color="titleColor" >
  5. <slot name="navBarLeft" />
  6. </custom-nav-bar>
  7. </template>
  8. <template #bottom v-if="showPageBottom">
  9. <slot name="pagebottom" />
  10. </template>
  11. <template #refresher="{refresherStatus}" >
  12. <custom-refresher :status="refresherStatus" />
  13. </template>
  14. <view class="custom-content">
  15. <slot name="content" />
  16. </view>
  17. <template #loadingMoreNoMore v-if="showLoadingNomore">
  18. <custom-nomore />
  19. </template>
  20. </z-paging>
  21. </template>
  22. <script setup>
  23. import {
  24. ref,
  25. computed,
  26. defineEmits,
  27. onMounted
  28. } from 'vue';
  29. const emit = defineEmits(['update:modelValue', 'layoutquery','refresh','scroll'])
  30. const props = defineProps({
  31. title: {
  32. type: String,
  33. default: ''
  34. },
  35. titleColor:{
  36. type: String,
  37. default: '#000000'
  38. },
  39. modelValue: {
  40. type: Array,
  41. default: [],
  42. },
  43. topHeight: {
  44. type: Number,
  45. default: 80
  46. },
  47. refresheronly:{
  48. type: Boolean,
  49. default: false
  50. },
  51. refresherEnabled:{
  52. type: Boolean,
  53. default: true
  54. },
  55. showBottom:{
  56. type: Boolean,
  57. default: false
  58. },
  59. backgroundColor: {
  60. type: String,
  61. default: 'linear-gradient(to top right, #CDDC39, #8BC34A, #FFEB3B)'
  62. },
  63. // 返回按钮相关配置
  64. back: {
  65. type: Object,
  66. default: function() {
  67. return {
  68. // 是否显示返回按钮,默认显示
  69. show: true,
  70. // 返回按钮的图片地址
  71. // imgUrl: require('../../static/images/ico_back.png')
  72. }
  73. }
  74. },
  75. showPageBottom:{
  76. type: Boolean,
  77. default: false
  78. },
  79. showLoadingNomore:{
  80. type: Boolean,
  81. default: true
  82. }
  83. })
  84. // 自定义组件 customerComp
  85. const tableData = computed({
  86. // 自定义组件内部获取父组件传递的数据
  87. get: () => props.modelValue ? props.modelValue : [],
  88. // 数据发生变化时同步修改父组件中的数据
  89. set: (val) => {
  90. emit('update:modelValue', val);
  91. }
  92. })
  93. const navbar = ref()
  94. // 监听页面滚动
  95. function onScroll(event) {
  96. navbar.value.scrollScroll(event.detail.scrollTop)
  97. emit('scroll',event.detail.scrollTop)
  98. }
  99. // 下拉刷新或滚动到底部时会自动触发此方法
  100. function onQuery(pageNo, pageSize) {
  101. emit('layoutquery', {
  102. pageNo,
  103. pageSize
  104. })
  105. }
  106. function onRefresh(){
  107. emit('refresh',)
  108. }
  109. const paging = ref()
  110. function complete(list) {
  111. paging.value.complete(list);
  112. }
  113. defineExpose({
  114. complete
  115. })
  116. </script>
  117. <style>
  118. .logo {
  119. height: 200rpx;
  120. width: 200rpx;
  121. margin-top: 200rpx;
  122. margin-left: auto;
  123. margin-right: auto;
  124. margin-bottom: 50rpx;
  125. }
  126. .text-area {
  127. display: flex;
  128. justify-content: center;
  129. }
  130. .title {
  131. font-size: 36rpx;
  132. color: #8f8f94;
  133. }
  134. .custom-content{
  135. width: 100%;
  136. height: 100%;
  137. }
  138. </style>