Skip to content

Commit

Permalink
chore: add xlsx, zip
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Jan 19, 2024
1 parent 454f8ef commit 9c074e1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
6 changes: 3 additions & 3 deletions packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export class STComponent implements AfterViewInit, OnChanges {
@Input() data?: string | STData[] | Observable<STData[]>;
@Input() columns?: STColumn[] | null;
@Input() contextmenu?: STContextmenuFn | null;
@Input({ transform: numberAttribute }) ps = 10;
@Input({ transform: numberAttribute }) pi = 1;
@Input({ transform: numberAttribute }) total = 0;
@Input({ transform: (v: unknown) => numberAttribute(v, 10) }) ps = 10;
@Input({ transform: (v: unknown) => numberAttribute(v, 1) }) pi = 1;
@Input({ transform: (v: unknown) => numberAttribute(v, 0) }) total = 0;
@Input() loading: boolean | null = null;
@Input({ transform: numberAttribute }) loadingDelay = 0;
@Input() loadingIndicator: TemplateRef<void> | null = null;
Expand Down
24 changes: 9 additions & 15 deletions packages/abc/tag-select/tag-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
EventEmitter,
Input,
OnInit,
Optional,
Output,
ViewEncapsulation,
booleanAttribute,
inject
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

import { DelonLocaleService, LocaleData } from '@delon/theme';
import { BooleanInput, InputBoolean } from '@delon/util/decorator';
import { NzIconDirective } from 'ng-zorro-antd/icon';

@Component({
Expand All @@ -36,26 +35,21 @@ import { NzIconDirective } from 'ng-zorro-antd/icon';
imports: [NzIconDirective]
})
export class TagSelectComponent implements OnInit {
static ngAcceptInputType_expandable: BooleanInput;

private destroy$ = inject(DestroyRef);
private readonly i18n = inject(DelonLocaleService);
private readonly directionality = inject(Directionality, { optional: true });
private readonly cdr = inject(ChangeDetectorRef);
private readonly destroy$ = inject(DestroyRef);
locale: LocaleData = {};
expand = false;
dir: Direction = 'ltr';
dir?: Direction = 'ltr';

/** 是否启用 `展开与收进` */
@Input() @InputBoolean() expandable = true;
@Input({ transform: booleanAttribute }) expandable = true;
@Output() readonly change = new EventEmitter<boolean>();

constructor(
private i18n: DelonLocaleService,
@Optional() private directionality: Directionality,
private cdr: ChangeDetectorRef
) {}

ngOnInit(): void {
this.dir = this.directionality.value;
this.directionality.change?.pipe(takeUntilDestroyed(this.destroy$)).subscribe((direction: Direction) => {
this.dir = this.directionality?.value;
this.directionality?.change?.pipe(takeUntilDestroyed(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
});
this.i18n.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/abc/xlsx/xlsx.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, Input } from '@angular/core';
import { Directive, Input, inject } from '@angular/core';

import { XlsxService } from './xlsx.service';
import { XlsxExportOptions } from './xlsx.types';
Expand All @@ -12,9 +12,9 @@ import { XlsxExportOptions } from './xlsx.types';
standalone: true
})
export class XlsxDirective {
@Input('xlsx') data!: XlsxExportOptions;
private readonly srv = inject(XlsxService);

constructor(private srv: XlsxService) {}
@Input('xlsx') data!: XlsxExportOptions;

_click(): void {
this.srv.export(this.data);
Expand Down
16 changes: 8 additions & 8 deletions packages/abc/xlsx/xlsx.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { Injectable, NgZone, inject } from '@angular/core';

import isUtf8 from 'isutf8';

Expand All @@ -15,18 +15,18 @@ declare var cptable: NzSafeAny;

@Injectable({ providedIn: 'root' })
export class XlsxService {
constructor(
private http: HttpClient,
private lazy: LazyService,
configSrv: AlainConfigService,
private ngZone: NgZone
) {
private readonly http = inject(HttpClient);
private readonly lazy = inject(LazyService);
private readonly ngZone = inject(NgZone);

private cog: AlainXlsxConfig;

constructor(configSrv: AlainConfigService) {
this.cog = configSrv.merge('xlsx', {
url: 'https://cdn.jsdelivr.net/npm/xlsx/dist/xlsx.full.min.js',
modules: [`https://cdn.jsdelivr.net/npm/xlsx/dist/cpexcel.js`]
})!;
}
private cog: AlainXlsxConfig;

private init(): Promise<LazyResult[]> {
return typeof XLSX !== 'undefined'
Expand Down
13 changes: 6 additions & 7 deletions packages/abc/zip/zip.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { Injectable, NgZone, inject } from '@angular/core';

import { saveAs } from 'file-saver';
import type jsZipType from 'jszip';
Expand All @@ -15,14 +15,13 @@ declare var JSZip: jsZipType;

@Injectable({ providedIn: 'root' })
export class ZipService {
private readonly http = inject(HttpClient);
private readonly lazy = inject(LazyService);
private readonly ngZone = inject(NgZone);

private cog: AlainZipConfig;

constructor(
private http: HttpClient,
private lazy: LazyService,
configSrv: AlainConfigService,
private ngZone: NgZone
) {
constructor(configSrv: AlainConfigService) {
this.cog = configSrv.merge('zip', {
url: 'https://cdn.jsdelivr.net/npm/jszip@3/dist/jszip.min.js',
utils: []
Expand Down

0 comments on commit 9c074e1

Please sign in to comment.