login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="content">
  3. <view class="text-area">
  4. <view class="text-area-content">
  5. <view class="logoText">
  6. <image class="logo" src="/static/logo/logo.png"></image>
  7. <text class="text1">广州医科大学</text>
  8. </view>
  9. <text class="text2">实验室管理系统</text>
  10. </view>
  11. <view class="form-area">
  12. <view class="form-area-content">
  13. <view class="name-area">
  14. <i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i>
  15. <u--input
  16. clearable
  17. placeholder="请输入工号"
  18. border="none"
  19. v-model="form.account"></u--input>
  20. </view>
  21. <view class="pwd-area">
  22. <i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i>
  23. <u--input
  24. border="none"
  25. v-model="form.password"
  26. placeholder="请输入密码"
  27. password
  28. clearable
  29. ></u--input>
  30. </view>
  31. </view>
  32. </view>
  33. <button class="form-area-btn" @click="toLogin">登 录</button>
  34. </view>
  35. <u-toast ref="uToast"></u-toast>
  36. </view>
  37. </template>
  38. <script>
  39. import { login,getInfo } from "@/api/user.js"
  40. import { setToken } from "@/utils/auth.js"
  41. import cache from '@/utils/storage.js'
  42. export default {
  43. data() {
  44. return {
  45. form:{
  46. account:'admin',
  47. password:'admin123'
  48. },
  49. showPassword: true,
  50. pwdType:"password"
  51. };
  52. },
  53. methods:{
  54. showPwd(){
  55. this.pwdType = "text"
  56. },
  57. toLogin(){
  58. uni.showLoading({
  59. title:"正在登录中",
  60. icon:'none',
  61. mask:true
  62. })
  63. try{
  64. login(this.form.account,this.form.password).then(res=>{
  65. setToken(res.data.token)
  66. getInfo().then(res=>{
  67. if(res.data.code===200){
  68. uni.hideLoading()
  69. cache.session.setJSON('role',res.data.roles[0])
  70. cache.session.setJSON('phone',res.data.user.phonenumber)
  71. cache.session.setJSON('email',res.data.user.email)
  72. cache.session.setJSON('nickName',res.data.user.nickName)
  73. cache.session.setJSON('userName',res.data.user.userName)
  74. cache.session.setJSON('userId',res.data.user.userId)
  75. uni.switchTab({
  76. url:'/pages/home/home'
  77. })
  78. }
  79. })
  80. })
  81. }catch(err){
  82. uni.hideLoading()
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .content {
  90. display: flex;
  91. flex-direction: column;
  92. align-items: center;
  93. justify-content: center;
  94. }
  95. .text-area {
  96. display: flex;
  97. justify-content: center;
  98. flex-direction: column;
  99. position: fixed;
  100. top: 25%;
  101. transform: translateY(-20%);
  102. text-align: center;
  103. width: 80%;
  104. }
  105. .text-area-content{
  106. .logoText{
  107. .logo{
  108. height: 100rpx;
  109. width: 100rpx;
  110. transform:translateY(20%);
  111. }
  112. .text1{
  113. color: $uni-text-color;
  114. font-size: 56rpx;
  115. transform:translateY(-10%);
  116. height: 100rpx;
  117. line-height: 100rpx;
  118. }
  119. margin-bottom: 20rpx;
  120. -webkit-box-reflect: below -16% -webkit-linear-gradient(transparent, transparent 65%, rgba(255, 255, 255, .3));
  121. }
  122. .text2{
  123. color: rgba(128, 128, 128, 1);
  124. font-size: 36rpx;
  125. line-height: 150%;
  126. }
  127. }
  128. .form-area{
  129. margin-top: 80rpx;
  130. margin-bottom: 160rpx;
  131. .name-area,.pwd-area{
  132. width: 100%;
  133. height: 100rpx;
  134. padding-left: 20rpx;
  135. padding-right: 20rpx;
  136. color: $uni-text-color-black;
  137. font-size: 30rpx;
  138. // line-height: 150%;
  139. border: rgba(0, 0, 0, 0.3) solid 2rpx;
  140. text-align: left;
  141. // box-sizing: border-box;
  142. display: flex;
  143. align-items: center;
  144. margin-bottom: 10rpx;
  145. }
  146. .name-area{
  147. border-radius: 20rpx 20rpx 0 0;
  148. }
  149. .pwd-area{
  150. border-radius:0 0 20rpx 20rpx ;
  151. }
  152. }
  153. .form-area-btn{
  154. height: 100rpx;
  155. width: 100%;
  156. line-height: 100rpx;
  157. outline: none;
  158. background: #19be6b;
  159. color: $uni-text-color-inverse;
  160. border-radius: 20rpx;
  161. margin-top: 30rpx;
  162. font-size: 32rpx;
  163. }
  164. </style>