wxLogin.vue 4.3 KB

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