cloud-web-corejs 1.0.54-dev.756 → 1.0.54-dev.759

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,661 +1,661 @@
1
- import { encode } from "js-base64";
2
- import settingConfig from "@/settings";
3
- import QRcode from "qrcode";
4
-
5
- function getUrlParams(url) {
6
- let result = {};
7
- if (url) {
8
- let urlStr = url.split("?")[1];
9
- const urlSearchParams = new URLSearchParams(urlStr);
10
- result = Object.fromEntries(urlSearchParams.entries());
11
- }
12
- return result;
13
- }
14
-
15
- export default {
16
- name: "Login",
17
- props: {
18
- lang: [String, Function],
19
- },
20
- components: {},
21
- data() {
22
- return {
23
- isCounting: false,
24
- countdown: 0,
25
- buttonText: this.$t1("获取验证码"),
26
- smsTimer: null,
27
- isRememberPassword: false,
28
- loginForm: {
29
- username: "",
30
- password: "",
31
- },
32
- loginRules: {
33
- username: [
34
- {
35
- required: true,
36
- trigger: "blur",
37
- },
38
- ],
39
- password: [
40
- {
41
- required: true,
42
- trigger: "blur",
43
- },
44
- ],
45
- },
46
- passwordType: "password",
47
- capsTooltip: false,
48
- loading: false,
49
- showDialog: false,
50
- redirect: undefined,
51
- otherQuery: {},
52
- // isChangeBackground: false,
53
- backgroundClass: "",
54
- hasLogin: false,
55
- showView: false,
56
- loginForm2: {
57
- username: null,
58
- smsCode: null,
59
- },
60
- activeName: "first",
61
- searchParam: {},
62
- showContent: true,
63
-
64
- qrTimer1: null,
65
- qrTimer2: null,
66
- qrContent: null,
67
- qrCodeFlag: 0,
68
- qrBase64: "",
69
- settingConfig: settingConfig,
70
- qrExpired: false,
71
- loginConfig: {},
72
- imageUrl: "",
73
- loginMethod: "",
74
-
75
- accountLoagin: true,
76
- phoneLogin: false,
77
- qrLogin: false,
78
- };
79
- },
80
- watch: {
81
- $route: {
82
- handler: function (route) {
83
- const query = route.query;
84
- if (query) {
85
- this.redirect = query.redirect;
86
- this.otherQuery = this.getOtherQuery(query);
87
- }
88
- },
89
- immediate: true,
90
- },
91
- },
92
- beforeDestroy() {
93
- this.clearQrLoginTimer();
94
- this.clearSmsTimer();
95
- // 兜底:登录组件随路由切换销毁时关闭跳转期 loading($baseLoading 挂在 body 上,
96
- // 不随组件销毁自动关闭)
97
- this.closeRedirectLoading();
98
- },
99
- created() {
100
- this.init();
101
- },
102
- mounted() {
103
- // if (this.loginForm.username === '') {
104
- // this.$refs.username.focus();
105
- // } else if (this.loginForm.password === '') {
106
- // this.$refs.password.focus();
107
- // }
108
- },
109
- destroyed() {
110
- // window.removeEventListener('storage', this.afterQRScan)
111
- window.removeEventListener("keydown", this.keyDown, false);
112
- },
113
- methods: {
114
- handleLoginConfig() {
115
- let loginConfig = this.$store.getters.loginConfig || {};
116
- this.loginConfig = loginConfig;
117
- this.initImage();
118
- this.initLoginMethod();
119
- },
120
- initImage() {
121
- //初始化登录图片
122
- let loginConfig = this.loginConfig;
123
- if (loginConfig?.attachments?.length) {
124
- this.imageUrl =
125
- loginConfig.attachments[0].domain + loginConfig.attachments[0].source;
126
- }
127
- },
128
-
129
- initLoginMethod() {
130
- let loginConfig = this.loginConfig?.login_method;
131
- if (loginConfig?.length) {
132
- this.accountLoagin = loginConfig.includes(1);
133
- this.phoneLogin = loginConfig.includes(2);
134
- this.qrLogin = loginConfig.includes(3);
135
- if (this.accountLoagin) {
136
- this.activeName = "first";
137
- } else if (this.phoneLogin) {
138
- this.activeName = "second";
139
- } else if (this.qrLogin) {
140
- this.activeName = "third";
141
- this.$nextTick(() => {
142
- this.initQR();
143
- });
144
- }
145
- } else {
146
- this.accountLoagin = true;
147
- this.phoneLogin = settingConfig.mobileLoginEnabled;
148
- this.qrLogin = settingConfig.qrLoginEnabled;
149
- }
150
- },
151
- initLang() {
152
- let lang = this.$route.query.lang;
153
- if (!lang && !!this.lang) {
154
- if (typeof this.lang === "function") {
155
- lang = this.lang();
156
- } else {
157
- lang = this.lang;
158
- }
159
- }
160
- if (lang) {
161
- this.$i18n.locale = lang;
162
- localStorage.setItem("i18n-lang", lang);
163
- }
164
- },
165
- init() {
166
- this.initLang();
167
- this.handleLoginConfig();
168
- let searchParam = getUrlParams(location.search);
169
- this.searchParam = searchParam;
170
- //小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
171
- let ssoParams = {};
172
- if (location.search) {
173
- ssoParams = searchParam;
174
- }
175
- // 获取URL参数
176
- const urlParams = this.$route.query;
177
- if (
178
- ssoParams.ticket ||
179
- "bear_portalsso" == urlParams.access ||
180
- urlParams.ticket
181
- ) {
182
- //小熊单点登录
183
- this.bearSsoLogin();
184
- } else if (searchParam.gatewayToken) {
185
- this.showContent = false;
186
- this.handleGatewayTokenLogin();
187
- } else if (searchParam.xtoken) {
188
- this.showContent = false;
189
- this.handleXTokenLogin();
190
- } else {
191
- //正常登陆
192
- this.login();
193
- }
194
- },
195
- keyDown(e) {
196
- //如果是回车则执行登录方法
197
- if (e.keyCode == 13 && e.target.nodeName != "INPUT") {
198
- let closeBtn = document.querySelector(".el-dialog__close");
199
- closeBtn && closeBtn.click();
200
- if (this.activeName == "third") return;
201
- this.handleLogin();
202
- }
203
- },
204
- checkCapslock(e) {
205
- const { key } = e;
206
- this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
207
- },
208
- showPwd() {
209
- if (this.passwordType === "password") {
210
- this.passwordType = "";
211
- } else {
212
- this.passwordType = "password";
213
- }
214
- this.$nextTick(() => {
215
- this.$refs.password.focus();
216
- });
217
- },
218
- handleLogin() {
219
- let loadingObj = null;
220
- let reqData = {};
221
- if (this.activeName == "first") {
222
- //账号密码登录
223
- loadingObj = this.$baseLoading();
224
- let password = encode(this.loginForm.password + "");
225
- reqData = { username: this.loginForm.username, password: password };
226
- } else {
227
- //手机验证码登录
228
- let username = this.loginForm2.username;
229
- let smsCode = this.loginForm2.smsCode;
230
- if (!username || !smsCode) {
231
- this.$baseAlert(this.$t1("请输入手机号和验证码"));
232
- return;
233
- }
234
- loadingObj = this.$baseLoading();
235
- reqData = { username: username, smsCode: smsCode, mode: "sms" };
236
- }
237
-
238
- if (settingConfig.i18nEnabled) {
239
- //登录传语种到后台
240
- let language = this.$i18n?.locale;
241
- if (language && language != "zh") {
242
- reqData.language = language;
243
- }
244
- }
245
-
246
- this.$store
247
- .dispatch("user/login2", reqData)
248
- .then((res) => {
249
- if (res.type == "success") {
250
- localStorage.removeItem("currentMenuId");
251
- this.rememberPassword();
252
- window.removeEventListener("keydown", this.keyDown, false);
253
- // 登录成功后的跳转链路(getWebPrefix → 路由守卫拉用户信息/生成动态路由 → 首页渲染)
254
- // 耗时较长,loading 保持打开防止期间登录页被再次操作;
255
- // 由 closeRedirectLoading 在跳转完成/中止/请求失败/组件销毁时统一收口
256
- this.redirectLoadingObj = loadingObj;
257
- this.handleRedirectUrl();
258
- } else {
259
- setTimeout(function () {
260
- loadingObj.close();
261
- }, 200);
262
- }
263
- })
264
- .catch((e) => {
265
- this.loading = false;
266
- setTimeout(function () {
267
- loadingObj.close();
268
- }, 200);
269
- console.error(e);
270
- });
271
- },
272
- getOtherQuery(query) {
273
- return Object.keys(query).reduce((acc, cur) => {
274
- if (cur !== "redirect") {
275
- acc[cur] = query[cur];
276
- }
277
- return acc;
278
- }, {});
279
- },
280
- initPassword() {
281
- var u = localStorage.getItem("login_info");
282
- var login_info;
283
- if (u) {
284
- login_info = JSON.parse(u);
285
- var username = login_info.username;
286
- var password = login_info.password;
287
- var isRememberPassword = login_info.isRememberPassword;
288
- if (isRememberPassword == "true") {
289
- this.isRememberPassword = true;
290
- this.loginForm.username = username;
291
- this.loginForm.password = password;
292
- }
293
- }
294
- },
295
- rememberPassword() {
296
- if (this.isRememberPassword) {
297
- var username = this.loginForm.username;
298
- var password = this.loginForm.password;
299
- var login_info = {
300
- username: username,
301
- password: password,
302
- isRememberPassword: "true",
303
- };
304
- localStorage.setItem("login_info", JSON.stringify(login_info));
305
- } else {
306
- localStorage.removeItem("login_info");
307
- }
308
- },
309
- changeBackground() {
310
- this.backgroundClass = "tc";
311
- },
312
- login() {
313
- let url = window.MAIN_WEB_PREFIX + "/index.html/#/login";
314
- if (
315
- self != top &&
316
- (process.env.NODE_ENV == "development" || self.host == parent.host)
317
- ) {
318
- parent.location.href = url;
319
- } else if (
320
- process.env.NODE_ENV !== "development" &&
321
- window.MAIN_WEB_PREFIX &&
322
- window.MAIN_WEB_PREFIX != window.WEB_PREFIX
323
- ) {
324
- window.location.href = url;
325
- }
326
- /* let lang = this.$route.query.lang;
327
- if(lang=="en-US"){
328
- changeLocale(lang);
329
- }else{
330
- changeLocale("zh-CN");
331
- } */
332
- // window.addEventListener('storage', this.afterQRScan)
333
-
334
- window.removeEventListener("keydown", this.keyDown, false);
335
- window.addEventListener("keydown", this.keyDown, false);
336
- this.changeBackground();
337
- this.initPassword();
338
- this.showView = true;
339
- },
340
- bearSsoLogin() {
341
- //小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
342
- let urlParams = {};
343
- if (location.search) {
344
- urlParams = getUrlParams(location.search);
345
- }
346
- //let urlParams = this.$route.query;
347
-
348
- // 获取URL参数
349
- console.log("urlParams", urlParams);
350
- const loginPath = process.env.VUE_APP_BASE_API;
351
- console.log("loginPath--->", loginPath);
352
-
353
- //&& loginPath ===window.location.href
354
- if (urlParams.ticket) {
355
- console.log("进入回调方法=================");
356
- this.$store.dispatch("user/clearToken");
357
- this.$http({
358
- url: USER_PREFIX + "/auth/idmLogin",
359
- method: `post`,
360
- data: { ticket: urlParams.ticket },
361
- isLoading: true,
362
- modalStrictly: true,
363
- success: (res) => {
364
- let token = res.objx;
365
- console.log("token", token);
366
- this.$store.dispatch("user/addToken", { token }).then((res) => {
367
- localStorage.removeItem("currentMenuId");
368
- this.rememberPassword();
369
- /*this.$router.push({
370
- path: '/'
371
- });*/
372
- this.loading = false;
373
- window.removeEventListener("keydown", this.keyDown, false);
374
- let redirect = sessionStorage.getItem("loginRedirect");
375
- this.handleRedirectUrl(redirect);
376
- });
377
- },
378
- fail: () => {
379
- this.showView = true;
380
- },
381
- error: () => {
382
- this.showView = true;
383
- },
384
- });
385
- } else {
386
- console.log("进入单点方法");
387
- let redirect = this.$route.query.redirect || "";
388
- this.$http({
389
- url: USER_PREFIX + "/auth/idmLoginUrl",
390
- method: `post`,
391
- data: {},
392
- isLoading: true,
393
- modalStrictly: true,
394
- success: (res) => {
395
- sessionStorage.setItem("loginRedirect", redirect);
396
- location.href = res.objx;
397
- // location.href = res.objx+"&redirect="+redirect;
398
- },
399
- fail: () => {
400
- this.showView = true;
401
- },
402
- error: () => {
403
- this.showView = true;
404
- },
405
- });
406
- }
407
- },
408
- sendCode() {
409
- if (this.isCounting) {
410
- return;
411
- }
412
- let mobile = this.loginForm2.username;
413
- if (!mobile) {
414
- this.$baseAlert("请输入手机号");
415
- return;
416
- }
417
-
418
- this.$http({
419
- url: USER_PREFIX + "/auth/sendSmsCode",
420
- method: `post`,
421
- data: { mobile: mobile },
422
- isLoading: true,
423
- success: (res) => {
424
- this.$message({
425
- message: res.content,
426
- type: "success",
427
- duration: 1500,
428
- });
429
- this.isCounting = true;
430
- this.countdown = 60;
431
- this.buttonText = this.$t1("60秒后重新获取");
432
- this.clearSmsTimer();
433
- this.smsTimer = setInterval(() => {
434
- this.countdown--;
435
- this.buttonText = this.$t1("{time}秒后重新获取", {
436
- time: this.countdown,
437
- });
438
- if (this.countdown == 0) {
439
- this.clearSmsTimer();
440
- this.isCounting = false;
441
- this.buttonText = this.$t1("获取验证码");
442
- }
443
- }, 1000);
444
- },
445
- });
446
- },
447
- clearSmsTimer() {
448
- if (this.smsTimer) {
449
- clearInterval(this.smsTimer);
450
- this.smsTimer = null;
451
- }
452
- },
453
- mobileLogin() {},
454
- handleRedirectUrl(redirect) {
455
- redirect = redirect || this.$route.query.redirect;
456
- let path = null;
457
- if (redirect && redirect.startsWith("/outLinkView")) {
458
- path = this.addParamToUrl(redirect, "hasToken", "true");
459
- } else {
460
- path = "/";
461
- }
462
- this.getWebPrefix((webPrefix) => {
463
- let prefix = webPrefix ? "/" + webPrefix : "";
464
- let ssotoken = this.searchParam.gatewayToken;
465
- let xtoken = this.searchParam.xtoken;
466
- if (prefix && prefix !== window.WEB_PREFIX) {
467
- // 整页跳转,loading 随页面卸载消失
468
- location.href = prefix + "/index.html" + path;
469
- } else if (!!ssotoken || !!xtoken) {
470
- prefix = prefix || window.WEB_PREFIX;
471
- location.href = prefix + "/index.html" + path;
472
- } else {
473
- this.$router.push(
474
- {
475
- path: path,
476
- },
477
- () => {
478
- // 跳转完成(守卫链+首页组件解析结束)
479
- this.closeRedirectLoading();
480
- },
481
- () => {
482
- // 跳转被中止(如守卫拉取用户信息失败后重定向回登录页),恢复登录页可操作
483
- this.closeRedirectLoading(true);
484
- }
485
- );
486
- }
487
- }, () => {
488
- // getWebPrefix 请求失败:恢复登录页可操作,避免 loading 永久卡死
489
- this.closeRedirectLoading(true);
490
- });
491
- /*if (redirect && redirect.startsWith("/outLinkView")) {
492
- let path = this.addParamToUrl(redirect, "hasToken", "true");
493
- this.$router.push({
494
- path: path
495
- });
496
- } else {
497
- this.$router.push({
498
- path: '/'
499
- });
500
- }*/
501
- },
502
- addParamToUrl(url, paramKey, paramValue) {
503
- var regex = new RegExp("([?&])" + paramKey + "=.*?(&|$)", "i");
504
- if (url.match(regex)) {
505
- url = url.replace(regex, "$1" + paramKey + "=" + paramValue + "$2");
506
- } else {
507
- url +=
508
- (url.indexOf("?") === -1 ? "?" : "&") + paramKey + "=" + paramValue;
509
- }
510
- return url;
511
- },
512
- getWebPrefix(callback, errorCallback) {
513
- this.$http({
514
- url: USER_PREFIX + "/auth/getWebPrefix",
515
- method: `post`,
516
- data: {},
517
- isLoading: true,
518
- success: (res) => {
519
- let webPrefix = res.objx;
520
- callback && callback(webPrefix);
521
- },
522
- fail: () => {
523
- errorCallback && errorCallback();
524
- },
525
- error: () => {
526
- errorCallback && errorCallback();
527
- },
528
- });
529
- },
530
- /**
531
- * 登录跳转期 loading 统一收口:跳转完成/中止、getWebPrefix 失败、组件销毁时调用。
532
- * reenable=true 时恢复登录页可操作(跳转失败仍停留在登录页的场景)
533
- */
534
- closeRedirectLoading(reenable) {
535
- if (this.redirectLoadingObj) {
536
- this.redirectLoadingObj.close();
537
- this.redirectLoadingObj = null;
538
- }
539
- if (reenable) {
540
- this.loading = false;
541
- window.addEventListener("keydown", this.keyDown, false);
542
- }
543
- },
544
- handleGatewayTokenLogin() {
545
- let ssotoken = this.searchParam.gatewayToken;
546
- let companycode = this.searchParam.entCode;
547
- this.$store
548
- .dispatch("user/login2", { ssotoken, companycode })
549
- .then((res) => {
550
- if (res.type == "success") {
551
- this.$nextTick(() => {
552
- this.handleRedirectUrl();
553
- });
554
- }
555
- });
556
- },
557
- handleXTokenLogin() {
558
- let xtoken = this.searchParam.xtoken;
559
- let companycode = this.searchParam.entCode;
560
- this.$store
561
- .dispatch("user/login2", { xtoken, companycode })
562
- .then((res) => {
563
- if (res.type == "success") {
564
- this.handleRedirectUrl();
565
- }
566
- });
567
- },
568
- /**二维码登录begin*/
569
- guid() {
570
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
571
- /[xy]/g,
572
- function (t) {
573
- var e = (16 * Math.random()) | 0;
574
- return ("x" == t ? e : (3 & e) | 8).toString(16);
575
- }
576
- );
577
- },
578
- initQR() {
579
- this.clearQrLoginTimer();
580
- this.qrExpired = true;
581
- let option = { width: 300, height: 300 };
582
- this.qrContent = this.guid();
583
- this.createQR(this.qrContent, option).then((url) => {
584
- this.qrExpired = false;
585
- this.qrBase64 = url;
586
- this.createQrLoginTimer();
587
- });
588
- },
589
- // 生成二维码
590
- createQR(content, options) {
591
- return new Promise((resolve, reject) => {
592
- QRcode.toDataURL(content, options).then((url) => {
593
- resolve(url);
594
- });
595
- });
596
- },
597
- changeTab() {
598
- // this.initQR();
599
- // return
600
- if (this.activeName == "third") {
601
- this.initQR();
602
- } else {
603
- this.clearQrLoginTimer();
604
- }
605
- },
606
- clearQrLoginTimer() {
607
- if (this.qrTimer1) {
608
- clearTimeout(this.qrTimer1);
609
- this.qrTimer1 = null;
610
- }
611
- if (this.qrTimer2) {
612
- clearTimeout(this.qrTimer2);
613
- this.qrTimer2 = null;
614
- }
615
- },
616
- createQrLoginTimer() {
617
- this.checkQrLoginTimerHanlde();
618
- this.qrTimer2 = setTimeout(() => {
619
- this.qrExpired = true;
620
- this.clearQrLoginTimer();
621
- }, 60000);
622
- },
623
- checkQrLoginTimerHanlde() {
624
- this.qrTimer1 = setTimeout(() => {
625
- this.checkQrLoginStatusHanlde();
626
- }, 3000);
627
- },
628
- checkQrLoginStatusHanlde() {
629
- if (this.qrExpired) {
630
- return;
631
- }
632
- this.$http({
633
- url: USER_PREFIX + "/auth/login",
634
- method: `post`,
635
- data: { as: this.qrContent },
636
- // isLoading: true,
637
- failMsg: false,
638
- success: (res) => {
639
- let token = res.objx;
640
- if (token) {
641
- this.$message({
642
- message: this.$t1("登录成功"),
643
- type: "success",
644
- });
645
- this.clearQrLoginTimer();
646
- this.$store.dispatch("user/addToken", { token }).then((res) => {
647
- localStorage.removeItem("currentMenuId");
648
- this.rememberPassword();
649
- this.loading = false;
650
- window.removeEventListener("keydown", this.keyDown, false);
651
- this.handleRedirectUrl();
652
- });
653
- } else {
654
- this.checkQrLoginTimerHanlde();
655
- }
656
- },
657
- });
658
- },
659
- /**二维码登录end*/
660
- },
661
- };
1
+ import { encode } from "js-base64";
2
+ import settingConfig from "@/settings";
3
+ import QRcode from "qrcode";
4
+
5
+ function getUrlParams(url) {
6
+ let result = {};
7
+ if (url) {
8
+ let urlStr = url.split("?")[1];
9
+ const urlSearchParams = new URLSearchParams(urlStr);
10
+ result = Object.fromEntries(urlSearchParams.entries());
11
+ }
12
+ return result;
13
+ }
14
+
15
+ export default {
16
+ name: "Login",
17
+ props: {
18
+ lang: [String, Function],
19
+ },
20
+ components: {},
21
+ data() {
22
+ return {
23
+ isCounting: false,
24
+ countdown: 0,
25
+ buttonText: this.$t1("获取验证码"),
26
+ smsTimer: null,
27
+ isRememberPassword: false,
28
+ loginForm: {
29
+ username: "",
30
+ password: "",
31
+ },
32
+ loginRules: {
33
+ username: [
34
+ {
35
+ required: true,
36
+ trigger: "blur",
37
+ },
38
+ ],
39
+ password: [
40
+ {
41
+ required: true,
42
+ trigger: "blur",
43
+ },
44
+ ],
45
+ },
46
+ passwordType: "password",
47
+ capsTooltip: false,
48
+ loading: false,
49
+ showDialog: false,
50
+ redirect: undefined,
51
+ otherQuery: {},
52
+ // isChangeBackground: false,
53
+ backgroundClass: "",
54
+ hasLogin: false,
55
+ showView: false,
56
+ loginForm2: {
57
+ username: null,
58
+ smsCode: null,
59
+ },
60
+ activeName: "first",
61
+ searchParam: {},
62
+ showContent: true,
63
+
64
+ qrTimer1: null,
65
+ qrTimer2: null,
66
+ qrContent: null,
67
+ qrCodeFlag: 0,
68
+ qrBase64: "",
69
+ settingConfig: settingConfig,
70
+ qrExpired: false,
71
+ loginConfig: {},
72
+ imageUrl: "",
73
+ loginMethod: "",
74
+
75
+ accountLoagin: true,
76
+ phoneLogin: false,
77
+ qrLogin: false,
78
+ };
79
+ },
80
+ watch: {
81
+ $route: {
82
+ handler: function (route) {
83
+ const query = route.query;
84
+ if (query) {
85
+ this.redirect = query.redirect;
86
+ this.otherQuery = this.getOtherQuery(query);
87
+ }
88
+ },
89
+ immediate: true,
90
+ },
91
+ },
92
+ beforeDestroy() {
93
+ this.clearQrLoginTimer();
94
+ this.clearSmsTimer();
95
+ // 兜底:登录组件随路由切换销毁时关闭跳转期 loading($baseLoading 挂在 body 上,
96
+ // 不随组件销毁自动关闭)
97
+ this.closeRedirectLoading();
98
+ },
99
+ created() {
100
+ this.init();
101
+ },
102
+ mounted() {
103
+ // if (this.loginForm.username === '') {
104
+ // this.$refs.username.focus();
105
+ // } else if (this.loginForm.password === '') {
106
+ // this.$refs.password.focus();
107
+ // }
108
+ },
109
+ destroyed() {
110
+ // window.removeEventListener('storage', this.afterQRScan)
111
+ window.removeEventListener("keydown", this.keyDown, false);
112
+ },
113
+ methods: {
114
+ handleLoginConfig() {
115
+ let loginConfig = this.$store.getters.loginConfig || {};
116
+ this.loginConfig = loginConfig;
117
+ this.initImage();
118
+ this.initLoginMethod();
119
+ },
120
+ initImage() {
121
+ //初始化登录图片
122
+ let loginConfig = this.loginConfig;
123
+ if (loginConfig?.attachments?.length) {
124
+ this.imageUrl =
125
+ loginConfig.attachments[0].domain + loginConfig.attachments[0].source;
126
+ }
127
+ },
128
+
129
+ initLoginMethod() {
130
+ let loginConfig = this.loginConfig?.login_method;
131
+ if (loginConfig?.length) {
132
+ this.accountLoagin = loginConfig.includes(1);
133
+ this.phoneLogin = loginConfig.includes(2);
134
+ this.qrLogin = loginConfig.includes(3);
135
+ if (this.accountLoagin) {
136
+ this.activeName = "first";
137
+ } else if (this.phoneLogin) {
138
+ this.activeName = "second";
139
+ } else if (this.qrLogin) {
140
+ this.activeName = "third";
141
+ this.$nextTick(() => {
142
+ this.initQR();
143
+ });
144
+ }
145
+ } else {
146
+ this.accountLoagin = true;
147
+ this.phoneLogin = settingConfig.mobileLoginEnabled;
148
+ this.qrLogin = settingConfig.qrLoginEnabled;
149
+ }
150
+ },
151
+ initLang() {
152
+ let lang = this.$route.query.lang;
153
+ if (!lang && !!this.lang) {
154
+ if (typeof this.lang === "function") {
155
+ lang = this.lang();
156
+ } else {
157
+ lang = this.lang;
158
+ }
159
+ }
160
+ if (lang) {
161
+ this.$i18n.locale = lang;
162
+ localStorage.setItem("i18n-lang", lang);
163
+ }
164
+ },
165
+ init() {
166
+ this.initLang();
167
+ this.handleLoginConfig();
168
+ let searchParam = getUrlParams(location.search);
169
+ this.searchParam = searchParam;
170
+ //小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
171
+ let ssoParams = {};
172
+ if (location.search) {
173
+ ssoParams = searchParam;
174
+ }
175
+ // 获取URL参数
176
+ const urlParams = this.$route.query;
177
+ if (
178
+ ssoParams.ticket ||
179
+ "bear_portalsso" == urlParams.access ||
180
+ urlParams.ticket
181
+ ) {
182
+ //小熊单点登录
183
+ this.bearSsoLogin();
184
+ } else if (searchParam.gatewayToken) {
185
+ this.showContent = false;
186
+ this.handleGatewayTokenLogin();
187
+ } else if (searchParam.xtoken) {
188
+ this.showContent = false;
189
+ this.handleXTokenLogin();
190
+ } else {
191
+ //正常登陆
192
+ this.login();
193
+ }
194
+ },
195
+ keyDown(e) {
196
+ //如果是回车则执行登录方法
197
+ if (e.keyCode == 13 && e.target.nodeName != "INPUT") {
198
+ let closeBtn = document.querySelector(".el-dialog__close");
199
+ closeBtn && closeBtn.click();
200
+ if (this.activeName == "third") return;
201
+ this.handleLogin();
202
+ }
203
+ },
204
+ checkCapslock(e) {
205
+ const { key } = e;
206
+ this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
207
+ },
208
+ showPwd() {
209
+ if (this.passwordType === "password") {
210
+ this.passwordType = "";
211
+ } else {
212
+ this.passwordType = "password";
213
+ }
214
+ this.$nextTick(() => {
215
+ this.$refs.password.focus();
216
+ });
217
+ },
218
+ handleLogin() {
219
+ let loadingObj = null;
220
+ let reqData = {};
221
+ if (this.activeName == "first") {
222
+ //账号密码登录
223
+ loadingObj = this.$baseLoading();
224
+ let password = encode(this.loginForm.password + "");
225
+ reqData = { username: this.loginForm.username, password: password };
226
+ } else {
227
+ //手机验证码登录
228
+ let username = this.loginForm2.username;
229
+ let smsCode = this.loginForm2.smsCode;
230
+ if (!username || !smsCode) {
231
+ this.$baseAlert(this.$t1("请输入手机号和验证码"));
232
+ return;
233
+ }
234
+ loadingObj = this.$baseLoading();
235
+ reqData = { username: username, smsCode: smsCode, mode: "sms" };
236
+ }
237
+
238
+ if (settingConfig.i18nEnabled) {
239
+ //登录传语种到后台
240
+ let language = this.$i18n?.locale;
241
+ if (language && language != "zh") {
242
+ reqData.language = language;
243
+ }
244
+ }
245
+
246
+ this.$store
247
+ .dispatch("user/login2", reqData)
248
+ .then((res) => {
249
+ if (res.type == "success") {
250
+ localStorage.removeItem("currentMenuId");
251
+ this.rememberPassword();
252
+ window.removeEventListener("keydown", this.keyDown, false);
253
+ // 登录成功后的跳转链路(getWebPrefix → 路由守卫拉用户信息/生成动态路由 → 首页渲染)
254
+ // 耗时较长,loading 保持打开防止期间登录页被再次操作;
255
+ // 由 closeRedirectLoading 在跳转完成/中止/请求失败/组件销毁时统一收口
256
+ this.redirectLoadingObj = loadingObj;
257
+ this.handleRedirectUrl();
258
+ } else {
259
+ setTimeout(function () {
260
+ loadingObj.close();
261
+ }, 200);
262
+ }
263
+ })
264
+ .catch((e) => {
265
+ this.loading = false;
266
+ setTimeout(function () {
267
+ loadingObj.close();
268
+ }, 200);
269
+ console.error(e);
270
+ });
271
+ },
272
+ getOtherQuery(query) {
273
+ return Object.keys(query).reduce((acc, cur) => {
274
+ if (cur !== "redirect") {
275
+ acc[cur] = query[cur];
276
+ }
277
+ return acc;
278
+ }, {});
279
+ },
280
+ initPassword() {
281
+ var u = localStorage.getItem("login_info");
282
+ var login_info;
283
+ if (u) {
284
+ login_info = JSON.parse(u);
285
+ var username = login_info.username;
286
+ var password = login_info.password;
287
+ var isRememberPassword = login_info.isRememberPassword;
288
+ if (isRememberPassword == "true") {
289
+ this.isRememberPassword = true;
290
+ this.loginForm.username = username;
291
+ this.loginForm.password = password;
292
+ }
293
+ }
294
+ },
295
+ rememberPassword() {
296
+ if (this.isRememberPassword) {
297
+ var username = this.loginForm.username;
298
+ var password = this.loginForm.password;
299
+ var login_info = {
300
+ username: username,
301
+ password: password,
302
+ isRememberPassword: "true",
303
+ };
304
+ localStorage.setItem("login_info", JSON.stringify(login_info));
305
+ } else {
306
+ localStorage.removeItem("login_info");
307
+ }
308
+ },
309
+ changeBackground() {
310
+ this.backgroundClass = "tc";
311
+ },
312
+ login() {
313
+ let url = window.MAIN_WEB_PREFIX + "/index.html/#/login";
314
+ if (
315
+ self != top &&
316
+ (process.env.NODE_ENV == "development" || self.host == parent.host)
317
+ ) {
318
+ parent.location.href = url;
319
+ } else if (
320
+ process.env.NODE_ENV !== "development" &&
321
+ window.MAIN_WEB_PREFIX &&
322
+ window.MAIN_WEB_PREFIX != window.WEB_PREFIX
323
+ ) {
324
+ window.location.href = url;
325
+ }
326
+ /* let lang = this.$route.query.lang;
327
+ if(lang=="en-US"){
328
+ changeLocale(lang);
329
+ }else{
330
+ changeLocale("zh-CN");
331
+ } */
332
+ // window.addEventListener('storage', this.afterQRScan)
333
+
334
+ window.removeEventListener("keydown", this.keyDown, false);
335
+ window.addEventListener("keydown", this.keyDown, false);
336
+ this.changeBackground();
337
+ this.initPassword();
338
+ this.showView = true;
339
+ },
340
+ bearSsoLogin() {
341
+ //小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
342
+ let urlParams = {};
343
+ if (location.search) {
344
+ urlParams = getUrlParams(location.search);
345
+ }
346
+ //let urlParams = this.$route.query;
347
+
348
+ // 获取URL参数
349
+ console.log("urlParams", urlParams);
350
+ const loginPath = process.env.VUE_APP_BASE_API;
351
+ console.log("loginPath--->", loginPath);
352
+
353
+ //&& loginPath ===window.location.href
354
+ if (urlParams.ticket) {
355
+ console.log("进入回调方法=================");
356
+ this.$store.dispatch("user/clearToken");
357
+ this.$http({
358
+ url: USER_PREFIX + "/auth/idmLogin",
359
+ method: `post`,
360
+ data: { ticket: urlParams.ticket },
361
+ isLoading: true,
362
+ modalStrictly: true,
363
+ success: (res) => {
364
+ let token = res.objx;
365
+ console.log("token", token);
366
+ this.$store.dispatch("user/addToken", { token }).then((res) => {
367
+ localStorage.removeItem("currentMenuId");
368
+ this.rememberPassword();
369
+ /*this.$router.push({
370
+ path: '/'
371
+ });*/
372
+ this.loading = false;
373
+ window.removeEventListener("keydown", this.keyDown, false);
374
+ let redirect = sessionStorage.getItem("loginRedirect");
375
+ this.handleRedirectUrl(redirect);
376
+ });
377
+ },
378
+ fail: () => {
379
+ this.showView = true;
380
+ },
381
+ error: () => {
382
+ this.showView = true;
383
+ },
384
+ });
385
+ } else {
386
+ console.log("进入单点方法");
387
+ let redirect = this.$route.query.redirect || "";
388
+ this.$http({
389
+ url: USER_PREFIX + "/auth/idmLoginUrl",
390
+ method: `post`,
391
+ data: {},
392
+ isLoading: true,
393
+ modalStrictly: true,
394
+ success: (res) => {
395
+ sessionStorage.setItem("loginRedirect", redirect);
396
+ location.href = res.objx;
397
+ // location.href = res.objx+"&redirect="+redirect;
398
+ },
399
+ fail: () => {
400
+ this.showView = true;
401
+ },
402
+ error: () => {
403
+ this.showView = true;
404
+ },
405
+ });
406
+ }
407
+ },
408
+ sendCode() {
409
+ if (this.isCounting) {
410
+ return;
411
+ }
412
+ let mobile = this.loginForm2.username;
413
+ if (!mobile) {
414
+ this.$baseAlert("请输入手机号");
415
+ return;
416
+ }
417
+
418
+ this.$http({
419
+ url: USER_PREFIX + "/auth/sendSmsCode",
420
+ method: `post`,
421
+ data: { mobile: mobile },
422
+ isLoading: true,
423
+ success: (res) => {
424
+ this.$message({
425
+ message: res.content,
426
+ type: "success",
427
+ duration: 1500,
428
+ });
429
+ this.isCounting = true;
430
+ this.countdown = 60;
431
+ this.buttonText = this.$t1("60秒后重新获取");
432
+ this.clearSmsTimer();
433
+ this.smsTimer = setInterval(() => {
434
+ this.countdown--;
435
+ this.buttonText = this.$t1("{time}秒后重新获取", {
436
+ time: this.countdown,
437
+ });
438
+ if (this.countdown == 0) {
439
+ this.clearSmsTimer();
440
+ this.isCounting = false;
441
+ this.buttonText = this.$t1("获取验证码");
442
+ }
443
+ }, 1000);
444
+ },
445
+ });
446
+ },
447
+ clearSmsTimer() {
448
+ if (this.smsTimer) {
449
+ clearInterval(this.smsTimer);
450
+ this.smsTimer = null;
451
+ }
452
+ },
453
+ mobileLogin() {},
454
+ handleRedirectUrl(redirect) {
455
+ redirect = redirect || this.$route.query.redirect;
456
+ let path = null;
457
+ if (redirect && redirect.startsWith("/outLinkView")) {
458
+ path = this.addParamToUrl(redirect, "hasToken", "true");
459
+ } else {
460
+ path = "/";
461
+ }
462
+ this.getWebPrefix((webPrefix) => {
463
+ let prefix = webPrefix ? "/" + webPrefix : "";
464
+ let ssotoken = this.searchParam.gatewayToken;
465
+ let xtoken = this.searchParam.xtoken;
466
+ if (prefix && prefix !== window.WEB_PREFIX) {
467
+ // 整页跳转,loading 随页面卸载消失
468
+ location.href = prefix + "/index.html" + path;
469
+ } else if (!!ssotoken || !!xtoken) {
470
+ prefix = prefix || window.WEB_PREFIX;
471
+ location.href = prefix + "/index.html" + path;
472
+ } else {
473
+ this.$router.push(
474
+ {
475
+ path: path,
476
+ },
477
+ () => {
478
+ // 跳转完成(守卫链+首页组件解析结束)
479
+ this.closeRedirectLoading();
480
+ },
481
+ () => {
482
+ // 跳转被中止(如守卫拉取用户信息失败后重定向回登录页),恢复登录页可操作
483
+ this.closeRedirectLoading(true);
484
+ }
485
+ );
486
+ }
487
+ }, () => {
488
+ // getWebPrefix 请求失败:恢复登录页可操作,避免 loading 永久卡死
489
+ this.closeRedirectLoading(true);
490
+ });
491
+ /*if (redirect && redirect.startsWith("/outLinkView")) {
492
+ let path = this.addParamToUrl(redirect, "hasToken", "true");
493
+ this.$router.push({
494
+ path: path
495
+ });
496
+ } else {
497
+ this.$router.push({
498
+ path: '/'
499
+ });
500
+ }*/
501
+ },
502
+ addParamToUrl(url, paramKey, paramValue) {
503
+ var regex = new RegExp("([?&])" + paramKey + "=.*?(&|$)", "i");
504
+ if (url.match(regex)) {
505
+ url = url.replace(regex, "$1" + paramKey + "=" + paramValue + "$2");
506
+ } else {
507
+ url +=
508
+ (url.indexOf("?") === -1 ? "?" : "&") + paramKey + "=" + paramValue;
509
+ }
510
+ return url;
511
+ },
512
+ getWebPrefix(callback, errorCallback) {
513
+ this.$http({
514
+ url: USER_PREFIX + "/auth/getWebPrefix",
515
+ method: `post`,
516
+ data: {},
517
+ isLoading: true,
518
+ success: (res) => {
519
+ let webPrefix = res.objx;
520
+ callback && callback(webPrefix);
521
+ },
522
+ fail: () => {
523
+ errorCallback && errorCallback();
524
+ },
525
+ error: () => {
526
+ errorCallback && errorCallback();
527
+ },
528
+ });
529
+ },
530
+ /**
531
+ * 登录跳转期 loading 统一收口:跳转完成/中止、getWebPrefix 失败、组件销毁时调用。
532
+ * reenable=true 时恢复登录页可操作(跳转失败仍停留在登录页的场景)
533
+ */
534
+ closeRedirectLoading(reenable) {
535
+ if (this.redirectLoadingObj) {
536
+ this.redirectLoadingObj.close();
537
+ this.redirectLoadingObj = null;
538
+ }
539
+ if (reenable) {
540
+ this.loading = false;
541
+ window.addEventListener("keydown", this.keyDown, false);
542
+ }
543
+ },
544
+ handleGatewayTokenLogin() {
545
+ let ssotoken = this.searchParam.gatewayToken;
546
+ let companycode = this.searchParam.entCode;
547
+ this.$store
548
+ .dispatch("user/login2", { ssotoken, companycode })
549
+ .then((res) => {
550
+ if (res.type == "success") {
551
+ this.$nextTick(() => {
552
+ this.handleRedirectUrl();
553
+ });
554
+ }
555
+ });
556
+ },
557
+ handleXTokenLogin() {
558
+ let xtoken = this.searchParam.xtoken;
559
+ let companycode = this.searchParam.entCode;
560
+ this.$store
561
+ .dispatch("user/login2", { xtoken, companycode })
562
+ .then((res) => {
563
+ if (res.type == "success") {
564
+ this.handleRedirectUrl();
565
+ }
566
+ });
567
+ },
568
+ /**二维码登录begin*/
569
+ guid() {
570
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
571
+ /[xy]/g,
572
+ function (t) {
573
+ var e = (16 * Math.random()) | 0;
574
+ return ("x" == t ? e : (3 & e) | 8).toString(16);
575
+ }
576
+ );
577
+ },
578
+ initQR() {
579
+ this.clearQrLoginTimer();
580
+ this.qrExpired = true;
581
+ let option = { width: 300, height: 300 };
582
+ this.qrContent = this.guid();
583
+ this.createQR(this.qrContent, option).then((url) => {
584
+ this.qrExpired = false;
585
+ this.qrBase64 = url;
586
+ this.createQrLoginTimer();
587
+ });
588
+ },
589
+ // 生成二维码
590
+ createQR(content, options) {
591
+ return new Promise((resolve, reject) => {
592
+ QRcode.toDataURL(content, options).then((url) => {
593
+ resolve(url);
594
+ });
595
+ });
596
+ },
597
+ changeTab() {
598
+ // this.initQR();
599
+ // return
600
+ if (this.activeName == "third") {
601
+ this.initQR();
602
+ } else {
603
+ this.clearQrLoginTimer();
604
+ }
605
+ },
606
+ clearQrLoginTimer() {
607
+ if (this.qrTimer1) {
608
+ clearTimeout(this.qrTimer1);
609
+ this.qrTimer1 = null;
610
+ }
611
+ if (this.qrTimer2) {
612
+ clearTimeout(this.qrTimer2);
613
+ this.qrTimer2 = null;
614
+ }
615
+ },
616
+ createQrLoginTimer() {
617
+ this.checkQrLoginTimerHanlde();
618
+ this.qrTimer2 = setTimeout(() => {
619
+ this.qrExpired = true;
620
+ this.clearQrLoginTimer();
621
+ }, 60000);
622
+ },
623
+ checkQrLoginTimerHanlde() {
624
+ this.qrTimer1 = setTimeout(() => {
625
+ this.checkQrLoginStatusHanlde();
626
+ }, 3000);
627
+ },
628
+ checkQrLoginStatusHanlde() {
629
+ if (this.qrExpired) {
630
+ return;
631
+ }
632
+ this.$http({
633
+ url: USER_PREFIX + "/auth/login",
634
+ method: `post`,
635
+ data: { as: this.qrContent },
636
+ // isLoading: true,
637
+ failMsg: false,
638
+ success: (res) => {
639
+ let token = res.objx;
640
+ if (token) {
641
+ this.$message({
642
+ message: this.$t1("登录成功"),
643
+ type: "success",
644
+ });
645
+ this.clearQrLoginTimer();
646
+ this.$store.dispatch("user/addToken", { token }).then((res) => {
647
+ localStorage.removeItem("currentMenuId");
648
+ this.rememberPassword();
649
+ this.loading = false;
650
+ window.removeEventListener("keydown", this.keyDown, false);
651
+ this.handleRedirectUrl();
652
+ });
653
+ } else {
654
+ this.checkQrLoginTimerHanlde();
655
+ }
656
+ },
657
+ });
658
+ },
659
+ /**二维码登录end*/
660
+ },
661
+ };