login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div id="index_login_container" class="animation-slide-right">
  3. <view class=" text-xl padding text-center">
  4. <text class=" text-bold title_color">欢迎来到水母星球!</text>
  5. </view>
  6. <view class="text-df text-center slogen">在此将会体验到操控专注力的神奇感觉</view>
  7. <div class="sub_slogen text-center">
  8. 现在,开始您的专注力旅程吧!
  9. </div>
  10. <div class="text-center padding-lr padding-top">
  11. <button class="cu-btn lg cu-btn-primary text-white text-center" @click="to_regist(0)" v-if="is_scan">注册</button>
  12. <button class="cu-btn lg cu-btn-primary text-white text-center" @click="to_scan" v-else>扫一扫加入水母星球</button>
  13. </div>
  14. <view class="text-center slogen_title">
  15. <text class="text-gray">如果您在我们实体店,请在店员的指导下连接水母智脑环</text>
  16. </view>
  17. <view class="text-center text-lg padding-lr" @click="to_regist(1)">
  18. <text class="text-gray under_line">账号登录</text>
  19. </view>
  20. <van-toast id="van-toast"/>
  21. <van-dialog id="van-dialog"/>
  22. <!-- <official-account @load="official_success"></official-account>-->
  23. </div>
  24. </template>
  25. <script>
  26. import Toast from '../../../static/vant/toast/toast';
  27. import Dialog from '../../../static/vant/dialog/dialog';
  28. import user_store from '@/store/index'
  29. import {userCheckInvite} from "../../requests/user";
  30. var $this
  31. export default {
  32. name: "login_container",
  33. data() {
  34. return {
  35. is_scan: false
  36. }
  37. },
  38. methods: {
  39. to_regist($status) {
  40. this.$emit('changeStatus', 'regist')
  41. this.$emit('changeTitle', $status)
  42. },
  43. to_scan() {
  44. wx.scanCode({
  45. onlyFromCamera: true,
  46. success(res) {
  47. let $data = res;
  48. if ($data.result) {
  49. let url = decodeURIComponent($data.result);
  50. let $code = url.match(/\?code=(.*)/);
  51. // 邀请码
  52. let $invite_code = $code[1]
  53. $this.do_invite_code($invite_code)
  54. }
  55. }
  56. })
  57. },
  58. //统一处理邀请码的方法
  59. do_invite_code($code) {
  60. $this.is_scan = true
  61. wx.login({
  62. success(res1) {
  63. let $js_code = res1.code
  64. console.log($js_code)
  65. userCheckInvite($code, $js_code).then((res) => {
  66. let $res = res.data;
  67. if ($res.code != 0) {
  68. Toast.fail($res.errmsg)
  69. }
  70. })
  71. }
  72. })
  73. user_store.setters.set_invite_code($code)
  74. },
  75. official_success($e) {
  76. console.log('关注组件加载成功', $e)
  77. }
  78. },
  79. mounted() {
  80. console.log(1)
  81. },
  82. onLoad(options) {
  83. let $this = this
  84. // 原有的code
  85. let $_code = wx.getStorageSync('code')
  86. if (options.q) {
  87. let url = decodeURIComponent(options.q)
  88. let $code = url.match(/\?code=(.*)/)[1];
  89. $this.do_invite_code($code)
  90. console.log('1---' + $_code, '2---' + $code)
  91. //判断新的code 和 旧的code 是否一致 不一致则重新登录
  92. if ($_code && $_code != $code) {
  93. Toast.fail('该用户已绑定邀请码')
  94. }
  95. }
  96. // 测试注释
  97. else {
  98. // 跳转到关于水母页面
  99. //设置是否扫码
  100. $this.is_scan = false
  101. Dialog.alert({
  102. transition: 'fade',
  103. message: '如需体验水母星球产品,请使用微信扫一扫水母星球邀请卡,注册水母星球会员',
  104. theme: 'round-button',
  105. })
  106. }
  107. },
  108. created() {
  109. $this = this
  110. }
  111. }
  112. </script>
  113. <style>
  114. .sub_slogen {
  115. font-size: 22px;
  116. margin-top: 110px;
  117. color: #4c4c4c;
  118. }
  119. /*扫码页*/
  120. .sub_slogen_sm {
  121. font-size: 15px;
  122. margin: 120px auto 0px;
  123. color: #4c4c4c;
  124. }
  125. .slogen_title {
  126. font-size: 11px;
  127. padding: 8px 0px;
  128. }
  129. </style>