luohairen
2024-11-12 b802c3a08a4515986cd2ee4430a8c64f25972a04
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<template>
  <div class="w-screen h-screen overflow-hidden">
    <img src="@/assets/background.png" class="w-full h-full object-cover absolute z-0" alt="">
    <div class="lowin lowin-blue mt-20">
      <div class="lowin-brand">
        <img src="@/assets/logo.png" alt="logo">
      </div>
      <div class="lowin-wrapper">
        <div class="lowin-box lowin-login">
          <div class="lowin-box-inner">
            <el-form ref="loginFormRef" :model="loginForm" :rules="loginRules">
              <p>语音视频培训系统</p>
              <div class="lowin-group">
                <el-form-item prop="userName">
                  <label>用户名 </label>
                  <el-input ref="userName" v-model="loginForm.userName" class="lowin-input" placeholder="用户名"
                            name="userName" type="text" tabindex="1" auto-complete="on"/>
                </el-form-item>
              </div>
              <div class="lowin-group password-group">
                <el-form-item prop="password">
                  <!-- <label>密码 <a href="#" class="forgot-link">忘记密码?</a></label> -->
                  <el-input class="lowin-input" :key="passwordType" ref="password" v-model="loginForm.password"
                            :type="passwordType" placeholder="密码" name="password" tabindex="2" auto-complete="on"
                            @keyup.native="checkCapslock" @blur="capsTooltip = false"
                            @keyup.enter.native="handleLogin"/>
                </el-form-item>
              </div>
 
              <el-button :loading="loading" class="lowin-btn login-btn" @click="handleLogin">登录</el-button>
            </el-form>
 
          </div>
        </div>
      </div>
    </div>
  </div>
 
  <el-dialog
      title="修改密码"
      v-model="forceUpdateShow"
      width="400px"
  >
    <div style="margin-bottom: 10px; color: #aa1111">您的密码已经过期,请重新设置~</div>
    <el-form ref="updatePasswordFormRef" :model="updatePasswordForm" :rules="updatePasswordRules">
      <el-form-item label="新密码" prop="newPassword">
        <el-input v-model="updatePasswordForm.newPassword" placeholder="应包含大小写、数字" show-password></el-input>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input v-model="updatePasswordForm.confirmPassword" placeholder="确认密码" show-password></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
              <el-button @click="forceUpdateShow = false">关 闭</el-button>
               <el-button type="primary" @click="changePassword">修 改</el-button>
              </span>
  </el-dialog>
</template>
 
<script setup>
import {ref, reactive, onMounted, nextTick} from 'vue';
import {useRouter} from 'vue-router';
import {ElMessage} from 'element-plus';
import {login, updatePassword} from '@/api/modules/user.js';
import {useUserStore} from '@/store/index.js';
 
const userStore = useUserStore();
 
const router = useRouter();
 
const forceUpdateShow = ref(false);
 
const updatePasswordForm = reactive({
  userId: null,
  newPassword: '',
  confirmPassword: ''
});
 
const validateUsername = (rule, value, callback) => {
  if (value.length < 5) {
    callback(new Error('用户名不能少于5个字符'));
  } else {
    callback();
  }
};
const validatePassword = (rule, value, callback) => {
  if (value.length < 5) {
    callback(new Error('密码不能少于5个字符'));
  } else {
    callback();
  }
};
const validateNewPassword = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请输入密码'))
  } else if (!/[A-Z]/.test(value)) {
    callback(new Error('密码必须包含至少一个大写字母'))
  } else if (!/[a-z]/.test(value)) {
    callback(new Error('密码必须包含至少一个小写字母'))
  } else if (!/[0-9]/.test(value)) {
    callback(new Error('密码必须包含至少一个数字'))
  } else {
    callback()
  }
}
 
const loginForm = reactive({
  userName: '',
  password: '',
  remember: false
});
const loginRules = reactive({
  userName: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
  password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
});
const updatePasswordRules = reactive({
  newPassword: [{required: true, trigger: 'blur', validator: validateNewPassword}]
});
const passwordType = ref('password');
const capsTooltip = ref(false);
const loading = ref(false);
const showDialog = ref(false);
 
 
const userName = ref(null);
const password = ref(null);
 
