empty.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // [z-paging]空数据图view模块
  2. import u from '.././z-paging-utils'
  3. export default {
  4. props: {
  5. //是否强制隐藏空数据图,默认为否
  6. hideEmptyView: {
  7. type: Boolean,
  8. default: u.gc('hideEmptyView', false)
  9. },
  10. //空数据图描述文字,默认为“没有数据哦~”
  11. emptyViewText: {
  12. type: [String, Object],
  13. default: u.gc('emptyViewText', null)
  14. },
  15. //是否显示空数据图重新加载按钮(无数据时),默认为否
  16. showEmptyViewReload: {
  17. type: Boolean,
  18. default: u.gc('showEmptyViewReload', false)
  19. },
  20. //加载失败时是否显示空数据图重新加载按钮,默认为是
  21. showEmptyViewReloadWhenError: {
  22. type: Boolean,
  23. default: u.gc('showEmptyViewReloadWhenError', true)
  24. },
  25. //空数据图点击重新加载文字,默认为“重新加载”
  26. emptyViewReloadText: {
  27. type: [String, Object],
  28. default: u.gc('emptyViewReloadText', null)
  29. },
  30. //空数据图图片,默认使用z-paging内置的图片
  31. emptyViewImg: {
  32. type: String,
  33. default: u.gc('emptyViewImg', '')
  34. },
  35. //空数据图“加载失败”描述文字,默认为“很抱歉,加载失败”
  36. emptyViewErrorText: {
  37. type: [String, Object],
  38. default: u.gc('emptyViewErrorText', null)
  39. },
  40. //空数据图“加载失败”图片,默认使用z-paging内置的图片
  41. emptyViewErrorImg: {
  42. type: String,
  43. default: u.gc('emptyViewErrorImg', '')
  44. },
  45. //空数据图样式
  46. emptyViewStyle: {
  47. type: Object,
  48. default: function() {
  49. return u.gc('emptyViewStyle', {});
  50. }
  51. },
  52. //空数据图容器样式
  53. emptyViewSuperStyle: {
  54. type: Object,
  55. default: function() {
  56. return u.gc('emptyViewSuperStyle', {});
  57. }
  58. },
  59. //空数据图img样式
  60. emptyViewImgStyle: {
  61. type: Object,
  62. default: function() {
  63. return u.gc('emptyViewImgStyle', {});
  64. }
  65. },
  66. //空数据图描述文字样式
  67. emptyViewTitleStyle: {
  68. type: Object,
  69. default: function() {
  70. return u.gc('emptyViewTitleStyle', {});
  71. }
  72. },
  73. //空数据图重新加载按钮样式
  74. emptyViewReloadStyle: {
  75. type: Object,
  76. default: function() {
  77. return u.gc('emptyViewReloadStyle', {});
  78. }
  79. },
  80. //空数据图片是否铺满z-paging,默认为是。若设置为否,则为填充满z-paging的剩余部分
  81. emptyViewFixed: {
  82. type: Boolean,
  83. default: u.gc('emptyViewFixed', false)
  84. },
  85. //空数据图片是否垂直居中,默认为是。emptyViewFixed为false时有效
  86. emptyViewCenter: {
  87. type: Boolean,
  88. default: u.gc('emptyViewCenter', true)
  89. },
  90. //加载中时是否自动隐藏空数据图,默认为是
  91. autoHideEmptyViewWhenLoading: {
  92. type: Boolean,
  93. default: u.gc('autoHideEmptyViewWhenLoading', true)
  94. },
  95. //用户下拉列表触发下拉刷新加载中时是否自动隐藏空数据图,默认为是
  96. autoHideEmptyViewWhenPull: {
  97. type: Boolean,
  98. default: u.gc('autoHideEmptyViewWhenPull', true)
  99. },
  100. //空数据view的z-index,默认为9
  101. emptyViewZIndex: {
  102. type: Number,
  103. default: u.gc('emptyViewZIndex', 9)
  104. },
  105. },
  106. computed: {
  107. finalEmptyViewImg() {
  108. return this.isLoadFailed ? this.emptyViewErrorImg : this.emptyViewImg;
  109. },
  110. finalShowEmptyViewReload() {
  111. return this.isLoadFailed ? this.showEmptyViewReloadWhenError : this.showEmptyViewReload;
  112. },
  113. showEmpty() {
  114. if (this.refresherOnly || this.hideEmptyView || this.totalData.length) return false;
  115. if (this.autoHideEmptyViewWhenLoading) {
  116. if (this.isAddedData && !this.firstPageLoaded && !this.loading) return true;
  117. } else {
  118. return true;
  119. }
  120. if (!this.autoHideEmptyViewWhenPull && !this.isUserReload) return true;
  121. return false;
  122. },
  123. },
  124. methods: {
  125. //点击了空数据view重新加载按钮
  126. _emptyViewReload() {
  127. let callbacked = false;
  128. this.$emit('emptyViewReload', reload => {
  129. if (reload === undefined || reload === true) {
  130. this.fromEmptyViewReload = true;
  131. this.reload();
  132. }
  133. callbacked = true;
  134. });
  135. this.$nextTick(() => {
  136. if (!callbacked) {
  137. this.fromEmptyViewReload = true;
  138. this.reload();
  139. }
  140. })
  141. },
  142. //点击了空数据view
  143. _emptyViewClick() {
  144. this.$emit('emptyViewClick');
  145. },
  146. }
  147. }