index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {
  2. getMyInfo,
  3. getVipInfo,
  4. getLearnCard
  5. } from '~/api/user'
  6. import {
  7. createStoreBindings
  8. } from 'mobx-miniprogram-bindings'
  9. import {
  10. store
  11. } from '~/store/index'
  12. const app = getApp()
  13. Page({
  14. data: {
  15. userInfo: {},
  16. vipTime: '',
  17. tasks: [],
  18. isIos: app.globalData.isIOS,
  19. activationModal: false,
  20. activationRes: {}
  21. },
  22. onLoad() {
  23. // 手工绑定
  24. this.storeBindings = createStoreBindings(this, {
  25. store,
  26. actions: {
  27. setUser: 'setUser'
  28. }
  29. })
  30. },
  31. async onShow() {
  32. if (typeof this.getTabBar === 'function') {
  33. this.getTabBar().setData({
  34. selected: 4
  35. })
  36. }
  37. let uid = wx.getStorageSync('uid') || ''
  38. if (!uid) {
  39. getApp().callBack = (res) => {
  40. this.setUserInfo()
  41. }
  42. } else {
  43. this.setUserInfo()
  44. }
  45. },
  46. // 设置用户信息及vip状态
  47. async setUserInfo() {
  48. let userInfo = await getMyInfo()
  49. let vipTime = await getVipInfo()
  50. this.setUser(userInfo.user)
  51. this.setData({
  52. userInfo,
  53. vipTime,
  54. })
  55. },
  56. activationCode() {
  57. wx.showModal({
  58. title: '请输入激活码',
  59. editable: true,
  60. success: async ({
  61. content
  62. }) => {
  63. if (content.trim()) {
  64. let activationRes = await getLearnCard({
  65. cardNo: content
  66. })
  67. console.log(activationRes);
  68. if (typeof this.getTabBar === 'function') {
  69. this.getTabBar().setData({
  70. mask: true
  71. })
  72. }
  73. this.setData({
  74. activationModal: true,
  75. activationRes
  76. })
  77. }
  78. /* */
  79. }
  80. })
  81. },
  82. jump({
  83. currentTarget
  84. }) {
  85. let url = currentTarget.dataset.url
  86. wx.navigateTo({
  87. url: url
  88. });
  89. },
  90. clipboar() {
  91. wx.setClipboardData({
  92. data: this.data.userInfo.user.eid,
  93. success: function (res) { //成功回调函数
  94. wx.showToast({
  95. title: '已复制',
  96. icon: "none"
  97. })
  98. }
  99. })
  100. },
  101. closeModal() {
  102. this.setData({
  103. activationModal: false
  104. })
  105. if (typeof this.getTabBar === 'function') {
  106. this.getTabBar().setData({
  107. mask: false
  108. })
  109. }
  110. },
  111. // 分享配置
  112. onShareAppMessage: function (res) {
  113. return {
  114. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  115. path: '/pages/index/index',
  116. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  117. }
  118. },
  119. onShareTimeline: function () {
  120. return {
  121. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  122. query: `uid=${wx.getStorageSync('uid')}`,
  123. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  124. }
  125. },
  126. })