wxLogin.vue 4.5 KB

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