index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. <button open-type="getPhoneNumber" @getphonenumber="getPhonenumber" class="get_phone">抖音用户手机号授权登录</button>
  15. <!-- <button class="get_phone" style="margin-top: 40rpx; background-color: #fff; color: #333">手机号验证登录</button> -->
  16. <view class="policy_content">
  17. <image
  18. class="checkbox"
  19. @click="changeAgreePolicy"
  20. :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'"
  21. ></image>
  22. 我已阅读并同意
  23. <navigator url="/pages/policy/index" style="color: #f89c33">《服务协议》</navigator>
  24. </view>
  25. <!-- #endif -->
  26. <button class="cancel_login" @click="cancelLogin()">取消登录</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. agreePolicy: false,
  35. };
  36. },
  37. onLoad(options) {
  38. // 获取页面参数
  39. if (options.redirect) {
  40. this.redirect = options.redirect;
  41. this.activity_id = options.activity_id;
  42. this.id = options.id;
  43. }
  44. },
  45. methods: {
  46. changeAgreePolicy() {
  47. this.agreePolicy = !this.agreePolicy;
  48. },
  49. cancelLogin() {
  50. // 返回上一页
  51. uni.navigateBack();
  52. },
  53. getPhonenumber(re) {
  54. // // 如果授权失败的话
  55. if (re.detail.errMsg != 'getPhoneNumber:ok') {
  56. uni.showToast({
  57. icon: 'error',
  58. title: '授权失败',
  59. });
  60. return;
  61. }
  62. // 授权成功以后,调用登录
  63. this.$http.request('api/wechat/phone_number', { code: re.detail.code }, 'post').then((re) => {
  64. // 成功的话
  65. if (re.code == 'success') {
  66. // 存储登录标识
  67. uni.setStorageSync('userLogin', re.data);
  68. // 跳转到页面
  69. if (this.redirect) {
  70. let url = this.redirect;
  71. if (this.activity_id) url = url + '?id=' + this.activity_id;
  72. if (this.id) url = url + '?id=' + this.id;
  73. uni.redirectTo({ url: url });
  74. } else uni.switchTab({ url: '/pages/user/index' });
  75. } else {
  76. uni.showToast({
  77. title: re.msg,
  78. icon: 'none',
  79. });
  80. }
  81. });
  82. },
  83. toPhoneLogin(re) {
  84. // 登录效果
  85. this.$http.request('api/wechat/phone_number', this.requestParam).then((re) => {
  86. // 成功的话
  87. if (re.code == 'success') {
  88. // 存储登录标识
  89. uni.setStorageSync('userLogin', re.data);
  90. // 跳转到页面
  91. uni.switchTab({ url: '/pages/user/index' });
  92. } else {
  93. uni.showToast({
  94. title: re.msg,
  95. icon: 'none',
  96. });
  97. }
  98. });
  99. },
  100. },
  101. };
  102. </script>
  103. <style lang="less">
  104. .logo_box {
  105. display: block;
  106. margin: 0rpx auto;
  107. margin-top: 80rpx;
  108. .logo_image {
  109. width: 320rpx;
  110. height: 320rpx;
  111. display: block;
  112. margin: 0rpx auto;
  113. }
  114. }
  115. .login_content {
  116. padding: 0 40px;
  117. .policy_content {
  118. margin-top: 40rpx;
  119. font-size: 26rpx;
  120. display: flex;
  121. align-items: center;
  122. .checkbox {
  123. width: 40rpx;
  124. height: 40rpx;
  125. }
  126. }
  127. }
  128. .get_phone {
  129. display: block;
  130. width: 100%;
  131. height: 80rpx;
  132. color: #ffffff;
  133. font-size: 28rpx;
  134. background: green;
  135. margin: 0rpx auto;
  136. line-height: 80rpx;
  137. margin-top: 160rpx;
  138. border-radius: 30rpx;
  139. border: 0rpx solid #dddddd;
  140. }
  141. .get_phone::after {
  142. border: 0rpx solid #dddddd;
  143. }
  144. .cancel_login {
  145. display: block;
  146. width: 100%;
  147. height: 80rpx;
  148. color: #666666;
  149. font-size: 28rpx;
  150. background: #dddddd;
  151. margin: 0rpx auto;
  152. line-height: 80rpx;
  153. margin-top: 40rpx;
  154. border-radius: 30rpx;
  155. border: 0rpx solid #dddddd;
  156. }
  157. .cancel_login::after {
  158. border: 0rpx solid #dddddd;
  159. }
  160. </style>