const loginFormRef = ref(null);
const updatePasswordFormRef = ref(null);
 
const checkCapslock = ({shiftKey, key} = {}) => {
  if (key && key.length === 1) {
    if (shiftKey && (key >= 'a' && key <= 'z') || !shiftKey && (key >= 'A' && key <= 'Z')) {
      capsTooltip.value = true;
    } else {
      capsTooltip.value = false;
    }
  }
  if (key === 'CapsLock' && capsTooltip.value === true) {
    capsTooltip.value = false;
  }
};
 
const showPwd = () => {
  if (passwordType.value === 'password') {
    passwordType.value = '';
  } else {
    passwordType.value = 'password';
  }
  nextTick(() => {
    password.value.focus();
  });
};
 
const handleLogin = () => {
  loginFormRef.value.validate((valid) => {
    if (valid) {
      loading.value = true;
      login(loginForm).then(res => {
        // 如果code为205,则强制修改密码
        if (res && res.code === 205) {
          updatePasswordForm.userId = res.data
          console.log(updatePasswordForm.userId)
          forceUpdateShow.value = true;
          console.log(forceUpdateShow.value)
          loading.value = false
        } else {
          loading.value = false;
          userStore.setUserInfo(res.data);
          router.push('/index');
        }
      }).catch(err => {
        loading.value = false;
      });
    }
  });
};
const changePassword = () => {
  updatePasswordFormRef.value.validate((valid) => {
    if (valid) {
      if (updatePasswordForm.newPassword !== updatePasswordForm.confirmPassword) {
        ElMessage.error('两次输入的密码不一致');
        return;
      }
      updatePassword(updatePasswordForm).then(res => {
        if (res.code === 1) {
          ElMessage.success('密码修改成功。请重新登录');
          loginForm.password = '';
          forceUpdateShow.value = false;
        }
      }).catch(error => {
        ElMessage.error('密码修改失败:' + error.message);
      });
    }
  });
};
onMounted(() => {
  if (loginForm.userName === '') {
    userName.value.focus();
  } else if (loginForm.password === '') {
    password.value.focus();
  }
});
</script>
 
<style scoped>
.lowin {
  /* variables */
  --color-primary: #44a0b3;
  --color-grey: rgba(68, 160, 179, .06);
  --color-dark: rgba(68, 160, 179, .5);
  --color-semidark: rgba(68, 160, 179, .5);
 
  text-align: center;
  font-family: 'Segoe UI';
  font-size: 14px;
}
 
.lowin .lowin-wrapper {
  -webkit-transition: all 1s;
  -o-transition: all 1s;
  transition: all 1s;
  -webkit-perspective: 1000px;
  perspective: 1000px;
  position: relative;
  height: 100%;
  width: 360px;
  margin: 0 auto;
}
 
.lowin.lowin-blue {
  --color-primary: #0081C6;
  --color-grey: rgba(0, 129, 198, .05);
  --color-dark: rgba(0, 129, 198, .7);
  --color-semidark: rgba(0, 129, 198, .45);
}
 
.lowin a {
  color: var(--color-primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--color-semidark);
  margin-top: -3px;
  padding-bottom: 2px;
}
 
