|
@@ -0,0 +1,329 @@
|
|
1
|
+<template>
|
|
2
|
+ <div class="login-container">
|
|
3
|
+ <el-form
|
|
4
|
+ ref="regisiterForm"
|
|
5
|
+ :model="regisiterForm"
|
|
6
|
+ :rules="regisiterRules"
|
|
7
|
+ class="login-form"
|
|
8
|
+ auto-complete="on"
|
|
9
|
+ label-position="left"
|
|
10
|
+ >
|
|
11
|
+ <div class="title-container">
|
|
12
|
+ <h3 class="title">注册账号</h3>
|
|
13
|
+ </div>
|
|
14
|
+
|
|
15
|
+ <el-form-item prop="name">
|
|
16
|
+ <span class="svg-container">
|
|
17
|
+ <svg-icon icon-class="user" />
|
|
18
|
+ </span>
|
|
19
|
+ <el-input
|
|
20
|
+ ref="name"
|
|
21
|
+ v-model="regisiterForm.name"
|
|
22
|
+ placeholder="用户名"
|
|
23
|
+ name="name"
|
|
24
|
+ type="text"
|
|
25
|
+ tabindex="1"
|
|
26
|
+ />
|
|
27
|
+ </el-form-item>
|
|
28
|
+
|
|
29
|
+ <el-form-item prop="password">
|
|
30
|
+ <span class="svg-container">
|
|
31
|
+ <svg-icon icon-class="password" />
|
|
32
|
+ </span>
|
|
33
|
+ <el-input
|
|
34
|
+ :key="passwordType"
|
|
35
|
+ ref="password"
|
|
36
|
+ v-model="regisiterForm.password"
|
|
37
|
+ :type="passwordType"
|
|
38
|
+ placeholder="密码"
|
|
39
|
+ name="password"
|
|
40
|
+ tabindex="2"
|
|
41
|
+ />
|
|
42
|
+ <span class="show-pwd" @click="showPwd">
|
|
43
|
+ <svg-icon
|
|
44
|
+ :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
|
45
|
+ />
|
|
46
|
+ </span>
|
|
47
|
+ </el-form-item>
|
|
48
|
+ <el-form-item prop="password2">
|
|
49
|
+ <span class="svg-container">
|
|
50
|
+ <svg-icon icon-class="password" />
|
|
51
|
+ </span>
|
|
52
|
+ <el-input
|
|
53
|
+ ref="password2"
|
|
54
|
+ v-model="regisiterForm.password2"
|
|
55
|
+ type="text"
|
|
56
|
+ placeholder="确认密码"
|
|
57
|
+ name="password2"
|
|
58
|
+ tabindex="3"
|
|
59
|
+ />
|
|
60
|
+ </el-form-item>
|
|
61
|
+ <el-form-item prop="phone">
|
|
62
|
+ <span class="svg-container">
|
|
63
|
+ <svg-icon icon-class="password" />
|
|
64
|
+ </span>
|
|
65
|
+ <el-input
|
|
66
|
+ ref="phone"
|
|
67
|
+ v-model="regisiterForm.phone"
|
|
68
|
+ type="tel"
|
|
69
|
+ placeholder="手机号"
|
|
70
|
+ name="phone"
|
|
71
|
+ tabindex="4"
|
|
72
|
+ />
|
|
73
|
+ </el-form-item>
|
|
74
|
+
|
|
75
|
+ <el-form-item prop="captcha" style="width:65%">
|
|
76
|
+ <span class="svg-container">
|
|
77
|
+ <svg-icon icon-class="password" />
|
|
78
|
+ </span>
|
|
79
|
+ <el-input
|
|
80
|
+ ref="captcha"
|
|
81
|
+ v-model="regisiterForm.captcha"
|
|
82
|
+ type="text"
|
|
83
|
+ placeholder="验证码"
|
|
84
|
+ tabindex="5"
|
|
85
|
+ name="captcha"
|
|
86
|
+ @keyup.enter.native="handleLogin"
|
|
87
|
+ />
|
|
88
|
+ <el-button style="position: absolute;right: -150px;top: 6px;" :disabled="disabled" @click="sendCode">{{ btnText }}</el-button>
|
|
89
|
+ </el-form-item>
|
|
90
|
+
|
|
91
|
+ <el-button
|
|
92
|
+ :loading="loading"
|
|
93
|
+ type="primary"
|
|
94
|
+ style="width: 100%; margin-bottom: 30px"
|
|
95
|
+ @click.native.prevent="handleLogin"
|
|
96
|
+ >注册</el-button>
|
|
97
|
+ <el-link :underline="false" style="margin:0" type="primary">
|
|
98
|
+ <router-link
|
|
99
|
+ :to="{path: '/login'}"
|
|
100
|
+ >登录系统</router-link>
|
|
101
|
+ </el-link>
|
|
102
|
+ <el-link :underline="false" style="float:right" type="primary">
|
|
103
|
+ <router-link
|
|
104
|
+ :to="{name: 'forgotPassword'}"
|
|
105
|
+ >忘记密码</router-link>
|
|
106
|
+ </el-link>
|
|
107
|
+ </el-form>
|
|
108
|
+ </div>
|
|
109
|
+</template>
|
|
110
|
+<script>
|
|
111
|
+import { getCaptcha, signUp } from '@/api/signup'
|
|
112
|
+import md5 from 'js-md5'
|
|
113
|
+export default {
|
|
114
|
+ name: 'Login',
|
|
115
|
+ data() {
|
|
116
|
+ const validatePhone = (rule, value, callback) => {
|
|
117
|
+ if (!value) {
|
|
118
|
+ return callback(new Error('手机号不能为空'))
|
|
119
|
+ } else {
|
|
120
|
+ const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
|
|
121
|
+ if (reg.test(value)) {
|
|
122
|
+ callback()
|
|
123
|
+ } else {
|
|
124
|
+ return callback(new Error('请输入正确的手机号'))
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+ }
|
|
128
|
+ return {
|
|
129
|
+ regisiterForm: {
|
|
130
|
+ name: undefined,
|
|
131
|
+ password: undefined,
|
|
132
|
+ phone: undefined,
|
|
133
|
+ captcha: '619400',
|
|
134
|
+ password2: undefined
|
|
135
|
+ },
|
|
136
|
+ regisiterRules: {
|
|
137
|
+ name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
|
138
|
+ password: [
|
|
139
|
+ { required: true, trigger: 'change', message: '请输入密码' }
|
|
140
|
+ ],
|
|
141
|
+ password2: [
|
|
142
|
+ { required: true, trigger: 'change', message: '请再次输入密码' }
|
|
143
|
+ ],
|
|
144
|
+ phone: [
|
|
145
|
+ { required: true, trigger: 'change', validator: validatePhone }
|
|
146
|
+ ],
|
|
147
|
+ captcha: [
|
|
148
|
+ { required: true, trigger: 'change', message: '请输入验证码' }
|
|
149
|
+ ]
|
|
150
|
+ },
|
|
151
|
+ disabled: false,
|
|
152
|
+ btnText: '发送验证码',
|
|
153
|
+ time: 0,
|
|
154
|
+ loading: false,
|
|
155
|
+ passwordType: 'password'
|
|
156
|
+ }
|
|
157
|
+ },
|
|
158
|
+ methods: {
|
|
159
|
+ sendCode() {
|
|
160
|
+ this.disabled = true
|
|
161
|
+
|
|
162
|
+ this.$refs.regisiterForm.validateField('phone', (errorMessage) => {
|
|
163
|
+ if (errorMessage) {
|
|
164
|
+ this.$message.error(errorMessage)
|
|
165
|
+
|
|
166
|
+ this.disabled = false
|
|
167
|
+ } else {
|
|
168
|
+ getCaptcha({ phone: this.regisiterForm.phone })
|
|
169
|
+ .then((e) => {})
|
|
170
|
+ .catch((res) => {
|
|
171
|
+ // console.log(res)
|
|
172
|
+ })
|
|
173
|
+ this.time = 60
|
|
174
|
+ const timer = setInterval(() => {
|
|
175
|
+ this.time-- // 倒计时递减
|
|
176
|
+ this.btnText = `${this.time}s后重新发送`
|
|
177
|
+ if (this.time === 0) {
|
|
178
|
+ this.disabled = false
|
|
179
|
+ this.btnText = '重新发送'
|
|
180
|
+ this.time = this.countDown
|
|
181
|
+ clearInterval(timer)
|
|
182
|
+ }
|
|
183
|
+ }, 1000)
|
|
184
|
+ }
|
|
185
|
+ })
|
|
186
|
+ },
|
|
187
|
+ showPwd() {
|
|
188
|
+ if (this.passwordType === 'password') {
|
|
189
|
+ this.passwordType = ''
|
|
190
|
+ } else {
|
|
191
|
+ this.passwordType = 'password'
|
|
192
|
+ }
|
|
193
|
+ this.$nextTick(() => {
|
|
194
|
+ this.$refs.password.focus()
|
|
195
|
+ })
|
|
196
|
+ },
|
|
197
|
+ handleLogin() {
|
|
198
|
+ this.$refs.regisiterForm.validate((valid) => {
|
|
199
|
+ if (valid) {
|
|
200
|
+ if (this.regisiterForm.password !== this.regisiterForm.password2) {
|
|
201
|
+ this.$message('密码输入不一致请重新输入')
|
|
202
|
+ this.$refs.password2.focus()
|
|
203
|
+ return false
|
|
204
|
+ } else {
|
|
205
|
+ this.regisiterForm.password = md5(this.regisiterForm.password)
|
|
206
|
+ signUp(this.regisiterForm).then((res) => {
|
|
207
|
+ this.$message('注册成功')
|
|
208
|
+ this.$router.push({ path: '/login' })
|
|
209
|
+ })
|
|
210
|
+ }
|
|
211
|
+ } else {
|
|
212
|
+ return false
|
|
213
|
+ }
|
|
214
|
+ })
|
|
215
|
+ }
|
|
216
|
+ }
|
|
217
|
+}
|
|
218
|
+</script>
|
|
219
|
+
|
|
220
|
+<style lang="scss">
|
|
221
|
+/* 修复input 背景不协调 和光标变色 */
|
|
222
|
+/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
|
223
|
+
|
|
224
|
+$bg: #283443;
|
|
225
|
+$light_gray: #fff;
|
|
226
|
+$cursor: #fff;
|
|
227
|
+
|
|
228
|
+@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
|
|
229
|
+ .login-container .el-input input {
|
|
230
|
+ color: $cursor;
|
|
231
|
+ }
|
|
232
|
+}
|
|
233
|
+
|
|
234
|
+/* reset element-ui css */
|
|
235
|
+.login-container {
|
|
236
|
+ .el-input {
|
|
237
|
+ display: inline-block;
|
|
238
|
+ height: 47px;
|
|
239
|
+ width: 85%;
|
|
240
|
+
|
|
241
|
+ input {
|
|
242
|
+ background: transparent;
|
|
243
|
+ border: 0px;
|
|
244
|
+ -webkit-appearance: none;
|
|
245
|
+ border-radius: 0px;
|
|
246
|
+ padding: 12px 5px 12px 15px;
|
|
247
|
+ color: $light_gray;
|
|
248
|
+ height: 47px;
|
|
249
|
+ caret-color: $cursor;
|
|
250
|
+
|
|
251
|
+ &:-webkit-autofill {
|
|
252
|
+ box-shadow: 0 0 0px 1000px $bg inset !important;
|
|
253
|
+ -webkit-text-fill-color: $cursor !important;
|
|
254
|
+ }
|
|
255
|
+ }
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ .el-form-item {
|
|
259
|
+ border: 1px solid rgba(255, 255, 255, 0.1);
|
|
260
|
+ background: rgba(0, 0, 0, 0.1);
|
|
261
|
+ border-radius: 5px;
|
|
262
|
+ color: #454545;
|
|
263
|
+ }
|
|
264
|
+}
|
|
265
|
+</style>
|
|
266
|
+
|
|
267
|
+<style lang="scss" scoped>
|
|
268
|
+$bg: #2d3a4b;
|
|
269
|
+$dark_gray: #889aa4;
|
|
270
|
+$light_gray: #eee;
|
|
271
|
+
|
|
272
|
+.login-container {
|
|
273
|
+ min-height: 100%;
|
|
274
|
+ width: 100%;
|
|
275
|
+ background-color: $bg;
|
|
276
|
+ overflow: hidden;
|
|
277
|
+
|
|
278
|
+ .login-form {
|
|
279
|
+ position: relative;
|
|
280
|
+ width: 520px;
|
|
281
|
+ max-width: 100%;
|
|
282
|
+ padding: 160px 35px 0;
|
|
283
|
+ margin: 0 auto;
|
|
284
|
+ overflow: hidden;
|
|
285
|
+ }
|
|
286
|
+
|
|
287
|
+ .tips {
|
|
288
|
+ font-size: 14px;
|
|
289
|
+ color: #fff;
|
|
290
|
+ margin-bottom: 10px;
|
|
291
|
+
|
|
292
|
+ span {
|
|
293
|
+ &:first-of-type {
|
|
294
|
+ margin-right: 16px;
|
|
295
|
+ }
|
|
296
|
+ }
|
|
297
|
+ }
|
|
298
|
+
|
|
299
|
+ .svg-container {
|
|
300
|
+ padding: 6px 5px 6px 15px;
|
|
301
|
+ color: $dark_gray;
|
|
302
|
+ vertical-align: middle;
|
|
303
|
+ width: 30px;
|
|
304
|
+ display: inline-block;
|
|
305
|
+ }
|
|
306
|
+
|
|
307
|
+ .title-container {
|
|
308
|
+ position: relative;
|
|
309
|
+
|
|
310
|
+ .title {
|
|
311
|
+ font-size: 26px;
|
|
312
|
+ color: $light_gray;
|
|
313
|
+ margin: 0px auto 40px auto;
|
|
314
|
+ text-align: center;
|
|
315
|
+ font-weight: bold;
|
|
316
|
+ }
|
|
317
|
+ }
|
|
318
|
+
|
|
319
|
+ .show-pwd {
|
|
320
|
+ position: absolute;
|
|
321
|
+ right: 10px;
|
|
322
|
+ top: 7px;
|
|
323
|
+ font-size: 16px;
|
|
324
|
+ color: $dark_gray;
|
|
325
|
+ cursor: pointer;
|
|
326
|
+ user-select: none;
|
|
327
|
+ }
|
|
328
|
+}
|
|
329
|
+</style>
|