index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. let regexp = /^[a-zA-Z0-9]{4}$/
  64. if (regexp.test(content)) {
  65. let activationRes = await getLearnCard({
  66. cardNo: content
  67. })
  68. console.log(activationRes);
  69. if (typeof this.getTabBar === 'function') {
  70. this.getTabBar().setData({
  71. mask: true
  72. })
  73. }
  74. this.setData({
  75. activationModal: true,
  76. activationRes
  77. })
  78. } else {
  79. if (typeof this.getTabBar === 'function') {
  80. this.getTabBar().setData({
  81. mask: true
  82. })
  83. }
  84. this.setData({
  85. activationModal: true,
  86. activationRes: {
  87. code: 581,
  88. message: '请检查激活码输入是否正确'
  89. }
  90. })
  91. }
  92. }
  93. })
  94. },
  95. jump({
  96. currentTarget
  97. }) {
  98. let url = currentTarget.dataset.url
  99. wx.navigateTo({
  100. url: url
  101. });
  102. },
  103. clipboar() {
  104. wx.setClipboardData({
  105. data: this.data.userInfo.user.eid,
  106. success: function (res) { //成功回调函数
  107. wx.showToast({
  108. title: '已复制',
  109. icon: "none"
  110. })
  111. }
  112. })
  113. },
  114. closeModal() {
  115. this.setData({
  116. activationModal: false
  117. })
  118. if (typeof this.getTabBar === 'function') {
  119. this.getTabBar().setData({
  120. mask: false
  121. })
  122. }
  123. },
  124. // 分享配置
  125. onShareAppMessage: function (res) {
  126. return {
  127. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  128. path: '/pages/index/index',
  129. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  130. }
  131. },
  132. onShareTimeline: function () {
  133. return {
  134. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  135. query: `uid=${wx.getStorageSync('uid')}`,
  136. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  137. }
  138. },
  139. })