.lowin * {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
 
.lowin .lowin-brand {
  overflow: hidden;
  width: 100px;
  height: 100px;
  margin: 0 auto -50px auto;
  border-radius: 50%;
  -webkit-box-shadow: 0 4px 40px rgba(0, 0, 0, .07);
  box-shadow: 0 4px 40px rgba(0, 0, 0, .07);
  padding: 10px;
  background-color: #fff;
  z-index: 1;
  position: relative;
}
 
.lowin .lowin-brand img {
  width: 100%;
}
 
.lowin .lowin-box {
  width: 100%;
  position: absolute;
  left: 0;
}
 
.lowin .lowin-box-inner {
  background-color: #fff;
  -webkit-box-shadow: 0 7px 25px rgba(0, 0, 0, .08);
  box-shadow: 0 7px 25px rgba(0, 0, 0, .08);
  padding: 60px 25px 25px 25px;
  text-align: left;
  border-radius: 3px;
}
 
.lowin .lowin-box::after {
  content: ' ';
  -webkit-box-shadow: 0 0 25px rgba(0, 0, 0, .1);
  box-shadow: 0 0 25px rgba(0, 0, 0, .1);
  -webkit-transform: translate(0, -92.6%) scale(.88);
  -ms-transform: translate(0, -92.6%) scale(.88);
  transform: translate(0, -92.6%) scale(.88);
  border-radius: 3px;
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  z-index: -1;
}
 
.lowin .lowin-box.lowin-flip {
  -webkit-transform: rotate3d(0, 1, 0, -180deg);
  transform: rotate3d(0, 1, 0, -180deg);
  display: none;
  opacity: 0;
}
 
.lowin .lowin-box p {
  color: var(--color-semidark);
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}
 
.lowin .lowin-box .lowin-group {
  margin-bottom: 30px;
}
 
.lowin .lowin-box label {
  margin-bottom: 5px;
  display: inline-block;
  width: 100%;
  color: var(--color-semidark);
  font-weight: 700;
}
 
.lowin .lowin-box label a {
  float: right;
}
 
.lowin .lowin-box .lowin-input {
  background-color: var(--color-grey);
  color: var(--color-dark);
  border: none;
  border-radius: 3px;
  padding: 5px 20px;
  width: 100%;
  outline: 0;
}
 
.lowin .lowin-box .lowin-btn {
  display: inline-block;
  width: 100%;
  border: none;
  color: #fff;
  border-radius: 3px;
  background-color: var(--color-primary);
  -webkit-box-shadow: 0 2px 7px var(--color-semidark);
  box-shadow: 0 2px 7px var(--color-semidark);
  font-weight: 700;
  outline: 0;
  cursor: pointer;
  -webkit-transition: all .5s;
  -o-transition: all .5s;
  transition: all .5s;
}
 
.lowin .lowin-box .lowin-btn:active {
  -webkit-box-shadow: none;
  box-shadow: none;
}
 
.lowin .lowin-box .lowin-btn:hover {
  opacity: .9;
}
 
.lowin .text-foot {
  text-align: center;
  padding: 10px;
  font-weight: 700;
  margin-top: 20px;
  color: var(--color-semidark);
}
 
/* animation */
.lowin .lowin-box.lowin-animated {
  -webkit-animation-name: LowinAnimated;
  animation-name: LowinAnimated;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}
 
.lowin .lowin-box.lowin-animatedback {
  -webkit-animation-name: LowinAnimatedBack;
  animation-name: LowinAnimatedBack;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}
 
.lowin .lowin-box.lowin-animated-flip {
  -webkit-animation-name: LowinAnimatedFlip;
  animation-name: LowinAnimatedFlip;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}
 
.lowin .lowin-box.lowin-animated-flipback {
  -webkit-animation-name: LowinAnimatedFlipBack;
  animation-name: LowinAnimatedFlipBack;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}
 
.lowin .lowin-brand.lowin-animated {
  -webkit-animation-name: LowinBrandAnimated;
  animation-name: LowinBrandAnimated;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}
 
.lowin .lowin-group.password-group {
  -webkit-transition: all 1s;
  -o-transition: all 1s;
  transition: all 1s;
}
 
.lowin .lowin-group.password-group.lowin-animated {
  -webkit-animation-name: LowinPasswordAnimated;
  animation-name: LowinPasswordAnimated;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
}
 
.lowin .lowin-group.password-group.lowin-animated-back {
  -webkit-animation-name: LowinPasswordAnimatedBack;
  animation-name: LowinPasswordAnimatedBack;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
}
 
@media screen and (max-width: 320px) {
  .lowin .lowin-wrapper {
    width: 100%;
  }
 
  .lowin .lowin-box {
    padding: 0 10px;
  }
}
</style>