wxLogin.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. id:res.data.data.id,
  46. gender:res.data.data.gender,
  47. realName:res.data.data.realName,
  48. email:res.data.data.email,
  49. headUrl:res.data.data.headUrl
  50. }));
  51. uni.hideLoading();
  52. that.$showToast('登录成功');
  53. setTimeout(()=>{
  54. uni.reLaunch({
  55. url:'/pagesHome/index'
  56. })
  57. },1500)
  58. }else that.$showToast(res.data.msg)
  59. })
  60. }
  61. })
  62. },
  63. cancelLogin(){
  64. uni.exitMiniProgram();
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. .page{
  71. background: #fff;
  72. .box{
  73. width: 100%;
  74. padding: 0 55rpx;
  75. box-sizing: border-box;
  76. display: flex;
  77. flex-direction: column;
  78. align-items: center;
  79. &>image{
  80. width: 182rpx;
  81. height: 182rpx;
  82. margin-top: 169rpx;
  83. }
  84. .title{
  85. font-family: PingFang-SC, PingFang-SC;
  86. font-weight: bold;
  87. font-size: 48rpx;
  88. color: #1D2129;
  89. line-height: 67rpx;
  90. text-align: center;
  91. position: relative;
  92. margin-top: 11rpx;
  93. z-index: 1;
  94. letter-spacing: 2rpx;
  95. &>image{
  96. width: 198rpx;
  97. height: 18rpx;
  98. position: absolute;
  99. z-index: -1;
  100. left: -14rpx;
  101. bottom: 4rpx;
  102. }
  103. }
  104. .tip{
  105. font-family: PingFangSC, PingFang SC;
  106. font-weight: 400;
  107. font-size: 28rpx;
  108. color: #86909C;
  109. line-height: 40rpx;
  110. margin-top: 88rpx;
  111. letter-spacing: 2rpx;
  112. }
  113. .login{
  114. width: 100%;
  115. height: 88rpx;
  116. background: #198CFF;
  117. border-radius: 16rpx;
  118. text-align: center;
  119. line-height: 88rpx;
  120. font-family: PingFang-SC, PingFang-SC;
  121. font-weight: bold;
  122. font-size: 32rpx;
  123. color: #FFFFFF;
  124. letter-spacing: 2rpx;
  125. margin-top: 36rpx;
  126. }
  127. .cancel{
  128. width: 100%;
  129. height: 88rpx;
  130. border: 1rpx solid #ECECEC;
  131. border-radius: 16rpx;
  132. text-align: center;
  133. line-height: 88rpx;
  134. font-family: PingFang-SC, PingFang-SC;
  135. font-weight: bold;
  136. font-size: 32rpx;
  137. color: #4E5969;
  138. letter-spacing: 2rpx;
  139. margin-top: 32rpx;
  140. }
  141. }
  142. }
  143. </style>