You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.0 KiB
Vue

<template>
<div class="login">
<div class="loginContain">
<div class="loginMain slideInDown">
<div class="ms-login">
<h3>用户登录</h3>
<el-form
:model="userInfo"
:rules="rules"
ref="loginForm"
label-width="0px"
class="ms-content"
size="medium"
>
<el-form-item prop="userName">
<el-input v-model="userInfo.userName" placeholder="用户名">
<span slot="prepend" class="el-icon-user"></span>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
type="password"
placeholder="密码"
show-password
v-model="userInfo.password"
@keyup.enter.native="submitForm()"
>
<span slot="prepend" class="el-icon-lock"></span>
</el-input>
</el-form-item>
<div class="login-btn">
<el-button type="primary" @click="submitForm()">登录</el-button>
</div>
</el-form>
</div>
</div>
</div>
</div>
</template>
<script>
import { loginJoggle } from "@/utils/api/index";
import { mapMutations } from "vuex";
export default {
name: "login",
components: {},
data: function () {
return {
userInfo: {
userName: "",
password: "",
},
rules: {
userName: [
{ required: true, message: "请输入用户名", trigger: "blur" },
],
password: [
{ required: true, message: "请输入密码", trigger: "blur" },
// { min: 6, max: 8, message: "请输入6-8位字符", trigger: "blur" },
],
},
token: "",
};
},
computed: {
...mapMutations(["SET_TOKEN", "SET_USERINFO"]),
},
methods: {
submitForm() {
this.$refs.loginForm.validate((valid) => {
if (valid) {
console.log(this.userInfo);
//注释
loginJoggle(this.userInfo)
.then((res) => {
if (res.code == 200) {
console.log(res.data);
this.$store.commit("SET_TOKEN", res.data.token); //将token保存在vuex中
this.$store.commit("SET_USERINFO", res.data); //将用户信息保存在vuex中
this.$router.push("/");
this.$message({
duration: 1500,
showClose: true,
message: "登录成功",
type: "success",
});
} else {
this.$message.error(res.msg);
}
})
.catch((err) => {});
} else {
this.$message.error("请输入账号和密码");
console.log("error submit!!");
return false;
}
});
},
getLogin() {},
},
created() {},
mounted() {},
};
</script>
<style lang="less">
.login {
//background: url(../../assets/loginbg.jpg) top #060c41 no-repeat;
background: linear-gradient(#141e30, #243b55);
width: 100%;
height: 100%;
background-size: inherit;
position: fixed;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: column;
.loginContain {
display: flex;
justify-content: flex-end;
align-items: center;
flex-wrap: nowrap;
flex-direction: column;
margin: auto;
position: relative;
z-index: 1;
.loginMain {
width: 400px;
height: auto;
// background-color: #0c1622;
margin: 100px auto;
border-radius: 10px;
box-shadow: 0 15px 25px 0 rgba(0, 0, 0, 0.6);
padding: 40px;
box-sizing: border-box;
animation: slideInDown 0.5s;
.ms-login {
h3 {
text-align: center;
color: aliceblue;
margin-bottom: 30px;
font-family: "Courier New", Courier, monospace;
}
.ms-content {
.el-input-group__append,
.el-input-group__prepend,
.el-input__inner {
border: 0.0625rem /* 1/16 */ solid #1479ad;
background: rgba(255, 255, 255, 0.1);
border-radius: 0.25rem 0 0 0.25rem /* 4/16 */ /* 4/16 */;
color: #fff;
}
.el-input__inner {
border: 0.0625rem /* 1/16 */ solid #1479ad;
background: rgba(255, 255, 255, 0.1);
border-radius: 0rem 00.25rem 0.25rem 0rem /* 4/16 */ /* 4/16 */;
color: #fff;
}
.el-form-item {
margin-bottom: 30px;
}
.login-btn {
text-align: center;
button {
width: 100%;
height: 36px;
margin-bottom: 10px;
}
}
}
}
}
.slideInDown {
animation-name: slideInDown;
}
}
@keyframes slideInDown {
0% {
transform: translateY(-100%);
visibility: visible;
}
100% {
transform: translateY(0);
}
}
}
</style>