index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const app = getApp()
  2. import {
  3. getBannerList
  4. } from '~/api/global'
  5. import share from '~/mixins/share'
  6. import {
  7. getSelfRead
  8. } from '~/api/user'
  9. import {
  10. getFollowWorks
  11. } from '~/api/works'
  12. import reachBottom from '~/mixins/reachBottom'
  13. Page({
  14. behaviors: [reachBottom, share],
  15. data: {
  16. navBarHeight: app.globalData.navBarHeight,
  17. bannerList: [],
  18. // 1关注的人的作品,2是自己的作品
  19. currentType: '1',
  20. isFixed: false
  21. },
  22. onShow() {
  23. if (typeof this.getTabBar === 'function') {
  24. this.getTabBar().setData({
  25. selected: 2
  26. })
  27. }
  28. let uid = wx.getStorageSync('uid')
  29. if (uid) {
  30. this.resetData()
  31. } else {
  32. getApp().callBack = (res) => {
  33. this.resetData()
  34. }
  35. }
  36. },
  37. loadMore() {
  38. if (this.data.currentType == '1') {
  39. this.getData(getFollowWorks, {})
  40. } else if (this.data.currentType == '2') {
  41. this.getData(getSelfRead, {})
  42. }
  43. },
  44. async getFollowWorks() {
  45. let res = await getFollowWorks()
  46. console.log(res);
  47. },
  48. changeType({
  49. target
  50. }) {
  51. if (target.dataset.type) {
  52. this.setData({
  53. currentType: target.dataset.type
  54. })
  55. this.resetData()
  56. }
  57. },
  58. /**
  59. * 监听页面滚动事件
  60. */
  61. onPageScroll(e) {
  62. if (e.scrollTop >= 110 && !this.data.isFixed) {
  63. this.setData({
  64. isFixed: true
  65. })
  66. } else if (e.scrollTop < 110 && this.data.isFixed) {
  67. this.setData({
  68. isFixed: false
  69. })
  70. }
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom() {
  76. this.loadMore()
  77. },
  78. })