login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view>
  3. <view class="login-wrap">
  4. <view class="logo"><image src="../../static/logo.png"></image></view>
  5. <view class="wechat-title">微信授权登录</view>
  6. <view class="wechat-desc">获得您的公开信息,以便为您提供更好的服务</view>
  7. <!-- <view class="wechat-login-btn" @click="onWxMiniLogin">授权登录</view> -->
  8. <button class="wechat-login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号码一键登录</button>
  9. <!-- <view class="wechat-go-home" @click="onGoHome">暂不登录</view> -->
  10. <view class="agreement-box" style="width: 80%;">
  11. <view class="agreement-text agree-text" @click="checkboxChange">
  12. <checkbox-group>
  13. <checkbox class="protocol-check" :checked="protocol"></checkbox>我已阅读并遵守
  14. <view class="agree-text">
  15. <view @click.stop="goRead">《用户协议与隐私政策》</view>
  16. </view>
  17. </checkbox-group>
  18. </view>
  19. </view>
  20. </view>
  21. <loading v-if="isSubmit" :layer="true"></loading>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. isSubmit:false,
  29. protocol: false,
  30. options:null,
  31. params:{
  32. code:null,
  33. encryptedData:null,
  34. iv:null,
  35. }
  36. }
  37. },
  38. onLoad(option) {
  39. this.options=option.item
  40. },
  41. methods: {
  42. getPhoneNumber(e){
  43. this.isSubmit = true;
  44. if(!this.protocol){
  45. this.isSubmit = false;
  46. this.$utils.msg("请同意用户协议");
  47. return ;
  48. }
  49. let that=this
  50. if(e.detail.errMsg == "getPhoneNumber:ok" && that.params.code){
  51. that.params.encryptedData=e.detail.encryptedData
  52. that.params.iv=e.detail.iv
  53. that.$http.wxLogin(that.params).then(res=>{
  54. if(res.code === 0){
  55. that.$store.commit("UPDATEMOBILE",res.data.mobile);
  56. that.$store.commit("UPDATEUSERS",res.data);
  57. that.$storage.setJson("token",res.data.token)
  58. that.$utils.switchTab('ucenter/index');
  59. that.isSubmit = false;
  60. }else{
  61. that.$utils.msg(res.msg);
  62. }
  63. }).catch(error=>{
  64. that.$utils.msg(error);
  65. });
  66. }
  67. },
  68. onGoHome(){
  69. this.$utils.switchTab("index/index");
  70. },
  71. checkboxChange(e){
  72. let that =this
  73. wx.login({
  74. success(res){
  75. that.params.code=res.code
  76. }
  77. })
  78. this.protocol = !this.protocol;
  79. },
  80. goRead(e){
  81. uni.navigateTo({
  82. url:'/pages/userAgreement/index'
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .agreement-box {
  90. width: 100%;
  91. margin: 30rpx auto 0;
  92. flex-direction: row;
  93. align-items: center;
  94. justify-content: center;
  95. .protocol-check {
  96. position: relative;top:-2px;transform:scale(0.6)
  97. }
  98. .agreement-text {
  99. width: 100%;
  100. font-size: 26rpx;
  101. font-weight: 500;
  102. color: #999999;
  103. .agree-text {
  104. display: inline-block;
  105. color: #2841c2;
  106. view{
  107. display: inline;
  108. }
  109. }
  110. }
  111. }
  112. .login-wrap {
  113. .logo {
  114. text-align: center;
  115. padding-top: 180rpx;
  116. image {
  117. width: 144rpx;
  118. height: 144rpx;
  119. border-radius: 50%;
  120. }
  121. }
  122. .wechat-title {
  123. font-size: 35rpx;
  124. font-weight: 500;
  125. color: #333;
  126. margin-top: 24rpx;
  127. text-align: center;
  128. }
  129. .wechat-desc {
  130. font-size: 28rpx;
  131. font-weight: 500;
  132. color: #999;
  133. margin-top: 24rpx;
  134. text-align: center;
  135. padding: 10rpx 50rpx;
  136. }
  137. .wechat-login-btn {
  138. height: 80rpx; line-height: 80rpx;
  139. color: #fff; background-color: #58be6b;
  140. text-align: center; border-radius: 50rpx;
  141. margin: 50rpx; font-size: 32rpx;
  142. }
  143. .wechat-go-home { text-align: center; font-size: 30rpx; color:#666; }
  144. }
  145. </style>