index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. onLoad(options) {
  39. // 获取页面参数
  40. if (options.redirect) {
  41. this.redirect = options.redirect;
  42. this.activity_id = options.activity_id;
  43. }
  44. },
  45. methods: {
  46. changeAgreePolicy() {
  47. this.agreePolicy = !this.agreePolicy;
  48. },
  49. methods: {
  50. getPhonenumber(re) {
  51. // // 如果授权失败的话
  52. if (re.detail.errMsg != "getPhoneNumber:ok") {
  53. uni.showToast({
  54. icon: "error",
  55. title: "授权失败",
  56. });
  57. return;
  58. }
  59. let share_uid = "";
  60. share_uid = uni.getStorageSync("share_uid");
  61. // 授权成功以后,调用登录
  62. this.$http.request("api/wechat/phone_number", { code: re.detail.code, share_uid: share_uid }, "post").then((re) => {
  63. // 成功的话
  64. if (re.code == "success") {
  65. // 存储登录标识
  66. uni.setStorageSync("userLogin", re.data);
  67. // 跳转到页面
  68. if (this.redirect) {
  69. let url = this.redirect;
  70. if (this.activity_id) url = url + "?id=" + this.activity_id;
  71. uni.redirectTo({ url: url });
  72. } else uni.switchTab({ url: "/pages/user/index" });
  73. } else {
  74. uni.showToast({
  75. title: re.msg,
  76. icon: "none",
  77. });
  78. }
  79. });
  80. },
  81. toPhoneLogin(re) {
  82. // 登录效果
  83. this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
  84. // 成功的话
  85. if (re.code == "success") {
  86. // 存储登录标识
  87. uni.setStorageSync("userLogin", re.data);
  88. // 跳转到页面
  89. uni.switchTab({ url: "/pages/user/index" });
  90. } else {
  91. uni.showToast({
  92. title: re.msg,
  93. icon: "none",
  94. });
  95. }
  96. });
  97. return;
  98. },
  99. },
  100. getPhonenumber(re) {
  101. // // 如果授权失败的话
  102. if (re.detail.errMsg != "getPhoneNumber:ok") {
  103. uni.showToast({
  104. icon: "error",
  105. title: "授权失败",
  106. });
  107. return;
  108. }
  109. // 授权成功以后,调用登录
  110. this.$http.request("api/wechat/phone_number", { code: re.detail.code }, "post").then((re) => {
  111. // 成功的话
  112. if (re.code == "success") {
  113. // 存储登录标识
  114. uni.setStorageSync("userLogin", re.data);
  115. // 跳转到页面
  116. if (this.redirect) {
  117. let url = this.redirect;
  118. if (this.activity_id) url = url + "?id=" + this.activity_id;
  119. uni.redirectTo({ url: url });
  120. } else uni.switchTab({ url: "/pages/user/index" });
  121. } else {
  122. uni.showToast({
  123. title: re.msg,
  124. icon: "none",
  125. });
  126. }
  127. });
  128. },
  129. toPhoneLogin(re) {
  130. // 登录效果
  131. this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
  132. // 成功的话
  133. if (re.code == "success") {
  134. // 存储登录标识
  135. uni.setStorageSync("userLogin", re.data);
  136. // 跳转到页面
  137. uni.switchTab({ url: "/pages/user/index" });
  138. } else {
  139. uni.showToast({
  140. title: re.msg,
  141. icon: "none",
  142. });
  143. }
  144. });
  145. },
  146. },
  147. };
  148. </script>
  149. <style lang="less">
  150. .logo_box {
  151. display: block;
  152. margin: 0rpx auto;
  153. margin-top: 80rpx;
  154. .logo_image {
  155. width: 320rpx;
  156. height: 320rpx;
  157. display: block;
  158. margin: 0rpx auto;
  159. }
  160. }
  161. .login_content {
  162. padding: 0 40px;
  163. .policy_content {
  164. margin-top: 40rpx;
  165. font-size: 26rpx;
  166. display: flex;
  167. align-items: center;
  168. .checkbox {
  169. width: 40rpx;
  170. height: 40rpx;
  171. }
  172. }
  173. }
  174. .get_phone {
  175. display: block;
  176. width: 100%;
  177. height: 80rpx;
  178. color: #ffffff;
  179. font-size: 28rpx;
  180. background: green;
  181. margin: 0rpx auto;
  182. line-height: 80rpx;
  183. margin-top: 160rpx;
  184. border-radius: 30rpx;
  185. border: 0rpx solid #dddddd;
  186. }
  187. .get_phone::after {
  188. border: 0rpx solid #dddddd;
  189. }
  190. </style>