login.vue 4.9 KB

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