@yelon/bis 17.3.2 → 18.0.1
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.
- package/LICENSE +21 -21
- package/README.md +1 -1
- package/config/bis.config.d.ts +3 -3
- package/config/index.d.ts +5 -5
- package/config/public_api.d.ts +1 -1
- package/esm2022/bis.mjs +4 -4
- package/esm2022/config/bis.config.mjs +14 -14
- package/esm2022/config/config.mjs +4 -4
- package/esm2022/config/public_api.mjs +1 -1
- package/esm2022/layout/layout-basic.component.mjs +518 -508
- package/esm2022/layout/layout-nav-application.component.mjs +372 -372
- package/esm2022/layout/layout-nav-group.component.mjs +166 -162
- package/esm2022/layout/layout-nav-tile.component.mjs +14 -14
- package/esm2022/layout/layout.mjs +4 -4
- package/esm2022/layout/layout.module.mjs +53 -53
- package/esm2022/layout/public_api.mjs +5 -5
- package/esm2022/public_api.mjs +8 -8
- package/esm2022/src/bis.module.mjs +16 -16
- package/esm2022/src/helper.mjs +44 -44
- package/esm2022/src/provide.mjs +7 -7
- package/esm2022/src/refresh-token.mjs +78 -78
- package/esm2022/src/startup.service.mjs +183 -183
- package/esm2022/src/yunzai-act.guard.mjs +87 -87
- package/esm2022/src/yunzai-analysis-addon.guard.mjs +98 -98
- package/esm2022/src/yunzai-default.interceptor.mjs +62 -62
- package/esm2022/yunzai-widgets/public_api.mjs +6 -6
- package/esm2022/yunzai-widgets/yunzai-clear-storage.component.mjs +46 -46
- package/esm2022/yunzai-widgets/yunzai-fullscreen.component.mjs +46 -46
- package/esm2022/yunzai-widgets/yunzai-i18n.component.mjs +138 -138
- package/esm2022/yunzai-widgets/yunzai-notify.component.mjs +179 -179
- package/esm2022/yunzai-widgets/yunzai-user.component.mjs +119 -119
- package/esm2022/yunzai-widgets/yunzai-widget.module.mjs +61 -61
- package/esm2022/yunzai-widgets/yunzai-widgets.mjs +4 -4
- package/fesm2022/bis.mjs +559 -559
- package/fesm2022/config.mjs +21 -21
- package/fesm2022/layout.mjs +1097 -1083
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/yunzai-widgets.mjs +563 -563
- package/index.d.ts +5 -5
- package/index.less +1 -1
- package/layout/index.d.ts +5 -5
- package/layout/layout-basic.component.d.ts +54 -54
- package/layout/layout-nav-application.component.d.ts +26 -26
- package/layout/layout-nav-group.component.d.ts +14 -14
- package/layout/layout-nav-tile.component.d.ts +5 -5
- package/layout/layout.module.d.ts +18 -18
- package/layout/public_api.d.ts +5 -5
- package/layout/style/index.less +181 -182
- package/package.json +68 -68
- package/public_api.d.ts +8 -8
- package/src/bis.module.d.ts +8 -8
- package/src/helper.d.ts +16 -16
- package/src/provide.d.ts +2 -2
- package/src/refresh-token.d.ts +6 -6
- package/src/startup.service.d.ts +24 -24
- package/src/yunzai-act.guard.d.ts +20 -20
- package/src/yunzai-analysis-addon.guard.d.ts +26 -26
- package/src/yunzai-default.interceptor.d.ts +2 -2
- package/theme-compact.less +3 -3
- package/theme-dark.less +46 -46
- package/theme-default.less +48 -48
- package/theme-variable.less +1 -0
- package/yunzai-widgets/index.d.ts +5 -5
- package/yunzai-widgets/public_api.d.ts +6 -6
- package/yunzai-widgets/yunzai-clear-storage.component.d.ts +8 -8
- package/yunzai-widgets/yunzai-fullscreen.component.d.ts +8 -8
- package/yunzai-widgets/yunzai-i18n.component.d.ts +19 -19
- package/yunzai-widgets/yunzai-notify.component.d.ts +25 -25
- package/yunzai-widgets/yunzai-user.component.d.ts +22 -22
- package/yunzai-widgets/yunzai-widget.module.d.ts +18 -18
package/fesm2022/bis.mjs
CHANGED
|
@@ -1,559 +1,559 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { NgModule, importProvidersFrom, makeEnvironmentProviders, inject, APP_INITIALIZER, Injector, Injectable, Inject } from '@angular/core';
|
|
3
|
-
import { YunzaiLayoutModule } from '@yelon/bis/layout';
|
|
4
|
-
import { YunzaiWidgetsModule } from '@yelon/bis/yunzai-widgets';
|
|
5
|
-
import * as i2 from '@angular/router';
|
|
6
|
-
import { Router } from '@angular/router';
|
|
7
|
-
import { YA_SERVICE_TOKEN } from '@yelon/auth';
|
|
8
|
-
import { YUNZAI_I18N_TOKEN, IGNORE_BASE_URL, MenuService, TitleService, SettingsService } from '@yelon/theme';
|
|
9
|
-
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
|
10
|
-
import { HttpClient, HttpErrorResponse, HttpResponseBase } from '@angular/common/http';
|
|
11
|
-
import { BehaviorSubject, throwError, filter, take, switchMap, catchError, of, mergeMap, combineLatest, map } from 'rxjs';
|
|
12
|
-
import { mergeBisConfig, BUSINESS_DEFAULT_CONFIG } from '@yelon/bis/config';
|
|
13
|
-
import * as i1 from '@yelon/util';
|
|
14
|
-
import { log, YUNZAI_CONFIG, YunzaiConfigService, WINDOW, useLocalStorageTenant, useLocalStorageUser, useLocalStorageHeader, useLocalStorageProjectInfo, useLocalStorageDefaultRoute, useLocalStorageCurrent, deepCopy } from '@yelon/util';
|
|
15
|
-
import { ACLService } from '@yelon/acl';
|
|
16
|
-
|
|
17
|
-
class BisModule {
|
|
18
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
19
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
20
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
21
|
-
}
|
|
22
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
23
|
-
type: NgModule,
|
|
24
|
-
args: [{
|
|
25
|
-
imports: [YunzaiLayoutModule, YunzaiWidgetsModule],
|
|
26
|
-
exports: [YunzaiLayoutModule, YunzaiWidgetsModule]
|
|
27
|
-
}]
|
|
28
|
-
}] });
|
|
29
|
-
|
|
30
|
-
function provideYunzaiBis() {
|
|
31
|
-
const provides = [];
|
|
32
|
-
provides.push(importProvidersFrom(BisModule));
|
|
33
|
-
return makeEnvironmentProviders(provides);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const CODEMESSAGE = {
|
|
37
|
-
200: '服务器成功返回请求的数据。',
|
|
38
|
-
201: '新建或修改数据成功。',
|
|
39
|
-
202: '一个请求已经进入后台排队(异步任务)。',
|
|
40
|
-
204: '删除数据成功。',
|
|
41
|
-
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
42
|
-
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
43
|
-
403: '用户得到授权,但是访问是被禁止的。',
|
|
44
|
-
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
45
|
-
406: '请求的格式不可得。',
|
|
46
|
-
410: '请求的资源被永久删除,且不会再得到的。',
|
|
47
|
-
422: '当创建一个对象时,发生一个验证错误。',
|
|
48
|
-
500: '服务器发生错误,请检查服务器。',
|
|
49
|
-
502: '网关错误。',
|
|
50
|
-
503: '服务不可用,服务器暂时过载或维护。',
|
|
51
|
-
504: '网关超时。'
|
|
52
|
-
};
|
|
53
|
-
function getAdditionalHeaders(headers) {
|
|
54
|
-
const res = {};
|
|
55
|
-
const lang = inject(YUNZAI_I18N_TOKEN).currentLang;
|
|
56
|
-
if (!headers?.has('Accept-Language') && lang) {
|
|
57
|
-
res['Accept-Language'] = lang;
|
|
58
|
-
}
|
|
59
|
-
return res;
|
|
60
|
-
}
|
|
61
|
-
function checkStatus(injector, ev) {
|
|
62
|
-
if ((ev.status >= 200 && ev.status < 300) || ev.status === 401) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const errortext = CODEMESSAGE[ev.status] || ev.statusText;
|
|
66
|
-
injector.get(NzNotificationService).error(`请求错误 ${ev.status}: ${ev.url}`, errortext);
|
|
67
|
-
}
|
|
68
|
-
function goTo(injector, url) {
|
|
69
|
-
setTimeout(() => injector.get(Router).navigateByUrl(url));
|
|
70
|
-
}
|
|
71
|
-
function toLogin(injector) {
|
|
72
|
-
injector.get(NzNotificationService).error(`未登录或登录已过期,请重新登录。`, ``);
|
|
73
|
-
goTo(injector, injector.get(YA_SERVICE_TOKEN).login_url);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let refreshToking = false;
|
|
77
|
-
let refreshToken$ = new BehaviorSubject(null);
|
|
78
|
-
const tryRefreshToken = (injector, ev, req, next) => {
|
|
79
|
-
// 连刷新Token的请求都错了,那就是真错了
|
|
80
|
-
if (['/auth/oauth/getOrCreateToken/webapp'].some(url => req.url.includes(url))) {
|
|
81
|
-
toLogin(injector);
|
|
82
|
-
return throwError(() => ev);
|
|
83
|
-
}
|
|
84
|
-
// 2、如果 `refreshToking` 为 `true` 表示已经在请求刷新 Token 中,后续所有请求转入等待状态,直至结果返回后再重新发起请求
|
|
85
|
-
if (refreshToking) {
|
|
86
|
-
return refreshToken$.pipe(filter(v => !!v), take(1), switchMap(() => next(reAttachToken(injector, req))));
|
|
87
|
-
}
|
|
88
|
-
// 3、尝试调用刷新 Token
|
|
89
|
-
refreshToking = true;
|
|
90
|
-
refreshToken$.next(null);
|
|
91
|
-
return refreshTokenRequest(injector).pipe(switchMap(res => {
|
|
92
|
-
// 通知后续请求继续执行
|
|
93
|
-
refreshToking = false;
|
|
94
|
-
refreshToken$.next(res);
|
|
95
|
-
// 重新保存新 token
|
|
96
|
-
injector.get(YA_SERVICE_TOKEN).set(res);
|
|
97
|
-
// 重新发起请求
|
|
98
|
-
return next(reAttachToken(injector, req));
|
|
99
|
-
}), catchError(err => {
|
|
100
|
-
refreshToking = false;
|
|
101
|
-
toLogin(injector);
|
|
102
|
-
return throwError(() => err);
|
|
103
|
-
}));
|
|
104
|
-
};
|
|
105
|
-
function reAttachToken(injector, req) {
|
|
106
|
-
const token = injector.get(YA_SERVICE_TOKEN).get()?.access_token;
|
|
107
|
-
return req.clone({
|
|
108
|
-
setHeaders: {
|
|
109
|
-
Authorization: `Bearer ${token}`
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function refreshTokenRequest(injector) {
|
|
114
|
-
const model = injector.get(YA_SERVICE_TOKEN).get();
|
|
115
|
-
const form = new FormData();
|
|
116
|
-
form.set('refresh_token', model?.refresh_token);
|
|
117
|
-
form.set('grant_type', 'refresh_token');
|
|
118
|
-
form.set('scope', 'webapp');
|
|
119
|
-
return injector.get(HttpClient).post(`/auth/oauth/getOrCreateToken/webapp`, form);
|
|
120
|
-
}
|
|
121
|
-
function buildAuthRefresh(injector) {
|
|
122
|
-
const tokenSrv = injector.get(YA_SERVICE_TOKEN);
|
|
123
|
-
tokenSrv.refresh
|
|
124
|
-
.pipe(filter(() => !refreshToking), switchMap(res => {
|
|
125
|
-
log(res);
|
|
126
|
-
refreshToking = true;
|
|
127
|
-
return refreshTokenRequest(injector);
|
|
128
|
-
}))
|
|
129
|
-
.subscribe({
|
|
130
|
-
next: res => {
|
|
131
|
-
res.expired = +new Date() + 1000 * 60 * 5;
|
|
132
|
-
refreshToking = false;
|
|
133
|
-
tokenSrv.set(res);
|
|
134
|
-
},
|
|
135
|
-
error: () => toLogin(injector)
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function provideYunzaiBindAuthRefresh() {
|
|
139
|
-
return [
|
|
140
|
-
{
|
|
141
|
-
provide: APP_INITIALIZER,
|
|
142
|
-
useFactory: (injector) => () => buildAuthRefresh(injector),
|
|
143
|
-
deps: [Injector],
|
|
144
|
-
multi: true
|
|
145
|
-
}
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function handleData(injector, ev, req, next) {
|
|
150
|
-
checkStatus(injector, ev);
|
|
151
|
-
const config = injector.get(YUNZAI_CONFIG).bis;
|
|
152
|
-
switch (ev.status) {
|
|
153
|
-
case 200:
|
|
154
|
-
return of(ev);
|
|
155
|
-
case 401:
|
|
156
|
-
if (config.refreshTokenEnabled && config.refreshTokenType === 're-request') {
|
|
157
|
-
const unAuthorizationReq = req.clone();
|
|
158
|
-
unAuthorizationReq.headers.delete('Authorization');
|
|
159
|
-
return tryRefreshToken(injector, ev, unAuthorizationReq, next);
|
|
160
|
-
}
|
|
161
|
-
toLogin(injector);
|
|
162
|
-
break;
|
|
163
|
-
case 403:
|
|
164
|
-
case 404:
|
|
165
|
-
case 500:
|
|
166
|
-
goTo(injector, `/exception/${ev.status}?url=${req.urlWithParams}`);
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
if (ev instanceof HttpErrorResponse) {
|
|
170
|
-
console.warn('未可知错误,大部分是由于后端不支持跨域CORS或无效配置引起,请参考 https://ng.yunzainfo.com/docs/server 解决跨域问题', ev);
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (ev instanceof HttpErrorResponse) {
|
|
175
|
-
return throwError(() => ev);
|
|
176
|
-
}
|
|
177
|
-
else if (ev._throw) {
|
|
178
|
-
return throwError(() => ev.body);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return of(ev);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
const yunzaiDefaultInterceptor = (req, next) => {
|
|
185
|
-
const config = mergeBisConfig(inject(YunzaiConfigService));
|
|
186
|
-
const { baseUrl } = config;
|
|
187
|
-
let url = req.url;
|
|
188
|
-
if (!req.context.get(IGNORE_BASE_URL) && !url.startsWith('https://') && !url.startsWith('http://')) {
|
|
189
|
-
url = baseUrl + (baseUrl.endsWith('/') && url.startsWith('/') ? url.substring(1) : url);
|
|
190
|
-
}
|
|
191
|
-
if (url.includes('.json') && url.includes('assets')) {
|
|
192
|
-
url = req.url;
|
|
193
|
-
}
|
|
194
|
-
const newReq = req.clone({ url, setHeaders: getAdditionalHeaders(req.headers) });
|
|
195
|
-
const injector = inject(Injector);
|
|
196
|
-
return next(newReq).pipe(mergeMap(ev => {
|
|
197
|
-
if (ev instanceof HttpResponseBase) {
|
|
198
|
-
return handleData(injector, ev, newReq, next);
|
|
199
|
-
}
|
|
200
|
-
return of(ev);
|
|
201
|
-
}), catchError((err) => handleData(injector, err, newReq, next)));
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
function provideYunzaiStartup() {
|
|
205
|
-
return [
|
|
206
|
-
YunzaiStartupService,
|
|
207
|
-
{
|
|
208
|
-
provide: APP_INITIALIZER,
|
|
209
|
-
useFactory: (startupService) => () => startupService.load(),
|
|
210
|
-
deps: [YunzaiStartupService],
|
|
211
|
-
multi: true
|
|
212
|
-
}
|
|
213
|
-
];
|
|
214
|
-
}
|
|
215
|
-
class YunzaiStartupService {
|
|
216
|
-
constructor() {
|
|
217
|
-
this.config = mergeBisConfig(inject(YunzaiConfigService));
|
|
218
|
-
this.menuService = inject(MenuService);
|
|
219
|
-
this.aclService = inject(ACLService);
|
|
220
|
-
this.titleService = inject(TitleService);
|
|
221
|
-
this.tokenService = inject(YA_SERVICE_TOKEN);
|
|
222
|
-
this.httpClient = inject(HttpClient);
|
|
223
|
-
this.settingService = inject(SettingsService);
|
|
224
|
-
this.i18n = inject(YUNZAI_I18N_TOKEN);
|
|
225
|
-
this.win = inject(WINDOW);
|
|
226
|
-
this.configService = inject(YunzaiConfigService);
|
|
227
|
-
}
|
|
228
|
-
load() {
|
|
229
|
-
let defaultLang = this.settingService.layout.lang || this.i18n.defaultLang;
|
|
230
|
-
const [setTenant] = useLocalStorageTenant();
|
|
231
|
-
const [setUser, getUser] = useLocalStorageUser();
|
|
232
|
-
const [setHeader] = useLocalStorageHeader();
|
|
233
|
-
const [setProject] = useLocalStorageProjectInfo();
|
|
234
|
-
const [setDefaultRoute] = useLocalStorageDefaultRoute();
|
|
235
|
-
const [setCurrent] = useLocalStorageCurrent();
|
|
236
|
-
return this.token().pipe(mergeMap((token) => {
|
|
237
|
-
this.configService.set('auth', {
|
|
238
|
-
token_send_key: 'Authorization',
|
|
239
|
-
token_send_template: `${token.token_type} \${access_token}`,
|
|
240
|
-
token_send_place: 'header'
|
|
241
|
-
});
|
|
242
|
-
this.tokenService.set(token);
|
|
243
|
-
return of(void 0);
|
|
244
|
-
}), mergeMap(() => {
|
|
245
|
-
return combineLatest([
|
|
246
|
-
this.httpClient.get(`/auth/user`),
|
|
247
|
-
this.httpClient.get(`/auth/allheader/v2`),
|
|
248
|
-
this.httpClient.get(`/app-manager/project/info`)
|
|
249
|
-
]).pipe(map(([user, header, project]) => {
|
|
250
|
-
setUser(user.principal);
|
|
251
|
-
setTenant(user.tenantId);
|
|
252
|
-
setHeader(header.data);
|
|
253
|
-
setProject(project.data);
|
|
254
|
-
return void 0;
|
|
255
|
-
}));
|
|
256
|
-
}), mergeMap(() => {
|
|
257
|
-
return this.i18n.loadLangData(defaultLang).pipe(map((langData) => {
|
|
258
|
-
this.i18n.use(defaultLang, langData);
|
|
259
|
-
return void 0;
|
|
260
|
-
}));
|
|
261
|
-
}), mergeMap(() => {
|
|
262
|
-
const yunzaiUser = getUser();
|
|
263
|
-
const yunzaiMenus = deepCopy(yunzaiUser.menu).filter(m => m.systemCode && m.systemCode === this.config.systemCode);
|
|
264
|
-
const currentMenu = yunzaiMenus.pop();
|
|
265
|
-
if (currentMenu) {
|
|
266
|
-
this.settingService.setApp({ name: currentMenu.text, description: currentMenu.intro });
|
|
267
|
-
this.settingService.setUser({
|
|
268
|
-
name: yunzaiUser.realname,
|
|
269
|
-
avatar: `${this.config.baseUrl}/filecenter/file/${yunzaiUser.avatarId}` || '',
|
|
270
|
-
email: yunzaiUser.email
|
|
271
|
-
});
|
|
272
|
-
this.titleService.default = currentMenu && currentMenu.text ? currentMenu.text : 'default application name';
|
|
273
|
-
this.titleService.setTitle(currentMenu && currentMenu.text ? currentMenu.text : 'no title');
|
|
274
|
-
const abilities = [];
|
|
275
|
-
generateAbility([currentMenu], abilities, '');
|
|
276
|
-
this.aclService.attachRole(yunzaiUser?.roles
|
|
277
|
-
.map((role) => {
|
|
278
|
-
return role.roleValue;
|
|
279
|
-
})
|
|
280
|
-
.filter((a) => !!a) || []);
|
|
281
|
-
this.aclService.attachAbility(abilities);
|
|
282
|
-
this.menuService.add([currentMenu]);
|
|
283
|
-
setCurrent({
|
|
284
|
-
name: currentMenu.text,
|
|
285
|
-
intro: currentMenu.intro || '',
|
|
286
|
-
icon: currentMenu.appIconUrl || './assets/tmp/img/avatar.jpg'
|
|
287
|
-
});
|
|
288
|
-
const attributes = currentMenu.attribute;
|
|
289
|
-
if (attributes) {
|
|
290
|
-
const attr = JSON.parse(attributes);
|
|
291
|
-
if (attr && attr.defaultRoute) {
|
|
292
|
-
setDefaultRoute(attr.defaultRoute);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
setDefaultRoute('/displayIndex');
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
setDefaultRoute('/displayIndex');
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return of(void 0);
|
|
303
|
-
}));
|
|
304
|
-
}
|
|
305
|
-
token() {
|
|
306
|
-
if (this.config.loginForm) {
|
|
307
|
-
return this.httpClient.post(`/auth/oauth/token?_allow_anonymous=true`, this.config.loginForm).pipe(map((response) => {
|
|
308
|
-
return response;
|
|
309
|
-
}));
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
const uri = encodeURIComponent(this.win.location.href);
|
|
313
|
-
return this.httpClient
|
|
314
|
-
.get(`/cas-proxy/app/validate_full?callback=${uri}&_allow_anonymous=true×tamp=${new Date().getTime()}`)
|
|
315
|
-
.pipe(map((response) => {
|
|
316
|
-
switch (response.errcode) {
|
|
317
|
-
case 2000:
|
|
318
|
-
return response.data;
|
|
319
|
-
case 2001:
|
|
320
|
-
this.win.location.href = response.msg;
|
|
321
|
-
throw Error("Cookie Error: Can't find Cas Cookie,So jump to login!");
|
|
322
|
-
default:
|
|
323
|
-
if (response.data) {
|
|
324
|
-
console.error(response.data);
|
|
325
|
-
throw Error(response.data);
|
|
326
|
-
}
|
|
327
|
-
else if (response.msg) {
|
|
328
|
-
console.error(response.msg);
|
|
329
|
-
throw Error(response.msg);
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
console.error('cas unknown error');
|
|
333
|
-
throw Error('Unknown Error: Cas auth exception!');
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
340
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
341
|
-
}
|
|
342
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
343
|
-
type: Injectable
|
|
344
|
-
}] });
|
|
345
|
-
function mapYzSideToYelonMenu(menus) {
|
|
346
|
-
menus.forEach(menu => {
|
|
347
|
-
if (menu.children && menu.hideChildren) {
|
|
348
|
-
menu.children.forEach(c => (c.hide = true));
|
|
349
|
-
}
|
|
350
|
-
menu.badgeDot = menu.badge_dot || null;
|
|
351
|
-
menu.badgeStatus = menu.badge_status || null;
|
|
352
|
-
menu.shortcutRoot = menu.shortcut_root || null;
|
|
353
|
-
menu.reuse = true;
|
|
354
|
-
if (menu.children) {
|
|
355
|
-
mapYzSideToYelonMenu(menu.children);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
function generateAbility(menus, abilities, prefix) {
|
|
360
|
-
menus.forEach(menu => {
|
|
361
|
-
if (menu.link) {
|
|
362
|
-
prefix += menu.link;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
prefix += '';
|
|
366
|
-
}
|
|
367
|
-
if (menu.menuAuths) {
|
|
368
|
-
menu.menuAuths.forEach((a) => {
|
|
369
|
-
abilities.push(`${prefix}:${a}`);
|
|
370
|
-
abilities.push(a);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
if (menu.children) {
|
|
374
|
-
generateAbility(menu.children, abilities, prefix);
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
class YunzaiAnalysisAddonGuardService {
|
|
380
|
-
constructor(configService, pathToRegexp, win, tokenService) {
|
|
381
|
-
this.configService = configService;
|
|
382
|
-
this.pathToRegexp = pathToRegexp;
|
|
383
|
-
this.win = win;
|
|
384
|
-
this.tokenService = tokenService;
|
|
385
|
-
this.bis = BUSINESS_DEFAULT_CONFIG;
|
|
386
|
-
this.menus = [];
|
|
387
|
-
this.links = [];
|
|
388
|
-
this.value = {};
|
|
389
|
-
this.bis = mergeBisConfig(this.configService);
|
|
390
|
-
const [, getUser] = useLocalStorageUser();
|
|
391
|
-
const user = getUser();
|
|
392
|
-
this.menus = deepCopy(user.menu || []).filter((m) => m.systemCode && m.systemCode === this.bis.systemCode);
|
|
393
|
-
if (user) {
|
|
394
|
-
this.value = {
|
|
395
|
-
systemCode: this.bis.systemCode,
|
|
396
|
-
userid: user.id,
|
|
397
|
-
realname: user.realname,
|
|
398
|
-
usertype: user.userType,
|
|
399
|
-
usercode: user.userCode,
|
|
400
|
-
username: user.username,
|
|
401
|
-
account: user.username,
|
|
402
|
-
deptid: user.deptId,
|
|
403
|
-
deptname: user.deptName,
|
|
404
|
-
token: this.tokenService.get()?.access_token
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
if (this.menus && this.menus.length > 0) {
|
|
408
|
-
this.value['system'] = this.menus[0].text;
|
|
409
|
-
}
|
|
410
|
-
this.getAllLinks(this.menus, this.links);
|
|
411
|
-
}
|
|
412
|
-
process(url) {
|
|
413
|
-
let flag = false;
|
|
414
|
-
this.links.forEach(link => {
|
|
415
|
-
if (link.link === url.split('?')[0]) {
|
|
416
|
-
flag = true;
|
|
417
|
-
this.value['routename'] = link.title;
|
|
418
|
-
this.value['routeurl'] = link.link;
|
|
419
|
-
if (this.win['yunzai']) {
|
|
420
|
-
this.win['yunzai'].setExtra(this.value);
|
|
421
|
-
}
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
const regexp = this.pathToRegexp.stringToRegexp(link, null, null);
|
|
425
|
-
if (regexp.test(url.split('?')[0])) {
|
|
426
|
-
flag = true;
|
|
427
|
-
this.value['routename'] = link.title;
|
|
428
|
-
this.value['routeurl'] = link.link;
|
|
429
|
-
if (this.win['yunzai']) {
|
|
430
|
-
this.win['yunzai'].setExtra(this.value);
|
|
431
|
-
}
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
if (!flag) {
|
|
436
|
-
this.value['routename'] = url;
|
|
437
|
-
this.value['routeurl'] = url;
|
|
438
|
-
if (this.win['yunzai']) {
|
|
439
|
-
this.win['yunzai'].setExtra(this.value);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
return true;
|
|
443
|
-
}
|
|
444
|
-
getAllLinks(menu, links) {
|
|
445
|
-
menu.forEach((sider) => {
|
|
446
|
-
if (sider.link) {
|
|
447
|
-
links.push({ title: sider.text ? sider.text : sider.link, link: sider.link });
|
|
448
|
-
}
|
|
449
|
-
if (sider.children && sider.children.length > 0) {
|
|
450
|
-
this.getAllLinks(sider.children, links);
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
455
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
456
|
-
}
|
|
457
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
458
|
-
type: Injectable,
|
|
459
|
-
args: [{
|
|
460
|
-
providedIn: 'root'
|
|
461
|
-
}]
|
|
462
|
-
}], ctorParameters: () => [{ type: i1.YunzaiConfigService }, { type: i1.PathToRegexpService }, { type: undefined, decorators: [{
|
|
463
|
-
type: Inject,
|
|
464
|
-
args: [WINDOW]
|
|
465
|
-
}] }, { type: undefined, decorators: [{
|
|
466
|
-
type: Inject,
|
|
467
|
-
args: [YA_SERVICE_TOKEN]
|
|
468
|
-
}] }] });
|
|
469
|
-
const analysisAddonCanActive = (_, state) => inject(YunzaiAnalysisAddonGuardService).process(state.url);
|
|
470
|
-
const analysisAddonCanActiveChild = (_, state) => inject(YunzaiAnalysisAddonGuardService).process(state.url);
|
|
471
|
-
|
|
472
|
-
class ActGuardService {
|
|
473
|
-
constructor(configService, pathToRegexp, router) {
|
|
474
|
-
this.configService = configService;
|
|
475
|
-
this.pathToRegexp = pathToRegexp;
|
|
476
|
-
this.router = router;
|
|
477
|
-
this.bis = BUSINESS_DEFAULT_CONFIG;
|
|
478
|
-
this.menus = [];
|
|
479
|
-
this.links = [];
|
|
480
|
-
log('act: ');
|
|
481
|
-
this.bis = mergeBisConfig(this.configService);
|
|
482
|
-
log('act: config ', this.bis);
|
|
483
|
-
const [, getUser] = useLocalStorageUser();
|
|
484
|
-
const user = getUser();
|
|
485
|
-
log('act: user ', user);
|
|
486
|
-
// @ts-ignore
|
|
487
|
-
this.menus = deepCopy(user.menu || []).filter((m) => m.systemCode && m.systemCode === this.bis.systemCode);
|
|
488
|
-
log('act: menus ', this.menus);
|
|
489
|
-
this.getAllLinks(this.menus, this.links);
|
|
490
|
-
log('act: links ', this.links);
|
|
491
|
-
}
|
|
492
|
-
process(url) {
|
|
493
|
-
log('act: can activate ', url);
|
|
494
|
-
if (this.preHandle(url)) {
|
|
495
|
-
return true;
|
|
496
|
-
}
|
|
497
|
-
log('act: can activate child prehandle success');
|
|
498
|
-
let canactivate = false;
|
|
499
|
-
this.links.forEach((link) => {
|
|
500
|
-
// path = /xxx
|
|
501
|
-
if (link === url.split('?')[0]) {
|
|
502
|
-
canactivate = true;
|
|
503
|
-
log(`act: link value ${link} equals url value ${url}`);
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
// paht = /xxx/:xx
|
|
507
|
-
const regexp = this.pathToRegexp.stringToRegexp(link, null, null);
|
|
508
|
-
log(`act: ${link} test ${url.split('?')[0]}`);
|
|
509
|
-
if (regexp.test(url.split('?')[0])) {
|
|
510
|
-
canactivate = true;
|
|
511
|
-
log(`act: test value ${canactivate}`);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
if (canactivate) {
|
|
516
|
-
log(`act: test sucess`);
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
log(`act: test error`);
|
|
521
|
-
this.router.navigate(['displayIndex']);
|
|
522
|
-
return false;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
preHandle(url) {
|
|
526
|
-
return (url.includes('error') ||
|
|
527
|
-
url.includes('exception') ||
|
|
528
|
-
url.includes('displayIndex') ||
|
|
529
|
-
url === '' ||
|
|
530
|
-
url === null ||
|
|
531
|
-
url === '/' ||
|
|
532
|
-
url.includes('iframePage'));
|
|
533
|
-
}
|
|
534
|
-
getAllLinks(menu, links) {
|
|
535
|
-
menu.forEach((sider) => {
|
|
536
|
-
if (sider.link) {
|
|
537
|
-
links.push(sider.link);
|
|
538
|
-
}
|
|
539
|
-
if (sider.children && sider.children.length > 0) {
|
|
540
|
-
this.getAllLinks(sider.children, links);
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
545
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
546
|
-
}
|
|
547
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
548
|
-
type: Injectable,
|
|
549
|
-
args: [{ providedIn: 'root' }]
|
|
550
|
-
}], ctorParameters: () => [{ type: i1.YunzaiConfigService }, { type: i1.PathToRegexpService }, { type: i2.Router }] });
|
|
551
|
-
const actGuardCanActive = (_, state) => inject(ActGuardService).process(state.url);
|
|
552
|
-
const actGuardCanActiveChild = (_, state) => inject(ActGuardService).process(state.url);
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Generated bundle index. Do not edit.
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
export { ActGuardService, BisModule, CODEMESSAGE, YunzaiAnalysisAddonGuardService, YunzaiStartupService, actGuardCanActive, actGuardCanActiveChild, analysisAddonCanActive, analysisAddonCanActiveChild, checkStatus, generateAbility, getAdditionalHeaders, goTo, mapYzSideToYelonMenu, provideYunzaiBindAuthRefresh, provideYunzaiBis, provideYunzaiStartup, toLogin, tryRefreshToken, yunzaiDefaultInterceptor };
|
|
559
|
-
//# sourceMappingURL=bis.mjs.map
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { NgModule, importProvidersFrom, makeEnvironmentProviders, inject, APP_INITIALIZER, Injector, Injectable, Inject } from '@angular/core';
|
|
3
|
+
import { YunzaiLayoutModule } from '@yelon/bis/layout';
|
|
4
|
+
import { YunzaiWidgetsModule } from '@yelon/bis/yunzai-widgets';
|
|
5
|
+
import * as i2 from '@angular/router';
|
|
6
|
+
import { Router } from '@angular/router';
|
|
7
|
+
import { YA_SERVICE_TOKEN } from '@yelon/auth';
|
|
8
|
+
import { YUNZAI_I18N_TOKEN, IGNORE_BASE_URL, MenuService, TitleService, SettingsService } from '@yelon/theme';
|
|
9
|
+
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
|
10
|
+
import { HttpClient, HttpErrorResponse, HttpResponseBase } from '@angular/common/http';
|
|
11
|
+
import { BehaviorSubject, throwError, filter, take, switchMap, catchError, of, mergeMap, combineLatest, map } from 'rxjs';
|
|
12
|
+
import { mergeBisConfig, BUSINESS_DEFAULT_CONFIG } from '@yelon/bis/config';
|
|
13
|
+
import * as i1 from '@yelon/util';
|
|
14
|
+
import { log, YUNZAI_CONFIG, YunzaiConfigService, WINDOW, useLocalStorageTenant, useLocalStorageUser, useLocalStorageHeader, useLocalStorageProjectInfo, useLocalStorageDefaultRoute, useLocalStorageCurrent, deepCopy } from '@yelon/util';
|
|
15
|
+
import { ACLService } from '@yelon/acl';
|
|
16
|
+
|
|
17
|
+
class BisModule {
|
|
18
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: BisModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
19
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.6", ngImport: i0, type: BisModule, imports: [YunzaiLayoutModule, YunzaiWidgetsModule], exports: [YunzaiLayoutModule, YunzaiWidgetsModule] }); }
|
|
20
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: BisModule, imports: [YunzaiLayoutModule, YunzaiWidgetsModule, YunzaiLayoutModule, YunzaiWidgetsModule] }); }
|
|
21
|
+
}
|
|
22
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: BisModule, decorators: [{
|
|
23
|
+
type: NgModule,
|
|
24
|
+
args: [{
|
|
25
|
+
imports: [YunzaiLayoutModule, YunzaiWidgetsModule],
|
|
26
|
+
exports: [YunzaiLayoutModule, YunzaiWidgetsModule]
|
|
27
|
+
}]
|
|
28
|
+
}] });
|
|
29
|
+
|
|
30
|
+
function provideYunzaiBis() {
|
|
31
|
+
const provides = [];
|
|
32
|
+
provides.push(importProvidersFrom(BisModule));
|
|
33
|
+
return makeEnvironmentProviders(provides);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const CODEMESSAGE = {
|
|
37
|
+
200: '服务器成功返回请求的数据。',
|
|
38
|
+
201: '新建或修改数据成功。',
|
|
39
|
+
202: '一个请求已经进入后台排队(异步任务)。',
|
|
40
|
+
204: '删除数据成功。',
|
|
41
|
+
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
42
|
+
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
43
|
+
403: '用户得到授权,但是访问是被禁止的。',
|
|
44
|
+
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
45
|
+
406: '请求的格式不可得。',
|
|
46
|
+
410: '请求的资源被永久删除,且不会再得到的。',
|
|
47
|
+
422: '当创建一个对象时,发生一个验证错误。',
|
|
48
|
+
500: '服务器发生错误,请检查服务器。',
|
|
49
|
+
502: '网关错误。',
|
|
50
|
+
503: '服务不可用,服务器暂时过载或维护。',
|
|
51
|
+
504: '网关超时。'
|
|
52
|
+
};
|
|
53
|
+
function getAdditionalHeaders(headers) {
|
|
54
|
+
const res = {};
|
|
55
|
+
const lang = inject(YUNZAI_I18N_TOKEN).currentLang;
|
|
56
|
+
if (!headers?.has('Accept-Language') && lang) {
|
|
57
|
+
res['Accept-Language'] = lang;
|
|
58
|
+
}
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
function checkStatus(injector, ev) {
|
|
62
|
+
if ((ev.status >= 200 && ev.status < 300) || ev.status === 401) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const errortext = CODEMESSAGE[ev.status] || ev.statusText;
|
|
66
|
+
injector.get(NzNotificationService).error(`请求错误 ${ev.status}: ${ev.url}`, errortext);
|
|
67
|
+
}
|
|
68
|
+
function goTo(injector, url) {
|
|
69
|
+
setTimeout(() => injector.get(Router).navigateByUrl(url));
|
|
70
|
+
}
|
|
71
|
+
function toLogin(injector) {
|
|
72
|
+
injector.get(NzNotificationService).error(`未登录或登录已过期,请重新登录。`, ``);
|
|
73
|
+
goTo(injector, injector.get(YA_SERVICE_TOKEN).login_url);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let refreshToking = false;
|
|
77
|
+
let refreshToken$ = new BehaviorSubject(null);
|
|
78
|
+
const tryRefreshToken = (injector, ev, req, next) => {
|
|
79
|
+
// 连刷新Token的请求都错了,那就是真错了
|
|
80
|
+
if (['/auth/oauth/getOrCreateToken/webapp'].some(url => req.url.includes(url))) {
|
|
81
|
+
toLogin(injector);
|
|
82
|
+
return throwError(() => ev);
|
|
83
|
+
}
|
|
84
|
+
// 2、如果 `refreshToking` 为 `true` 表示已经在请求刷新 Token 中,后续所有请求转入等待状态,直至结果返回后再重新发起请求
|
|
85
|
+
if (refreshToking) {
|
|
86
|
+
return refreshToken$.pipe(filter(v => !!v), take(1), switchMap(() => next(reAttachToken(injector, req))));
|
|
87
|
+
}
|
|
88
|
+
// 3、尝试调用刷新 Token
|
|
89
|
+
refreshToking = true;
|
|
90
|
+
refreshToken$.next(null);
|
|
91
|
+
return refreshTokenRequest(injector).pipe(switchMap(res => {
|
|
92
|
+
// 通知后续请求继续执行
|
|
93
|
+
refreshToking = false;
|
|
94
|
+
refreshToken$.next(res);
|
|
95
|
+
// 重新保存新 token
|
|
96
|
+
injector.get(YA_SERVICE_TOKEN).set(res);
|
|
97
|
+
// 重新发起请求
|
|
98
|
+
return next(reAttachToken(injector, req));
|
|
99
|
+
}), catchError(err => {
|
|
100
|
+
refreshToking = false;
|
|
101
|
+
toLogin(injector);
|
|
102
|
+
return throwError(() => err);
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
function reAttachToken(injector, req) {
|
|
106
|
+
const token = injector.get(YA_SERVICE_TOKEN).get()?.access_token;
|
|
107
|
+
return req.clone({
|
|
108
|
+
setHeaders: {
|
|
109
|
+
Authorization: `Bearer ${token}`
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function refreshTokenRequest(injector) {
|
|
114
|
+
const model = injector.get(YA_SERVICE_TOKEN).get();
|
|
115
|
+
const form = new FormData();
|
|
116
|
+
form.set('refresh_token', model?.refresh_token);
|
|
117
|
+
form.set('grant_type', 'refresh_token');
|
|
118
|
+
form.set('scope', 'webapp');
|
|
119
|
+
return injector.get(HttpClient).post(`/auth/oauth/getOrCreateToken/webapp`, form);
|
|
120
|
+
}
|
|
121
|
+
function buildAuthRefresh(injector) {
|
|
122
|
+
const tokenSrv = injector.get(YA_SERVICE_TOKEN);
|
|
123
|
+
tokenSrv.refresh
|
|
124
|
+
.pipe(filter(() => !refreshToking), switchMap(res => {
|
|
125
|
+
log(res);
|
|
126
|
+
refreshToking = true;
|
|
127
|
+
return refreshTokenRequest(injector);
|
|
128
|
+
}))
|
|
129
|
+
.subscribe({
|
|
130
|
+
next: res => {
|
|
131
|
+
res.expired = +new Date() + 1000 * 60 * 5;
|
|
132
|
+
refreshToking = false;
|
|
133
|
+
tokenSrv.set(res);
|
|
134
|
+
},
|
|
135
|
+
error: () => toLogin(injector)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function provideYunzaiBindAuthRefresh() {
|
|
139
|
+
return [
|
|
140
|
+
{
|
|
141
|
+
provide: APP_INITIALIZER,
|
|
142
|
+
useFactory: (injector) => () => buildAuthRefresh(injector),
|
|
143
|
+
deps: [Injector],
|
|
144
|
+
multi: true
|
|
145
|
+
}
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handleData(injector, ev, req, next) {
|
|
150
|
+
checkStatus(injector, ev);
|
|
151
|
+
const config = injector.get(YUNZAI_CONFIG).bis;
|
|
152
|
+
switch (ev.status) {
|
|
153
|
+
case 200:
|
|
154
|
+
return of(ev);
|
|
155
|
+
case 401:
|
|
156
|
+
if (config.refreshTokenEnabled && config.refreshTokenType === 're-request') {
|
|
157
|
+
const unAuthorizationReq = req.clone();
|
|
158
|
+
unAuthorizationReq.headers.delete('Authorization');
|
|
159
|
+
return tryRefreshToken(injector, ev, unAuthorizationReq, next);
|
|
160
|
+
}
|
|
161
|
+
toLogin(injector);
|
|
162
|
+
break;
|
|
163
|
+
case 403:
|
|
164
|
+
case 404:
|
|
165
|
+
case 500:
|
|
166
|
+
goTo(injector, `/exception/${ev.status}?url=${req.urlWithParams}`);
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
if (ev instanceof HttpErrorResponse) {
|
|
170
|
+
console.warn('未可知错误,大部分是由于后端不支持跨域CORS或无效配置引起,请参考 https://ng.yunzainfo.com/docs/server 解决跨域问题', ev);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (ev instanceof HttpErrorResponse) {
|
|
175
|
+
return throwError(() => ev);
|
|
176
|
+
}
|
|
177
|
+
else if (ev._throw) {
|
|
178
|
+
return throwError(() => ev.body);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return of(ev);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const yunzaiDefaultInterceptor = (req, next) => {
|
|
185
|
+
const config = mergeBisConfig(inject(YunzaiConfigService));
|
|
186
|
+
const { baseUrl } = config;
|
|
187
|
+
let url = req.url;
|
|
188
|
+
if (!req.context.get(IGNORE_BASE_URL) && !url.startsWith('https://') && !url.startsWith('http://')) {
|
|
189
|
+
url = baseUrl + (baseUrl.endsWith('/') && url.startsWith('/') ? url.substring(1) : url);
|
|
190
|
+
}
|
|
191
|
+
if (url.includes('.json') && url.includes('assets')) {
|
|
192
|
+
url = req.url;
|
|
193
|
+
}
|
|
194
|
+
const newReq = req.clone({ url, setHeaders: getAdditionalHeaders(req.headers) });
|
|
195
|
+
const injector = inject(Injector);
|
|
196
|
+
return next(newReq).pipe(mergeMap(ev => {
|
|
197
|
+
if (ev instanceof HttpResponseBase) {
|
|
198
|
+
return handleData(injector, ev, newReq, next);
|
|
199
|
+
}
|
|
200
|
+
return of(ev);
|
|
201
|
+
}), catchError((err) => handleData(injector, err, newReq, next)));
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function provideYunzaiStartup() {
|
|
205
|
+
return [
|
|
206
|
+
YunzaiStartupService,
|
|
207
|
+
{
|
|
208
|
+
provide: APP_INITIALIZER,
|
|
209
|
+
useFactory: (startupService) => () => startupService.load(),
|
|
210
|
+
deps: [YunzaiStartupService],
|
|
211
|
+
multi: true
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
class YunzaiStartupService {
|
|
216
|
+
constructor() {
|
|
217
|
+
this.config = mergeBisConfig(inject(YunzaiConfigService));
|
|
218
|
+
this.menuService = inject(MenuService);
|
|
219
|
+
this.aclService = inject(ACLService);
|
|
220
|
+
this.titleService = inject(TitleService);
|
|
221
|
+
this.tokenService = inject(YA_SERVICE_TOKEN);
|
|
222
|
+
this.httpClient = inject(HttpClient);
|
|
223
|
+
this.settingService = inject(SettingsService);
|
|
224
|
+
this.i18n = inject(YUNZAI_I18N_TOKEN);
|
|
225
|
+
this.win = inject(WINDOW);
|
|
226
|
+
this.configService = inject(YunzaiConfigService);
|
|
227
|
+
}
|
|
228
|
+
load() {
|
|
229
|
+
let defaultLang = this.settingService.layout.lang || this.i18n.defaultLang;
|
|
230
|
+
const [setTenant] = useLocalStorageTenant();
|
|
231
|
+
const [setUser, getUser] = useLocalStorageUser();
|
|
232
|
+
const [setHeader] = useLocalStorageHeader();
|
|
233
|
+
const [setProject] = useLocalStorageProjectInfo();
|
|
234
|
+
const [setDefaultRoute] = useLocalStorageDefaultRoute();
|
|
235
|
+
const [setCurrent] = useLocalStorageCurrent();
|
|
236
|
+
return this.token().pipe(mergeMap((token) => {
|
|
237
|
+
this.configService.set('auth', {
|
|
238
|
+
token_send_key: 'Authorization',
|
|
239
|
+
token_send_template: `${token.token_type} \${access_token}`,
|
|
240
|
+
token_send_place: 'header'
|
|
241
|
+
});
|
|
242
|
+
this.tokenService.set(token);
|
|
243
|
+
return of(void 0);
|
|
244
|
+
}), mergeMap(() => {
|
|
245
|
+
return combineLatest([
|
|
246
|
+
this.httpClient.get(`/auth/user`),
|
|
247
|
+
this.httpClient.get(`/auth/allheader/v2`),
|
|
248
|
+
this.httpClient.get(`/app-manager/project/info`)
|
|
249
|
+
]).pipe(map(([user, header, project]) => {
|
|
250
|
+
setUser(user.principal);
|
|
251
|
+
setTenant(user.tenantId);
|
|
252
|
+
setHeader(header.data);
|
|
253
|
+
setProject(project.data);
|
|
254
|
+
return void 0;
|
|
255
|
+
}));
|
|
256
|
+
}), mergeMap(() => {
|
|
257
|
+
return this.i18n.loadLangData(defaultLang).pipe(map((langData) => {
|
|
258
|
+
this.i18n.use(defaultLang, langData);
|
|
259
|
+
return void 0;
|
|
260
|
+
}));
|
|
261
|
+
}), mergeMap(() => {
|
|
262
|
+
const yunzaiUser = getUser();
|
|
263
|
+
const yunzaiMenus = deepCopy(yunzaiUser.menu).filter(m => m.systemCode && m.systemCode === this.config.systemCode);
|
|
264
|
+
const currentMenu = yunzaiMenus.pop();
|
|
265
|
+
if (currentMenu) {
|
|
266
|
+
this.settingService.setApp({ name: currentMenu.text, description: currentMenu.intro });
|
|
267
|
+
this.settingService.setUser({
|
|
268
|
+
name: yunzaiUser.realname,
|
|
269
|
+
avatar: `${this.config.baseUrl}/filecenter/file/${yunzaiUser.avatarId}` || '',
|
|
270
|
+
email: yunzaiUser.email
|
|
271
|
+
});
|
|
272
|
+
this.titleService.default = currentMenu && currentMenu.text ? currentMenu.text : 'default application name';
|
|
273
|
+
this.titleService.setTitle(currentMenu && currentMenu.text ? currentMenu.text : 'no title');
|
|
274
|
+
const abilities = [];
|
|
275
|
+
generateAbility([currentMenu], abilities, '');
|
|
276
|
+
this.aclService.attachRole(yunzaiUser?.roles
|
|
277
|
+
.map((role) => {
|
|
278
|
+
return role.roleValue;
|
|
279
|
+
})
|
|
280
|
+
.filter((a) => !!a) || []);
|
|
281
|
+
this.aclService.attachAbility(abilities);
|
|
282
|
+
this.menuService.add([currentMenu]);
|
|
283
|
+
setCurrent({
|
|
284
|
+
name: currentMenu.text,
|
|
285
|
+
intro: currentMenu.intro || '',
|
|
286
|
+
icon: currentMenu.appIconUrl || './assets/tmp/img/avatar.jpg'
|
|
287
|
+
});
|
|
288
|
+
const attributes = currentMenu.attribute;
|
|
289
|
+
if (attributes) {
|
|
290
|
+
const attr = JSON.parse(attributes);
|
|
291
|
+
if (attr && attr.defaultRoute) {
|
|
292
|
+
setDefaultRoute(attr.defaultRoute);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
setDefaultRoute('/displayIndex');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
setDefaultRoute('/displayIndex');
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return of(void 0);
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
token() {
|
|
306
|
+
if (this.config.loginForm) {
|
|
307
|
+
return this.httpClient.post(`/auth/oauth/token?_allow_anonymous=true`, this.config.loginForm).pipe(map((response) => {
|
|
308
|
+
return response;
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const uri = encodeURIComponent(this.win.location.href);
|
|
313
|
+
return this.httpClient
|
|
314
|
+
.get(`/cas-proxy/app/validate_full?callback=${uri}&_allow_anonymous=true×tamp=${new Date().getTime()}`)
|
|
315
|
+
.pipe(map((response) => {
|
|
316
|
+
switch (response.errcode) {
|
|
317
|
+
case 2000:
|
|
318
|
+
return response.data;
|
|
319
|
+
case 2001:
|
|
320
|
+
this.win.location.href = response.msg;
|
|
321
|
+
throw Error("Cookie Error: Can't find Cas Cookie,So jump to login!");
|
|
322
|
+
default:
|
|
323
|
+
if (response.data) {
|
|
324
|
+
console.error(response.data);
|
|
325
|
+
throw Error(response.data);
|
|
326
|
+
}
|
|
327
|
+
else if (response.msg) {
|
|
328
|
+
console.error(response.msg);
|
|
329
|
+
throw Error(response.msg);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
console.error('cas unknown error');
|
|
333
|
+
throw Error('Unknown Error: Cas auth exception!');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiStartupService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
340
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiStartupService }); }
|
|
341
|
+
}
|
|
342
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiStartupService, decorators: [{
|
|
343
|
+
type: Injectable
|
|
344
|
+
}] });
|
|
345
|
+
function mapYzSideToYelonMenu(menus) {
|
|
346
|
+
menus.forEach(menu => {
|
|
347
|
+
if (menu.children && menu.hideChildren) {
|
|
348
|
+
menu.children.forEach(c => (c.hide = true));
|
|
349
|
+
}
|
|
350
|
+
menu.badgeDot = menu.badge_dot || null;
|
|
351
|
+
menu.badgeStatus = menu.badge_status || null;
|
|
352
|
+
menu.shortcutRoot = menu.shortcut_root || null;
|
|
353
|
+
menu.reuse = true;
|
|
354
|
+
if (menu.children) {
|
|
355
|
+
mapYzSideToYelonMenu(menu.children);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function generateAbility(menus, abilities, prefix) {
|
|
360
|
+
menus.forEach(menu => {
|
|
361
|
+
if (menu.link) {
|
|
362
|
+
prefix += menu.link;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
prefix += '';
|
|
366
|
+
}
|
|
367
|
+
if (menu.menuAuths) {
|
|
368
|
+
menu.menuAuths.forEach((a) => {
|
|
369
|
+
abilities.push(`${prefix}:${a}`);
|
|
370
|
+
abilities.push(a);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (menu.children) {
|
|
374
|
+
generateAbility(menu.children, abilities, prefix);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
class YunzaiAnalysisAddonGuardService {
|
|
380
|
+
constructor(configService, pathToRegexp, win, tokenService) {
|
|
381
|
+
this.configService = configService;
|
|
382
|
+
this.pathToRegexp = pathToRegexp;
|
|
383
|
+
this.win = win;
|
|
384
|
+
this.tokenService = tokenService;
|
|
385
|
+
this.bis = BUSINESS_DEFAULT_CONFIG;
|
|
386
|
+
this.menus = [];
|
|
387
|
+
this.links = [];
|
|
388
|
+
this.value = {};
|
|
389
|
+
this.bis = mergeBisConfig(this.configService);
|
|
390
|
+
const [, getUser] = useLocalStorageUser();
|
|
391
|
+
const user = getUser();
|
|
392
|
+
this.menus = deepCopy(user.menu || []).filter((m) => m.systemCode && m.systemCode === this.bis.systemCode);
|
|
393
|
+
if (user) {
|
|
394
|
+
this.value = {
|
|
395
|
+
systemCode: this.bis.systemCode,
|
|
396
|
+
userid: user.id,
|
|
397
|
+
realname: user.realname,
|
|
398
|
+
usertype: user.userType,
|
|
399
|
+
usercode: user.userCode,
|
|
400
|
+
username: user.username,
|
|
401
|
+
account: user.username,
|
|
402
|
+
deptid: user.deptId,
|
|
403
|
+
deptname: user.deptName,
|
|
404
|
+
token: this.tokenService.get()?.access_token
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (this.menus && this.menus.length > 0) {
|
|
408
|
+
this.value['system'] = this.menus[0].text;
|
|
409
|
+
}
|
|
410
|
+
this.getAllLinks(this.menus, this.links);
|
|
411
|
+
}
|
|
412
|
+
process(url) {
|
|
413
|
+
let flag = false;
|
|
414
|
+
this.links.forEach(link => {
|
|
415
|
+
if (link.link === url.split('?')[0]) {
|
|
416
|
+
flag = true;
|
|
417
|
+
this.value['routename'] = link.title;
|
|
418
|
+
this.value['routeurl'] = link.link;
|
|
419
|
+
if (this.win['yunzai']) {
|
|
420
|
+
this.win['yunzai'].setExtra(this.value);
|
|
421
|
+
}
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const regexp = this.pathToRegexp.stringToRegexp(link, null, null);
|
|
425
|
+
if (regexp.test(url.split('?')[0])) {
|
|
426
|
+
flag = true;
|
|
427
|
+
this.value['routename'] = link.title;
|
|
428
|
+
this.value['routeurl'] = link.link;
|
|
429
|
+
if (this.win['yunzai']) {
|
|
430
|
+
this.win['yunzai'].setExtra(this.value);
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
if (!flag) {
|
|
436
|
+
this.value['routename'] = url;
|
|
437
|
+
this.value['routeurl'] = url;
|
|
438
|
+
if (this.win['yunzai']) {
|
|
439
|
+
this.win['yunzai'].setExtra(this.value);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
getAllLinks(menu, links) {
|
|
445
|
+
menu.forEach((sider) => {
|
|
446
|
+
if (sider.link) {
|
|
447
|
+
links.push({ title: sider.text ? sider.text : sider.link, link: sider.link });
|
|
448
|
+
}
|
|
449
|
+
if (sider.children && sider.children.length > 0) {
|
|
450
|
+
this.getAllLinks(sider.children, links);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiAnalysisAddonGuardService, deps: [{ token: i1.YunzaiConfigService }, { token: i1.PathToRegexpService }, { token: WINDOW }, { token: YA_SERVICE_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
455
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiAnalysisAddonGuardService, providedIn: 'root' }); }
|
|
456
|
+
}
|
|
457
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: YunzaiAnalysisAddonGuardService, decorators: [{
|
|
458
|
+
type: Injectable,
|
|
459
|
+
args: [{
|
|
460
|
+
providedIn: 'root'
|
|
461
|
+
}]
|
|
462
|
+
}], ctorParameters: () => [{ type: i1.YunzaiConfigService }, { type: i1.PathToRegexpService }, { type: undefined, decorators: [{
|
|
463
|
+
type: Inject,
|
|
464
|
+
args: [WINDOW]
|
|
465
|
+
}] }, { type: undefined, decorators: [{
|
|
466
|
+
type: Inject,
|
|
467
|
+
args: [YA_SERVICE_TOKEN]
|
|
468
|
+
}] }] });
|
|
469
|
+
const analysisAddonCanActive = (_, state) => inject(YunzaiAnalysisAddonGuardService).process(state.url);
|
|
470
|
+
const analysisAddonCanActiveChild = (_, state) => inject(YunzaiAnalysisAddonGuardService).process(state.url);
|
|
471
|
+
|
|
472
|
+
class ActGuardService {
|
|
473
|
+
constructor(configService, pathToRegexp, router) {
|
|
474
|
+
this.configService = configService;
|
|
475
|
+
this.pathToRegexp = pathToRegexp;
|
|
476
|
+
this.router = router;
|
|
477
|
+
this.bis = BUSINESS_DEFAULT_CONFIG;
|
|
478
|
+
this.menus = [];
|
|
479
|
+
this.links = [];
|
|
480
|
+
log('act: ');
|
|
481
|
+
this.bis = mergeBisConfig(this.configService);
|
|
482
|
+
log('act: config ', this.bis);
|
|
483
|
+
const [, getUser] = useLocalStorageUser();
|
|
484
|
+
const user = getUser();
|
|
485
|
+
log('act: user ', user);
|
|
486
|
+
// @ts-ignore
|
|
487
|
+
this.menus = deepCopy(user.menu || []).filter((m) => m.systemCode && m.systemCode === this.bis.systemCode);
|
|
488
|
+
log('act: menus ', this.menus);
|
|
489
|
+
this.getAllLinks(this.menus, this.links);
|
|
490
|
+
log('act: links ', this.links);
|
|
491
|
+
}
|
|
492
|
+
process(url) {
|
|
493
|
+
log('act: can activate ', url);
|
|
494
|
+
if (this.preHandle(url)) {
|
|
495
|
+
return true;
|
|
496
|
+
}
|
|
497
|
+
log('act: can activate child prehandle success');
|
|
498
|
+
let canactivate = false;
|
|
499
|
+
this.links.forEach((link) => {
|
|
500
|
+
// path = /xxx
|
|
501
|
+
if (link === url.split('?')[0]) {
|
|
502
|
+
canactivate = true;
|
|
503
|
+
log(`act: link value ${link} equals url value ${url}`);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
// paht = /xxx/:xx
|
|
507
|
+
const regexp = this.pathToRegexp.stringToRegexp(link, null, null);
|
|
508
|
+
log(`act: ${link} test ${url.split('?')[0]}`);
|
|
509
|
+
if (regexp.test(url.split('?')[0])) {
|
|
510
|
+
canactivate = true;
|
|
511
|
+
log(`act: test value ${canactivate}`);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
if (canactivate) {
|
|
516
|
+
log(`act: test sucess`);
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
log(`act: test error`);
|
|
521
|
+
this.router.navigate(['displayIndex']);
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
preHandle(url) {
|
|
526
|
+
return (url.includes('error') ||
|
|
527
|
+
url.includes('exception') ||
|
|
528
|
+
url.includes('displayIndex') ||
|
|
529
|
+
url === '' ||
|
|
530
|
+
url === null ||
|
|
531
|
+
url === '/' ||
|
|
532
|
+
url.includes('iframePage'));
|
|
533
|
+
}
|
|
534
|
+
getAllLinks(menu, links) {
|
|
535
|
+
menu.forEach((sider) => {
|
|
536
|
+
if (sider.link) {
|
|
537
|
+
links.push(sider.link);
|
|
538
|
+
}
|
|
539
|
+
if (sider.children && sider.children.length > 0) {
|
|
540
|
+
this.getAllLinks(sider.children, links);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: ActGuardService, deps: [{ token: i1.YunzaiConfigService }, { token: i1.PathToRegexpService }, { token: i2.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
545
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: ActGuardService, providedIn: 'root' }); }
|
|
546
|
+
}
|
|
547
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: ActGuardService, decorators: [{
|
|
548
|
+
type: Injectable,
|
|
549
|
+
args: [{ providedIn: 'root' }]
|
|
550
|
+
}], ctorParameters: () => [{ type: i1.YunzaiConfigService }, { type: i1.PathToRegexpService }, { type: i2.Router }] });
|
|
551
|
+
const actGuardCanActive = (_, state) => inject(ActGuardService).process(state.url);
|
|
552
|
+
const actGuardCanActiveChild = (_, state) => inject(ActGuardService).process(state.url);
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Generated bundle index. Do not edit.
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
export { ActGuardService, BisModule, CODEMESSAGE, YunzaiAnalysisAddonGuardService, YunzaiStartupService, actGuardCanActive, actGuardCanActiveChild, analysisAddonCanActive, analysisAddonCanActiveChild, checkStatus, generateAbility, getAdditionalHeaders, goTo, mapYzSideToYelonMenu, provideYunzaiBindAuthRefresh, provideYunzaiBis, provideYunzaiStartup, toLogin, tryRefreshToken, yunzaiDefaultInterceptor };
|
|
559
|
+
//# sourceMappingURL=bis.mjs.map
|