z-paging-empty-view.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. /**
  19. * z-paging-empty-view 空数据组件
  20. * @description 通用的 z-paging 空数据组件
  21. * @tutorial https://z-paging.zxlee.cn/api/sub-components/main.html#z-paging-empty-view配置
  22. * @property {Boolean} emptyViewFixed 空数据图片是否铺满 z-paging,默认为 false。若设置为 true,则为填充满 z-paging 的剩余部分
  23. * @property {String} emptyViewText 空数据图描述文字,默认为 '没有数据哦~'
  24. * @property {String} emptyViewImg 空数据图图片,默认使用 z-paging 内置的图片 (建议使用绝对路径,开头不要添加 "@",请以 "/" 开头)
  25. * @property {String} emptyViewReloadText 空数据图点击重新加载文字,默认为 '重新加载'
  26. * @property {Object} emptyViewStyle 空数据图样式,可设置空数据 view 的 top 等,如: empty-view-style="{'top':'100rpx'}" (如果空数据图不是 fixed 布局,则此处是 margin-top),默认为 {}
  27. * @property {Object} emptyViewImgStyle 空数据图 img 样式,默认为 {}
  28. * @property {Object} emptyViewTitleStyle 空数据图描述文字样式,默认为 {}
  29. * @property {Object} emptyViewReloadStyle 空数据图重新加载按钮样式,默认为 {}
  30. * @property {Boolean} showEmptyViewReload 是否显示空数据图重新加载按钮(无数据时),默认为 false
  31. * @property {Boolean} isLoadFailed 是否是加载失败,默认为 false
  32. * @property {String} unit 空数据图中布局的单位,默认为 'rpx'
  33. * @event {Function} reload 点击了重新加载按钮
  34. * @event {Function} viewClick 点击了空数据图 view
  35. * @example <z-paging-empty-view empty-view-text="暂无数据" />
  36. */
  37. export default {
  38. name: "z-paging-empty-view",
  39. data() {
  40. return {
  41. };
  42. },
  43. props: {
  44. // 空数据描述文字
  45. emptyViewText: {
  46. type: String,
  47. default: '没有数据哦~'
  48. },
  49. // 空数据图片
  50. emptyViewImg: {
  51. type: String,
  52. default: ''
  53. },
  54. // 是否显示空数据图重新加载按钮
  55. showEmptyViewReload: {
  56. type: Boolean,
  57. default: false
  58. },
  59. // 空数据点击重新加载文字
  60. emptyViewReloadText: {
  61. type: String,
  62. default: '重新加载'
  63. },
  64. // 是否是加载失败
  65. isLoadFailed: {
  66. type: Boolean,
  67. default: false
  68. },
  69. // 空数据图样式
  70. emptyViewStyle: {
  71. type: Object,
  72. default: function() {
  73. return {}
  74. }
  75. },
  76. // 空数据图img样式
  77. emptyViewImgStyle: {
  78. type: Object,
  79. default: function() {
  80. return {}
  81. }
  82. },
  83. // 空数据图描述文字样式
  84. emptyViewTitleStyle: {
  85. type: Object,
  86. default: function() {
  87. return {}
  88. }
  89. },
  90. // 空数据图重新加载按钮样式
  91. emptyViewReloadStyle: {
  92. type: Object,
  93. default: function() {
  94. return {}
  95. }
  96. },
  97. // 空数据图z-index
  98. emptyViewZIndex: {
  99. type: Number,
  100. default: 9
  101. },
  102. // 空数据图片是否使用fixed布局并铺满z-paging
  103. emptyViewFixed: {
  104. type: Boolean,
  105. default: true
  106. },
  107. // 空数据图中布局的单位,默认为rpx
  108. unit: {
  109. type: String,
  110. default: 'rpx'
  111. }
  112. },
  113. computed: {
  114. emptyImg() {
  115. return this.isLoadFailed ? zStatic.base64Error : zStatic.base64Empty;
  116. },
  117. finalEmptyViewStyle(){
  118. this.emptyViewStyle['z-index'] = this.emptyViewZIndex;
  119. return this.emptyViewStyle;
  120. }
  121. },
  122. methods: {
  123. // 点击了reload按钮
  124. reloadClick() {
  125. this.$emit('reload');
  126. },
  127. // 点击了空数据view
  128. emptyViewClick() {
  129. this.$emit('viewClick');
  130. }
  131. }
  132. }
  133. </script>
  134. <style scoped>
  135. .zp-container{
  136. /* #ifndef APP-NVUE */
  137. display: flex;
  138. /* #endif */
  139. align-items: center;
  140. justify-content: center;
  141. }
  142. .zp-container-fixed {
  143. /* #ifndef APP-NVUE */
  144. position: absolute;
  145. top: 0;
  146. left: 0;
  147. width: 100%;
  148. height: 100%;
  149. /* #endif */
  150. /* #ifdef APP-NVUE */
  151. flex: 1;
  152. /* #endif */
  153. }
  154. .zp-main{
  155. /* #ifndef APP-NVUE */
  156. display: flex;
  157. /* #endif */
  158. flex-direction: column;
  159. align-items: center;
  160. padding: 50rpx 0rpx;
  161. }
  162. .zp-main-image-rpx {
  163. width: 240rpx;
  164. height: 240rpx;
  165. }
  166. .zp-main-image-px {
  167. width: 120px;
  168. height: 120px;
  169. }
  170. .zp-main-title {
  171. color: #aaaaaa;
  172. text-align: center;
  173. }
  174. .zp-main-title-rpx {
  175. font-size: 28rpx;
  176. margin-top: 10rpx;
  177. padding: 0rpx 20rpx;
  178. }
  179. .zp-main-title-px {
  180. font-size: 14px;
  181. margin-top: 5px;
  182. padding: 0px 10px;
  183. }
  184. .zp-main-error-btn {
  185. border: solid 1px #dddddd;
  186. color: #aaaaaa;
  187. }
  188. .zp-main-error-btn-rpx {
  189. font-size: 28rpx;
  190. padding: 8rpx 24rpx;
  191. border-radius: 6rpx;
  192. margin-top: 50rpx;
  193. }
  194. .zp-main-error-btn-px {
  195. font-size: 14px;
  196. padding: 4px 12px;
  197. border-radius: 3px;
  198. margin-top: 25px;
  199. }
  200. </style>