index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {
  2. getActivities,
  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. rankList: [],
  13. },
  14. onLoad(options) {
  15. this.getLocUserInfo()
  16. if (Object.keys(this.data.userInfo).length > 0) {
  17. this.getRankList()
  18. } else {
  19. getApp().callBack = (res) => {
  20. this.getLocUserInfo()
  21. this.getRankList()
  22. }
  23. }
  24. },
  25. onShow() {
  26. if (typeof this.getTabBar === 'function') {
  27. this.getTabBar().setData({
  28. selected: 0
  29. })
  30. }
  31. },
  32. async getRankList() {
  33. let res = await getActivities({
  34. classify: 2,
  35. grade: this.data.userInfo.grade
  36. })
  37. console.log(res);
  38. this.setData({
  39. rankList: res
  40. })
  41. },
  42. async getLocUserInfo() {
  43. this.storeBindings = createStoreBindings(this, {
  44. store,
  45. fields: {
  46. userInfo: 'userInfo'
  47. },
  48. })
  49. this.storeBindings.updateStoreBindings()
  50. },
  51. })