z-paging-empty-view.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!-- z-paging -->
  2. <!-- github地址:https://github.com/SmileZXLee/uni-z-paging -->
  3. <!-- dcloud地址:https://ext.dcloud.net.cn/plugin?id=3935 -->
  4. <!-- 反馈QQ群:790460711 -->
  5. <!-- 空数据占位view,此组件支持easycom规范,可以在项目中直接引用 -->
  6. <template>
  7. <view :class="{'zp-container':true,'zp-container-fixed':emptyViewFixed}" :style="[finalEmptyViewStyle]" @click="emptyViewClick">
  8. <view class="zp-main">
  9. <image v-if="!emptyViewImg.length" :class="{'zp-main-image-rpx':unit==='rpx','zp-main-image-px':unit==='px'}" :style="[emptyViewImgStyle]" :src="emptyImg" />
  10. <image v-else :class="{'zp-main-image-rpx':unit==='rpx','zp-main-image-px':unit==='px'}" mode="aspectFit" :style="[emptyViewImgStyle]" :src="emptyViewImg" />
  11. <text class="zp-main-title" :class="{'zp-main-title-rpx':unit==='rpx','zp-main-title-px':unit==='px'}" :style="[emptyViewTitleStyle]">{{emptyViewText}}</text>
  12. <text v-if="showEmptyViewReload" :class="{'zp-main-error-btn':true,'zp-main-error-btn-rpx':unit==='rpx','zp-main-error-btn-px':unit==='px'}" :style="[emptyViewReloadStyle]" @click.stop="reloadClick">{{emptyViewReloadText}}</text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import zStatic from '../z-paging/js/z-paging-static'
  18. export default {
  19. name: "z-paging-empty-view",
  20. data() {
  21. return {
  22. };
  23. },
  24. props: {
  25. // 空数据描述文字
  26. emptyViewText: {
  27. type: String,
  28. default: '没有数据哦~'
  29. },
  30. // 空数据图片
  31. emptyViewImg: {
  32. type: String,
  33. default: ''
  34. },
  35. // 是否显示空数据图重新加载按钮
  36. showEmptyViewReload: {
  37. type: Boolean,
  38. default: false
  39. },
  40. // 空数据点击重新加载文字
  41. emptyViewReloadText: {
  42. type: String,
  43. default: '重新加载'
  44. },
  45. // 是否是加载失败
  46. isLoadFailed: {
  47. type: Boolean,
  48. default: false
  49. },
  50. // 空数据图样式
  51. emptyViewStyle: {
  52. type: Object,
  53. default: function() {
  54. return {}
  55. }
  56. },
  57. // 空数据图img样式
  58. emptyViewImgStyle: {
  59. type: Object,
  60. default: function() {
  61. return {}
  62. }
  63. },
  64. // 空数据图描述文字样式
  65. emptyViewTitleStyle: {
  66. type: Object,
  67. default: function() {
  68. return {}
  69. }
  70. },
  71. // 空数据图重新加载按钮样式
  72. emptyViewReloadStyle: {
  73. type: Object,
  74. default: function() {
  75. return {}
  76. }
  77. },
  78. // 空数据图z-index
  79. emptyViewZIndex: {
  80. type: Number,
  81. default: 9
  82. },
  83. // 空数据图片是否使用fixed布局并铺满z-paging
  84. emptyViewFixed: {
  85. type: Boolean,
  86. default: true
  87. },
  88. // 空数据图中布局的单位,默认为rpx
  89. unit: {
  90. type: String,
  91. default: 'rpx'
  92. }
  93. },
  94. computed: {
  95. emptyImg() {
  96. return this.isLoadFailed ? zStatic.base64Error : zStatic.base64Empty;
  97. },
  98. finalEmptyViewStyle(){
  99. this.emptyViewStyle['z-index'] = this.emptyViewZIndex;
  100. return this.emptyViewStyle;
  101. }
  102. },
  103. methods: {
  104. // 点击了reload按钮
  105. reloadClick() {
  106. this.$emit('reload');
  107. },
  108. // 点击了空数据view
  109. emptyViewClick() {
  110. this.$emit('viewClick');
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .zp-container{
  117. /* #ifndef APP-NVUE */
  118. display: flex;
  119. /* #endif */
  120. align-items: center;
  121. justify-content: center;
  122. }
  123. .zp-container-fixed {
  124. /* #ifndef APP-NVUE */
  125. position: absolute;
  126. top: 0;
  127. left: 0;
  128. width: 100%;
  129. height: 100%;
  130. /* #endif */
  131. /* #ifdef APP-NVUE */
  132. flex: 1;
  133. /* #endif */
  134. }
  135. .zp-main{
  136. /* #ifndef APP-NVUE */
  137. display: flex;
  138. /* #endif */
  139. flex-direction: column;
  140. align-items: center;
  141. padding: 50rpx 0rpx;
  142. }
  143. .zp-main-image-rpx {
  144. width: 240rpx;
  145. height: 240rpx;
  146. }
  147. .zp-main-image-px {
  148. width: 120px;
  149. height: 120px;
  150. }
  151. .zp-main-title {
  152. color: #aaaaaa;
  153. text-align: center;
  154. }
  155. .zp-main-title-rpx {
  156. font-size: 28rpx;
  157. margin-top: 10rpx;
  158. padding: 0rpx 20rpx;
  159. }
  160. .zp-main-title-px {
  161. font-size: 14px;
  162. margin-top: 5px;
  163. padding: 0px 10px;
  164. }
  165. .zp-main-error-btn {
  166. border: solid 1px #dddddd;
  167. color: #aaaaaa;
  168. }
  169. .zp-main-error-btn-rpx {
  170. font-size: 28rpx;
  171. padding: 8rpx 24rpx;
  172. border-radius: 6rpx;
  173. margin-top: 50rpx;
  174. }
  175. .zp-main-error-btn-px {
  176. font-size: 14px;
  177. padding: 4px 12px;
  178. border-radius: 3px;
  179. margin-top: 25px;
  180. }
  181. </style>