wxLogin.vue 3.5 KB

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