index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. getBannerList
  3. } from '~/api/global'
  4. import {
  5. createStoreBindings
  6. } from 'mobx-miniprogram-bindings'
  7. import {
  8. store
  9. } from '~/store/index'
  10. Page({
  11. data: {
  12. activityList: false,
  13. bannerList: []
  14. },
  15. onShow() {
  16. if (typeof this.getTabBar === 'function') {
  17. this.getTabBar().setData({
  18. selected: 1
  19. })
  20. this.getLocUserInfo()
  21. if (Object.keys(this.data.userInfo).length > 0) {
  22. this.getBannerList()
  23. this.setData({
  24. activityList: true
  25. })
  26. } else {
  27. getApp().callBack = (res) => {
  28. this.getLocUserInfo()
  29. this.getBannerList()
  30. this.setData({
  31. activityList: true
  32. })
  33. }
  34. }
  35. }
  36. },
  37. onHide() {
  38. this.setData({
  39. activityList: false
  40. })
  41. },
  42. async getBannerList() {
  43. let bannerList = await getBannerList({
  44. grade: this.data.userInfo.grade,
  45. })
  46. this.setData({
  47. bannerList,
  48. })
  49. },
  50. resetData() {
  51. this.selectComponent('#activityList').getActivities()
  52. this.getBannerList()
  53. },
  54. async getLocUserInfo() {
  55. this.storeBindings = createStoreBindings(this, {
  56. store,
  57. fields: {
  58. userInfo: 'userInfo'
  59. },
  60. })
  61. this.storeBindings.updateStoreBindings()
  62. },
  63. onUnload() {
  64. this.storeBindings.destroyStoreBindings()
  65. },
  66. })