index.js 2.4 KB

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