Login.vue 2.6 KB
Newer Older
L
lin-xin 已提交
1 2 3 4
<template>
    <div class="login-wrap">
        <div class="ms-title">后台管理系统</div>
        <div class="ms-login">
L
lin-xin 已提交
5 6 7
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm">
                <el-form-item prop="username">
                    <el-input v-model="ruleForm.username" placeholder="username"></el-input>
L
lin-xin 已提交
8
                </el-form-item>
L
lin-xin 已提交
9 10
                <el-form-item prop="password">
                    <el-input type="password" placeholder="password" v-model="ruleForm.password" @keyup.enter.native="submitForm('ruleForm')"></el-input>
L
lin-xin 已提交
11 12 13 14
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </div>
L
lin-xin 已提交
15
                <p style="font-size:12px;line-height:30px;color:#999;">Tips : 用户名和密码随便填。</p>
L
lin-xin 已提交
16 17 18 19 20 21 22 23 24 25
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        data: function(){
            return {
                ruleForm: {
L
lin-xin 已提交
26 27
                    username: 'admin',
                    password: '123123'
L
lin-xin 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40
                },
                rules: {
                    username: [
                        { required: true, message: '请输入用户名', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入密码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
L
lin-xin 已提交
41
                this.$refs[formName].validate((valid) => {
L
lin-xin 已提交
42
                    if (valid) {
L
lin-xin 已提交
43
                        localStorage.setItem('ms_username',this.ruleForm.username);
L
lin-xin 已提交
44
                        this.$router.push('/');
L
lin-xin 已提交
45 46 47 48 49 50 51 52 53 54
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        }
    }
</script>

L
lin-xin 已提交
55
<style scoped>
L
lin-xin 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    .login-wrap{
        position: relative;
        width:100%;
        height:100%;
    }
    .ms-title{
        position: absolute;
        top:50%;
        width:100%;
        margin-top: -230px;
        text-align: center;
        font-size:30px;
        color: #fff;

    }
    .ms-login{
        position: absolute;
        left:50%;
        top:50%;
L
lin-xin 已提交
75
        width:300px;
L
lin-xin 已提交
76 77
        height:160px;
        margin:-150px 0 0 -190px;
L
lin-xin 已提交
78
        padding:40px;
L
lin-xin 已提交
79 80 81 82 83 84 85
        border-radius: 5px;
        background: #fff;
    }
    .login-btn{
        text-align: center;
    }
    .login-btn button{
L
lin-xin 已提交
86 87
        width:100%;
        height:36px;
L
lin-xin 已提交
88 89
    }
</style>