Blame view

ant-design-vue-jeecg/src/components/layouts/UserLayoutLogin.vue 15.4 KB
1
2
3
4
5
6
7
<template>
  <div id="userLayout" :class="['user-layout-wrapper']">
    <div class="left-div">
      <div id="logo">
        <div id="logoImg">
          <img src="~@/assets/logo.png" alt="" srcset="" class="imge">
        </div>
谭毅彬 authored
8
        <div id="text">华恒WMS仓储管理系统</div>
9
10
      </div>
      <div id="backgroundImg">
谭毅彬 authored
11
        <img src="~@/assets/beijingtu.jpg" alt="" srcset="" class="imge"/>
12
13
      </div>
      <div id="copyright">
谭毅彬 authored
14
        <div id="company">Copyright &copy; 2024 华恒焊接股份有限公司</div>
15
16
17
      </div>
    </div>
    <div class="right-div">
谭毅彬 authored
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
      <div class="right-login">
        <a-form-model ref="form" :model="model" :rules="validatorRules">
          <div id="welcome">欢迎来到华恒仓储管理系统</div>
          <a-form-model-item required prop="username">
            <a-input id="name" v-model="model.username" size="default"  autocomplete="off" placeholder="请输入帐户名  / admin" @blur="getWarehouse">
            </a-input>
          </a-form-model-item>
          <a-form-model-item required prop="password">
            <a-input id="password" v-model="model.password" size="default" type="password" autocomplete="new-password" @input="maskPassword" placeholder="请输入密码">
            </a-input>
          </a-form-model-item>
          <a-form-model-item prop="warehouseCode">
            <a-select
              show-search
              placeholder="请选择仓库"
              option-filter-prop="label"
              v-model="model.warehouseCode" id="warehouseCode">
              <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{
                  item.name
                }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
          <a-form-item>
            <a-button id="logIn" size="default" type="primary" htmlType="submit" class="login-button"
              :loading="loginBtn" @click.stop.prevent="handleSubmit" :disabled="loginBtn">登 录</a-button>
          </a-form-item>
        </a-form-model>
      </div>
谭毅彬 authored
47
    </div>
48
49
50
51
52
53
54
    <two-step-captcha v-if="requiredTwoStepCaptcha" :visible="stepCaptchaVisible" @success="stepCaptchaSuccess" @cancel="stepCaptchaCancel"></two-step-captcha>
    <login-select-tenant ref="loginSelect" @success="loginSelectOk" ></login-select-tenant>

  </div>
</template>

<script>
谭毅彬 authored
55
56
57
58
59
60
61
62
63
import RouteView from '@/components/layouts/RouteView'
import { mixinDevice } from '@/utils/mixin.js'
import LoginAccount from '@views/user/LoginAccount.vue'
import { mapActions } from 'vuex'
import { getAction } from '@api/manage'
import { getWarehouseByUserCode } from '@api/api'
import TwoStepCaptcha from '@comp/tools/TwoStepCaptcha.vue'
import LoginSelectTenant from '@views/user/LoginSelectTenant.vue'
import { timeFix } from '@/utils/util'
64
65

