Sfoglia il codice sorgente

ADD

搜索分页功能
RegMs If 4 anni fa
parent
commit
78fdb2dce4
2 ha cambiato i file con 41 aggiunte e 2 eliminazioni
  1. 39 1
      miniprogram/pages/search/search.js
  2. 2 1
      miniprogram/pages/search/search.wxml

+ 39 - 1
miniprogram/pages/search/search.js

@@ -14,7 +14,9 @@ Page({
     searchText: '',
     hotTagData: [],
     hotBarData: [],
+    pageToken: 0,
     searchResult: [],
+    loading: false,
     searchHistory: []
   },
 
@@ -98,7 +100,43 @@ Page({
         res.result.list[i] = util.dbToMsg(res.result.list[i])
       }
       this.setData({
-        searchResult: res.result.list
+        searchResult: res.result.list,
+        pageToken: res.result.next_page_token
+      })
+    })
+  },
+
+  loadMore: function () {
+    if (this.data.loading) {
+      return
+    }
+    this.setData({
+      loading: true
+    })
+    wx.showNavigationBarLoading()
+    wx.cloud.callFunction({
+      name: 'listMessages',
+      data: {
+        keyword: this.data.searchText,
+        page_token: this.data.pageToken,
+        page_size: 20
+      }
+    }).then(res => {
+      wx.hideNavigationBarLoading()
+      if (res.result.status !== 'OK') {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+        return
+      }
+      for (let i = 0; i < res.result.list.length; i++) {
+        res.result.list[i] = util.dbToMsg(res.result.list[i])
+      }
+      this.setData({
+        searchResult: this.data.searchResult.concat(res.result.list),
+        pageToken: res.result.next_page_token,
+        loading: false
       })
     })
   },

+ 2 - 1
miniprogram/pages/search/search.wxml

@@ -38,7 +38,8 @@
   </view>
 </scroll-view>
 
-<scroll-view wx:if="{{searchEnable}}" class="search-block secondary-background-color" scroll-y bindtap="blur">
+<scroll-view wx:if="{{searchEnable}}" class="search-block secondary-background-color" scroll-y bindtap="blur"
+  bindscrolltolower="loadMore">
   <view class="result-bar">
     <view wx:for="{{searchResult}}" wx:for-item="msg" wx:key="_id">
       <itemCard item="{{msg}}" />