login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. if (url.indexOf("jellyfish") != -1) {
  67. Toast.fail("请先登录");
  68. return false;
  69. } else {
  70. // 邀请码
  71. let $invite_code = $code[1];
  72. $this.do_invite_code($invite_code);
  73. }
  74. }
  75. },
  76. });
  77. },
  78. //统一处理邀请码的方法
  79. do_invite_code($code) {
  80. $this.is_scan = true;
  81. wx.login({
  82. success(res1) {
  83. let $js_code = res1.code;
  84. console.log($js_code);
  85. userCheckInvite($code, $js_code).then((res) => {
  86. let $res = res.data;
  87. if ($res.code != 0) {
  88. Toast.fail($res.errmsg);
  89. }
  90. });
  91. },
  92. });
  93. user_store.setters.set_invite_code($code);
  94. },
  95. official_success($e) {
  96. console.log("关注组件加载成功", $e);
  97. },
  98. onClickHide() {
  99. $this.official_show = false;
  100. },
  101. },
  102. mounted() {
  103. mpvue.login({
  104. success($res) {
  105. let $js_code = $res.code;
  106. user_store.setters.setJsCode($js_code);
  107. //检验js_code
  108. userCheckUnionid($js_code).then((res) => {
  109. let $res = res.data;
  110. let $data = $res.data;
  111. $this.official_show = $data["have_unionid"] == 2;
  112. });
  113. },
  114. });
  115. },
  116. onLoad(options) {
  117. let $this = this;
  118. // 原有的code
  119. let $_code = wx.getStorageSync("code");
  120. if (options.q) {
  121. let url = decodeURIComponent(options.q);
  122. let $code = url.match(/\?code=(.*)/)[1];
  123. $this.do_invite_code($code);
  124. console.log("1---" + $_code, "2---" + $code);
  125. //判断新的code 和 旧的code 是否一致 不一致则重新登录
  126. if ($_code && $_code != $code) {
  127. Toast.fail("该用户已绑定邀请码");
  128. }
  129. }
  130. // 测试注释
  131. else {
  132. // 跳转到关于水母页面
  133. //设置是否扫码
  134. $this.is_scan = false;
  135. Dialog.alert({
  136. transition: "fade",
  137. message:
  138. "如需体验水母星球产品,请使用微信扫一扫水母星球邀请卡,注册水母星球会员",
  139. theme: "round-button",
  140. });
  141. }
  142. },
  143. created() {
  144. $this = this;
  145. },
  146. };
  147. </script>
  148. <style>
  149. .sub_slogen {
  150. font-size: 22px;
  151. margin-top: 110px;
  152. color: #4c4c4c;
  153. }
  154. /*扫码页*/
  155. .sub_slogen_sm {
  156. font-size: 15px;
  157. margin: 120px auto 0px;
  158. color: #4c4c4c;
  159. }
  160. .slogen_title {
  161. font-size: 11px;
  162. padding: 8px 0px;
  163. }
  164. .official_container {
  165. width: 300px;
  166. margin: auto;
  167. margin-top: 300px;
  168. }
  169. </style>