| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <template>
- <div class="login">
- <el-card class="box-card">
- <div slot="header"
- class="clearfix">
- <span>遵义医科大学附属医院登录入口</span>
- </div>
- <div>
- <el-form class="demo-ruleForm"
- ref="lform"
- :model="loginform"
- :rules="rules"
- label-width="80px">
- <el-form-item label="用户名"
- prop="username">
- <el-input name="username"
- v-model="loginform.username"></el-input>
- </el-form-item>
- <el-form-item label="密码"
- prop="password">
- <el-input name="password"
- type="password"
- v-model="loginform.password"
- autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item>
- <el-button type="primary"
- :loading="loading"
- @click="login">登录</el-button>
- <el-button type="text">
- <router-link to="/">回到首页</router-link>
- </el-button>
- </el-form-item>
- </el-form>
- </div>
- </el-card>
- </div>
- </template>
- <script>
- import crypto from "sm-crypto";
- import { setToken } from "@/utils/auth";
- import { signIn } from "@/api/login";
- import to from 'await-to-js'
- export default {
- data() {
- return {
- labelPosition: "right",
- loginform: {
- username: "",
- password: "",
- },
- rules: {
- username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
- password: [
- { required: true, message: "请输入密码", trigger: "blur" },
- {
- min: 5,
- max: 20,
- message: "密码长度在 5 到 20 个字符",
- trigger: "blur",
- },
- ],
- },
- loading: false,
- };
- },
- methods: {
- login() {
- this.$refs.lform.validate(async (valid) => {
- if (valid) {
- const params = JSON.parse(JSON.stringify(this.loginform));
- params.password = crypto.sm3(params.password);
- const [err, res] = await to(signIn(params));
- if (err) {
- this.loading = false;
- return;
- }
- this.$message.success("登录成功");
- setToken(res.data.token);
- if(this.$route.query.redirect) {
- this.$router.push(this.$route.query.redirect);
- } else {
- this.$router.push("/");
- }
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- a {
- text-decoration: none;
- color: #409eff;
- }
- .login {
- width: 100%;
- height: calc(100vh - 116px);
- display: flex;
- align-items: center;
- justify-content: center;
- background: url('../assets/img/login.png') center no-repeat;
- background-size: 100% 100%;
- }
- .text {
- font-size: 14px;
- }
- .item {
- margin-bottom: 18px;
- }
- .clearfix:before,
- .clearfix:after {
- display: table;
- content: "";
- }
- .clearfix:after {
- clear: both;
- }
- .box-card {
- width: 480px;
- margin: 0 auto;
- }
- .el-form-item__content {
- text-align: start;
- }
- </style>
|