blob: fd4a9c1d486784bac126e33cf7501669ff097a7b [file] [log] [blame]
huibing.xie1f1606f2018-08-20 15:46:55 +08001<template>
2 <div class="login-container">
3 <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
4 <h3 class="title">离校管理系统</h3>
5 <el-form-item prop="username">
6 <span class="svg-container svg-container_login">
7 <svg-icon icon-class="user" />
8 </span>
9 <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="username" />
10 </el-form-item>
11 <el-form-item prop="password">
12 <span class="svg-container">
13 <svg-icon icon-class="password"></svg-icon>
14 </span>
15 <el-input name="password" :type="pwdType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
16 placeholder="password"></el-input>
17 <span class="show-pwd" @click="showPwd"><svg-icon icon-class="eye" /></span>
18 </el-form-item>
19 <el-form-item>
20 <el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
21 登录
22 </el-button>
23 </el-form-item>
24 </el-form>
25 </div>
26</template>
27
28<script>
29import { isvalidUsername } from '@/utils/validate'
30
31export default {
32 name: 'login',
33 data() {
34 const validateUsername = (rule, value, callback) => {
35 if (!isvalidUsername(value)) {
36 callback(new Error('请输入正确的用户名'))
37 } else {
38 callback()
39 }
40 }
41 const validatePass = (rule, value, callback) => {
42 if (value.length < 5) {
43 callback(new Error('密码不能小于5位'))
44 } else {
45 callback()
46 }
47 }
48 return {
49 loginForm: {
50 username: 'admin',
51 password: 'admin'
52 },
53 loginRules: {
54 username: [{ required: true, trigger: 'blur', validator: validateUsername }],
55 password: [{ required: true, trigger: 'blur', validator: validatePass }]
56 },
57 loading: false,
58 pwdType: 'password'
59 }
60 },
61 methods: {
62 showPwd() {
63 if (this.pwdType === 'password') {
64 this.pwdType = ''
65 } else {
66 this.pwdType = 'password'
67 }
68 },
69 handleLogin() {
70 this.$refs.loginForm.validate(valid => {
71 if (valid) {
72 this.loading = true
73 this.$store.dispatch('Login', this.loginForm).then(() => {
74 this.loading = false
75 this.$router.push({ path: '/' })
76 }).catch(() => {
77 this.loading = false
78 })
79 } else {
80 console.log('error submit!!')
81 return false
82 }
83 })
84 }
85 }
86}
87</script>
88
89<style rel="stylesheet/scss" lang="scss">
90$bg:#2d3a4b;
91$light_gray:#eee;
92
93/* reset element-ui css */
94.login-container {
95 .el-input {
96 display: inline-block;
97 height: 47px;
98 width: 85%;
99 input {
100 background: transparent;
101 border: 0px;
102 -webkit-appearance: none;
103 border-radius: 0px;
104 padding: 12px 5px 12px 15px;
105 color: $light_gray;
106 height: 47px;
107 &:-webkit-autofill {
108 -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
109 -webkit-text-fill-color: #fff !important;
110 }
111 }
112 }
113 .el-form-item {
114 border: 1px solid rgba(255, 255, 255, 0.1);
115 background: rgba(0, 0, 0, 0.1);
116 border-radius: 5px;
117 color: #454545;
118 }
119}
120
121</style>
122
123<style rel="stylesheet/scss" lang="scss" scoped>
124$bg:#2d3a4b;
125$dark_gray:#889aa4;
126$light_gray:#eee;
127.login-container {
128 position: fixed;
129 height: 100%;
130 width: 100%;
131 background-color: $bg;
132 .login-form {
133 position: absolute;
134 left: 0;
135 right: 0;
136 width: 520px;
137 padding: 35px 35px 15px 35px;
138 margin: 120px auto;
139 }
140 .svg-container {
141 padding: 6px 5px 6px 15px;
142 color: $dark_gray;
143 vertical-align: middle;
144 width: 30px;
145 display: inline-block;
146 &_login {
147 font-size: 20px;
148 }
149 }
150 .title {
151 font-size: 26px;
152 font-weight: 400;
153 color: $light_gray;
154 margin: 0px auto 40px auto;
155 text-align: center;
156 font-weight: bold;
157 }
158 .show-pwd {
159 position: absolute;
160 right: 10px;
161 top: 7px;
162 font-size: 16px;
163 color: $dark_gray;
164 cursor: pointer;
165 user-select: none;
166 }
167}
168</style>