index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view>
  3. <view class="logo_box">
  4. <image src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/logo2.jpg" class="logo_image"></image>
  5. </view>
  6. <view class="login_content">
  7. <!-- #ifdef MP-WEIXIN -->
  8. <button open-type="getPhoneNumber" @getphonenumber="getPhonenumber" class="get_phone">授权登录</button>
  9. <!-- #endif -->
  10. <!-- #ifdef H5 -->
  11. <button @click="toPhoneLogin" class="get_phone">授权登录</button>
  12. <!-- #endif -->
  13. <!-- #ifdef MP-TOUTIAO -->
  14. <view>
  15. <button @click="toutiao_login" class="get_phone">抖音用户手机号授权登录</button>
  16. <!-- <button class="get_phone" style="margin-top: 40rpx; background-color: #fff; color: #333">手机号验证登录</button> -->
  17. <view class="policy_content">
  18. <image
  19. class="checkbox"
  20. @click="changeAgreePolicy"
  21. :src="agreePolicy ? 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checked.png' : 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checkbox.png'"
  22. ></image>
  23. 我已阅读并同意
  24. <navigator url="/pages/policy/index" style="color: #e03519">《服务协议》</navigator>
  25. </view>
  26. </view>
  27. <!-- #endif -->
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. agreePolicy: false,
  36. };
  37. },
  38. methods: {
  39. changeAgreePolicy() {
  40. this.agreePolicy = !this.agreePolicy;
  41. },
  42. methods: {
  43. getPhonenumber(re) {
  44. // // 如果授权失败的话
  45. if (re.detail.errMsg != "getPhoneNumber:ok") {
  46. uni.showToast({
  47. icon: "error",
  48. title: "授权失败",
  49. });
  50. return;
  51. }
  52. let share_uid = "";
  53. share_uid = uni.getStorageSync("share_uid");
  54. // 授权成功以后,调用登录
  55. this.$http.request("api/wechat/phone_number", { code: re.detail.code, share_uid: share_uid }, "post").then((re) => {
  56. // 成功的话
  57. if (re.code == "success") {
  58. // 存储登录标识
  59. uni.setStorageSync("userLogin", re.data);
  60. // 跳转到页面
  61. uni.switchTab({ url: "/pages/user/index" });
  62. } else {
  63. uni.showToast({
  64. title: re.msg,
  65. icon: "none",
  66. });
  67. }
  68. });
  69. },
  70. toPhoneLogin(re) {
  71. // 登录效果
  72. this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
  73. // 成功的话
  74. if (re.code == "success") {
  75. // 存储登录标识
  76. uni.setStorageSync("userLogin", re.data);
  77. // 跳转到页面
  78. uni.switchTab({ url: "/pages/user/index" });
  79. } else {
  80. uni.showToast({
  81. title: re.msg,
  82. icon: "none",
  83. });
  84. }
  85. });
  86. return;
  87. },
  88. },
  89. getPhonenumber(re) {
  90. // // 如果授权失败的话
  91. if (re.detail.errMsg != "getPhoneNumber:ok") {
  92. uni.showToast({
  93. icon: "error",
  94. title: "授权失败",
  95. });
  96. return;
  97. }
  98. // 授权成功以后,调用登录
  99. this.$http.request("api/wechat/phone_number", { code: re.detail.code }, "post").then((re) => {
  100. // 成功的话
  101. if (re.code == "success") {
  102. // 存储登录标识
  103. uni.setStorageSync("userLogin", re.data);
  104. // 跳转到页面
  105. uni.switchTab({ url: "/pages/user/index" });
  106. } else {
  107. uni.showToast({
  108. title: re.msg,
  109. icon: "none",
  110. });
  111. }
  112. });
  113. },
  114. toPhoneLogin(re) {
  115. // 登录效果
  116. this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
  117. // 成功的话
  118. if (re.code == "success") {
  119. // 存储登录标识
  120. uni.setStorageSync("userLogin", re.data);
  121. // 跳转到页面
  122. uni.switchTab({ url: "/pages/user/index" });
  123. } else {
  124. uni.showToast({
  125. title: re.msg,
  126. icon: "none",
  127. });
  128. }
  129. });
  130. },
  131. },
  132. };
  133. </script>
  134. <style lang="less">
  135. .logo_box {
  136. display: block;
  137. margin: 0rpx auto;
  138. margin-top: 80rpx;
  139. .logo_image {
  140. width: 320rpx;
  141. height: 320rpx;
  142. display: block;
  143. margin: 0rpx auto;
  144. }
  145. }
  146. .login_content {
  147. padding: 0 40px;
  148. .policy_content {
  149. margin-top: 40rpx;
  150. font-size: 26rpx;
  151. display: flex;
  152. align-items: center;
  153. .checkbox {
  154. width: 40rpx;
  155. height: 40rpx;
  156. }
  157. }
  158. }
  159. .get_phone {
  160. display: block;
  161. width: 100%;
  162. height: 80rpx;
  163. color: #ffffff;
  164. font-size: 28rpx;
  165. background: green;
  166. margin: 0rpx auto;
  167. line-height: 80rpx;
  168. margin-top: 160rpx;
  169. border-radius: 30rpx;
  170. border: 0rpx solid #dddddd;
  171. }
  172. .get_phone::after {
  173. border: 0rpx solid #dddddd;
  174. }
  175. </style>