|
|
@@ -1,68 +1,44 @@
|
|
|
-Component({
|
|
|
+const util = require('../../utils/util.js')
|
|
|
+
|
|
|
+Page({
|
|
|
data: {
|
|
|
pageToken: 0,
|
|
|
favorData: []
|
|
|
},
|
|
|
|
|
|
- lifetimes: {
|
|
|
- ready: function () {
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中"
|
|
|
- })
|
|
|
- wx.cloud.callFunction({
|
|
|
- name: 'listMessages',
|
|
|
- data: {
|
|
|
- favorite: true,
|
|
|
- page_token: this.data.pageToken,
|
|
|
- page_size: 20
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- wx.hideLoading()
|
|
|
- if (res.result.status !== 'OK') {
|
|
|
- wx.showToast({
|
|
|
- title: res.result.errMsg,
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- favorData: this.data.favorData.concat(res.result.list),
|
|
|
- pageToken: res.result.next_page_token
|
|
|
+ loadFavoriteData: function () {
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
+ wx.cloud.callFunction({
|
|
|
+ name: 'listMessages',
|
|
|
+ data: {
|
|
|
+ favorite: true,
|
|
|
+ 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({
|
|
|
+ favorData: this.data.favorData.concat(res.result.list),
|
|
|
+ pageToken: res.result.next_page_token
|
|
|
})
|
|
|
+ })
|
|
|
+ },
|
|
|
|
|
|
- // const db = wx.cloud.database()
|
|
|
- // db.collection("likeData").where({
|
|
|
- // type: "message"
|
|
|
- // }).get({
|
|
|
- // success: function (res) {
|
|
|
- // if (res.data.length == 0) {
|
|
|
- // wx.hideLoading()
|
|
|
- // return
|
|
|
- // }
|
|
|
- // this.processData(res.data)
|
|
|
- // }.bind(this)
|
|
|
- // })
|
|
|
- }
|
|
|
+ onLoad: function () {
|
|
|
+ this.loadFavoriteData()
|
|
|
},
|
|
|
|
|
|
- methods: {
|
|
|
- processData: function (arr) {
|
|
|
- const db = wx.cloud.database()
|
|
|
- for (let i = 0; i < arr.length; i++) {
|
|
|
- db.collection("mainData").doc(arr[i].id).get({
|
|
|
- success: function (res) {
|
|
|
- arr[i].publisherAvatar = res.data.publisherAvatar
|
|
|
- arr[i].publisherName = res.data.publisherName
|
|
|
- arr[i].title = res.data.title
|
|
|
- arr[i].subTitle = res.data.subTitle
|
|
|
- this.setData({
|
|
|
- newNews: arr
|
|
|
- })
|
|
|
- wx.hideLoading()
|
|
|
- }.bind(this)
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
+ onReachBottom: function () {
|
|
|
+ this.loadFavoriteData()
|
|
|
}
|
|
|
})
|