企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
* 在调用页的json中加入属性 ~~~ "enablePullDownRefresh": true, "backgroundTextStyle": "dark", ~~~ * 页面的初始数据 ~~~ PIN: 1, next: 1, list: [], list_cache: [], down_note: '', loading: 0, ~~~ * onLoad 生命周期函数--监听页面加载 ~~~ this.up(); ~~~ * 页面相关事件处理函数--监听用户下拉动作 ~~~ //>页面相关事件处理函数--监听用户下拉动作 onPullDownRefresh: function () { this.up(); wx.stopPullDownRefresh(); }, ~~~ * 页面上拉触底事件的处理函数 ~~~ //>页面上拉触底事件的处理函数 onReachBottom: function () { this.down(); }, ~~~ * 刷新初始化 ~~~ up(){ if(this.data.loading == 1){ wx.showToast({ title: '加载中,请稍后', icon: 'error', duration: 1000 }); return false; } let arr = {}; arr.PIN = 1; arr.list = []; arr.loading = 1; this.setData(arr); this.load_data(); }, ~~~ * 加载初始化 ~~~ down() { if(this.data.PIN == this.data.next){ let arr = {}; arr.down_note = '我是有底线的~'; this.setData(arr); return false; } if(this.data.loading == 1){ wx.showToast({ title: '加载中,请稍后', icon: 'error', duration: 1000 }); return false; } let arr = {}; arr.PIN = this.data.next; arr.down_note = '加载中'; arr.loading = 1; this.setData(arr); this.load_data(); }, ~~~ * 数据通信 ~~~ load_data() { let that = this; let data = {}; data.u_id = this.data.u_id; data.PIN = this.data.PIN; app.globalData.net('url',data).then(res => { let arr = {}; if(!res.succeed){ arr.loading \= 0; that.setData(arr); return false; } let option = Number(res.option); arr.next = res.next; arr.PIN = res.PIN; arr.list_cache = res.list; res.list.length <= 0 ? arr.down_note = (option == 1 ? '暂无数据' : '我是有底线的~') : null; that.setData(arr); setTimeout(() => { that.load_list(); }, 1000); }); }, ~~~ * 渲染数据 ~~~ load_list(){ let arr = {}; let list_cache = this.data.list_cache; if(list_cache.length <= 0){ this.data.down_note == '暂无数据' ? null : arr.down_note = ''; arr.loading = 0; this.setData(arr); return false; } let list = this.data.list; list.push(list_cache[0]); list_cache.shift(list_cache[0]); arr.list = list; arr.list_cache = list_cache; this.setData(arr); setTimeout(() => { this.load_list(); }, 100); }, ~~~ * 模板 ~~~ <view class="list" wx:for="{{list}}" wx:key="index"> </view> <view class="more" wx:if="{{down_note != ''}}"><view>{{down_note}}</view></view> ~~~