Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Jan 20, 2024
1 parent 94a0176 commit ec08c71
Show file tree
Hide file tree
Showing 26 changed files with 171 additions and 184 deletions.
3 changes: 1 addition & 2 deletions docs/i18n.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Of course, you can also use runtime changes:
```ts
import { en_US, DelonLocaleService } from '@delon/theme';
...
constructor(private delonLocaleService: DelonLocaleService) {
}
private readonly i18n = inject(DelonLocaleService);

switchLanguage() {
this.delonLocaleService.setLocale(en_US);
Expand Down
3 changes: 1 addition & 2 deletions docs/i18n.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export class AppModule { }
```ts
import { en_US, DelonLocaleService } from '@delon/theme';
...
constructor(private delonLocaleService: DelonLocaleService) {
}
private readonly i18n = inject(DelonLocaleService);

switchLanguage() {
this.delonLocaleService.setLocale(en_US);
Expand Down
12 changes: 6 additions & 6 deletions packages/form/src/validator.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, NgZone } from '@angular/core';
import { Injectable, NgZone, inject } from '@angular/core';

import Ajv from 'ajv';
import addFormats from 'ajv-formats';
Expand All @@ -22,18 +22,18 @@ export abstract class SchemaValidatorFactory {

@Injectable()
export class AjvSchemaValidatorFactory extends SchemaValidatorFactory {
private readonly ngZone = inject(NgZone);
private readonly cogSrv = inject(AlainConfigService);

protected ajv!: Ajv;
protected options!: AlainSFConfig;

constructor(
@Inject(AlainConfigService) cogSrv: AlainConfigService,
private ngZone: NgZone
) {
constructor() {
super();
if (!(typeof document === 'object' && !!document)) {
return;
}
this.options = mergeConfig(cogSrv);
this.options = mergeConfig(this.cogSrv);
const customOptions = this.options.ajv || {};
this.ngZone.runOutsideAngular(() => {
this.ajv = new Ajv({
Expand Down
31 changes: 15 additions & 16 deletions packages/theme/setting-drawer/setting-drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Inject,
inject,
Input,
isDevMode,
NgZone,
OnInit,
Optional
OnInit
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

Expand All @@ -33,14 +32,22 @@ import { ALAINDEFAULTVAR, DEFAULT_COLORS, DEFAULT_VARS } from './setting-drawer.
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SettingDrawerComponent implements OnInit {
private readonly cdr = inject(ChangeDetectorRef);
private readonly msg = inject(NzMessageService);
private readonly settingSrv = inject(SettingsService);
private readonly lazy = inject(LazyService);
private readonly ngZone = inject(NgZone);
private readonly doc = inject(DOCUMENT);
private readonly directionality = inject(Directionality, { optional: true });

@Input({ transform: booleanAttribute }) autoApplyColor = true;
@Input() compilingText = 'Compiling...';
@Input() devTips = `When the color can't be switched, you need to run it once: npm run color-less`;
@Input() lessJs = 'https://cdn.jsdelivr.net/npm/less';

private loadedLess = false;
private dir$ = this.directionality.change?.pipe(takeUntilDestroyed());
dir: Direction = 'ltr';
private dir$ = this.directionality?.change?.pipe(takeUntilDestroyed());
dir?: Direction = 'ltr';
isDev = isDevMode();
collapse = false;
get layout(): Layout {
Expand All @@ -50,15 +57,7 @@ export class SettingDrawerComponent implements OnInit {
color: string;
colors = DEFAULT_COLORS;

constructor(
private cdr: ChangeDetectorRef,
private msg: NzMessageService,
private settingSrv: SettingsService,
private lazy: LazyService,
private ngZone: NgZone,
@Inject(DOCUMENT) private doc: NzSafeAny,
@Optional() private directionality: Directionality
) {
constructor() {
this.color = this.cachedData['@primary-color'] || this.DEFAULT_PRIMARY;
this.resetData(this.cachedData, false);
}
Expand All @@ -72,8 +71,8 @@ export class SettingDrawerComponent implements OnInit {
}

ngOnInit(): void {
this.dir = this.directionality.value;
this.dir$.subscribe((direction: Direction) => {
this.dir = this.directionality?.value;
this.dir$?.subscribe((direction: Direction) => {
this.dir = direction;
this.cdr.detectChanges();
});
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/locale/locale.tokens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InjectionToken } from '@angular/core';

export const DELON_LOCALE = new InjectionToken<string>('delon-locale');
import type { FullLocaleData } from './locale.types';

export const DELON_LOCALE = new InjectionToken<FullLocaleData>('delon-locale');
4 changes: 2 additions & 2 deletions packages/util/decorator/zone-outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function makeFn(type: 'runOutsideAngular' | 'run', options?: ZoneOptions): Decor
*
* ```ts
* class MockClass {
* constructor(public ngZone: NgZone) {}
* readonly ngZone = inject(NgZone);
*
* {AT}ZoneOutside()
* runOutsideAngular(): void {}
Expand All @@ -55,7 +55,7 @@ export function ZoneOutside(options?: ZoneOptions): DecoratorType {
*
* ```ts
* class MockClass {
* constructor(public ngZone: NgZone) {}
* readonly ngZone = inject(NgZone);
*
* {AT}ZoneRun()
* run(): void {}
Expand Down
13 changes: 6 additions & 7 deletions packages/util/format/currency.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyPipe, formatNumber } from '@angular/common';
import { DEFAULT_CURRENCY_CODE, Inject, Injectable, LOCALE_ID } from '@angular/core';
import { DEFAULT_CURRENCY_CODE, Injectable, LOCALE_ID, inject } from '@angular/core';

import { AlainConfigService, AlainUtilCurrencyConfig } from '@delon/util/config';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
Expand All @@ -14,15 +14,14 @@ import {

@Injectable({ providedIn: 'root' })
export class CurrencyService {
private readonly locale = inject(LOCALE_ID);
private readonly defCurrencyCode = inject(DEFAULT_CURRENCY_CODE, { optional: true }) ?? 'USD';

private c: AlainUtilCurrencyConfig;
private readonly currencyPipe: CurrencyPipe;

constructor(
cog: AlainConfigService,
@Inject(LOCALE_ID) private locale: string,
@Inject(DEFAULT_CURRENCY_CODE) _defaultCurrencyCode: string = 'USD'
) {
this.currencyPipe = new CurrencyPipe(locale, _defaultCurrencyCode);
constructor(cog: AlainConfigService) {
this.currencyPipe = new CurrencyPipe(this.locale, this.defCurrencyCode);
this.c = cog.merge('utilCurrency', {
startingUnit: 'yuan',
megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
Expand Down
6 changes: 3 additions & 3 deletions packages/util/other/lazy.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { BehaviorSubject, Observable, filter, share } from 'rxjs';

import type { NzSafeAny } from 'ng-zorro-antd/core/types';
Expand Down Expand Up @@ -28,12 +28,12 @@ export interface LazyLoadOptions {
*/
@Injectable({ providedIn: 'root' })
export class LazyService {
private readonly doc = inject(DOCUMENT);

private list: { [key: string]: boolean } = {};
private cached: { [key: string]: LazyResult } = {};
private _notify: BehaviorSubject<LazyResult[]> = new BehaviorSubject<LazyResult[]>([]);

constructor(@Inject(DOCUMENT) private doc: NzSafeAny) {}

get change(): Observable<LazyResult[]> {
return this._notify.asObservable().pipe(
share(),
Expand Down
14 changes: 7 additions & 7 deletions packages/util/pipes/currency/cny.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, inject } from '@angular/core';

import { CurrencyCNYOptions, CurrencyService } from '@delon/util/format';

/**
* Converted into RMB notation.
*
* 转化成人民币表示法
*/
@Pipe({ name: 'cny', standalone: true })
export class CurrencyCNYPipe implements PipeTransform {
constructor(private srv: CurrencyService) {}
private readonly srv = inject(CurrencyService);

/**
* Converted into RMB notation.
*
* 转化成人民币表示法
*/
transform(value: number | string, options?: CurrencyCNYOptions): string {
return this.srv.cny(value, options);
}
Expand Down
21 changes: 8 additions & 13 deletions packages/util/pipes/currency/mega.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core';
import { LOCALE_ID, Pipe, PipeTransform, inject } from '@angular/core';

import { CurrencyMegaOptions, CurrencyService } from '@delon/util/format';

/**
* Large number format filter
*
* 大数据格式化
*/
@Pipe({ name: 'mega', standalone: true })
export class CurrencyMegaPipe implements PipeTransform {
private isCN = false;
constructor(
private srv: CurrencyService,
@Inject(LOCALE_ID) locale: string
) {
this.isCN = locale.startsWith('zh');
}
private readonly srv = inject(CurrencyService);
private isCN = inject(LOCALE_ID).startsWith('zh');

/**
* Large number format filter
*
* 大数据格式化
*/
transform(value: number | string, options?: CurrencyMegaOptions): string {
const res = this.srv.mega(value, options);
return res.value + (this.isCN ? res.unitI18n : res.unit);
Expand Down
23 changes: 12 additions & 11 deletions packages/util/pipes/currency/price.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, inject } from '@angular/core';

import { CurrencyFormatOptions, CurrencyService } from '@delon/util/format';

/**
* Format a number with commas as thousands separators
*
* 格式化货币,用逗号将数字格式化为千位分隔符
* ```ts
* 10000 => `10,000`
* 10000.567 => `10,000.57`
* ```
*/
@Pipe({ name: 'price', standalone: true })
export class CurrencyPricePipe implements PipeTransform {
constructor(private srv: CurrencyService) {}
/**
* Format a number with commas as thousands separators
*
* 格式化货币,用逗号将数字格式化为千位分隔符
* ```ts
* 10000 => `10,000`
* 10000.567 => `10,000.57`
* ```
*/
private readonly srv = inject(CurrencyService);

transform(value: number | string, options?: CurrencyFormatOptions): string {
return this.srv.format(value, options);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/util/pipes/filter/filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Pipe, PipeTransform } from '@angular/core';

import type { NzSafeAny } from 'ng-zorro-antd/core/types';

/**
* Filter array
*
* 过滤数组
*/
// eslint-disable-next-line @angular-eslint/no-pipe-impure
@Pipe({ name: 'filter', standalone: true, pure: false })
export class FilterPipe implements PipeTransform {
/**
* Filter array
*
* 过滤数组
*/
transform<T>(array: readonly T[], matcher: (item: T, ...args: NzSafeAny[]) => boolean, ...args: NzSafeAny[]): T[] {
return array.filter(i => matcher(i, ...args));
}
Expand Down
38 changes: 19 additions & 19 deletions packages/util/pipes/format/mask.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { Pipe, PipeTransform } from '@angular/core';

import { formatMask, FormatMaskOption } from '@delon/util/format';

/**
* Format mask
*
* 格式化掩码
*
* | 字符 | 描述 |
* | --- | --- |
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
* | `9` | 任意数字 |
* | `#` | 任意字符 |
* | `U` | 转换大写 |
* | `L` | 转换小写 |
* | `*` | 转换为 `*` 字符 |
*
* ```ts
* formatMask('123', '(###)') => (123)
* formatMask('15900000000', '999****9999') => 159****0000
* ```
*/
@Pipe({ name: 'mask', standalone: true })
export class FormatMaskPipe implements PipeTransform {
/**
* Format mask
*
* 格式化掩码
*
* | 字符 | 描述 |
* | --- | --- |
* | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
* | `9` | 任意数字 |
* | `#` | 任意字符 |
* | `U` | 转换大写 |
* | `L` | 转换小写 |
* | `*` | 转换为 `*` 字符 |
*
* ```ts
* formatMask('123', '(###)') => (123)
* formatMask('15900000000', '999****9999') => 159****0000
* ```
*/
transform(value: string, mask: string | FormatMaskOption): string {
return formatMask(value, mask);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';<% if(!modal) { %>
import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%>, inject } from '@angular/core';<% if(!modal) { %>
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';<% } %>
import { SFSchema, SFUISchema } from '@delon/form';
Expand All @@ -17,6 +17,12 @@ import { SHARED_IMPORTS } from '@shared';<%}%>
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
export class <%= componentName %> implements OnInit {
private readonly http = inject(_HttpClient);
private readonly msgSrv = inject(NzMessageService);<% if(modal) { %>
private readonly modal = inject(NzModalRef);<% } else { %>
private readonly route = inject(ActivatedRoute);
readonly location = inject(Location);<% } %>

<% if(modal) { %>record: any = {};<% } else { %>
id = this.route.snapshot.params.id;<% } %>
i: any;
Expand Down Expand Up @@ -47,14 +53,6 @@ export class <%= componentName %> implements OnInit {
},
};

constructor(<% if(modal) { %>
private modal: NzModalRef,<% } else { %>
private route: ActivatedRoute,
public location: Location,<% } %>
private msgSrv: NzMessageService,
public http: _HttpClient,
) {}

ngOnInit(): void {
<% if(modal) { %>if (this.record.id > 0)<% } else { %>if (this.id > 0)<% } %>
this.http.get(`/user/${this.record.id}`).subscribe(res => (this.i = res));
Expand Down
Loading

0 comments on commit ec08c71

Please sign in to comment.