Blame view

merchant-web-master/src/views/login/index.vue 18.4 KB
3f535f30   杨鑫   '初始'
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
  <template>
    <div class="login" :style="'background-color:#3f9b6a;'">
    <!-- <div class="login" :style="'background-image:url(' + Background + ');'"> -->
      <!-- 登录 -->
  
      <div v-if="getPassword" class="loginBox">
        <div class="logoimg">
      <img src="@/assets/images/logo.png"/>
     </div>
        <div class="leftBox" style="display:none" />
        <div class="rightBox">
          <h2>商家登录</h2>
          <div class="tabTouch">
            <div
              v-for="(item, index) in activeList"
              :key="index"
              :class="[tabIndex != index ? 'touchOne' : 'touchTwo']"
              @click="touchTab(index)"
            >{{ item.name }}</div>
          </div>
          <!-- 账户密码登录 -->
          <div v-if="!tabIndex">
            <el-form
              ref="loginForm"
              :model="loginForm"
              :rules="loginRules"
              label-position="left"
              label-width="0px"
              class="login-form"
            >
              <el-form-item prop="username">
                <el-input
                  v-model="loginForm.username"
                  type="text"
                  maxlength="11"
                  auto-complete="off"
                  placeholder="请输入账户"
                  class="iptHeight"
                >
                  <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
                </el-input>
              </el-form-item>
              <el-form-item prop="password">
                <el-input
                  v-model="loginForm.password"
                  type="password"
                  class="iptHeight"
                  auto-complete="off"
                  placeholder="请输入密码"
                  @keyup.enter.native="handleAccountLogin"
                >
                  <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                </el-input>
              </el-form-item>
              <div class="boxBottom">
a4aeeb1e   杨鑫   '最新'
56
57
  				<div></div>
                <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin: 0 0 25px 0">自动登录</el-checkbox> -->
3f535f30   杨鑫   '初始'
58
59
60
61
62
63
64
                <div class="forgetPsd" @click="runForgetPassord">忘记密码</div>
              </div>
  
              <el-form-item style="width: 100%">
                <el-button
                  :loading="loading"
                  size="medium"
e65c626a   杨鑫   '改bug'
65
                  style="width: 100%; border-radius: 20px;background-color: #3F9B6A;color: #fff;"
3f535f30   杨鑫   '初始'
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
                  @click.native.prevent="handleAccountLogin"
                >
                  <span v-if="!loading">登 录</span>
                  <span v-else>登 录 中...</span>
                </el-button>
              </el-form-item>
            </el-form>
          </div>
          <!-- 手机号登录 -->
          <div v-else>
            <el-form
              ref="anthorForm"
              :model="anthorForm"
              :rules="anthorRules"
              label-position="left"
              label-width="0px"
              class="login-form"
            >
              <el-form-item prop="username">
                <el-input
                  v-model="anthorForm.username"
                  type="text"
                  maxlength="11"
                  auto-complete="off"
                  placeholder="请输入手机号码"
                  class="iptHeight"
                >
                  <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
                </el-input>
              </el-form-item>
              <el-form-item prop="code">
                <el-input
                  v-model="anthorForm.code"
                  type="text"
                  class="iptHeight"
                  auto-complete="off"
                  style="width: 63%"
                  placeholder="请输入验证码"
                  @keyup.enter.native="handlePhoneLogin"
                >
                  <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                </el-input>
                <div class="login-code">
                  <el-button
                    class="codeBtn"
                    type="primary"
                    :loading="codeloading"
                    @click="getCode(anthorForm.username)"
                  >
                    <span v-if="!codeloading">获取验证码</span>
                    <span v-else>{{ count }} s</span>
                  </el-button>
                </div>
              </el-form-item>
              <div class="boxBottom">
a4aeeb1e   杨鑫   '最新'
121
                <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin: 0 0 25px 0">自动登录</el-checkbox> -->
3f535f30   杨鑫   '初始'
122
123
124
125
126
127
              </div>
  
              <el-form-item style="width: 100%">
                <el-button
                  :loading="loading"
                  size="medium"
e65c626a   杨鑫   '改bug'
128
                  style="width: 100%; border-radius: 20px;background-color: #3F9B6A;color: #fff;"
