empty.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: u.gc('emptyViewStyle', {})
  49. },
  50. // 空数据图容器样式
  51. emptyViewSuperStyle: {
  52. type: Object,
  53. default: u.gc('emptyViewSuperStyle', {})
  54. },
  55. // 空数据图img样式
  56. emptyViewImgStyle: {
  57. type: Object,
  58. default: u.gc('emptyViewImgStyle', {})
  59. },
  60. // 空数据图描述文字样式
  61. emptyViewTitleStyle: {
  62. type: Object,
  63. default: u.gc('emptyViewTitleStyle', {})
  64. },
  65. // 空数据图重新加载按钮样式
  66. emptyViewReloadStyle: {
  67. type: Object,
  68. default: u.gc('emptyViewReloadStyle', {})
  69. },
  70. // 空数据图片是否铺满z-paging,默认为否,即填充满z-paging内列表(滚动区域)部分。若设置为否,则为填铺满整个z-paging
  71. emptyViewFixed: {
  72. type: Boolean,
  73. default: u.gc('emptyViewFixed', false)
  74. },
  75. // 空数据图片是否垂直居中,默认为是,若设置为否即为从空数据容器顶部开始显示。emptyViewFixed为false时有效
  76. emptyViewCenter: {
  77. type: Boolean,
  78. default: u.gc('emptyViewCenter', true)
  79. },
  80. // 加载中时是否自动隐藏空数据图,默认为是
  81. autoHideEmptyViewWhenLoading: {
  82. type: Boolean,
  83. default: u.gc('autoHideEmptyViewWhenLoading', true)
  84. },
  85. // 用户下拉列表触发下拉刷新加载中时是否自动隐藏空数据图,默认为是
  86. autoHideEmptyViewWhenPull: {
  87. type: Boolean,
  88. default: u.gc('autoHideEmptyViewWhenPull', true)
  89. },
  90. // 空数据view的z-index,默认为9
  91. emptyViewZIndex: {
  92. type: Number,
  93. default: u.gc('emptyViewZIndex', 9)
  94. },
  95. },
  96. data() {
  97. return {
  98. customerEmptyViewErrorText: ''
  99. }
  100. },
  101. computed: {
  102. finalEmptyViewImg() {
  103. return this.isLoadFailed ? this.emptyViewErrorImg : this.emptyViewImg;
  104. },
  105. finalShowEmptyViewReload() {
  106. return this.isLoadFailed ? this.showEmptyViewReloadWhenError : this.showEmptyViewReload;
  107. },
  108. // 是否展示空数据图
  109. showEmpty() {
  110. if (this.isOnly || this.hideEmptyView || this.realTotalData.length) return false;
  111. if (this.autoHideEmptyViewWhenLoading) {
  112. if (this.isAddedData && !this.firstPageLoaded && !this.loading) return true;
  113. } else {
  114. return true;
  115. }
  116. return !this.autoHideEmptyViewWhenPull && !this.isUserReload;
  117. },
  118. },
  119. methods: {
  120. // 点击了空数据view重新加载按钮
  121. _emptyViewReload() {
  122. let callbacked = false;
  123. this.$emit('emptyViewReload', reload => {
  124. if (reload === undefined || reload === true) {
  125. this.fromEmptyViewReload = true;
  126. this.reload().catch(() => {});
  127. }
  128. callbacked = true;
  129. });
  130. // 如果用户没有禁止默认的点击重新加载刷新列表事件,则触发列表重新刷新
  131. this.$nextTick(() => {
  132. if (!callbacked) {
  133. this.fromEmptyViewReload = true;
  134. this.reload().catch(() => {});
  135. }
  136. })
  137. },
  138. // 点击了空数据view
  139. _emptyViewClick() {
  140. this.$emit('emptyViewClick');
  141. },
  142. }
  143. }