login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. <image class="logo1" src="/static//images/schoolName.png"></image>
  8. <!-- <text class="text1"></text> -->
  9. </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. <text class="input-label">工号</text>
  16. <!-- <i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i> -->
  17. <u--input
  18. clearable
  19. placeholder="请输入工号"
  20. border="none"
  21. v-model="form.account"
  22. maxlength="10"></u--input>
  23. </view>
  24. <view class="pwd-area">
  25. <text class="input-label">
  26. 密码
  27. </text>
  28. <!-- <i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i> -->
  29. <view class="password-input">
  30. <u--input
  31. border="none"
  32. v-model="form.password"
  33. placeholder="请输入密码"
  34. clearable
  35. :type="pwdType"
  36. >
  37. </u--input>
  38. <i @click="showPwd()" class="iconfont" style="margin-left: 10rpx;" :class="showP?'icon-xianshi':'icon-yincang'"></i>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <button class="form-area-btn" @click="toLogin">登 录</button>
  44. </view>
  45. <u-toast ref="uToast"></u-toast>
  46. </view>
  47. </template>
  48. <script>
  49. import { login,getInfo } from "@/api/user.js"
  50. import { setToken } from "@/utils/auth.js"
  51. import cache from '@/utils/storage.js'
  52. export default {
  53. data() {
  54. return {
  55. form:{
  56. account:'',
  57. password:''
  58. },
  59. showP:false,
  60. showPassword: true,
  61. pwdType:"password"
  62. };
  63. },
  64. methods:{
  65. showPwd(){
  66. this.showP = !this.showP
  67. if(this.showP){
  68. this.pwdType = "text"
  69. }else{
  70. this.pwdType = "password"
  71. }
  72. },
  73. toLogin(){
  74. uni.showLoading({
  75. title:"正在登录中",
  76. icon:'none',
  77. mask:true
  78. })
  79. try{
  80. login(this.form.account,this.form.password).then(res=>{
  81. setToken(res.data.token)
  82. getInfo().then(res=>{
  83. if(res.data.code===200){
  84. uni.hideLoading()
  85. cache.session.setJSON('role',res.data.roles[0])
  86. cache.session.setJSON('phone',res.data.user.phonenumber)
  87. cache.session.setJSON('email',res.data.user.email)
  88. cache.session.setJSON('nickName',res.data.user.nickName)
  89. cache.session.setJSON('userName',res.data.user.userName)
  90. cache.session.setJSON('userId',res.data.user.userId)
  91. uni.switchTab({
  92. url:'/pages/home/home'
  93. })
  94. }
  95. })
  96. })
  97. }catch(err){
  98. uni.hideLoading()
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .content {
  106. display: flex;
  107. flex-direction: column;
  108. align-items: center;
  109. justify-content: center;
  110. }
  111. .text-area {
  112. display: flex;
  113. justify-content: center;
  114. flex-direction: column;
  115. position: fixed;
  116. top: 25%;
  117. transform: translateY(-20%);
  118. text-align: center;
  119. width: 80%;
  120. // overflow: hidden;
  121. }
  122. .text-area-content{
  123. animation-name: logoText;
  124. animation-duration: 1s;
  125. .logoText{
  126. .logo{
  127. height: 100rpx;
  128. width: 100rpx;
  129. }
  130. .logo1{
  131. height: 100rpx;
  132. width: 280rpx;
  133. }
  134. .text1_bck{
  135. color: $uni-text-color;
  136. font-size: 56rpx;
  137. transform:translateY(-10%);
  138. height: 100rpx;
  139. line-height: 100rpx;
  140. }
  141. margin-bottom: 20rpx;
  142. -webkit-box-reflect: below -20% -webkit-linear-gradient(transparent, transparent 50%, rgba(255, 255, 255, .3));
  143. }
  144. .text2{
  145. color: rgba(128, 128, 128, 1);
  146. font-size: 36rpx;
  147. line-height: 150%;
  148. }
  149. }
  150. .form-area{
  151. margin-top: 80rpx;
  152. margin-bottom: 160rpx;
  153. .name-area,.pwd-area{
  154. width: 100%;
  155. // height: 100rpx;
  156. // padding-left: 20rpx;
  157. // padding-right: 20rpx;
  158. color: $uni-text-color-black;
  159. font-size: 30rpx;
  160. // line-height: 150%;
  161. border-bottom: rgba(0, 0, 0, 0.2) solid 2rpx;
  162. text-align: left;
  163. // box-sizing: border-box;
  164. display: flex;
  165. // align-items: center;
  166. flex-direction: column;
  167. margin-bottom: 10rpx;
  168. }
  169. .name-area{
  170. // border-radius: 20rpx 20rpx 0 0;
  171. }
  172. .pwd-area{
  173. // border-radius:0 0 20rpx 20rpx ;
  174. .password-input{
  175. display:flex;
  176. align-items: center;
  177. .iconfont{
  178. color: #8c8986;
  179. }
  180. }
  181. }
  182. .input-label{
  183. margin: 16rpx 0;
  184. font-size: 26rpx;
  185. }
  186. }
  187. .form-area-btn{
  188. height: 100rpx;
  189. width: 100%;
  190. line-height: 100rpx;
  191. outline: none;
  192. background: #19be6b;
  193. color: $uni-text-color-inverse;
  194. border-radius: 20rpx;
  195. margin-top: 30rpx;
  196. font-size: 32rpx;
  197. }
  198. @keyframes logoText {
  199. from {
  200. transform: scaleY(0);
  201. }
  202. to {
  203. transform: scaleY(1);
  204. }
  205. }
  206. </style>