export default {
谭毅彬 authored
66
67
  name: 'UserLayout',
  components: { LoginSelectTenant, TwoStepCaptcha },
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  data() {
    return {
      requestCodeSuccess: false,
      randCodeImage: '',
      currdatetime: '',
      requiredTwoStepCaptcha: false,
      stepCaptchaVisible: false,
      maskedPassword: '',
      loginType: 0,
      loginBtn: false,
      warehouseList: {},
      querySource: {},
      model: {
        username: '',
        password: '',
谭毅彬 authored
83
        warehouseCode: ''
84
85
86
87
        // inputCode: ''
      },
      validatorRules: {
        username: [
谭毅彬 authored
88
89
          {
            required: true,
谭毅彬 authored
90
            message: <span style="color: red; font-weight: bold; margin-left: 10%; font-size: 0.85vw;">请输入用户名!</span>
谭毅彬 authored
91
92
          },
          { validator: this.handleUsernameOrEmail }
93
        ],
谭毅彬 authored
94
95
96
        password: [
          {
            required: true,
谭毅彬 authored
97
            message: <span style="color: red; font-weight: bold; margin-left: 10%; font-size: 0.85vw;">请输入密码!</span>,
谭毅彬 authored
98
99
100
101
102
103
            validator: 'click'
          }
        ],
        warehouseCode: [
          {
            required: true,
谭毅彬 authored
104
            message: <span style="color: red; font-weight: bold; margin-left: 10%; font-size: 0.85vw;">请选择仓库!</span>,
谭毅彬 authored
105
106
107
108
            trigger: 'change',
            validator: 'click'
          }
        ]
109
110
111
112
      }
    }
  },
  created() {
谭毅彬 authored
113
114
    this.handleChangeCheckCode()
    this.getWarehouse()
115
116
117
118
119
120
121
122
123
  },

  methods: {
    stepCaptchaCancel() {
      this.Logout().then(() => {
        this.loginBtn = false
        this.stepCaptchaVisible = false
      })
    },
肖超群 authored
124
125
126
127
128
    stepCaptchaSuccess() {
      this.loginSuccess()
    },
    handleSubmit() {
谭毅彬 authored
129
      this.loginBtn = true
130
      // if (this.customActiveKey === 'tab1') {
谭毅彬 authored
131
132
      // 使用账户密码登录
      this.handleLogin(this.rememberMe)
133
134
135
136
137
138
139
      // } else {
      //   //手机号码登录
      //   this.$refs.plogin.handleLogin(this.rememberMe)
      // }
    },
    // 校验失败
    validateFail() {
谭毅彬 authored
140
      this.loginBtn = false
141
142
143
144
145
146
147
148
    },
    requestSuccess(loginResult) {
      this.$refs.loginSelect.show(loginResult)
    },
    loginSelectOk() {
      this.loginSuccess()
    },
    loginSuccess() {
谭毅彬 authored
149
      this.$router.push({ path: '/dashboard/analysis' })
150
151
      this.$notification.success({
        message: '欢迎',
谭毅彬 authored
152
153
        description: `${timeFix()},欢迎回来`
      })
154
155
156
    },
    //登录后台失败
    requestFailed(err) {
谭毅彬 authored
157
      let description = ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试'
158
159
160
      this.$notification['error']({
        message: '登录失败',
        description: description,
谭毅彬 authored
161
162
        duration: 4
      })
163
164
165
166
      //账户密码登录错误后更新验证码
      if (this.customActiveKey === 'tab1' && description.indexOf('密码错误') > 0) {
        this.$refs.alogin.handleChangeCheckCode()
      }
谭毅彬 authored
167
      this.loginBtn = false
168
169
170
171
    },
    ...mapActions(['Login']),
    /**刷新验证码*/
    handleChangeCheckCode() {
谭毅彬 authored
172
      this.currdatetime = new Date().getTime()
173
      // this.model.inputCode = ''
谭毅彬 authored
174
175
176
177
178
179
180
181
182
183
184
      getAction(`/sys/randomImage/${this.currdatetime}`)
        .then(res => {
          if (res.success) {
            this.randCodeImage = res.result
            this.requestCodeSuccess = true
          } else {
            this.$message.error(res.message)
            this.requestCodeSuccess = false
          }
        })
        .catch(() => {
185
          this.requestCodeSuccess = false
谭毅彬 authored
186
        })
187
188
189
    },

    getWarehouse() {
谭毅彬 authored
190
191
192
193
194
      const that = this
      this.querySource.username = that.model.username
      let obj = getWarehouseByUserCode(that.querySource)
      obj.then(res => {
        that.warehouseList = res.result
195
        if (this.warehouseList != null) {
谭毅彬 authored
196
          this.model.warehouseCode = this.warehouseList[0].code
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
        }
      })
    },

    maskPassword() {
      //获取输入框的值
      let value = this.model.password
      if (value != '') {
        //如果不为空,逐个字符判断是否为圆点
        for (let i = 0; i < value.length; i++) {
          if (value.charAt(i) != '\u25CF') {
            //如果不是圆点,表示该字符为用户输入的值,放到真实值的对应位置
            let char = value.charAt(i)
            this.maskedPassword = this.maskedPassword.slice(0, i) + char + this.maskedPassword.slice(i)
            //将该字符替换为圆点
            value = value.slice(0, i) + '\u25CF' + value.slice(i + 1)
          }
        }
        //防止真实值和圆点的数量不对应。
        this.maskedPassword = this.maskedPassword.slice(0, value.length)
        //将转换过的字符串显示给用户
        this.model.password = value
      } else {
        //保持一致性
        this.maskedPassword = ''
      }
    },

    // 判断登录类型
    handleUsernameOrEmail(rule, value, callback) {
谭毅彬 authored
227
      const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
      if (regex.test(value)) {
        this.loginType = 0
      } else {
        this.loginType = 1
      }
      callback()
    },
    /**
     * 验证字段
     * @param arr
     * @param callback
     */
    validateFields(arr, callback) {
      let promiseArray = []
      for (let item of arr) {
        let p = new Promise((resolve, reject) => {
谭毅彬 authored
244
          this.$refs['form'].validateField(item, err => {
245
            if (!err) {
谭毅彬 authored
246
              resolve()
247
            } else {
谭毅彬 authored
248
              reject(err)
249
250
            }
          })
谭毅彬 authored
251
        })
252
253
        promiseArray.push(p)
      }
谭毅彬 authored
254
255
256
257
258
259
260
      Promise.all(promiseArray)
        .then(() => {
          callback()
        })
        .catch(err => {
          callback(err)
        })
261
262
263
264
265
266
    },
    acceptUsername(username) {
      this.model['username'] = username
    },
    // 账号密码登录
    handleLogin(rememberMe) {
谭毅彬 authored
267
      this.validateFields(['username', 'password'], err => {
268
269
270
271
272
273
        if (!err) {
          let loginParams = {
            username: this.model.username,
            password: this.maskedPassword,
            warehouseCode: this.model.warehouseCode,
            checkKey: this.currdatetime,
谭毅彬 authored
274
            remember_me: rememberMe
275
          }
谭毅彬 authored
276
277
278
279
280
281
282
283
284
285
286
287
288
          this.Login(loginParams)
            .then(res => {
              this.$emit('success', res.result)
              this.loginSuccess()
            })
            .catch(err => {
              this.validateFail()
              this.requestFailed(err)
              this.$emit('fail', err)
              if (err.code == 499) {
                this.$router.push({ path: '/user/systemTokenModal' })
              }
            })
289
290
291
292
293
294
295
296
297
298
299
        } else {
          this.validateFail()
          this.$emit('validateFail')
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
谭毅彬 authored
300
谭毅彬 authored
301
302
303
304
305
#userLayout {
  height: 100%;
  display: flex; /* 设置flex布局 */
  width: 100%; /* 容器宽度设置为100% */
}
306
谭毅彬 authored
307
/deep/ .ant-select-selection__rendered {
谭毅彬 authored
308
309
310
311
  margin-top: 0vw;
  justify-content: center;
  margin-left: 0.5vw;
  line-height: 2vw;
谭毅彬 authored
312
}
谭毅彬 authored
313
谭毅彬 authored
314
315
316
/deep/ .ant-form {
  width: 100%;
}
317
谭毅彬 authored
318
319
320
321
///deep/ .ant-select-dropdown-menu-item-selected{
//  font-size: 18px;
//  height: 30px;
//}
322
谭毅彬 authored
323
.left-div {
谭毅彬 authored
324
325
326
  flex: 0 0 65%; /* 左侧div宽度为容器的70% */
  width: 65%;
  height: 100%; /* 使 div 占满父容器高度 */
327
328
329
330
  flex-direction: column;
  justify-content: center; /* 垂直居中 */
  align-items: center; /* 水平居中 */
  // height: 100vh; /* 使容器的高度为视口高度 */
谭毅彬 authored
331
}
332
谭毅彬 authored
333
.right-div {
谭毅彬 authored
334
335
336
  flex: 0 0 35%;
  width: 35%;
  height: 100%; /* 使 div 占满父容器高度 */
谭毅彬 authored
337
  display: flex;
谭毅彬 authored
338
339
340
341
342
  justify-content: center; /* 水平居中 */
  align-items: center;     /* 垂直居中 */
}

.right-login {
谭毅彬 authored
343
  background-color: #fafafa;
谭毅彬 authored
344
345
346
347
348
349
350
351
352
  border-radius: 0.5vw;       /* 设置圆角半径 */
  width: 80%;
  height: 60%; /* 使 div 占满父容器高度 */
  display: flex;           /* 使用 flexbox 进行子元素布局 */
  flex-direction: column;  /* 垂直排列子元素 */
  justify-content: center;  /* 垂直居中子元素 */
  align-items: center;     /* 水平居中子元素 */
  box-shadow: 1vw 1vw 1vw #c3c3c3;
  border: 0.1vw solid #ccc;     /* 增加边框线 */
谭毅彬 authored
353
}
谭毅彬 authored
354
谭毅彬 authored
355
#logo {
谭毅彬 authored
356
  height: 10%;
谭毅彬 authored
357
358
  width: 100%;
  display: flex;
359
  align-items: center; /* 使 logo 和文本在水平方向上居中 */
谭毅彬 authored
360
}
谭毅彬 authored
361
#backgroundImg {
谭毅彬 authored
362
  height: 80%; /* 使容器充满视口高度 */
谭毅彬 authored
363
  display: flex;
谭毅彬 authored
364
365
  justify-content: center; /* 水平居中 */
  align-items: center;     /* 垂直居中 */
谭毅彬 authored
366
  .imge {
谭毅彬 authored
367
    height: 85%;
368
369
370
371
    background-size: contain;
    background-repeat: no-repeat;
    position: relative;
  }
谭毅彬 authored
372
}
谭毅彬 authored
373
374
375
376
377
#copyright {
  height: 10%; /* 高度为视口的 10% */
  width: 100%; /* 确保宽度不超出容器 */
  position: fixed; /* 固定定位 */
  bottom: 0; /* 靠底部对齐 */
谭毅彬 authored
378
  display: flex;
谭毅彬 authored
379
  align-items: flex-end; /* 垂直方向上靠下对齐 */
谭毅彬 authored
380
  padding: 1vw; /* 添加内边距 */
谭毅彬 authored
381
382
}
#logoImg {
谭毅彬 authored
383
  width: 10vw;
384
385
  height: 100%;
  line-height: 4.5vw;
谭毅彬 authored
386
387
  margin-left: 2vw;
  margin-right: 0.5vw;
谭毅彬 authored
388
  font-size: 0vw;
谭毅彬 authored
389
390
391
  float: right;
  position: relative;
  .imge {
谭毅彬 authored
392
393
    width: 9.5vw;
    height: 1.5vw;
谭毅彬 authored
394
    right: 5%; /* 水平居右 */
395
  }
谭毅彬 authored
396
397
}
#text {
398
399
  height: 100%;
  line-height: 4.5vw;
谭毅彬 authored
400
  width: 100%;
谭毅彬 authored
401
402
  font-size: 1.1vw;
  margin-bottom: 0vw;
谭毅彬 authored
403
404
405
  color: #333333;
  font-family: 'Microsoft YaHei', 'SimSun', sans-serif;
  font-weight: bold;
406
  text-align: left; /* 确保文本居中 */
谭毅彬 authored
407
408
409
410
411
412
413
414
}
#form-container {
  width: 200px; /* 设置宽度 */
  height: 50px; /* 设置高度 */
  //margin-left: 820px;
  //margin-top: 100px;
}
#company {
谭毅彬 authored
415
416
417
418
419
  text-align: center; /* 水平居中对齐 */
  // color: #ac1e2b; /* 字体颜色 */
  font-size: 0.9vw; /* 字体大小 */
  font-family: 'Microsoft YaHei', 'SimSun', sans-serif; /* 字体系列 */
  width: 100%; /* 宽度 100% */
