riku
2022-10-17 eb7366f400867d3f401fe60f06d848d6d1448457
base/behaviors/b_loadingStatus.js
@@ -1,22 +1,37 @@
/**
 * 数据加载监听
 * 数据加载状态监听
 * @see './b_loadingToast.js' 和 '../../component/loadingstatus'
 */
module.exports = Behavior({
  data: {
    cPage: 1,
    tPage: 1,
    perPage: 10,
    totalCount: 0,
    loading: false,
    needLoadMore: false
    needLoadMore: false,
    timeout: false
  },
  timeoutId: '',
  lastLoading: false,
  observers: {
    'loading': function (loading) {
      if (this.lastLoading == loading) return
      if (loading) {
        clearTimeout(this.timeoutId)
        this._loadStart()
        this._loading()
        this.timeoutId = setTimeout(() => {
          this.setData({
            loading: false,
            timeout: true
          })
        }, 10000);
      } else {
        clearTimeout(this.timeoutId)
        this._loadComplete()
      }
      this.lastLoading = loading
    },
    'cPage, tPage': function (cPage, tPage) {
      this.setData({
@@ -31,7 +46,7 @@
  },
  methods: {
    _onReachBottom() {
      console.log('_onReachBottom');
      // console.log('_onReachBottom');
      let {cPage, tPage, loading} = this.data
      if (!loading && cPage < tPage) {
        if (typeof this.loadmore === 'function') {
@@ -59,6 +74,6 @@
      if (typeof this.loadComplete === 'function') {
        this.loadComplete()
      }
    }
    },
  }
})