login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. <view class="wechat-go-home" @click="onGoHome">暂不登录</view>
  9. <view class="agreement-box" style="width: 80%;">
  10. <view class="agreement-text agree-text">
  11. <checkbox-group @change="checkboxChange">
  12. <checkbox value="1" class="protocol-check"></checkbox>我已阅读并遵守
  13. <view class="agree-text">
  14. <view>《用户协议》</view>
  15. <view>《隐私协议》</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. }
  32. },
  33. onLoad(option) {
  34. this.options=option.item
  35. },
  36. methods: {
  37. onWxMiniLogin(){
  38. // if(!this.protocol){
  39. // this.isSubmit = false;
  40. // this.$utils.msg("请同意用户协议");
  41. // return ;
  42. // }
  43. var that = this;
  44. this.isSubmit = true;
  45. wx.getUserProfile({
  46. desc: '授权',
  47. success: (res) => {
  48. let userInfo = JSON.parse(res.rawData);
  49. wx.login({
  50. success: function (resData){
  51. let params = {};
  52. params.userInfo = userInfo;
  53. // params.code = resData.code;
  54. const userCode={code:resData.code}
  55. that.$http.wxgetCode(userCode).then(result=>{
  56. if(result.code === 0){
  57. const wxuserinfo={...result.data,...userInfo}
  58. that.$store.commit("UPDATEUSERS",wxuserinfo);
  59. //有token就存储token
  60. if(wxuserinfo.token){
  61. that.$store.commit("UPDATETOKEN",wxuserinfo.token);
  62. }
  63. //有手机号就存储手机号
  64. if(wxuserinfo.mobile){
  65. that.$store.commit("UPDATEMOBILE",wxuserinfo.mobile);
  66. }
  67. if(that.options === 'scan'){
  68. that.$utils.switchTab('scan/index');
  69. }
  70. else{
  71. that.$utils.switchTab('ucenter/index');
  72. }
  73. that.isSubmit = false;
  74. }
  75. else if(result.code === 1){
  76. that.$utils.msg(result.msg);
  77. that.isSubmit = false;
  78. }
  79. else{
  80. that.$utils.msg(result.message);
  81. that.isSubmit = false;
  82. }
  83. }).catch(error=>{
  84. that.isSubmit = false;
  85. that.$utils.msg(error);
  86. });
  87. },
  88. fail:function (err){
  89. that.isSubmit = false;
  90. that.$utils.msg(err);
  91. }
  92. })
  93. },
  94. fail: res=>{
  95. that.$utils.msg("您无权限请求该接口");
  96. }
  97. })
  98. },
  99. onGoHome(){
  100. this.$utils.switchTab("index/index");
  101. },
  102. checkboxChange(e){
  103. this.protocol = e.detail.value[0] != undefined;
  104. },
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .agreement-box {
  110. width: 100%;
  111. margin: 30rpx auto 0;
  112. flex-direction: row;
  113. align-items: center;
  114. justify-content: center;
  115. .protocol-check {
  116. position: relative;top:-2px;transform:scale(0.6)
  117. }
  118. .agreement-text {
  119. width: 100%;
  120. font-size: 26rpx;
  121. font-weight: 500;
  122. color: #999999;
  123. .agree-text {
  124. display: inline-block;
  125. color: #2841c2;
  126. view{
  127. display: inline;
  128. }
  129. }
  130. }
  131. }
  132. .login-wrap {
  133. .logo {
  134. text-align: center;
  135. padding-top: 180rpx;
  136. image {
  137. width: 144rpx;
  138. height: 144rpx;
  139. border-radius: 50%;
  140. }
  141. }
  142. .wechat-title {
  143. font-size: 35rpx;
  144. font-weight: 500;
  145. color: #333;
  146. margin-top: 24rpx;
  147. text-align: center;
  148. }
  149. .wechat-desc {
  150. font-size: 28rpx;
  151. font-weight: 500;
  152. color: #999;
  153. margin-top: 24rpx;
  154. text-align: center;
  155. padding: 10rpx 50rpx;
  156. }
  157. .wechat-login-btn {
  158. height: 80rpx; line-height: 80rpx;
  159. color: #fff; background-color: #58be6b;
  160. text-align: center; border-radius: 50rpx;
  161. margin: 50rpx; font-size: 32rpx;
  162. }
  163. .wechat-go-home { text-align: center; font-size: 30rpx; color:#666; }
  164. }
  165. </style>