Login.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="login">
  3. <el-card class="box-card">
  4. <div slot="header"
  5. class="clearfix">
  6. <span>遵义医科大学附属医院登录入口</span>
  7. </div>
  8. <div>
  9. <el-form class="demo-ruleForm"
  10. ref="lform"
  11. :model="loginform"
  12. :rules="rules"
  13. label-width="80px">
  14. <el-form-item label="用户名"
  15. prop="username">
  16. <el-input name="username"
  17. v-model="loginform.username"></el-input>
  18. </el-form-item>
  19. <el-form-item label="密码"
  20. prop="password">
  21. <el-input name="password"
  22. type="password"
  23. v-model="loginform.password"
  24. autocomplete="off"></el-input>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary"
  28. :loading="loading"
  29. @click="login">登录</el-button>
  30. <el-button type="text">
  31. <router-link to="/">回到首页</router-link>
  32. </el-button>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. </el-card>
  37. </div>
  38. </template>
  39. <script>
  40. import crypto from "sm-crypto";
  41. import { setToken } from "@/utils/auth";
  42. import { signIn } from "@/api/login";
  43. import to from 'await-to-js'
  44. export default {
  45. data() {
  46. return {
  47. labelPosition: "right",
  48. loginform: {
  49. username: "",
  50. password: "",
  51. },
  52. rules: {
  53. username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  54. password: [
  55. { required: true, message: "请输入密码", trigger: "blur" },
  56. {
  57. min: 5,
  58. max: 20,
  59. message: "密码长度在 5 到 20 个字符",
  60. trigger: "blur",
  61. },
  62. ],
  63. },
  64. loading: false,
  65. };
  66. },
  67. methods: {
  68. login() {
  69. this.$refs.lform.validate(async (valid) => {
  70. if (valid) {
  71. const params = JSON.parse(JSON.stringify(this.loginform));
  72. params.password = crypto.sm3(params.password);
  73. const [err, res] = await to(signIn(params));
  74. if (err) {
  75. this.loading = false;
  76. return;
  77. }
  78. this.$message.success("登录成功");
  79. setToken(res.data.token);
  80. if(this.$route.query.redirect) {
  81. this.$router.push(this.$route.query.redirect);
  82. } else {
  83. this.$router.push("/");
  84. }
  85. }
  86. });
  87. },
  88. },
  89. };
  90. </script>
  91. <style lang="scss" scoped>
  92. a {
  93. text-decoration: none;
  94. color: #409eff;
  95. }
  96. .login {
  97. width: 100%;
  98. height: calc(100vh - 116px);
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. background: url('../assets/img/login.png') center no-repeat;
  103. background-size: 100% 100%;
  104. }
  105. .text {
  106. font-size: 14px;
  107. }
  108. .item {
  109. margin-bottom: 18px;
  110. }
  111. .clearfix:before,
  112. .clearfix:after {
  113. display: table;
  114. content: "";
  115. }
  116. .clearfix:after {
  117. clear: both;
  118. }
  119. .box-card {
  120. width: 480px;
  121. margin: 0 auto;
  122. }
  123. .el-form-item__content {
  124. text-align: start;
  125. }
  126. </style>