diff --git a/packages/abc/qr/demo/basic.md b/packages/abc/qr/demo/basic.md deleted file mode 100644 index 607fc6169c..0000000000 --- a/packages/abc/qr/demo/basic.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -order: 1 -title: - zh-CN: 基础样例 - en-US: Basic Usage ---- - -## zh-CN - -最简单的用法。 - -## en-US - -Simplest of usage. - -```ts -import { Component, OnInit } from '@angular/core'; - -import { QRModule } from '@delon/abc/qr'; -import { NzButtonModule } from 'ng-zorro-antd/button'; - -@Component({ - selector: 'app-demo', - template: ` -

{{ type }}

- -
- @for (t of types; track $index) { - - } -
- `, - standalone: true, - imports: [QRModule, NzButtonModule] -}) -export class DemoComponent implements OnInit { - types = ['url', 'email', 'tel', 'cn', 'vcard']; - value = ''; - type = ''; - change(type: string): void { - this.type = type; - switch (type) { - case 'url': - this.value = 'https://ng-alain.com/'; - break; - case 'email': - this.value = 'mailto:cipchk@qq.com'; - break; - case 'tel': - this.value = 'tel:15900000000'; - break; - case 'cn': - this.value = '你好🇨🇳'; - break; - case 'vcard': - this.value = `BEGIN:VCARD -VERSION:4.0 -N:色;卡;;Mr.; -FN:卡色 -ORG:NG-ALAIN -TITLE:NG-ALAIN -PHOTO;MEDIATYPE=image/svg:https://ng-alain.com/assets/img/logo-color.svg -TEL;TYPE=work,voice;VALUE=uri:tel:15900000000 -ADR;TYPE=WORK;PREF=1;LABEL="中国上海":;;上海;中国 -EMAIL:cipchk@qq.com -x-qq:94458893 -END:VCARD`; - break; - } - } - - ngOnInit(): void { - this.change('url'); - } -} -``` diff --git a/packages/abc/qr/demo/design.md b/packages/abc/qr/demo/design.md deleted file mode 100644 index 645d43fe1b..0000000000 --- a/packages/abc/qr/demo/design.md +++ /dev/null @@ -1,146 +0,0 @@ ---- -order: 2 -title: - zh-CN: 设计器 - en-US: Designer ---- - -## zh-CN - -利用 `change` 可以回调二维码 dataURL 值。 - -## en-US - -Get QR code (dataURL value) via `change`. - -```ts -import { Component } from '@angular/core'; -import { FormsModule } from '@angular/forms'; - -import { QRModule } from '@delon/abc/qr'; -import { SEModule } from '@delon/abc/se'; -import { NzButtonModule } from 'ng-zorro-antd/button'; -import { NzGridModule } from 'ng-zorro-antd/grid'; -import { NzInputModule } from 'ng-zorro-antd/input'; -import { NzInputNumberModule } from 'ng-zorro-antd/input-number'; -import { NzSelectModule } from 'ng-zorro-antd/select'; - -@Component({ - selector: 'app-demo', - template: ` -
-
- -
-
- - - -
-
- -
-
- -
-
-
-
- - -
-
- -
-
- -
-
-
-
- - - - - - - - - - - - - - - - - - px - - - - px - -
-
-
- `, - standalone: true, - imports: [ - QRModule, - NzGridModule, - SEModule, - NzInputModule, - NzInputNumberModule, - NzButtonModule, - FormsModule, - NzGridModule, - NzSelectModule - ] -}) -export class DemoComponent { - value = 'https://ng-alain.com/'; - background = '#ffffff'; - backgroundAlpha = 1.0; - foreground = '#000000'; - foregroundAlpha = 1.0; - level = 'L'; - mime = 'image/png'; - padding = 10; - size = 220; - - change(dataURL: string): void { - console.log(dataURL); - } -} -``` diff --git a/packages/abc/qr/index.en-US.md b/packages/abc/qr/index.en-US.md deleted file mode 100644 index 59f2231564..0000000000 --- a/packages/abc/qr/index.en-US.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -type: Basic -order: 3 -title: qr -subtitle: QR -cols: 1 -module: import { QRModule } from '@delon/abc/qr'; -deprecated: 18.0.0 ---- - -# Will be removed in 18.0.0, please use [nz-qrcode](https://ng.ant.design/components/qr-code) instead. - -Generate a QR code based on [qrious](https://github.com/neocotic/qrious). - - -Qr libary is lazy loading by default,you can change the default CDN path via [Global Configuration](/docs/global-config). By default: `https://cdn.jsdelivr.net/npm/qrious/dist/qrious.min.js`. Or install dependence via `npm i --save qrious`, and import script path in `angular.json`. - -**Use local path** - -```json -// angular.json -{ - "glob": "**/qrious.min.js", - "input": "./node_modules/qrious/dist", - "output": "assets/qrious/" -} -``` - -```ts -// global-config.module.ts -const alainConfig: AlainConfig = { - qr: { - lib: '/assets/qrious/qrious.min.js' - } -}; -``` - -## API - -### qr - -| Property | Description | Type | Default | Global Config | -|----------|-------------|------|---------|---------------| -| `[value]` | Value encoded within the QR code | `string | () => string` | - | | -| `[background]` | Background colour of the QR code | `string` | `white` | ✅ | -| `[backgroundAlpha]` | Background alpha of the QR code | `number` | `1` | ✅ | -| `[foreground]` | Foreground colour of the QR code | `string` | `white` | ✅ | -| `[foregroundAlpha]` | Foreground alpha of the QR code | `number` | `1` | ✅ | -| `[level]` | Error correction level of the QR code | `'L','M','Q','H'` | `'L'` | ✅ | -| `[mime]` | MIME type used to render the image for the QR code | `string` | `image/png` | ✅ | -| `[padding]` | Padding for the QR code (pixels) | `number` | `10` | ✅ | -| `[size]` | Size of the QR code (pixels) | `number` | `220` | ✅ | -| `[delay]` | Delayed rendering, unit: ms | `number` | `0` | ✅ | -| `(change)` | change event | `EventEmitter` | - | | - -## FAQ - -### Custom LOGO - -Refer to [#100](https://github.com/neocotic/qrious/issues/100#issuecomment-308249343). - -### Why not center - -Please refer to [#111](https://github.com/neocotic/qrious/issues/111) for the reason. The solution is to set `padding` to `null`, for example: - -```html - -```` diff --git a/packages/abc/qr/index.ts b/packages/abc/qr/index.ts deleted file mode 100644 index 4aaf8f92ed..0000000000 --- a/packages/abc/qr/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './public_api'; diff --git a/packages/abc/qr/index.zh-CN.md b/packages/abc/qr/index.zh-CN.md deleted file mode 100644 index 25de5d8ce6..0000000000 --- a/packages/abc/qr/index.zh-CN.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -type: Basic -order: 3 -title: qr -subtitle: 二维码 -cols: 1 -module: import { QRModule } from '@delon/abc/qr'; -deprecated: 18.0.0 ---- - -# 将在 18.0.0 中移除,请使用 [nz-qrcode](https://ng.ant.design/components/qr-code) 替代 - -基于 [qrious](https://github.com/neocotic/qrious) 生成二维码。 - -默认二维码的操作并不是刚需的原因,因此采用一种延迟加载脚本的形式,可以通过[全局配置](/docs/global-config)配置来改变默认 CDN 路径,默认情况下使用 `https://cdn.jsdelivr.net/npm/qrious/dist/qrious.min.js`。或安装 `npm i --save qrious` 依赖包并在 `angular.json` 的 `scripts` 引用 `"node_modules/qrious/dist/qrious.min.js"`。 - -**使用本地路径** - -```json -// angular.json -{ - "glob": "**/qrious.min.js", - "input": "./node_modules/qrious/dist", - "output": "assets/qrious/" -} -``` - -```ts -// global-config.module.ts -const alainConfig: AlainConfig = { - qr: { - lib: '/assets/qrious/qrious.min.js' - } -}; -``` - -## API - -### qr - -| 成员 | 说明 | 类型 | 默认值 | 全局配置 | -|----|----|----|-----|------| -| `[value]` | 值 | `string | () => string` | - | | -| `[background]` | 背景 | `string` | `white` | ✅ | -| `[backgroundAlpha]` | 背景透明级别,范围:`0-1` 之间 | `number` | `1` | ✅ | -| `[foreground]` | 前景 | `string` | `white` | ✅ | -| `[foregroundAlpha]` | 前景透明级别,范围:`0-1` 之间 | `number` | `1` | ✅ | -| `[level]` | 误差校正级别 | `'L','M','Q','H'` | `'L'` | ✅ | -| `[mime]` | 二维码输出图片MIME类型 | `string` | `image/png` | ✅ | -| `[padding]` | 内边距(单位:px) | `number,null` | `10` | ✅ | -| `[size]` | 大小(单位:px) | `number` | `220` | ✅ | -| `[delay]` | 延迟渲染,单位:毫秒 | `number` | `0` | ✅ | -| `(change)` | 变更时回调,返回二维码dataURL值 | `EventEmitter` | - | | - -## 常见问题 - -### 自定义LOGO - -参考 [#100](https://github.com/neocotic/qrious/issues/100#issuecomment-308249343) 的写法。 - -### 为什么没有居中 - -原因请参考 [#111](https://github.com/neocotic/qrious/issues/111),解决的办法设置 `padding` 为 `null`,例如: - -```html - -``` diff --git a/packages/abc/qr/ng-package.json b/packages/abc/qr/ng-package.json deleted file mode 100644 index f69690e99e..0000000000 --- a/packages/abc/qr/ng-package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "lib": { - "flatModuleFile": "qr", - "entryFile": "public_api.ts" - } -} diff --git a/packages/abc/qr/public_api.ts b/packages/abc/qr/public_api.ts deleted file mode 100644 index 330eb17e70..0000000000 --- a/packages/abc/qr/public_api.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { QRComponent } from './qr.component'; -export * from './qr.config'; -export * from './qr.types'; -export { QRModule } from './qr.module'; diff --git a/packages/abc/qr/qr.component.ts b/packages/abc/qr/qr.component.ts deleted file mode 100644 index 7ee19267e3..0000000000 --- a/packages/abc/qr/qr.component.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { Platform } from '@angular/cdk/platform'; -import { - AfterViewInit, - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - EventEmitter, - Input, - OnChanges, - OnDestroy, - Output, - ViewEncapsulation, - numberAttribute -} from '@angular/core'; -import { Subscription, filter } from 'rxjs'; - -import { AlainConfigService, AlainQRConfig } from '@delon/util/config'; -import { LazyService } from '@delon/util/other'; -import type { NzSafeAny } from 'ng-zorro-antd/core/types'; - -import { QR_DEFULAT_CONFIG } from './qr.config'; -import { QROptions } from './qr.types'; - -/** - * @deprecated Will be removed in 18.0.0, please use [nz-qrcode](https://ng.ant.design/components/qr-code) instead. - */ -@Component({ - selector: 'qr', - exportAs: 'qr', - template: `@if (dataURL) { - - }`, - host: { - '[style.display]': `'inline-block'`, - '[style.height.px]': 'size', - '[style.width.px]': 'size' - }, - preserveWhitespaces: false, - changeDetection: ChangeDetectionStrategy.OnPush, - encapsulation: ViewEncapsulation.None -}) -export class QRComponent implements OnChanges, AfterViewInit, OnDestroy { - private lazy$?: Subscription; - private qr: NzSafeAny; - private cog: AlainQRConfig; - private option!: QROptions; - private inited = false; - - dataURL!: string; - - @Input() background?: string; - @Input() backgroundAlpha?: number; - @Input() foreground?: string; - @Input() foregroundAlpha?: number; - @Input() level?: string; - @Input() mime?: string; - @Input({ transform: (v: unknown) => (v == null ? null : numberAttribute(v)) }) padding?: number; - @Input({ transform: numberAttribute }) size?: number; - @Input() value: string | (() => string) = ''; - @Input({ transform: numberAttribute }) delay?: number; - @Output() readonly change = new EventEmitter(); - - constructor( - private cdr: ChangeDetectorRef, - configSrv: AlainConfigService, - private lazySrv: LazyService, - private platform: Platform - ) { - this.cog = configSrv.merge('qr', QR_DEFULAT_CONFIG)!; - Object.assign(this, this.cog); - } - - private init(): void { - if (!this.inited) { - return; - } - - if (this.qr == null) { - this.qr = new (window as NzSafeAny).QRious(); - } - this.qr.set(this.option); - this.dataURL = this.qr.toDataURL(); - this.change.emit(this.dataURL); - this.cdr.detectChanges(); - } - - private initDelay(): void { - this.inited = true; - setTimeout(() => this.init(), this.delay); - } - - ngAfterViewInit(): void { - if (!this.platform.isBrowser) { - return; - } - if ((window as NzSafeAny).QRious) { - this.initDelay(); - return; - } - const url = this.cog.lib!; - this.lazy$ = this.lazySrv.change - .pipe(filter(ls => ls.length === 1 && ls[0].path === url && ls[0].status === 'ok')) - .subscribe(() => this.initDelay()); - this.lazySrv.load(url); - } - - ngOnChanges(): void { - const option: QROptions = { - background: this.background, - backgroundAlpha: this.backgroundAlpha, - foreground: this.foreground, - foregroundAlpha: this.foregroundAlpha, - level: this.level as NzSafeAny, - mime: this.mime, - padding: this.padding, - size: this.size, - value: typeof this.value === 'function' ? this.value() : this.toUtf8ByteArray(this.value) - }; - this.option = option; - this.init(); - } - - private toUtf8ByteArray(str: string): string { - str = encodeURI(str); - const result: number[] = []; - for (let i = 0; i < str.length; i++) { - if (str.charAt(i) !== '%') { - result.push(str.charCodeAt(i)); - } else { - result.push(parseInt(str.substring(i + 1, 2), 16)); - i += 2; - } - } - return result.map(v => String.fromCharCode(v)).join(''); - } - - ngOnDestroy(): void { - if (this.lazy$) { - this.lazy$.unsubscribe(); - } - } -} diff --git a/packages/abc/qr/qr.config.ts b/packages/abc/qr/qr.config.ts deleted file mode 100644 index 273da3c873..0000000000 --- a/packages/abc/qr/qr.config.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AlainQRConfig } from '@delon/util/config'; - -export const QR_DEFULAT_CONFIG: AlainQRConfig = { - lib: `https://cdn.jsdelivr.net/npm/qrious/dist/qrious.min.js`, - background: 'white', - backgroundAlpha: 1, - foreground: 'black', - foregroundAlpha: 1, - level: 'L', - mime: 'image/png', - padding: 10, - size: 220, - delay: 0 -}; diff --git a/packages/abc/qr/qr.module.ts b/packages/abc/qr/qr.module.ts deleted file mode 100644 index a9b35a7621..0000000000 --- a/packages/abc/qr/qr.module.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; - -import { QRComponent } from './qr.component'; - -const COMPONENTS = [QRComponent]; - -/** - * @deprecated Will be removed in 18.0.0, please use [nz-qrcode](https://ng.ant.design/components/qr-code) instead. - */ -@NgModule({ - imports: [CommonModule], - declarations: COMPONENTS, - exports: COMPONENTS -}) -export class QRModule {} diff --git a/packages/abc/qr/qr.spec.ts b/packages/abc/qr/qr.spec.ts deleted file mode 100644 index 45191a0be7..0000000000 --- a/packages/abc/qr/qr.spec.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { Component, DebugElement, ViewChild } from '@angular/core'; -import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { of } from 'rxjs'; - -import { createTestContext } from '@delon/testing'; -import { NzSafeAny } from 'ng-zorro-antd/core/types'; - -import { AlainConfigService, LazyService } from '../../util'; -import { QRComponent } from './qr.component'; -import { QRModule } from './qr.module'; - -describe('abc: qr', () => { - let fixture: ComponentFixture; - let dl: DebugElement; - let context: TestComponent; - const win: NzSafeAny = window; - - class MockQRious { - set(): jasmine.Spy { - return jasmine.createSpy('set'); - } - toDataURL(): jasmine.Spy { - return jasmine.createSpy('toDataURL'); - } - } - - function createModule(): void { - TestBed.configureTestingModule({ - imports: [QRModule], - declarations: [TestComponent] - }); - } - - function mockQRious(): void { - win.QRious = MockQRious; - } - - afterEach(() => { - delete win.QRious; - }); - - describe('', () => { - beforeEach(fakeAsync(() => { - createModule(); - mockQRious(); - ({ fixture, dl, context } = createTestContext(TestComponent)); - fixture.detectChanges(); - spyOn(context, 'change'); - tick(100); - })); - - function getDataURL(): string { - return (dl.query(By.css('img')).nativeElement as HTMLImageElement).src; - } - - it('should be generate a qr', () => { - expect(getDataURL().length).toBeGreaterThan(1); - }); - - it('should be support unicode value', () => { - context.value = 'test'; - fixture.detectChanges(); - expect(context.change).toHaveBeenCalled(); - context.value = `中国🇨🇳`; - fixture.detectChanges(); - expect(context.change).toHaveBeenCalled(); - }); - - it('should be function value', () => { - context.value = () => `1`; - fixture.detectChanges(); - expect(context.change).toHaveBeenCalled(); - }); - }); - - it('should be lazy load libary', () => { - createModule(); - const cogSrv = TestBed.inject(AlainConfigService); - const lazySrv = TestBed.inject(LazyService); - spyOn(cogSrv, 'merge').and.returnValue({ lib: '1.js' }); - spyOnProperty(lazySrv, 'change').and.returnValue(of([{ path: '1.js', status: 'ok' }])); - ({ fixture, dl, context } = createTestContext(TestComponent)); - fixture.detectChanges(); - mockQRious(); - spyOn(context, 'change'); - context.value = '11'; - fixture.detectChanges(); - expect(context.change).toHaveBeenCalled(); - }); -}); - -@Component({ - template: ` - - ` -}) -class TestComponent { - @ViewChild('comp', { static: true }) - comp!: QRComponent; - - value: string | (() => string) = 'https://ng-alain.com/'; - background = 'white'; - backgroundAlpha = 1.0; - foreground = 'black'; - foregroundAlpha = 1.0; - level = 'L'; - mime = 'image/png'; - padding = 10; - size = 220; - - change(): void {} -} diff --git a/packages/abc/qr/qr.types.ts b/packages/abc/qr/qr.types.ts deleted file mode 100644 index 4b3b086000..0000000000 --- a/packages/abc/qr/qr.types.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { AlainQRConfig } from '@delon/util/config'; - -export interface QROptions extends AlainQRConfig { - value: string; -} diff --git a/packages/util/config/abc/index.ts b/packages/util/config/abc/index.ts index 863cc374c9..de36e34b05 100644 --- a/packages/util/config/abc/index.ts +++ b/packages/util/config/abc/index.ts @@ -4,7 +4,6 @@ export * from './date-picker.type'; export * from './loading.type'; export * from './lodop.type'; export * from './page-header.type'; -export * from './qr.type'; export * from './se.type'; export * from './sv.type'; export * from './sg.type'; diff --git a/packages/util/config/abc/qr.type.ts b/packages/util/config/abc/qr.type.ts deleted file mode 100644 index 69667b5530..0000000000 --- a/packages/util/config/abc/qr.type.ts +++ /dev/null @@ -1,25 +0,0 @@ -export interface AlainQRConfig { - /** - * [qrious](https://github.com/neocotic/qrious) 外网地址,默认:`https://cdn.jsdelivr.net/npm/qrious/dist/qrious.min.js` - * - * 若在 `angular.json` 配置 `"scripts": [ "node_modules/qrious/dist/qrious.min.js" ]` 则优先使用 - */ - lib?: string; - /** 背景,默认:`white` */ - background?: string; - /** 背景透明级别,范围:`0-1` 之间,默认:`1` */ - backgroundAlpha?: number; - /** 前景,默认:`black` */ - foreground?: string; - /** 前景透明级别,范围:`0-1` 之间,默认:`1` */ - foregroundAlpha?: number; - /** 误差校正级别,默认:`L` */ - level?: 'L' | 'M' | 'Q' | 'H'; - /** 二维码输出图片MIME类型,默认:`image/png` */ - mime?: string; - /** 内边距(单位:px),默认:`10` */ - padding?: number; - /** 大小(单位:px),默认:`220` */ - size?: number; - delay?: number; -} diff --git a/packages/util/config/config.types.ts b/packages/util/config/config.types.ts index 85a3880555..0ef50735c4 100644 --- a/packages/util/config/config.types.ts +++ b/packages/util/config/config.types.ts @@ -12,7 +12,6 @@ import { AlainOnboardingConfig, AlainPageHeaderConfig, AlainPdfConfig, - AlainQRConfig, AlainSEConfig, AlainSGConfig, AlainSTConfig, @@ -40,7 +39,6 @@ export interface AlainConfig { onboarding?: AlainOnboardingConfig; lodop?: AlainLodopConfig; pageHeader?: AlainPageHeaderConfig; - qr?: AlainQRConfig; se?: AlainSEConfig; sg?: AlainSGConfig; sv?: AlainSVConfig; diff --git a/scripts/site/route-paths.txt b/scripts/site/route-paths.txt index c690461877..1abc811d36 100644 --- a/scripts/site/route-paths.txt +++ b/scripts/site/route-paths.txt @@ -117,8 +117,6 @@ /components/page-header/zh /components/pdf/en /components/pdf/zh -/components/qr/en -/components/qr/zh /components/quick-menu/en /components/quick-menu/zh /components/result/en @@ -344,4 +342,4 @@ /util/pipes-format/en /util/pipes-format/zh /util/token/en -/util/token/zh \ No newline at end of file +/util/token/zh