myFavor.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Component({
  2. data: {
  3. pageToken: 0,
  4. favorData: []
  5. },
  6. lifetimes: {
  7. ready: function () {
  8. wx.showLoading({
  9. title: "加载中"
  10. })
  11. wx.cloud.callFunction({
  12. name: 'listMessages',
  13. data: {
  14. favorite: true,
  15. page_token: this.data.pageToken,
  16. page_size: 20
  17. }
  18. }).then(res => {
  19. wx.hideLoading()
  20. if (res.result.status !== 'OK') {
  21. wx.showToast({
  22. title: res.result.errMsg,
  23. icon: 'none'
  24. })
  25. return
  26. }
  27. this.setData({
  28. favorData: this.data.favorData.concat(res.result.list),
  29. pageToken: res.result.next_page_token
  30. })
  31. })
  32. // const db = wx.cloud.database()
  33. // db.collection("likeData").where({
  34. // type: "message"
  35. // }).get({
  36. // success: function (res) {
  37. // if (res.data.length == 0) {
  38. // wx.hideLoading()
  39. // return
  40. // }
  41. // this.processData(res.data)
  42. // }.bind(this)
  43. // })
  44. }
  45. },
  46. methods: {
  47. processData: function (arr) {
  48. const db = wx.cloud.database()
  49. for (let i = 0; i < arr.length; i++) {
  50. db.collection("mainData").doc(arr[i].id).get({
  51. success: function (res) {
  52. arr[i].publisherAvatar = res.data.publisherAvatar
  53. arr[i].publisherName = res.data.publisherName
  54. arr[i].title = res.data.title
  55. arr[i].subTitle = res.data.subTitle
  56. this.setData({
  57. newNews: arr
  58. })
  59. wx.hideLoading()
  60. }.bind(this)
  61. })
  62. }
  63. }
  64. }
  65. })