loading.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // [z-paging]loading相关模块
  2. import u from '.././z-paging-utils'
  3. import Enum from '.././z-paging-enum'
  4. export default {
  5. props: {
  6. //第一次加载后自动隐藏loading slot,默认为是
  7. autoHideLoadingAfterFirstLoaded: {
  8. type: Boolean,
  9. default: u.gc('autoHideLoadingAfterFirstLoaded', true)
  10. },
  11. //loading slot是否铺满屏幕并固定,默认为否
  12. loadingFullFixed: {
  13. type: Boolean,
  14. default: u.gc('loadingFullFixed', false)
  15. },
  16. //是否自动显示系统Loading:即uni.showLoading,若开启则将在刷新列表时(调用reload、refresh时)显示,下拉刷新和滚动到底部加载更多不会显示,默认为false。
  17. autoShowSystemLoading: {
  18. type: Boolean,
  19. default: u.gc('autoShowSystemLoading', false)
  20. },
  21. //显示系统Loading时是否显示透明蒙层,防止触摸穿透,默认为是(H5、App、微信小程序、百度小程序有效)
  22. systemLoadingMask: {
  23. type: Boolean,
  24. default: u.gc('systemLoadingMask', true)
  25. },
  26. //显示系统Loading时显示的文字,默认为"加载中"
  27. systemLoadingText: {
  28. type: [String, Object],
  29. default: u.gc('systemLoadingText', null)
  30. },
  31. },
  32. data() {
  33. return {
  34. loading: false,
  35. loadingForNow: false,
  36. }
  37. },
  38. watch: {
  39. loadingStatus(newVal) {
  40. this.$emit('loadingStatusChange', newVal);
  41. this.$nextTick(()=>{
  42. this.loadingStatusAfterRender = newVal;
  43. })
  44. // #ifdef APP-NVUE
  45. if (this.useChatRecordMode) {
  46. if (this.pageNo === this.defaultPageNo && newVal === Enum.More.NoMore) {
  47. this.nIsFirstPageAndNoMore = true;
  48. return;
  49. }
  50. }
  51. this.nIsFirstPageAndNoMore = false;
  52. // #endif
  53. },
  54. loading(newVal){
  55. if (newVal) {
  56. this.loadingForNow = newVal;
  57. }
  58. },
  59. },
  60. computed: {
  61. showLoading() {
  62. if (this.firstPageLoaded || !this.loading || !this.loadingForNow) return false;
  63. if (this.finalShowSystemLoading){
  64. uni.showLoading({
  65. title: this.finalSystemLoadingText,
  66. mask: this.systemLoadingMask
  67. })
  68. }
  69. return this.autoHideLoadingAfterFirstLoaded ? (this.fromEmptyViewReload ? true : !this.pagingLoaded) : this.loadingType === Enum.LoadingType.Refresher;
  70. },
  71. finalShowSystemLoading() {
  72. return this.autoShowSystemLoading && this.loadingType === Enum.LoadingType.Refresher;
  73. }
  74. },
  75. methods: {
  76. //处理开始加载更多状态
  77. _startLoading(isReload = false) {
  78. if ((this.showLoadingMoreWhenReload && !this.isUserPullDown) || !isReload) {
  79. this.loadingStatus = Enum.More.Loading;
  80. }
  81. this.loading = true;
  82. },
  83. //停止系统loading和refresh
  84. _endSystemLoadingAndRefresh(){
  85. this.finalShowSystemLoading && uni.hideLoading();
  86. !this.useCustomRefresher && uni.stopPullDownRefresh();
  87. // #ifdef APP-NVUE
  88. this.usePageScroll && uni.stopPullDownRefresh();
  89. // #endif
  90. }
  91. }
  92. }