login.vue 3.8 KB

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