wxLogin.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='登录' :showback='false'></cus-header>
  4. <div class="box">
  5. <image :src="imgBase+'login/login_logo.png'"></image>
  6. <div class="title">
  7. 欢迎登录传能
  8. <image :src="imgBase+'login/login_textbg.png'"></image>
  9. </div>
  10. <div class="tip">请完成微信授权以继续使用</div>
  11. <button class="login" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">同意授权登录</button>
  12. <div class="cancel" @tap="cancelLogin">取消登录</div>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. data(){
  19. return {
  20. imgBase:this.$imgBase
  21. }
  22. },
  23. methods:{
  24. decryptPhoneNumber(e){
  25. if(uni.getStorageSync('token')){
  26. uni.reLaunch({
  27. url:'/pagesHome/index'
  28. })
  29. return
  30. }
  31. if(e.detail.code) this.wxLogin(e.detail.code);
  32. },
  33. wxLogin(code){
  34. uni.showLoading({ title:'登录中' });
  35. let that = this;
  36. wx.login({
  37. success(res){
  38. that.$api.get('/wx/login',{
  39. code:res.code,
  40. phoneCode:code
  41. },false).then(res=>{
  42. if(res.data.code===0){
  43. uni.setStorageSync('token',res.data.data.token);
  44. uni.setStorageSync('userInfo',JSON.stringify({
  45. gender:res.data.data.gender,
  46. realName:res.data.data.realName,
  47. email:res.data.data.email,
  48. headUrl:res.data.data.headUrl
  49. }));
  50. uni.hideLoading();
  51. that.$showToast('登录成功');
  52. setTimeout(()=>{
  53. uni.reLaunch({
  54. url:'/pagesHome/index'
  55. })
  56. },1500)
  57. }else that.$showToast(res.data.msg)
  58. })
  59. }
  60. })
  61. },
  62. cancelLogin(){
  63. uni.exitMiniProgram();
  64. }
  65. }
  66. }
  67. </script>
  68. <style scoped lang="scss">
  69. .page{
  70. background: #fff;
  71. .box{
  72. width: 100%;
  73. padding: 0 55rpx;
  74. box-sizing: border-box;
  75. display: flex;
  76. flex-direction: column;
  77. align-items: center;
  78. &>image{
  79. width: 182rpx;
  80. height: 182rpx;
  81. margin-top: 169rpx;
  82. }
  83. .title{
  84. font-family: PingFang-SC, PingFang-SC;
  85. font-weight: bold;
  86. font-size: 48rpx;
  87. color: #1D2129;
  88. line-height: 67rpx;
  89. text-align: center;
  90. position: relative;
  91. margin-top: 11rpx;
  92. z-index: 1;
  93. letter-spacing: 2rpx;
  94. &>image{
  95. width: 198rpx;
  96. height: 18rpx;
  97. position: absolute;
  98. z-index: -1;
  99. left: -14rpx;
  100. bottom: 4rpx;
  101. }
  102. }
  103. .tip{
  104. font-family: PingFangSC, PingFang SC;
  105. font-weight: 400;
  106. font-size: 28rpx;
  107. color: #86909C;
  108. line-height: 40rpx;
  109. margin-top: 88rpx;
  110. letter-spacing: 2rpx;
  111. }
  112. .login{
  113. width: 100%;
  114. height: 88rpx;
  115. background: #198CFF;
  116. border-radius: 16rpx;
  117. text-align: center;
  118. line-height: 88rpx;
  119. font-family: PingFang-SC, PingFang-SC;
  120. font-weight: bold;
  121. font-size: 32rpx;
  122. color: #FFFFFF;
  123. letter-spacing: 2rpx;
  124. margin-top: 36rpx;
  125. }
  126. .cancel{
  127. width: 100%;
  128. height: 88rpx;
  129. border: 1rpx solid #ECECEC;
  130. border-radius: 16rpx;
  131. text-align: center;
  132. line-height: 88rpx;
  133. font-family: PingFang-SC, PingFang-SC;
  134. font-weight: bold;
  135. font-size: 32rpx;
  136. color: #4E5969;
  137. letter-spacing: 2rpx;
  138. margin-top: 32rpx;
  139. }
  140. }
  141. }
  142. </style>