Skip to content

Commit

Permalink
fix(bis): fix i18nName and layout user
Browse files Browse the repository at this point in the history
  • Loading branch information
devcui committed Feb 16, 2023
1 parent 72db50a commit 7aa452e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/auth/src/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const AUTH_DEFAULT_CONFIG: YunzaiAuthConfig = {
token_send_template: '${token}',
token_send_place: 'header',
login_url: '/login',
ignores: [/\/login/, /assets\//, /passport\//],
ignores: [/\/login/, /assets\//, /passport\//, /\/auth\/oauth\/getOrCreateToken\/webapp/, /\/auth\/oauth\/token/],
allow_anonymous_key: `_allow_anonymous`,
executeOtherInterceptors: true,
refreshTime: 3000,
refreshOffset: 6000
Expand Down
24 changes: 23 additions & 1 deletion packages/auth/src/token/base.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
HttpHandler,
HttpInterceptor,
HttpRequest,
HTTP_INTERCEPTORS
HTTP_INTERCEPTORS,
HttpParams
} from '@angular/common/http';
import { Injectable, Injector, Optional } from '@angular/core';
import { Observable, Observer } from 'rxjs';
Expand Down Expand Up @@ -44,6 +45,27 @@ export abstract class BaseInterceptor implements HttpInterceptor {
}
}

const ignoreKey = options.allow_anonymous_key!;
let ignored = false;
let params = req.params;
let url = req.url;
if (req.params.has(ignoreKey)) {
params = req.params.delete(ignoreKey);
ignored = true;
}
const urlArr = req.url.split('?');
if (urlArr.length > 1) {
const queryStringParams = new HttpParams({ fromString: urlArr[1] });
if (queryStringParams.has(ignoreKey)) {
const queryString = queryStringParams.delete(ignoreKey).toString();
url = queryString.length > 0 ? `${urlArr[0]}?${queryString}` : urlArr[0];
ignored = true;
}
}
if (ignored) {
return next.handle(req.clone({ params, url }));
}

if (this.isAuth(options)) {
req = this.setReq(req, options);
} else {
Expand Down
8 changes: 6 additions & 2 deletions packages/bis/src/layout-basic/layout-basic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ import { LayoutDisplayService } from './layout-display.service';
</div>
</nz-dropdown-menu>
</layout-default-header-item>
<layout-default-header-item direction="right">
<yunzai-user></yunzai-user>
</layout-default-header-item>
<!-- setting end -->
</layout-default>
<ng-template #asideUserTpl>
Expand All @@ -93,7 +96,7 @@ import { LayoutDisplayService } from './layout-display.service';
<router-outlet></router-outlet>
</ng-template> `
})
export class YzLayoutBasicComponent implements OnInit, OnDestroy {
class YunzaiLayoutBasicComponent implements OnInit, OnDestroy {
public NavType = NavType;
private state: LayoutBasicState = {
options: {
Expand Down Expand Up @@ -166,7 +169,7 @@ export class YzLayoutBasicComponent implements OnInit, OnDestroy {

initAside(): void {
const aside: LayoutBasicAside = this.cacheService.get('_yz_current', { mode: 'none' });
this.state.aside = aside;
this.state.aside = { ...aside };
}

initLogo(): void {
Expand Down Expand Up @@ -220,3 +223,4 @@ export class YzLayoutBasicComponent implements OnInit, OnDestroy {
this.state.destroy$.complete();
}
}
export { YunzaiLayoutBasicComponent as YzLayoutBasicComponent, YunzaiLayoutBasicComponent };
2 changes: 1 addition & 1 deletion packages/bis/src/yunzai-i18n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ class YunzaiI18NService extends YunzaiI18nBaseService {
}
}

export { YunzaiI18NService as YzI18nService, YunzaiI18NService };
export { YunzaiI18NService as YzI18NService, YunzaiI18NService };
4 changes: 2 additions & 2 deletions packages/bis/src/yunzai-startup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class YunzaiStartupService {
// cache current
this.cacheService.set('_yz_current', {
name: currentMenu.text,
intro: currentMenu.intro,
icon: currentMenu.appIconUrl
intro: currentMenu.intro || '',
icon: currentMenu.appIconUrl || './assets/tmp/img/avatar.jpg'
});
// cache displayIndex
const attributes = currentMenu.attribute;
Expand Down
4 changes: 4 additions & 0 deletions packages/util/config/auth/auth.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface YunzaiAuthConfig {
* 忽略TOKEN的URL地址列表,默认值为:`[/\/login/, /assets\//, /passport\//]`
*/
ignores?: RegExp[];
/**
* 允许匿名登录KEY,若请求参数中带有该KEY表示忽略TOKEN,默认:`_allow_anonymous`
*/
allow_anonymous_key?: string;
/**
* 是否校验失效时命中后继续调用后续拦截器的 `intercept` 方法,默认:`true`
*/
Expand Down

0 comments on commit 7aa452e

Please sign in to comment.