index.js 3.7 KB

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