login.vue 4.2 KB

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