|
@@ -1,27 +1,30 @@
|
|
1
|
+import { Component, OnInit } from "@angular/core";
|
|
2
|
+import { Router } from "@angular/router";
|
|
3
|
+import { FormBuilder, Validators, FormGroup } from "@angular/forms";
|
|
4
|
+import { NzMessageService } from "ng-zorro-antd/message";
|
1
|
5
|
|
2
|
|
-import { Component, OnInit } from '@angular/core';
|
3
|
|
-import { Router } from '@angular/router'
|
4
|
|
-import { FormBuilder, Validators, FormGroup } from '@angular/forms';
|
5
|
|
-import { NzMessageService } from 'ng-zorro-antd/message';
|
6
|
|
-
|
7
|
|
-import { MainService } from '../../services/main.service'
|
8
|
|
-import { AES, mode, pad, enc } from 'crypto-js';
|
|
6
|
+import { MainService } from "../../services/main.service";
|
|
7
|
+import { AES, mode, pad, enc } from "crypto-js";
|
9
|
8
|
|
10
|
9
|
@Component({
|
11
|
|
- selector: 'app-login',
|
12
|
|
- templateUrl: './login.component.html',
|
13
|
|
- styleUrls: ['./login.component.less'],
|
|
10
|
+ selector: "app-login",
|
|
11
|
+ templateUrl: "./login.component.html",
|
|
12
|
+ styleUrls: ["./login.component.less"],
|
14
|
13
|
})
|
15
|
14
|
export class LoginComponent implements OnInit {
|
16
|
15
|
validateForm: FormGroup;
|
17
|
16
|
loading: boolean = false;
|
18
|
17
|
// 是否单点登录
|
19
|
18
|
isSingleSignOn: boolean;
|
20
|
|
- constructor(private router: Router, private fb: FormBuilder, private mainService: MainService, private msg: NzMessageService) {
|
21
|
|
- }
|
|
19
|
+ constructor(
|
|
20
|
+ private router: Router,
|
|
21
|
+ private fb: FormBuilder,
|
|
22
|
+ private mainService: MainService,
|
|
23
|
+ private msg: NzMessageService
|
|
24
|
+ ) {}
|
22
|
25
|
ngOnInit() {
|
23
|
26
|
let url = location.href;
|
24
|
|
- this.isSingleSignOn = url.includes('?');
|
|
27
|
+ this.isSingleSignOn = url.includes("?");
|
25
|
28
|
if (this.isSingleSignOn) {
|
26
|
29
|
this.singleSignOn();
|
27
|
30
|
} else {
|
|
@@ -31,40 +34,40 @@ export class LoginComponent implements OnInit {
|
31
|
34
|
//单点登录
|
32
|
35
|
singleSignOn() {
|
33
|
36
|
let url = location.href;
|
34
|
|
- let paramsStr = url.split('?')[1];
|
|
37
|
+ let paramsStr = url.split("?")[1];
|
35
|
38
|
let paramsObj = {};
|
36
|
|
- paramsStr.split('&').forEach(item => {
|
37
|
|
- let arr = item.split('=');
|
|
39
|
+ paramsStr.split("&").forEach((item) => {
|
|
40
|
+ let arr = item.split("=");
|
38
|
41
|
paramsObj[arr[0] + 1] = arr[1];
|
39
|
|
- })
|
|
42
|
+ });
|
40
|
43
|
this.singleSignOnLogin(paramsObj);
|
41
|
44
|
}
|
42
|
45
|
// 单点登录
|
43
|
46
|
singleSignOnLogin(paramsObj): void {
|
44
|
|
- const loadingId = this.msg.loading('登录中..', { nzDuration: 0 }).messageId;
|
|
47
|
+ const loadingId = this.msg.loading("登录中..", { nzDuration: 0 }).messageId;
|
45
|
48
|
this.loading = true;
|
46
|
49
|
this.mainService.singleSignOnLogin(paramsObj).subscribe(
|
47
|
|
- data => {
|
|
50
|
+ (data) => {
|
48
|
51
|
this.loading = false;
|
49
|
52
|
this.msg.remove(loadingId);
|
50
|
|
- localStorage.removeItem('remember');
|
51
|
|
- this.apiLogin(data.userId,data.pwd);
|
52
|
|
- },err=>{
|
|
53
|
+ this.apiLogin(data.userId, data.pwd, true);
|
|
54
|
+ },
|
|
55
|
+ (err) => {
|
53
|
56
|
this.loading = false;
|
54
|
57
|
this.msg.remove(loadingId);
|
55
|
|
- this.msg.error('登录失败', {
|
56
|
|
- nzDuration: 1000
|
|
58
|
+ this.msg.error("登录失败", {
|
|
59
|
+ nzDuration: 1000,
|
57
|
60
|
});
|
58
|
|
- this.router.navigateByUrl('/login');
|
|
61
|
+ this.router.navigateByUrl("/login");
|
59
|
62
|
}
|
60
|
|
- )
|
|
63
|
+ );
|
61
|
64
|
}
|
62
|
65
|
//aes加密
|
63
|
66
|
encryptByEnAES(data: string): string {
|
64
|
67
|
let Key = "dsadmin";
|
65
|
68
|
let tmpAES = AES.encrypt(data, Key, {
|
66
|
69
|
mode: mode.CBC,
|
67
|
|
- padding: pad.Pkcs7
|
|
70
|
+ padding: pad.Pkcs7,
|
68
|
71
|
});
|
69
|
72
|
return tmpAES.toString();
|
70
|
73
|
}
|
|
@@ -73,7 +76,7 @@ export class LoginComponent implements OnInit {
|
73
|
76
|
let Key = "dsadmin";
|
74
|
77
|
let tmpDeAES = AES.decrypt(data, Key, {
|
75
|
78
|
mode: mode.CBC,
|
76
|
|
- padding: pad.Pkcs7
|
|
79
|
+ padding: pad.Pkcs7,
|
77
|
80
|
});
|
78
|
81
|
return tmpDeAES.toString(enc.Utf8);
|
79
|
82
|
}
|
|
@@ -81,25 +84,25 @@ export class LoginComponent implements OnInit {
|
81
|
84
|
// 初始化菜单
|
82
|
85
|
initMenu(menu) {
|
83
|
86
|
let menuLis = this.transform(menu);
|
84
|
|
- menuLis.forEach(item => {
|
|
87
|
+ menuLis.forEach((item) => {
|
85
|
88
|
item.flag = false;
|
86
|
89
|
item.flagBg = false;
|
87
|
|
- item.childrens.forEach(value => {
|
|
90
|
+ item.childrens.forEach((value) => {
|
88
|
91
|
value.flag = false;
|
89
|
|
- })
|
90
|
|
- })
|
91
|
|
- localStorage.setItem('menu', JSON.stringify(menuLis));
|
92
|
|
- localStorage.setItem('index', 'true');//首页默认高亮
|
|
92
|
+ });
|
|
93
|
+ });
|
|
94
|
+ localStorage.setItem("menu", JSON.stringify(menuLis));
|
|
95
|
+ localStorage.setItem("index", "true"); //首页默认高亮
|
93
|
96
|
}
|
94
|
97
|
|
95
|
98
|
// 初始化登录表单
|
96
|
99
|
initForm() {
|
97
|
100
|
let username, passsword;
|
98
|
101
|
// 如果本地存储的有remember字段(记住密码功能)
|
99
|
|
- if (localStorage.getItem('remember')) {
|
100
|
|
- let remember = JSON.parse(localStorage.getItem('remember'));
|
|
102
|
+ if (localStorage.getItem("remember")) {
|
|
103
|
+ let remember = JSON.parse(localStorage.getItem("remember"));
|
101
|
104
|
// 比较记住密码的功能是否在有效期内
|
102
|
|
- if (remember.date > (new Date().getTime())) {
|
|
105
|
+ if (remember.date > new Date().getTime()) {
|
103
|
106
|
username = this.encryptByDeAES(remember.username);
|
104
|
107
|
passsword = this.encryptByDeAES(remember.password);
|
105
|
108
|
}
|
|
@@ -108,14 +111,14 @@ export class LoginComponent implements OnInit {
|
108
|
111
|
this.validateForm = this.fb.group({
|
109
|
112
|
userName: [username || null, [Validators.required]],
|
110
|
113
|
password: [passsword || null, [Validators.required]],
|
111
|
|
- remember: [true]
|
|
114
|
+ remember: [true],
|
112
|
115
|
});
|
113
|
116
|
}
|
114
|
117
|
// enter触发
|
115
|
118
|
enterUp(e): void {
|
116
|
119
|
let keyCode = e.which || e.keyCode || 0;
|
117
|
120
|
if (keyCode == 13) {
|
118
|
|
- this.submitForm()
|
|
121
|
+ this.submitForm();
|
119
|
122
|
}
|
120
|
123
|
}
|
121
|
124
|
// 登录
|
|
@@ -125,113 +128,119 @@ export class LoginComponent implements OnInit {
|
125
|
128
|
this.validateForm.controls[i].updateValueAndValidity();
|
126
|
129
|
}
|
127
|
130
|
// 用户名和密码必填
|
128
|
|
- if (!this.validateForm.value.userName || !this.validateForm.value.password) {
|
129
|
|
- this.msg.info('用户名或密码不能为空!');
|
|
131
|
+ if (
|
|
132
|
+ !this.validateForm.value.userName ||
|
|
133
|
+ !this.validateForm.value.password
|
|
134
|
+ ) {
|
|
135
|
+ this.msg.info("用户名或密码不能为空!");
|
130
|
136
|
return;
|
131
|
137
|
}
|
132
|
|
- this.apiLogin(this.validateForm.value.userName,this.validateForm.value.password);
|
|
138
|
+ this.apiLogin(
|
|
139
|
+ this.validateForm.value.userName,
|
|
140
|
+ this.validateForm.value.password
|
|
141
|
+ );
|
133
|
142
|
}
|
134
|
|
- // 登录接口
|
135
|
|
- apiLogin(user,pwd){
|
136
|
|
- const loadingId = this.msg.loading('登录中..', { nzDuration: 0 }).messageId;
|
|
143
|
+ // 登录接口,true是单点登录
|
|
144
|
+ apiLogin(user, pwd, flag = false) {
|
|
145
|
+ const loadingId = this.msg.loading("登录中..", { nzDuration: 0 }).messageId;
|
137
|
146
|
this.loading = true;
|
138
|
|
- this.mainService.login(user, pwd).subscribe(
|
139
|
|
- data => {
|
140
|
|
- this.loading = false;
|
141
|
|
- this.msg.remove(loadingId);
|
142
|
|
- if (data.status == 200) {
|
|
147
|
+ this.mainService.login(user, pwd).subscribe((data) => {
|
|
148
|
+ this.loading = false;
|
|
149
|
+ this.msg.remove(loadingId);
|
|
150
|
+ if (data.status == 200) {
|
|
151
|
+ if (!flag) {
|
143
|
152
|
// 记住密码勾选中
|
144
|
153
|
if (this.validateForm.value.remember) {
|
145
|
154
|
let remember = {
|
146
|
155
|
username: this.encryptByEnAES(this.validateForm.value.userName),
|
147
|
156
|
password: this.encryptByEnAES(this.validateForm.value.password),
|
148
|
|
- date: new Date().getTime() + 90 * 24 * 3600 * 1000//3个月
|
149
|
|
- }
|
150
|
|
- localStorage.setItem('remember', JSON.stringify(remember));
|
|
157
|
+ date: new Date().getTime() + 90 * 24 * 3600 * 1000, //3个月
|
|
158
|
+ };
|
|
159
|
+ localStorage.setItem("remember", JSON.stringify(remember));
|
151
|
160
|
} else {
|
152
|
|
- localStorage.removeItem('remember');
|
|
161
|
+ localStorage.removeItem("remember");
|
153
|
162
|
}
|
154
|
|
- this.toRoute2(data)
|
155
|
|
- this.initMenu(data.user.menu)
|
156
|
|
- } else {
|
157
|
|
- this.msg.error(data.remarks, {
|
158
|
|
- nzDuration: 1000
|
159
|
|
- });
|
160
|
163
|
}
|
|
164
|
+ this.toRoute2(data);
|
|
165
|
+ this.initMenu(data.user.menu);
|
|
166
|
+ } else {
|
|
167
|
+ this.msg.error(data.remarks, {
|
|
168
|
+ nzDuration: 1000,
|
|
169
|
+ });
|
161
|
170
|
}
|
162
|
|
- )
|
|
171
|
+ });
|
163
|
172
|
}
|
164
|
173
|
|
165
|
174
|
// 页面跳转
|
166
|
175
|
toRoute2(data) {
|
167
|
176
|
let roleMenus = data.user.menu;
|
168
|
|
- let canLogin = false;//是否可以进入系统主页面(无护士端,调度台,药房端权限)
|
169
|
|
- let successLoginMsg = true;//登录成功提示,true是提示,false不提示
|
|
177
|
+ let canLogin = false; //是否可以进入系统主页面(无护士端,调度台,药房端权限)
|
|
178
|
+ let successLoginMsg = true; //登录成功提示,true是提示,false不提示
|
170
|
179
|
let fwt = false;
|
171
|
180
|
let ddt = false;
|
172
|
181
|
let yfang = false;
|
173
|
|
- roleMenus.forEach(e => {
|
174
|
|
- if (e.title.includes('药房端')) {
|
|
182
|
+ roleMenus.forEach((e) => {
|
|
183
|
+ if (e.title.includes("药房端")) {
|
175
|
184
|
yfang = true;
|
176
|
|
- console.log('药房端')
|
177
|
|
- } else if (e.title.includes('护士端')) {
|
|
185
|
+ console.log("药房端");
|
|
186
|
+ } else if (e.title.includes("护士端")) {
|
178
|
187
|
fwt = true;
|
179
|
|
- console.log('护士端')
|
180
|
|
- } else if (e.title.includes('调度台')) {
|
|
188
|
+ console.log("护士端");
|
|
189
|
+ } else if (e.title.includes("调度台")) {
|
181
|
190
|
ddt = true;
|
182
|
|
- console.log('调度台')
|
|
191
|
+ console.log("调度台");
|
183
|
192
|
}
|
184
|
|
- canLogin = true
|
|
193
|
+ canLogin = true;
|
185
|
194
|
});
|
186
|
195
|
if (fwt) {
|
187
|
196
|
// 护士角色跳护士端
|
188
|
197
|
if (successLoginMsg) {
|
189
|
|
- this.msg.success('登录成功!', {
|
190
|
|
- nzDuration: 1000
|
|
198
|
+ this.msg.success("登录成功!", {
|
|
199
|
+ nzDuration: 1000,
|
191
|
200
|
});
|
192
|
201
|
}
|
193
|
202
|
successLoginMsg = false;
|
194
|
|
- localStorage.setItem('user', JSON.stringify(data.user))
|
195
|
|
- this.router.navigateByUrl('/nurse');
|
|
203
|
+ localStorage.setItem("user", JSON.stringify(data.user));
|
|
204
|
+ this.router.navigateByUrl("/nurse");
|
196
|
205
|
|
197
|
206
|
return;
|
198
|
207
|
} else if (ddt) {
|
199
|
208
|
// 调度台
|
200
|
209
|
if (successLoginMsg) {
|
201
|
|
- this.msg.success('登录成功!', {
|
202
|
|
- nzDuration: 1000
|
|
210
|
+ this.msg.success("登录成功!", {
|
|
211
|
+ nzDuration: 1000,
|
203
|
212
|
});
|
204
|
213
|
}
|
205
|
214
|
successLoginMsg = false;
|
206
|
|
- localStorage.setItem('user', JSON.stringify(data.user))
|
207
|
|
- this.router.navigateByUrl('/dispatchingDesk');
|
|
215
|
+ localStorage.setItem("user", JSON.stringify(data.user));
|
|
216
|
+ this.router.navigateByUrl("/dispatchingDesk");
|
208
|
217
|
return;
|
209
|
218
|
} else if (yfang) {
|
210
|
219
|
// 药房端
|
211
|
220
|
if (successLoginMsg) {
|
212
|
|
- this.msg.success('登录成功!', {
|
213
|
|
- nzDuration: 1000
|
|
221
|
+ this.msg.success("登录成功!", {
|
|
222
|
+ nzDuration: 1000,
|
214
|
223
|
});
|
215
|
224
|
}
|
216
|
225
|
successLoginMsg = false;
|
217
|
|
- localStorage.setItem('user', JSON.stringify(data.user))
|
218
|
|
- this.router.navigateByUrl('/pharmacy');
|
|
226
|
+ localStorage.setItem("user", JSON.stringify(data.user));
|
|
227
|
+ this.router.navigateByUrl("/pharmacy");
|
219
|
228
|
return;
|
220
|
229
|
}
|
221
|
230
|
// 有菜单可以进入系统主页面
|
222
|
231
|
if (!canLogin) {
|
223
|
|
- this.msg.success('暂无权限进入系统!', {
|
224
|
|
- nzDuration: 1000
|
|
232
|
+ this.msg.success("暂无权限进入系统!", {
|
|
233
|
+ nzDuration: 1000,
|
225
|
234
|
});
|
226
|
235
|
} else {
|
227
|
236
|
if (successLoginMsg) {
|
228
|
|
- this.msg.success('登录成功!', {
|
229
|
|
- nzDuration: 1000
|
|
237
|
+ this.msg.success("登录成功!", {
|
|
238
|
+ nzDuration: 1000,
|
230
|
239
|
});
|
231
|
240
|
}
|
232
|
241
|
successLoginMsg = false;
|
233
|
|
- localStorage.setItem('user', JSON.stringify(data.user))
|
234
|
|
- this.router.navigateByUrl('/main/home');
|
|
242
|
+ localStorage.setItem("user", JSON.stringify(data.user));
|
|
243
|
+ this.router.navigateByUrl("/main/home");
|
235
|
244
|
}
|
236
|
245
|
}
|
237
|
246
|
|
|
@@ -259,8 +268,8 @@ export class LoginComponent implements OnInit {
|
259
|
268
|
const idMapping = nodes.reduce((acc, el, i) => {
|
260
|
269
|
acc[el.id] = i;
|
261
|
270
|
return acc;
|
262
|
|
- }, {})
|
263
|
|
- nodes.forEach(el => {
|
|
271
|
+ }, {});
|
|
272
|
+ nodes.forEach((el) => {
|
264
|
273
|
if (el.parentid === null || el.parentid === undefined) {
|
265
|
274
|
parents.push(el);
|
266
|
275
|
} else {
|
|
@@ -268,6 +277,6 @@ export class LoginComponent implements OnInit {
|
268
|
277
|
parentEl.childrens = [...(parentEl.childrens || []), el];
|
269
|
278
|
}
|
270
|
279
|
});
|
271
|
|
- return parents
|
|
280
|
+ return parents;
|
272
|
281
|
}
|
273
|
282
|
}
|