login.html
3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./css/index.css" />
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/page.css">
<script src="./js/browser.min.js"></script>
</head>
<body>
<!-- <div id="loginApp" v-cloak> -->
<div id="loginApp">
<div class="login-container">
<el-form :model="loginForm" :rules="rules" ref="loginForm" class="login-form">
<div class="login-header">
<h3 class="login-title">Login Form</h3>
</div>
<el-form-item prop="loginName">
<el-input ref="username" v-model.trim="loginForm.loginName"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input ref="password" type="password" v-model.trim="loginForm.password">
</el-input>
</el-form-item>
<el-button type="primary" style="width: 100%;" @click="submitForm">登 录</el-button>
</el-form>
</div>
</div>
<!-- import Vue before Element -->
<script src="./js/vue.js"></script>
<!-- import JavaScript -->
<script src="./js/index.js"></script>
<script src="./js/axios.js"></script>
<script src="./js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/cookie.js"></script>
<script src="./js/request.js"></script>
<script>
new Vue({
el: '#loginApp',
data() {
const validateUsername = (rule, value, callback) => {
if (!value) {
callback(new Error('请输入用户名'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
const regexp = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,16}$/
if (!value) {
callback(new Error('请输入密码'))
} else if (!regexp.test(value)) {
callback(new Error('请输入不小于六位包含字母数字的密码!'))
} else {
callback()
}
}
return {
loginForm: {
loginName: '',
password: ''
},
// paswordType: 'password',
rules: {
loginName: [
{ required: true, trigger: 'blur', validator: validateUsername }
],
password: [
{ required: true, trigger: 'blur', validator: validatePassword }
]
}
}
},
mounted() {
// console.log({ get, post })
// if (this.loginForm.name === '') {
// this.$refs.username.focus()
// } else if (this.loginForm.password === '') {
// this.$refs.password.focus()
// }
},
methods: {
submitForm() {
this.$refs.loginForm.validate(valid => {
if (valid) {
post(
window._CONF_.reportApiUrl + '/users/login',
this.loginForm
).then(res => {
const { data, code } = res
if (code === 200) {
Cookies.set('atoken', data.atoken)
const currentPath = window.location.href
window.location.replace(currentPath.substr(0, currentPath.lastIndexOf('/') + 1))
}
})
.catch(err => {
console.log(err)
})
}
})
},
resetForm() {
this.loginForm.name = ''
this.loginForm.password = ''
this.$refs.loginForm.resetFields()
},
}
})
</script>
</body>
</html>