谭毅彬 authored
420
421
}
#welcome {
谭毅彬 authored
422
  margin-top: 2.2vw;
谭毅彬 authored
423
424
  color: #333333;
  font-size: 1.5vw;
谭毅彬 authored
425
  align-content: end;
谭毅彬 authored
426
  font-family: 'Microsoft YaHei', 'SimSun', sans-serif;
谭毅彬 authored
427
  text-align: center;
谭毅彬 authored
428
  margin-left: 0vw;
谭毅彬 authored
429
  margin-bottom: 3vw;
谭毅彬 authored
430
}
谭毅彬 authored
431
#name {
谭毅彬 authored
432
  border-width: 0.1vw;
谭毅彬 authored
433
434
435
436
437
438
  border-style: solid;
  border-radius: 0.6vw;
  width: 85%;
  height: 3vw;
  line-height: 3vw;
  margin-left: 8%;
谭毅彬 authored
439
  margin-bottom: 0.5vw;
谭毅彬 authored
440
441
442
  background-image: url(../../assets/huiyuan.png);
  padding-left: 12%; /* 留出图片的空间 */
  background-repeat: no-repeat;
谭毅彬 authored
443
444
  background-position: 0.6vw center;
  background-size: 1.6vw 1.6vw;
谭毅彬 authored
445
446
  font-size: 1vw;
  color: #333333;
