index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {
  2. getUserInfo,
  3. getVipInfo
  4. } from '~/api/user'
  5. import {
  6. getProducts,
  7. getTasks,
  8. submitTask
  9. } from '~/api/global'
  10. import {
  11. getOpenidNoLogin
  12. } from '~/utils/httpUtilNoLogin';
  13. let app = getApp()
  14. Page({
  15. data: {
  16. userInfo: {},
  17. vipTime: '',
  18. isIos: false,
  19. tasks: [],
  20. // isIos: app.globalData.isIOS,
  21. productNum: {},
  22. productVip: {}
  23. },
  24. onLoad() {
  25. this.getProducts()
  26. },
  27. async onShow() {
  28. let uid = wx.getStorageSync('uid') || ''
  29. // 没登陆先走静默登录,登录后直接获取用户信息
  30. if (!uid) {
  31. getOpenidNoLogin(async () => {
  32. this.setUserInfo()
  33. })
  34. } else {
  35. this.setUserInfo()
  36. }
  37. },
  38. // 设置用户信息及vip状态和任务完成情况
  39. async setUserInfo() {
  40. let userInfo = await getUserInfo()
  41. let vipTime = await getVipInfo()
  42. this.getTasks()
  43. this.setData({
  44. userInfo,
  45. vipTime,
  46. })
  47. console.log(userInfo);
  48. // 如果用户没有头像及昵称的话就提醒获取
  49. if (!userInfo.user.avatar && !userInfo.user.wechatName) {
  50. wx.navigateTo({
  51. url: `/pages/login/login`
  52. });
  53. }
  54. },
  55. async getTasks() {
  56. let tasks = await getTasks()
  57. this.setData({
  58. tasks
  59. })
  60. },
  61. async getProducts() {
  62. let products = await getProducts()
  63. let productVip = products.find(item => {
  64. return item.type == 1
  65. })
  66. let productNum = products.find(item => {
  67. return item.type == 2
  68. })
  69. this.setData({
  70. productNum,
  71. productVip
  72. })
  73. },
  74. // 支付
  75. toPay({
  76. currentTarget
  77. }) {
  78. let type = currentTarget.dataset.type
  79. },
  80. // 提交任务
  81. async submitTask({
  82. currentTarget
  83. }) {
  84. let id = currentTarget.dataset.type
  85. await submitTask({
  86. id
  87. })
  88. wx.showToast({
  89. title: id == '1' ? '签到成功!' : id == 3 ? "观看成功!" : "",
  90. icon: "none"
  91. })
  92. this.getTasks()
  93. },
  94. jump({
  95. currentTarget
  96. }) {
  97. let url = currentTarget.dataset.url
  98. wx.navigateTo({
  99. url: url
  100. });
  101. },
  102. switcher({
  103. currentTarget
  104. }) {
  105. wx.reLaunch({
  106. url: `/pages/index/index?tabbarIndx=${currentTarget.dataset.index}`
  107. });
  108. },
  109. // 调起广告
  110. rewardedVideo() {
  111. if (this.data.tasks.length != 3 || this.data.tasks[2].completed) {
  112. return
  113. }
  114. this.selectComponent('#advert').rewardedVideo();
  115. },
  116. /* showShare() {
  117. this.selectComponent('#shareSelect').showModal()
  118. }, */
  119. // 分享配置
  120. onShareAppMessage: function (res) {
  121. const user = wx.getStorageSync('user');
  122. console.log(`/pages/index/index?sid=${user.uid}`);
  123. return {
  124. title: `邀请你一起来朗读课文`,
  125. path: `/pages/index/index?uid=${user.uid}`,
  126. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
  127. }
  128. },
  129. })