login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. jumpPage:null,
  37. }
  38. },
  39. onShow() {
  40. if(this.$storage.getJson("token")){
  41. this.onGoHome()
  42. }
  43. },
  44. onLoad(option) {
  45. this.options=option.item
  46. if(option.topage){
  47. this.jumpPage=option.topage
  48. }
  49. },
  50. methods: {
  51. getPhoneNumber(e){
  52. this.isSubmit = true;
  53. if(!this.protocol){
  54. this.isSubmit = false;
  55. this.$utils.msg("请同意用户协议");
  56. return ;
  57. }
  58. let that=this
  59. if(e.detail.errMsg == "getPhoneNumber:ok" && that.params.code){
  60. that.params.encryptedData=e.detail.encryptedData
  61. that.params.iv=e.detail.iv
  62. that.$http.wxLogin(that.params).then(res=>{
  63. if(res.code === 0){
  64. that.$store.commit("UPDATEMOBILE",res.data.mobile);
  65. that.$store.commit("UPDATEUSERS",res.data);
  66. that.$storage.setJson("token",res.data.token)
  67. if(that.jumpPage){
  68. uni.navigateTo({
  69. url:'/pages/powerchange/index?stationCode='+that.jumpPage
  70. })
  71. }else{
  72. that.$utils.switchTab('ucenter/index');
  73. }
  74. that.isSubmit = false;
  75. }else{
  76. that.$utils.msg(res.msg);
  77. }
  78. }).catch(error=>{
  79. that.$utils.msg(error);
  80. });
  81. }
  82. },
  83. onGoHome(){
  84. this.$utils.switchTab("index/index");
  85. },
  86. checkboxChange(e){
  87. let that =this
  88. wx.login({
  89. success(res){
  90. that.params.code=res.code
  91. }
  92. })
  93. this.protocol = !this.protocol;
  94. },
  95. goRead(e){
  96. uni.navigateTo({
  97. url:'/pages/userAgreement/index'
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. .agreement-box {
  105. width: 100%;
  106. margin: 30rpx auto 0;
  107. flex-direction: row;
  108. align-items: center;
  109. justify-content: center;
  110. .protocol-check {
  111. position: relative;top:-2px;transform:scale(0.6)
  112. }
  113. .agreement-text {
  114. width: 100%;
  115. font-size: 26rpx;
  116. font-weight: 500;
  117. color: #999999;
  118. .agree-text {
  119. display: inline-block;
  120. color: #2841c2;
  121. view{
  122. display: inline;
  123. }
  124. }
  125. }
  126. }
  127. .login-wrap {
  128. .logo {
  129. text-align: center;
  130. padding-top: 180rpx;
  131. image {
  132. width: 144rpx;
  133. height: 144rpx;
  134. border-radius: 50%;
  135. }
  136. }
  137. .wechat-title {
  138. font-size: 35rpx;
  139. font-weight: 500;
  140. color: #333;
  141. margin-top: 24rpx;
  142. text-align: center;
  143. }
  144. .wechat-desc {
  145. font-size: 28rpx;
  146. font-weight: 500;
  147. color: #999;
  148. margin-top: 24rpx;
  149. text-align: center;
  150. padding: 10rpx 50rpx;
  151. }
  152. .wechat-login-btn {
  153. height: 80rpx; line-height: 80rpx;
  154. color: #fff; background-color: #58be6b;
  155. text-align: center; border-radius: 50rpx;
  156. margin: 50rpx; font-size: 32rpx;
  157. }
  158. .wechat-go-home { text-align: center; font-size: 30rpx; color:#666; }
  159. }
  160. </style>