riku
2026-01-22 f14ea940fb32105de8b592992e3f53c62f31d84d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * 数据加载状态监听
 * @see './bLoadingToast.js' 和 '../../component/loadingstatus'
 */
module.exports = Behavior({
  data: {
    cPage: 1,
    tPage: 1,
    perPage: 10,
    totalCount: 0,
    loading: 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({
        needLoadMore: cPage < tPage
      })
    },
    'reachBottom': function(reachBottom) {
      if (reachBottom) {
        this._onReachBottom()
      }
    },
  },
  methods: {
    _onReachBottom() {
      // console.log('_onReachBottom');
      let {cPage, tPage, loading} = this.data
      if (!loading && cPage < tPage) {
        if (typeof this.loadmore === 'function') {
          this.loadmore(cPage)          
        }
      }
    },
    // 加载开始通知
    _loadStart() {
      this.triggerEvent('loadStart')
      if (typeof this.loadStart === 'function') {
        this.loadStart()
      }
    },
    // 加载中通知
    _loading() {
      this.triggerEvent('loading')
      if (typeof this.loading === 'function') {
        this.loading()
      }
    },
    // 加载完成通知
    _loadComplete() {
      this.triggerEvent('loadComplete')
      if (typeof this.loadComplete === 'function') {
        this.loadComplete()
      }
    },
  }
})