login.vue 3.3 KB

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