1.LoginForm login box component (requires elementUI)
![Insert picture description here](https://img-blog.csdnimg.cn/20210104170337478.png)
<template>
<el-form ref="loginForm" :model="model" :rules="rules" class="login-form">
<div class="title-container">
<h3 class="title">平 台 登 录</h3>
</div>
<el-form-item>
<span class="svg-container">
<svg-icon icon-class="user" />
</span>
<el-input
ref="username"
v-model="model.username"
placeholder="Username"
name="username"
type="text"
tabindex="1"
auto-complete="on"
/>
</el-form-item>
<el-form-item prop="password">
<span class="svg-container">
<svg-icon icon-class="password" />
</span>
<el-input
:key="passwordType"
ref="password"
v-model="model.password"
:type="passwordType"
placeholder="Password"
name="password"
tabindex="2"
auto-complete="on"
@keyup.enter.native="handleLogin"
/>
<span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
</span>
</el-form-item>
<el-button :loading="loading" type="primary" @click.native.prevent="subBtn()" plain round>登录</el-button>
<el-link type="info">忘记密码</el-link>
</el-form>
</template>
<script>
export default {
name: "LoginForm",
props:{
"rules": {
type: Object,
default: ()=>{
return {
}}
},
"model": {
type: Object,
required: true,
}
},
data() {
return {
loading: false,
passwordType: 'password',
redirect: undefined
}
},
methods:{
showPwd() {
if (this.passwordType === 'password') {
this.passwordType = ''
} else {
this.passwordType = 'password'
}
this.$nextTick(() => {
this.$refs.password.focus()
})
},
subBtn(){
this.$refs.loginForm.validate(valid => {
if (valid){
this.$emit('submitBtnClick')
} else {
console.log('error submit!!')
return false
}
})
},
handleLogin(){
this.$emit('submitBtnClick')
}
}
}
</script>
<style lang="scss">
$cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
.login-container .el-input input {
color: $cursor;
}
}
.login-container {
.el-input {
display: inline-block;
height: 47px;
width: 85%;
input {
background: transparent;
border: 0px;
-webkit-appearance: none;
-webkit-transition: background-color 43200s ease-in-out 0s;
border-radius: 0px;
padding: 12px 5px 12px 15px;
color: white;
height: 35px;
caret-color: $cursor;
&:-webkit-autofill {
color: #FFF !important;
-webkit-text-fill-color: #FFF;
-webkit-transition: background-color 43200s ease-in-out 0s;
transition: background-color 43200s ease-in-out 0s;
&:hover,&:focus {
color: #FFF !important;
-webkit-text-fill-color: #FFF;
-webkit-transition: background-color 43200s ease-in-out 0s;
transition: background-color 43200s ease-in-out 0s;
}
}
}
}
}
</style>
<style lang="scss" scoped>
.login-form {
position: relative;
width: 350px;
max-width: 100%;
padding: 140px 0px 80px;
overflow: hidden;
border: 2px solid #06c;
background-color: rgba(130,187,232,0.1);
-moz-box-shadow:4px -4px 50px #57E7F4;
-webkit-box-shadow:4px -2px 50px #57E7F4;
box-shadow:4px -4px 50px #57E7F4;
.el-form-item{
border-top: 1px solid #57E7F4;
height: 45px;
margin:0;
.svg-container {
padding: 6px 5px 6px 15px;
color: white;
vertical-align: middle;
width: 30px;
display: inline-block;
}
.show-pwd {
position: absolute;
right: 10px;
top: 7px;
font-size: 16px;
color: white;
cursor: pointer;
user-select: none;
}
}
.el-form-item:nth-child(3){
border-bottom: 1px solid #57E7F4;
}
.title-container {
position: relative;
margin-bottom:20px;
.title {
font-size: 26px;
color: white;
margin: 0px 30px 40px 30px;
text-align: center;
font-weight: bold;
display: inline-block;
}
}
.el-button{
width: 130px;
height: 40px;
font-size:1em;
font-weight: bold;
background-color: #293140;
border: 3px #3bb6f4 solid;
margin-left: 35px;
margin-top: 50px;
color: #3bb6f4;
}
.el-button:hover{
background-color: #156cd2;
color: #fff;
}
.el-link{
float:right;
margin-top:70px ;
margin-right: 40px;
}
}
</style>
2. Use the login box component
![Insert picture description here](https://img-blog.csdnimg.cn/20210104170523694.png)
<template>
<div class="login-container">
<LoginForm :model.sync="loginForm" @submitBtnClick="handleLogin()"></LoginForm>
</div>
</template>
<script>
import LoginForm from '@/components/loginForm'
export default {
data() {
return {
loginForm: {
username: 'admin',
password: ''
},
}
},
methods: {
handleLogin() {
}
},
components:{
LoginForm
}
}
</script>
<style lang="scss" scoped>
</style>
3. Login page
![Insert picture description here](https://img-blog.csdnimg.cn/2021010417112820.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpb25jYXRjaA==,size_16,color_FFFFFF,t_70)
<template>
<div class="login-container">
<LoginForm :model.sync="loginForm" :rules="loginRules" @submitBtnClick="handleLogin()" class="loginForm"></LoginForm>
</div>
</template>
<script>
import LoginForm from '@/components/loginForm'
export default {
data() {
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('The password can not be less than 6 digits'))
} else {
callback()
}
}
return {
loginForm: {
username: 'admin',
password: ''
},
loginRules: {
password: [{
required: true, trigger: 'blur', validator: validatePassword }]
},
}
},
methods: {
handleLogin() {
}
},
components:{
LoginForm
}
}
</script>
<style lang="scss" scoped>
.title {
margin-top: 70px;
}
.login-container {
min-height: 100%;
width: 100%;
overflow: hidden;
background: url('/img/login/test5.png') no-repeat;
background-size:100% 100%;
}
.loginForm {
float: right;
margin: 240px 300px 0 0;
}
</style>