提交 | 用户 | 时间
|
e57a89
|
1 |
<template> |
懒 |
2 |
<div class="register"> |
|
3 |
<el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form"> |
|
4 |
<h3 class="title">江宸MES管理系统</h3> |
|
5 |
<el-form-item prop="username"> |
|
6 |
<el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号"> |
|
7 |
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> |
|
8 |
</el-input> |
|
9 |
</el-form-item> |
|
10 |
<el-form-item prop="password"> |
|
11 |
<el-input |
|
12 |
v-model="registerForm.password" |
|
13 |
type="password" |
|
14 |
auto-complete="off" |
|
15 |
placeholder="密码" |
|
16 |
@keyup.enter.native="handleRegister" |
|
17 |
> |
|
18 |
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
|
19 |
</el-input> |
|
20 |
</el-form-item> |
|
21 |
<el-form-item prop="confirmPassword"> |
|
22 |
<el-input |
|
23 |
v-model="registerForm.confirmPassword" |
|
24 |
type="password" |
|
25 |
auto-complete="off" |
|
26 |
placeholder="确认密码" |
|
27 |
@keyup.enter.native="handleRegister" |
|
28 |
> |
|
29 |
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
|
30 |
</el-input> |
|
31 |
</el-form-item> |
|
32 |
<el-form-item prop="code" v-if="captchaEnabled"> |
|
33 |
<el-input |
|
34 |
v-model="registerForm.code" |
|
35 |
auto-complete="off" |
|
36 |
placeholder="验证码" |
|
37 |
style="width: 63%" |
|
38 |
@keyup.enter.native="handleRegister" |
|
39 |
> |
|
40 |
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> |
|
41 |
</el-input> |
|
42 |
<div class="register-code"> |
|
43 |
<img :src="codeUrl" @click="getCode" class="register-code-img"/> |
|
44 |
</div> |
|
45 |
</el-form-item> |
|
46 |
<el-form-item style="width:100%;"> |
|
47 |
<el-button |
|
48 |
:loading="loading" |
|
49 |
size="medium" |
|
50 |
type="primary" |
|
51 |
style="width:100%;" |
|
52 |
@click.native.prevent="handleRegister" |
|
53 |
> |
|
54 |
<span v-if="!loading">注 册</span> |
|
55 |
<span v-else>注 册 中...</span> |
|
56 |
</el-button> |
|
57 |
<div style="float: right;"> |
|
58 |
<router-link class="link-type" :to="'/login'">使用已有账户登录</router-link> |
|
59 |
</div> |
|
60 |
</el-form-item> |
|
61 |
</el-form> |
|
62 |
<!-- 底部 --> |
|
63 |
<div class="el-register-footer"> |
|
64 |
<span>Copyright © 2018-2023 jcdm.vip All Rights Reserved.</span> |
|
65 |
</div> |
|
66 |
</div> |
|
67 |
</template> |
|
68 |
|
|
69 |
<script> |
|
70 |
import { getCodeImg, register } from "@/api/login"; |
|
71 |
|
|
72 |
export default { |
|
73 |
name: "Register", |
|
74 |
data() { |
|
75 |
const equalToPassword = (rule, value, callback) => { |
|
76 |
if (this.registerForm.password !== value) { |
|
77 |
callback(new Error("两次输入的密码不一致")); |
|
78 |
} else { |
|
79 |
callback(); |
|
80 |
} |
|
81 |
}; |
|
82 |
return { |
|
83 |
codeUrl: "", |
|
84 |
registerForm: { |
|
85 |
username: "", |
|
86 |
password: "", |
|
87 |
confirmPassword: "", |
|
88 |
code: "", |
|
89 |
uuid: "" |
|
90 |
}, |
|
91 |
registerRules: { |
|
92 |
username: [ |
|
93 |
{ required: true, trigger: "blur", message: "请输入您的账号" }, |
|
94 |
{ min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur' } |
|
95 |
], |
|
96 |
password: [ |
|
97 |
{ required: true, trigger: "blur", message: "请输入您的密码" }, |
|
98 |
{ min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' } |
|
99 |
], |
|
100 |
confirmPassword: [ |
|
101 |
{ required: true, trigger: "blur", message: "请再次输入您的密码" }, |
|
102 |
{ required: true, validator: equalToPassword, trigger: "blur" } |
|
103 |
], |
|
104 |
code: [{ required: true, trigger: "change", message: "请输入验证码" }] |
|
105 |
}, |
|
106 |
loading: false, |
|
107 |
captchaEnabled: true |
|
108 |
}; |
|
109 |
}, |
|
110 |
created() { |
|
111 |
this.getCode(); |
|
112 |
}, |
|
113 |
methods: { |
|
114 |
getCode() { |
|
115 |
getCodeImg().then(res => { |
|
116 |
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; |
|
117 |
if (this.captchaEnabled) { |
|
118 |
this.codeUrl = "data:image/gif;base64," + res.img; |
|
119 |
this.registerForm.uuid = res.uuid; |
|
120 |
} |
|
121 |
}); |
|
122 |
}, |
|
123 |
handleRegister() { |
|
124 |
this.$refs.registerForm.validate(valid => { |
|
125 |
if (valid) { |
|
126 |
this.loading = true; |
|
127 |
register(this.registerForm).then(res => { |
|
128 |
const username = this.registerForm.username; |
|
129 |
this.$alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", '系统提示', { |
|
130 |
dangerouslyUseHTMLString: true, |
|
131 |
type: 'success' |
|
132 |
}).then(() => { |
|
133 |
this.$router.push("/login"); |
|
134 |
}).catch(() => {}); |
|
135 |
}).catch(() => { |
|
136 |
this.loading = false; |
|
137 |
if (this.captchaEnabled) { |
|
138 |
this.getCode(); |
|
139 |
} |
|
140 |
}) |
|
141 |
} |
|
142 |
}); |
|
143 |
} |
|
144 |
} |
|
145 |
}; |
|
146 |
</script> |
|
147 |
|
|
148 |
<style rel="stylesheet/scss" lang="scss"> |
|
149 |
.register { |
|
150 |
display: flex; |
|
151 |
justify-content: center; |
|
152 |
align-items: center; |
|
153 |
height: 100%; |
|
154 |
background-image: url("../assets/images/login-background.jpg"); |
|
155 |
background-size: cover; |
|
156 |
} |
|
157 |
.title { |
|
158 |
margin: 0px auto 30px auto; |
|
159 |
text-align: center; |
|
160 |
color: #707070; |
|
161 |
} |
|
162 |
|
|
163 |
.register-form { |
|
164 |
border-radius: 6px; |
|
165 |
background: #ffffff; |
|
166 |
width: 400px; |
|
167 |
padding: 25px 25px 5px 25px; |
|
168 |
.el-input { |
|
169 |
height: 38px; |
|
170 |
input { |
|
171 |
height: 38px; |
|
172 |
} |
|
173 |
} |
|
174 |
.input-icon { |
|
175 |
height: 39px; |
|
176 |
width: 14px; |
|
177 |
margin-left: 2px; |
|
178 |
} |
|
179 |
} |
|
180 |
.register-tip { |
|
181 |
font-size: 13px; |
|
182 |
text-align: center; |
|
183 |
color: #bfbfbf; |
|
184 |
} |
|
185 |
.register-code { |
|
186 |
width: 33%; |
|
187 |
height: 38px; |
|
188 |
float: right; |
|
189 |
img { |
|
190 |
cursor: pointer; |
|
191 |
vertical-align: middle; |
|
192 |
} |
|
193 |
} |
|
194 |
.el-register-footer { |
|
195 |
height: 40px; |
|
196 |
line-height: 40px; |
|
197 |
position: fixed; |
|
198 |
bottom: 0; |
|
199 |
width: 100%; |
|
200 |
text-align: center; |
|
201 |
color: #fff; |
|
202 |
font-family: Arial; |
|
203 |
font-size: 12px; |
|
204 |
letter-spacing: 1px; |
|
205 |
} |
|
206 |
.register-code-img { |
|
207 |
height: 38px; |
|
208 |
} |
|
209 |
</style> |