guide.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="flex-column">
  3. <!-- 标题 -->
  4. <view class="top">
  5. <view class="YS-title" style="color: #4169E1;">欢迎您的使用</view>
  6. <view class="YS-subtitle">醍摩豆家长助您孩子成长</view>
  7. </view>
  8. <view class="detail-image" :style="{backgroundImage:`url(${image})`}"></view>
  9. <button class="btn" plain="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取您的孩子信息</button>
  10. <!-- 动画 -->
  11. <view class="ocean"></view>
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. mapState,
  17. mapMutations
  18. } from 'vuex'
  19. //引入解密工具
  20. import WXBizDataCrypt from "@/utils/WXBizDataCrypt.js";
  21. export default {
  22. computed: {
  23. ...mapState('m_parent', ['token', 'parentInfo'])
  24. },
  25. data() {
  26. return {
  27. image: 'https://image.meiye.art/pic_1631411821366jJzYRG2jdJOxwXZk_jz7o',
  28. isClick: false
  29. }
  30. },
  31. methods: {
  32. ...mapMutations('m_parent', ['updateChildrenData', 'updateUserData', 'updatePhoneNumber']),
  33. //获取用户手机号
  34. async getPhoneNumber(e) {
  35. if (this.isClick === false) {
  36. this.isClick = true
  37. if (e.detail.errMsg !== "getPhoneNumber:ok") {
  38. return uni.showToast({
  39. title: '您已拒绝授权',
  40. icon: 'error'
  41. });
  42. } else {
  43. try {
  44. if (this.token) {
  45. let proof = await new WXBizDataCrypt('wx5705da8747c77cfe',
  46. this.token.miniappData.session_key)
  47. let numData = await proof.decryptData(e.detail.encryptedData, e.detail.iv)
  48. this.updatePhoneNumber(numData.phoneNumber)
  49. console.log(numData.phoneNumber);
  50. //初始化App
  51. // await this.$initStart(numData.phoneNumber)
  52. this.$api.getChildrenInfo({
  53. mobile: '17711533106'
  54. }).then(res => {
  55. console.log('返回数据', res);
  56. this.updateChildrenData(res.data.guardian.students)
  57. }).catch(err => {
  58. uni.showToast({
  59. title: '加载数据失败~',
  60. icon: 'error',
  61. })
  62. })
  63. this.$api.getUserData({
  64. phoneNumber: numData.phoneNumber
  65. }).then(res => {
  66. console.log('返回数据', res);
  67. this.updateUserData(res.data)
  68. }).catch(err => {
  69. uni.showToast({
  70. title: '加载数据失败~',
  71. icon: 'error',
  72. })
  73. })
  74. uni.navigateTo({
  75. url: '/subpkg/startup/options'
  76. })
  77. } else {
  78. this.$logOut()
  79. return uni.showToast({
  80. title: '获取不到您的信息请重新登录',
  81. icon: 'error'
  82. });
  83. }
  84. } catch (e) {
  85. this.$logOut()
  86. return uni.showToast({
  87. title: '身份验证已过期请重新登录',
  88. icon: 'error'
  89. });
  90. }
  91. }
  92. this.isClick = false
  93. }
  94. },
  95. },
  96. }
  97. </script>
  98. <style lang="scss">
  99. @import 'startup_pages.scss';
  100. .detail-image {
  101. height: 600rpx;
  102. margin: 400rpx 0 0 0;
  103. background-size: 100% 100%;
  104. }
  105. </style>