wxLogin.vue 5.3 KB

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