login.vue 4.4 KB

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