3f535f30   杨鑫   '初始'
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
                  @click.native.prevent="handlePhoneLogin"
                >
                  <span v-if="!loading">登 录</span>
                  <span v-else>登 录 中...</span>
                </el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
      <!-- 找回密码 -->
      <div v-else class="loginBox">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span style="margin-left: 25px">找回密码</span>
            <el-button
e65c626a   杨鑫   '改bug'
145
146
              
              style="border-radius: 20px;background-color: #3F9B6A;color: #fff;float: right; padding: 3px 0"
3f535f30   杨鑫   '初始'
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
              @click="getPassword=true"
            >返回登录</el-button>
            <div class="cardBox">
              <el-form
                ref="retrievePwd"
                :model="retrievePwdForm"
                :rules="retrievePwdRules"
                label-position="left"
                label-width="0px"
                class="login-form"
              >
                <el-form-item prop="username">
                  <el-input
                    v-model="retrievePwdForm.username"
                    type="text"
                    maxlength="11"
                    auto-complete="off"
                    placeholder="请输入手机号码"
                    class="iptHeight"
                  >
                    <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
                  </el-input>
                </el-form-item>
                <el-form-item prop="code">
                  <el-input
                    v-model="retrievePwdForm.code"
                    type="text"
                    class="iptHeight"
                    auto-complete="off"
                    style="width: 63%"
                    placeholder="请输入验证码"
                    @keyup.enter.native="forgetPwdFn"
                  >
                    <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                  </el-input>
                  <div class="login-code">
                    <el-button
                      class="codeBtn"
                      type="primary"
                      :loading="codeloading"
                      @click="getCode(retrievePwdForm.username)"
                    >
                      <span v-if="!codeloading">获取验证码</span>
                      <span v-else>{{ count }} s</span>
                    </el-button>
                  </div>
                </el-form-item>
                <el-form-item prop="newPassword">
                  <el-input
                    v-model="retrievePwdForm.newPassword"
                    type="password"
                    maxlength="11"
                    auto-complete="off"
                    placeholder="新密码"
                    class="iptHeight"
                  >
                    <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                  </el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input
                    v-model="retrievePwdForm.password"
                    type="password"
                    maxlength="11"
                    auto-complete="off"
                    placeholder="确认密码"
                    class="iptHeight"
                  >
                    <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                  </el-input>
                </el-form-item>
                <el-form-item style="width: 100%">
                  <el-button
                    :loading="loading"
                    size="medium"
                    type="primary"
                    style="width: 100%; border-radius: 20px"
                    @click.native.prevent="forgetPwdFn"
                  >
                    <span v-if="!loading">确 认 修 改</span>
                    <span v-else>提 交 中...</span>
                  </el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </el-card>
      </div>
      <!--  底部  -->
      <!-- <div class="login-footer">© 2019 antis</div> -->
    </div>
  </template>
  
  <script>
  // import { validUsername } from '@/utils/validate'
  import { adminBuild, forgetPassword } from '@/api/user'
  import {
    getUserId
  } from '@/utils/auth' // get token from cookie
  const TIME_COUNT = 60 // 更改倒计时时间
  import Background from '@/assets/images/background.jpg'
  import { getCode } from '@/api/account'
  const JM = require('@/utils/rsaEncrypt.js')
  export default {
    name: 'Login',
    data() {
      // const validateUsername = (rule, value, callback) => {
      //   if (!validUsername(value)) {
      //     callback(new Error('Please enter the correct user name'))
      //   } else {
      //     callback()
      //   }
      // }
      // const validatePassword = (rule, value, callback) => {
      //   if (value.length < 6) {
      //     callback(new Error('The password can not be less than 6 digits'))
      //   } else {
      //     callback()
      //   }
      // }
      return {
        Background: Background,
        cookiePass: '',
        loginForm: {
          username: '',
          password: '',
          rememberMe: false
        },
        anthorForm: {
          username: '',
          code: '',
          rememberMe: false
        },
        retrievePwdForm: {
          code: '',
          newPassword: '',
          password: '',
          username: '' // 手机号
        },
        tabIndex: 0,
        activeList: [
          {
            name: '账户密码登录',
            id: 0
          },
          {
            name: '手机号码登录',
            id: 1
          }
        ],
        retrievePwdRules: {
          username: [
            { required: true, trigger: 'blur', message: '手机号码不能为空' }
          ],
          code: [
            { required: true, trigger: 'blur', message: '验证码不能为空' }
          ],
          newPassword: [
            { required: true, trigger: 'blur', message: '密码不能为空' }
          ],
          password: [
            { required: true, trigger: 'blur', message: '确认密码不能为空' }
          ]
        },
        loginRules: {
          username: [
            { required: true, trigger: 'blur', message: '用户名不能为空' }
          ],
          password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
        },
        anthorRules: {
          username: [
            { required: true, trigger: 'blur', message: '手机号不能为空' }
          ],
          code: [{ required: true, trigger: 'blur', message: '验证码不能为空' }]
        },
        loading: false,
        codeloading: false,
        count: '',
        timer: null,
        redirect: undefined,
        getPassword: true
      }
    },
    watch: {
      $route: {
        handler: function(route) {
          this.redirect = route.query && route.query.redirect
        },
        immediate: true
      }
    },
    methods: {
      // 点击tab
      touchTab(index) {
        console.log(index)
        this.tabIndex = index
      },
      // 获取验证码
      async getCode(phone) {
        console.log(phone)
        if (phone === '' || phone === undefined) {
          this.$message.error('请填写电话号码')
          return
        }
57b010a3   杨鑫   最新1
352
353
        const res = await getCode({phone:phone})
        if (res.code === '200') {
3f535f30   杨鑫   '初始'
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
          this.$message({
            message: '发送成功,请注意查看手机短信',
            type: 'success'
          })
          if (!this.timer) {
            this.codeloading = true
            this.count = TIME_COUNT
            this.timer = setInterval(() => {
              if (this.count > 1 && this.count <= TIME_COUNT) {
                this.count--
              } else {
                clearInterval(this.timer) // 清除定时器
                this.timer = null
                this.codeloading = false
              }
            }, 1000)
          }
        }
  
        // if (!this.timer) {
        //   this.codeloading = true
        //   this.count = TIME_COUNT
        //   this.show = false
        //   const res = await getCode({ phone })
        //   if (res.code === '') {
        //     this.$message({
        //       message: '发送成功,请注意查看手机短信',
        //       type: 'success'
        //     })
        //   }
        //   this.timer = setInterval(() => {
        //     if (this.count > 0 && this.count <= TIME_COUNT) {
        //       this.count--
        //     } else {
        //       this.show = true
        //       clearInterval(this.timer) // 清除定时器
        //       this.timer = null
        //       this.codeloading = false
        //     }
        //   }, 1000)
        // }
      },
      // 忘记密码
      runForgetPassord() {
        this.getPassword = false
      },
      showPwd() {
        if (this.passwordType === 'password') {
          this.passwordType = ''
        } else {
          this.passwordType = 'password'
        }
        this.$nextTick(() => {
          this.$refs.password.focus()
        })
      },
      // 账户登录
      handleAccountLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.loading = true
            const data = {
              // username: JM.encrypt(this.loginForm.username),
              // password: JM.encrypt(this.loginForm.password),
              username: this.loginForm.username,
              password: this.loginForm.password,
              rememberMe: this.loginForm.rememberMe
            }
            this.$store
              .dispatch('user/login', data)
              .then(() => {
                console.log(this.redirect)
                this.$router.push({ path: this.redirect || '/' })
                this.loading = false
                adminBuild({ platformUserId: getUserId() }).then(res => {
                  console.log(res)
                })
              })
              .catch(() => {
                this.loading = false
              })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      // 手机号码
      handlePhoneLogin() {
        console.log(this.anthorForm)
        this.$refs.anthorForm.validate(valid => {
          if (valid) {
            this.loading = true
            const data = {
57b010a3   杨鑫   最新1
448
449
450
451
              username: this.anthorForm.username ,
  			// JM.encrypt(this.anthorForm.username),
              code:this.anthorForm.code,
  			// JM.encrypt(this.anthorForm.code),
3f535f30   杨鑫   '初始'
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
              rememberMe: this.anthorForm.rememberMe
            }
            this.$store
              .dispatch('user/login', data)
              .then(() => {
                this.$router.push({ path: this.redirect || '/' })
                this.loading = false
                adminBuild({ platformUserId: getUserId() }).then(res => {
                  console.log(res)
                })
              })
              .catch(() => {
                this.loading = false
              })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      // 找回密码
      forgetPwdFn() {
        console.log(this.retrievePwdForm)
        this.$refs.retrievePwd.validate(valid => {
          if (valid) {
            this.loading = true
            const data = {
e65c626a   杨鑫   '改bug'
479
480
481
482
483
484
485
486
              // username: JM.encrypt(this.retrievePwdForm.username),
              // code: JM.encrypt(this.retrievePwdForm.code),
              // password: JM.encrypt(this.retrievePwdForm.password),
              // newPassword: JM.encrypt(this.retrievePwdForm.newPassword)
  			username: this.retrievePwdForm.username,
  			code:this.retrievePwdForm.code,
  			password: this.retrievePwdForm.password,
  			newPassword:this.retrievePwdForm.newPassword
3f535f30   杨鑫   '初始'
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
            }
            forgetPassword(data).then(res => {
              if (res.code === '') {
                this.loading = false
                this.$message({
                  message: '修改成功',
                  type: 'success'
                })
                this.getPassword = true
              }
            }).catch(() => {
              this.loading = false
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
  </script>
  
  <style rel="stylesheet/scss" lang="scss">
  .logoimg{
     position: absolute;
      top: -100px;
      left: 50px;
  }
  .login {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-size: cover;
  }
  .loginBox {
    position:relative;
    width: 500px !important;
    height: 500px;
    // width: 900px !important;
    // height: 600px;
    display: flex;
    background: #ffffff;
    border-radius: 20px;
  }
  .leftBox {
    width: 325px;
    height: 250px;
    margin: 180px 0 0 30px;
    background: url("../../assets/images/logo.png") 50% no-repeat;
    // background: url("../../assets/images/home-content.png") 50% no-repeat;
    background-size: cover;
  }
  .rightBox {
    margin: auto;
    h2 {
      text-align: center;
    }
  }
  .tabTouch {
    display: flex;
    justify-content: space-around;
    align-content: center;
    width: 360px;
57b010a3   杨鑫   最新1
552
    // margin-left: 8px;
3f535f30   杨鑫   '初始'
553
554
555
556
557
558
  }
  .touchOne {
    color: #666666;
    padding: 20px;
  }
  .touchTwo {
e65c626a   杨鑫   '改bug'
559
    border-bottom: 1px solid #3F9B6A;
3f535f30   杨鑫   '初始'
560
    padding: 20px;
e65c626a   杨鑫   '改bug'
561
    color: #3F9B6A;
3f535f30   杨鑫   '初始'
562
563
564
565
566
567
  }
  .boxBottom {
    display: flex;
    justify-content: space-between;
    .forgetPsd {
      font-size: 14px;
e65c626a   杨鑫   '改bug'
568
      color: #3F9B6A;
3f535f30   杨鑫   '初始'
569
570
571
572
      cursor: pointer;
    }
  }
  .title {
3f535f30   杨鑫   '初始'
573
574
575
576
577
578
579
    text-align: center;
    color: #707070;
  }
  
  .login-form {
    border-radius: 6px;
    background: #ffffff;
57b010a3   杨鑫   最新1
580
581
    // width: 90%;
    padding: 25px 0 0 0 ;
3f535f30   杨鑫   '初始'
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
    .el-input {
      height: 38px;
      input {
        height: 38px;
      }
    }
    .input-icon {
      height: 39px;
      width: 14px;
      margin-left: 2px;
    }
  }
  .iptHeight {
    height: 54px !important;
    input {
      height: 54px !important;
    }
    span {
      display: flex;
      align-items: center;
    }
    .input-icon {
      width: 20px;
      height: 20px;
    }
  }
  .login-tip {
    font-size: 13px;
    text-align: center;
    color: #bfbfbf;
  }
  .login-code {
    float: right;
    .codeBtn {
      height: 54px;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100px;
a4aeeb1e   杨鑫   '最新'
621
622
      background: #3F9B6A;
      color: #fff;
3f535f30   杨鑫   '初始'
623
624
625
626
627
628
629
630
631
632
      border: none;
    }
    img {
      vertical-align: middle;
    }
  }
  .box-card {
    width: 100%;
    height: 100%;
    .clearfix {
e65c626a   杨鑫   '改bug'
633
      // width: 50%;
3f535f30   杨鑫   '初始'
634
635
636
637
638
639
640
641
642
643
      margin: 10% auto;
    }
  }
  .login-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
  }
  </style>