index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div
  3. ref="login"
  4. class="login"
  5. style="position: relative;"
  6. >
  7. <div class="card">
  8. <el-card shadow="hover">
  9. <div class="icon">
  10. <img
  11. src="@/assets/login/u18.svg"
  12. alt=""
  13. >
  14. <p>人员能力评估系统</p>
  15. </div>
  16. <div class="form">
  17. <el-form
  18. :model="form"
  19. :rules="rules"
  20. ref="form"
  21. label-width="60px"
  22. >
  23. <el-form-item prop="username">
  24. <i
  25. slot="label"
  26. class="iconfont icon-zhanghao"
  27. ></i>
  28. <el-input v-model="form.username"></el-input>
  29. </el-form-item>
  30. <el-form-item prop="password">
  31. <i
  32. slot="label"
  33. class="iconfont icon-mima"
  34. ></i>
  35. <el-input
  36. type="password"
  37. v-model="form.password"
  38. ></el-input>
  39. </el-form-item>
  40. <el-form-item label-width="0">
  41. <el-button
  42. type="primary"
  43. @click="Submit('form')"
  44. >登录</el-button>
  45. </el-form-item>
  46. </el-form>
  47. </div>
  48. </el-card>
  49. </div>
  50. <img
  51. style="position:absolute;bottom:0;height:50px"
  52. src="@/assets/login/1.png"
  53. alt=""
  54. class="logo"
  55. >
  56. </div>
  57. </template>
  58. <script>
  59. import Login from '@/api/login'
  60. export default {
  61. data () {
  62. return {
  63. form: {
  64. username: '',
  65. password: '',
  66. },
  67. rules: {
  68. username: [
  69. { required: true, message: "请输入账号名称", trigger: 'blur' }
  70. ],
  71. password: [{ required: true, message: "请输入账号密码", trigger: 'blur' }]
  72. }
  73. }
  74. },
  75. mounted () {
  76. // 监听键盘事件
  77. this.$refs["login"].addEventListener("keydown", e => {
  78. if (e.keyCode == 13) this.Submit('form');
  79. });
  80. },
  81. methods: {
  82. Submit (data) {
  83. let that = this;
  84. this.$refs[data].validate((valid) => {
  85. if (valid) {
  86. Login.login(that.form).then(res => {
  87. try {
  88. let { data } = res, { token, user_id, username } = data;
  89. sessionStorage.setItem("token", `JWT ${token}`);
  90. sessionStorage.setItem("user_id", user_id);
  91. sessionStorage.setItem("username", username)
  92. that.$router.push({ path: '/' })
  93. } catch (err) {
  94. this.$message.error(`数据处理:${err}`);
  95. }
  96. });
  97. }
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="less" scoped>
  104. .login {
  105. height: 100vh;
  106. width: 100vw;
  107. background-color: #3867b7;
  108. display: flex;
  109. align-items: center;
  110. justify-content: space-around;
  111. .card {
  112. width: 350px;
  113. height: 420px;
  114. .el-card {
  115. height: 100%;
  116. .icon {
  117. margin: 20px 0;
  118. text-align: center;
  119. p {
  120. margin: 0;
  121. font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  122. font-weight: 700;
  123. font-style: normal;
  124. font-size: 24px;
  125. color: #3867b7;
  126. line-height: 28px;
  127. }
  128. }
  129. .form {
  130. margin-top: 20px;
  131. .el-form-item {
  132. position: relative;
  133. i {
  134. // position: absolute;
  135. // z-index: 5;
  136. display: inline-block;
  137. border: 1px solid #dcdfe6;
  138. width: 38px;
  139. text-align: center;
  140. line-height: 38px;
  141. box-sizing: border-box;
  142. border-radius: 4px;
  143. }
  144. .el-button {
  145. width: 100%;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </style>