Login.vue
10.4 KB
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
<template>
<div class="dv">
<div class="login-left">
<img src="~@/assets/leCangHead.png" alt="" />
</div>
<div class="main">
<div class="timeBox padding-xl" style="color:#606266">
<div>
<p class="text-24 text-white" style="margin:-180px 0px 120px 285px;" v-html="formateTime(date)"></p>
</div>
<div>
<p class="text-24 text-white" style="margin:-165px 0px 130px 205px;" v-html="formateDate(date)"></p>
</div>
</div>
<div class="desc" style="text-align: center; font-size:4vw;color:#606266">WCS</div>
<a-form-model class="user-layout-login" @keyup.enter.native="handleSubmit">
<a-tabs
:activeKey="customActiveKey"
:tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }"
@change="handleTabClick"
>
<a-tab-pane key="tab1" :tab="$t('system.accountLoginWithPassword')">
<login-account
ref="alogin"
@validateFail="validateFail"
@success="requestSuccess"
@fail="requestFailed"
></login-account>
</a-tab-pane>
</a-tabs>
<a-form-item style="margin-top:24px">
<div class='btn-style'>
<a-button
size="large"
type="primary"
htmlType="submit"
class="login-button"
:loading="loginBtn"
@click.stop.prevent="handleSubmit"
:disabled="loginBtn"
>{{ $t('button.ok') }}</a-button
>
<div class="select">
<a-select v-model="language" @change="handleLanguageChange">
<a-select-option value="zh-CN">中文</a-select-option>
<a-select-option value="en-US">English</a-select-option>
</a-select>
</div>
</div>
</a-form-item>
</a-form-model>
<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>
</div>
<!-- 登录框 -->
</template>
<script>
import Vue from 'vue'
import { ACCESS_TOKEN, ENCRYPTED_STRING } from '@/store/mutation-types'
import ThirdLogin from './third/ThirdLogin'
import LoginSelectTenant from './LoginSelectTenant'
import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha'
import { getEncryptedString } from '@/utils/encryption/aesEncrypt'
import { timeFix } from '@/utils/util'
import LoginAccount from './LoginAccount'
import LoginPhone from './LoginPhone'
import { languageChange } from '@/api/api'
export default {
components: {
LoginSelectTenant,
TwoStepCaptcha,
ThirdLogin,
LoginAccount,
LoginPhone
},
data() {
return {
customActiveKey: 'tab1',
rememberMe: true,
loginBtn: false,
requiredTwoStepCaptcha: false,
stepCaptchaVisible: false,
querySource: {},
language:'en-US',
encryptedString: {
key: '',
iv: ''
},
date: new Date().getTime()
}
},
created() {
Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData()
this.rememberMe = true
this.loadTime()
this.language = this.$ls.get('language')
},
methods: {
handleLanguageChange(lang) {
this.$ls.set('language', lang)
window.location.reload()
// languageChange(lang).then(res => {
// if (res.success) {
// }
// })
},
loadTime() {
var _this = this;
setInterval(() => {
_this.date += 1000;
}, 1000);
// this.$api.serveTime({}).then(res => {
// console.log("服务器时间", res);
// var _this = this;
// _this.servertime = res;
// setInterval(() => {
// _this.date += 1000;
// console.log(_this.date, '**');
// }, 1000);
// });
},
// 转换时间戳
formateTime(time) {
var date = new Date(time);
var year = date.getFullYear();
var month =
date.getMonth() + 1 < 10
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute =
date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second =
date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var week = ["日", "一", "二", "三", "四", "五", "六"][date.getDay()];
// return year + "年" + month + "月" + day + "日" + hour + ":" + minute + ":" + second;
return (
'<span style="font-size: 40px; text-shadow: 0px 2px 7px rgba(51, 51, 51, 0.6);">' +
hour +
":" +
minute + ":" + second +
"</span>"
);
},
formateDate(time) {
var date = new Date(time);
var year = date.getFullYear();
var month =
date.getMonth() + 1 < 10
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute =
date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second =
date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var week = [this.$t('system.sunday'), this.$t('system.monday'), this.$t('system.tuesday'),
this.$t('system.wednesday'), this.$t('system.thursday'), this.$t('system.friday'), this.$t('system.saturday')][date.getDay()];
// return year + "年" + month + "月" + day + "日" + hour + ":" + minute + ":" + second;
return (
"<div style='text-align:left;font-size: 12px;'>" +
year +
"/" +
month +
"/" +
day +
"" +
"</div><div style='text-align:left;font-size: 12px;'>" + week + "</div>"
);
},
handleTabClick(key) {
this.customActiveKey = key
},
handleRememberMeChange(e) {
this.rememberMe = e.target.checked
},
/**跳转到登录页面的参数-账号获取*/
getRouterData() {
this.$nextTick(() => {
let temp = this.$route.params.username || this.$route.query.username || ''
if (temp) {
this.$refs.alogin.acceptUsername(temp)
}
})
},
timeFix() {
const time = new Date()
const hour = time.getHours()
return hour < 9
? this.$t('system.goodMorning1')
: hour <= 11
? this.$t('system.goodMorning2')
: hour <= 13
? this.$t('system.goodAfternoon1')
: hour < 20
? this.$t('system.goodAfternoon2')
: this.$t('system.goodEvening')
},
//登录
handleSubmit() {
this.loginBtn = true
if (this.customActiveKey === 'tab1') {
// 使用账户密码登录
this.$refs.alogin.handleLogin(this.rememberMe)
} else {
//手机号码登录
this.$refs.plogin.handleLogin(this.rememberMe)
}
},
// 校验失败
validateFail() {
this.loginBtn = false
},
// 登录后台成功
requestSuccess(loginResult) {
this.$refs.loginSelect.show(loginResult)
},
//登录后台失败
requestFailed(err) {
let description =
((err.response || {}).data || {}).message || err.message || this.$t('system.requestEncounteredError')
this.$notification['error']({
message: this.$t('system.loginFailed'),
description: description,
duration: 4
})
//账户密码登录错误后更新验证码
if (this.customActiveKey === 'tab1' && description.indexOf('密码错误') > 0) {
this.$refs.alogin.handleChangeCheckCode()
}
this.loginBtn = false
},
loginSelectOk() {
this.loginSuccess()
},
//登录成功
loginSuccess() {
this.$router.push({ path: '/dashboard/analysis' })
this.$notification.success({
message: this.$t('system.welcome'),
description: this.timeFix()
})
},
stepCaptchaSuccess() {
this.loginSuccess()
},
stepCaptchaCancel() {
this.Logout().then(() => {
this.loginBtn = false
this.stepCaptchaVisible = false
})
},
//获取密码加密规则
getEncrypte() {
var encryptedString = Vue.ls.get(ENCRYPTED_STRING)
if (encryptedString == null) {
getEncryptedString().then(data => {
this.encryptedString = data
})
} else {
this.encryptedString = encryptedString
}
}
}
}
</script>
<style lang="less" scoped>
.dv {
display: flex;
flex-direction: row;
width: 100%;
height: 100vh !important;
}
.user-layout-login {
position: relative;
label {
font-size: 14px;
}
.getCaptcha {
display: block;
width: 100%;
height: 40px;
}
.forge-password {
font-size: 14px;
}
button.login-button {
padding: 0 15px;
font-size: 16px;
height: 40px;
width: 70%;
}
.user-login-other {
text-align: left;
margin-top: 24px;
line-height: 22px;
.item-icon {
font-size: 24px;
color: rgba(0, 0, 0, 0.2);
margin-left: 16px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
&:hover {
color: #1890ff;
}
}
.register {
float: right;
}
}
.valid-error .ant-select-selection__placeholder {
color: #f5222d;
}
}
.main {
width: 668px;
// height: 100%;
font-size: 20px;
margin: 200px 100px 200px 100px;
color: antiquewhite;
}
.login-left {
width: inherit;
height: 100%;
// border: 1px solid yellowgreen;
background: url('~@/assets/leCang.jpg') no-repeat;
background-size: cover;
// background-size: 100% 100%;
img {
width: 220px;
position: relative;
left: 19px;
top: 27px;
}
}
.btn-style {
width: 100%;
// border: 1px solid red;
display: flex;
justify-content: space-between;
}
.select {
// display: inline-block;
width: 95px;
height: 40px;
// position: relative;
// left: 296px;
// top: -66px;
// vertical-align: middle;
// padding: 0;
// overflow: hidden;
// background-color: #fff;
// color: #555;
// border: 1px solid #aaa;
// text-shadow: none;
// border-radius: 4px;
// transition: box-shadow 0.25s ease;
z-index: 2;
}
</style>