index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const app = getApp()
  2. import {
  3. getHotrecommendList
  4. } from "~/api/works"
  5. import reachBottom from '~/mixins/reachBottom'
  6. import {
  7. createStoreBindings
  8. } from 'mobx-miniprogram-bindings'
  9. import {
  10. store
  11. } from '~/store/index'
  12. Page({
  13. behaviors: [reachBottom],
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  19. currentType: '1'
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onShow() {
  25. if (typeof this.getTabBar === 'function') {
  26. this.getTabBar().setData({
  27. selected: 1
  28. })
  29. }
  30. getApp().callBack = (res) => {
  31. this.storeBindings = createStoreBindings(this, {
  32. store,
  33. fields: {
  34. userInfo: 'userInfo'
  35. },
  36. })
  37. this.storeBindings.updateStoreBindings()
  38. this.loadMore()
  39. }
  40. },
  41. onUnload() {
  42. this.storeBindings.destroyStoreBindings()
  43. },
  44. loadMore() {
  45. this.getData(getHotrecommendList, {
  46. grade: this.data.userInfo.grade
  47. })
  48. },
  49. onReachBottom() {
  50. console.log('触底');
  51. this.loadMore()
  52. },
  53. selectType({
  54. target
  55. }) {
  56. if (target.dataset.type) {
  57. this.setData({
  58. currentType: target.dataset.type
  59. })
  60. }
  61. },
  62. })