谭毅彬 authored
447
  // box-shadow: 1vw 1vw 1vw #c3c3c3;
谭毅彬 authored
448
}
谭毅彬 authored
449
450
451
452
453
454
455
456
457
458
459
460
461
462
::v-deep .ant-select-selection {
  border-width: 0.1vw;
  border-style: solid;
  border-radius: 0.6vw;
  width: 100% !important;
  height: 3vw;
  line-height: 3vw;
  background-image: url(../../assets/cangku.png);
  padding-left: 12%; /* 留出图片的空间 */
  background-repeat: no-repeat;
  background-position: 0.6vw center;
  background-size: 1.6vw 1.6vw;
  font-size: 1vw;
  color: #333333;
谭毅彬 authored
463
  // box-shadow: 1vw 1vw 1vw #c3c3c3;
谭毅彬 authored
464
465
}
谭毅彬 authored
466
467
468
469
470
471
472
473
#name::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  overflow: hidden;
}
#name::placeholder {
谭毅彬 authored
474
  font-size: 1vw;
谭毅彬 authored
475
476
477
478
  color: #999999;
  padding-left: 0px;
}
#password {
谭毅彬 authored
479
  border-width: 0.1vw;
谭毅彬 authored
480
481
482
483
484
485
  border-style: solid;
  border-radius: 0.6vw;
  width: 85%;
  height: 3vw;
  line-height: 3vw;
  margin-left: 8%;
