wxLogin.vue 3.4 KB

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