谭毅彬 authored
486
  margin-top: 0vw;
谭毅彬 authored
487
  margin-bottom: 0.5vw;
谭毅彬 authored
488
489
490
  background-image: url(../../assets/mima.png);
  padding-left: 12%; /* 留出图片的空间 */
  background-repeat: no-repeat;
谭毅彬 authored
491
492
  background-position: 0.6vw center;
  background-size: 1.6vw 1.6vw;
谭毅彬 authored
493
494
  font-size: 1vw;
  color: #333333;
谭毅彬 authored
495
  // box-shadow: 1vw 1vw 1vw #c3c3c3;
谭毅彬 authored
496
}
谭毅彬 authored
497
498
#warehouseCode {
  border-color: #ebf3fd;
谭毅彬 authored
499
  border-width: 0vw;
谭毅彬 authored
500
501
502
503
504
505
  border-style: solid;
  border-radius: 0.6vw;
  width: 85%;
  height: 3vw;
  line-height: 3vw;
  margin-left: 8%;
谭毅彬 authored
506
  margin-top: 0vw;
谭毅彬 authored
507
508
509
510
511
  margin-bottom: 2.5vw;
  font-size: 1vw;
  text-align: center;
  //color: #333333;
}
谭毅彬 authored
512
513
514
515
516
517
518
519
#password::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  overflow: hidden;
}
#password::placeholder {
谭毅彬 authored
520
  font-size: 1vw;
谭毅彬 authored
521
522
523
  color: #999999;
  padding-left: 0px;
}
谭毅彬 authored
524
525
526
527
528
529
530
531
532
533
534
535
536
/deep/ .ant-form-explain {
  margin-top: 0.2vw;
  margin-bottom: 0.2vw;
  min-height: 1.2vw;
  font-size: 0.8vw;
}

/deep/ .ant-select-arrow {
  font-size: 1vw;
  right: 1vw;
  margin-top: -0.4vw;
}
谭毅彬 authored
537
/deep/ .ant-form-item-control {
谭毅彬 authored
538
  line-height: 0vw;
谭毅彬 authored
539
}
谭毅彬 authored
540
谭毅彬 authored
541
/deep/ .ant-select-selection__rendered {
谭毅彬 authored
542
  line-height: 2.85vw;
谭毅彬 authored
543
544
545
546
547
548
549
550
551

}

/deep/ .ant-col {
  min-height: 5.6vw;
}

/deep/ .ant-form-item-with-help {
  margin-bottom: 0vw;
谭毅彬 authored
552
}
谭毅彬 authored
553
谭毅彬 authored
554
/deep/ .ant-form-item {
谭毅彬 authored
555
556
  font-size: 3vw;
  margin-bottom: 0vw;
谭毅彬 authored
557
558
}
谭毅彬 authored
559
560
561
562
563
564
565
a-select {
  width: 100%;
  height: 100%;
  font-size: 16px;
  color: #333;
  background-color: #fff;
  border: 1px solid #ccc;
谭毅彬 authored
566
  border-radius: 0.6vw;
谭毅彬 authored
567
568
569
}
#logIn {
  border-color: #ac1e2b;
谭毅彬 authored
570
  border-width: 0.1vw;
谭毅彬 authored
571
572
573
574
575
576
  border-style: solid;
  border-radius: 0.6vw;
  width: 85%;
  height: 3vw;
  line-height: 3vw;
  margin-left: 8%;
谭毅彬 authored
577
  font-size: 1.2vw;
谭毅彬 authored
578
579
580
581
582
  align-items: center;
  justify-content: center;
  display: flex;
  color: #ebf3fd;
  background-color: red;
谭毅彬 authored
583
  // box-shadow: 1vw 1vw 1vw #c3c3c3;
谭毅彬 authored
584
}
585
</style>