rd-outer-component 0.0.66 → 0.0.68

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EventEmitter, forwardRef, Component, Input, Output, NgModule, ViewChild, createComponent, Injectable, Pipe } from '@angular/core';
2
+ import { EventEmitter, forwardRef, Component, Input, Output, NgModule, ViewChild, createComponent, Injectable, Optional, SkipSelf, Pipe } from '@angular/core';
3
3
  import * as i2 from '@angular/forms';
4
4
  import { NG_VALUE_ACCESSOR, ReactiveFormsModule, FormsModule, NG_VALIDATORS } from '@angular/forms';
5
5
  import * as i1 from '@angular/common';
@@ -34,7 +34,6 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
34
34
  import * as i1$1 from 'ng-zorro-antd/notification';
35
35
  import { NzNotificationModule } from 'ng-zorro-antd/notification';
36
36
  import * as i2$3 from '@angular/platform-browser';
37
- import { RouterModule } from '@angular/router';
38
37
  import { Subject, isObservable, of } from 'rxjs';
39
38
  import { debounceTime, filter, switchMap } from 'rxjs/operators';
40
39
 
@@ -1786,6 +1785,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1786
1785
  }]
1787
1786
  }] });
1788
1787
 
1788
+ // notification.component.ts
1789
1789
  const borderColorMap = {
1790
1790
  success: '#bbf7e0',
1791
1791
  warn: '#fef0c3',
@@ -1795,14 +1795,16 @@ class RdNotificationComponent {
1795
1795
  constructor(notificationService, sanitizer) {
1796
1796
  this.notificationService = notificationService;
1797
1797
  this.sanitizer = sanitizer;
1798
+ this.notifications = new Map();
1798
1799
  }
1799
1800
  showNotification(data) {
1800
- this.notification = this.notificationService.template(this.notificationTpl, {
1801
+ const notificationId = this.generateId();
1802
+ const notification = this.notificationService.template(this.notificationTpl, {
1801
1803
  nzData: data,
1802
1804
  nzDuration: data.duration || 8 * 1000,
1803
1805
  nzStyle: {
1804
1806
  borderRadius: '4px',
1805
- border: `1px solid ${borderColorMap[data?.type]}`,
1807
+ border: `1px solid ${borderColorMap[data?.type] || '#e5e7eb'}`,
1806
1808
  boxShadow: '0px 8px 16px 0px rgba(31, 41, 55, 0.08)',
1807
1809
  display: 'flex',
1808
1810
  padding: '0',
@@ -1811,20 +1813,34 @@ class RdNotificationComponent {
1811
1813
  },
1812
1814
  nzClass: 'custom-wallet-notification',
1813
1815
  nzCloseIcon: this.closeTpl,
1816
+ nzKey: notificationId, // 添加唯一 key
1814
1817
  });
1818
+ this.notifications.set(notificationId, notification);
1819
+ // 自动清理
1820
+ setTimeout(() => {
1821
+ this.notifications.delete(notificationId);
1822
+ }, data.duration || 8000);
1815
1823
  }
1816
1824
  getDesc(desc) {
1817
1825
  return this.sanitizer.bypassSecurityTrustHtml(desc);
1818
1826
  }
1819
1827
  onClick(data) {
1820
- if (this.notification?.messageId) {
1821
- this.notificationService.remove(this.notification?.messageId);
1822
- }
1823
1828
  if (data.onLinkClick) {
1824
- // 明确检查存在性
1825
1829
  data.onLinkClick();
1826
1830
  }
1827
1831
  }
1832
+ generateId() {
1833
+ return `rd-notification-${Date.now()}-${Math.random()
1834
+ .toString(36)
1835
+ .substr(2, 9)}`;
1836
+ }
1837
+ ngOnDestroy() {
1838
+ // 清理所有通知
1839
+ this.notifications.forEach((notification, id) => {
1840
+ this.notificationService.remove(id);
1841
+ });
1842
+ this.notifications.clear();
1843
+ }
1828
1844
  }
1829
1845
  RdNotificationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationComponent, deps: [{ token: i1$1.NzNotificationService }, { token: i2$3.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
1830
1846
  RdNotificationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: RdNotificationComponent, selector: "app-rd-notification", viewQueries: [{ propertyName: "notificationTpl", first: true, predicate: ["notificationTpl"], descendants: true, static: true }, { propertyName: "closeTpl", first: true, predicate: ["closeTpl"], descendants: true, static: true }], ngImport: i0, template: "<ng-template #notificationTpl let-data=\"data\">\n <div class=\"rd-custom-notification\"></div>\n <div\n class=\"rd-custom-notification-icon\"\n [class]=\"\n data.type === 'warn'\n ? 'rd-custom-warn-background'\n : data.type === 'error'\n ? 'rd-custom-error-background'\n : ''\n \"\n >\n <img\n [hidden]=\"data.type !== 'success'\"\n src=\"assets/img/icon/success-tip.svg\"\n />\n <img [hidden]=\"data.type !== 'warn'\" src=\"assets/img/icon/warm-tip.svg\" />\n <img [hidden]=\"data.type !== 'error'\" src=\"assets/img/icon/error-tip.svg\" />\n </div>\n <div class=\"rd-custom-notification-container\">\n <div class=\"rd-custom-notification-title\">{{ data.title }}</div>\n <div\n class=\"rd-custom-notification-desc\"\n [innerHTML]=\"getDesc(data.desc)\"\n ></div>\n <div\n *ngIf=\"data.actionDesc\"\n class=\"rd-custom-notification-link\"\n (click)=\"onClick(data)\"\n >\n {{ data.actionDesc }}\n </div>\n </div>\n</ng-template>\n\n<ng-template #closeTpl>\n <div class=\"rd-custom-notification-close\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n >\n <path\n d=\"M3.40039 3.3999L8.00039 7.9999M12.6004 12.5999L8.00039 7.9999M8.00039 7.9999L12.6004 3.3999L3.40039 12.5999\"\n stroke=\"#030712\"\n stroke-width=\"1.36\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n </div>\n</ng-template>\n", styles: [".rd-custom-notification-container{padding:12px 40px 12px 12px}.rd-custom-notification-container .rd-custom-notification-title{font-size:12px;font-weight:600}.rd-custom-notification-container .rd-custom-notification-desc{font-size:12px;font-weight:500;margin-top:4px}.rd-custom-notification-container .rd-custom-notification-link{color:#367af6;font-size:13px;font-style:normal;font-weight:600;line-height:16px;cursor:pointer;margin-top:12px;padding:0 2px}.rd-custom-warn-background{background-color:#fef0c3!important}.rd-custom-error-background{background-color:#fce8eb!important}.rd-custom-notification-icon{display:flex;width:40px;padding:16px 12px;justify-content:center;align-items:center;flex-shrink:0;align-self:stretch;background-color:#dcfcf0}.rd-custom-notification-icon svg{flex-shrink:0;width:20px;height:20px}.rd-custom-notification-close{padding:16px 12px}.rd-custom-notification-close svg{width:16px}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
@@ -1839,67 +1855,140 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1839
1855
  args: ['closeTpl', { static: true }]
1840
1856
  }] } });
1841
1857
 
1842
- class RdNotificationModule {
1843
- }
1844
- RdNotificationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1845
- RdNotificationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, declarations: [RdNotificationComponent], imports: [CommonModule,
1846
- RouterModule,
1847
- FormsModule,
1848
- ReactiveFormsModule,
1849
- NzNotificationModule], exports: [RdNotificationComponent] });
1850
- RdNotificationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, imports: [CommonModule,
1851
- RouterModule,
1852
- FormsModule,
1853
- ReactiveFormsModule,
1854
- NzNotificationModule] });
1855
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, decorators: [{
1856
- type: NgModule,
1857
- args: [{
1858
- declarations: [RdNotificationComponent],
1859
- imports: [
1860
- CommonModule,
1861
- RouterModule,
1862
- FormsModule,
1863
- ReactiveFormsModule,
1864
- NzNotificationModule,
1865
- ],
1866
- exports: [RdNotificationComponent],
1867
- }]
1868
- }] });
1869
-
1858
+ // notification.service.ts
1870
1859
  class RdNotificationService {
1871
- constructor(applicationRef, injector) {
1872
- this.applicationRef = applicationRef;
1860
+ constructor(injector, environmentInjector // 添加 EnvironmentInjector
1861
+ ) {
1873
1862
  this.injector = injector;
1874
- this.createNotificationComponent();
1863
+ this.environmentInjector = environmentInjector;
1864
+ this.isCreating = false;
1865
+ // 防止重复实例化
1866
+ if (RdNotificationService.instance) {
1867
+ return RdNotificationService.instance;
1868
+ }
1869
+ RdNotificationService.instance = this;
1870
+ }
1871
+ ensureComponentCreated() {
1872
+ return new Promise((resolve) => {
1873
+ if (this.notificationComponentRef) {
1874
+ resolve();
1875
+ return;
1876
+ }
1877
+ if (this.isCreating) {
1878
+ // 如果正在创建,等待创建完成
1879
+ const checkInterval = setInterval(() => {
1880
+ if (this.notificationComponentRef && !this.isCreating) {
1881
+ clearInterval(checkInterval);
1882
+ resolve();
1883
+ }
1884
+ }, 10);
1885
+ return;
1886
+ }
1887
+ this.isCreating = true;
1888
+ try {
1889
+ // 使用 setTimeout 避免在 Angular 生命周期内创建组件
1890
+ setTimeout(() => {
1891
+ // Angular 15+ 的正确用法
1892
+ this.notificationComponentRef = createComponent(RdNotificationComponent, {
1893
+ environmentInjector: this.environmentInjector,
1894
+ elementInjector: this.injector,
1895
+ });
1896
+ const hostView = this.notificationComponentRef
1897
+ .hostView;
1898
+ const rootNode = hostView.rootNodes[0];
1899
+ if (document.body) {
1900
+ document.body.appendChild(rootNode);
1901
+ }
1902
+ else {
1903
+ // 如果 document.body 还不存在,等待 DOM 准备就绪
1904
+ document.addEventListener('DOMContentLoaded', () => {
1905
+ document.body.appendChild(rootNode);
1906
+ });
1907
+ }
1908
+ this.notificationComponentRef.changeDetectorRef.detectChanges();
1909
+ this.isCreating = false;
1910
+ resolve();
1911
+ });
1912
+ }
1913
+ catch (error) {
1914
+ console.error('Failed to create notification component:', error);
1915
+ this.isCreating = false;
1916
+ resolve();
1917
+ }
1918
+ });
1875
1919
  }
1876
- createNotificationComponent() {
1877
- // 创建组件
1878
- this.notificationComponent = createComponent(RdNotificationComponent, {
1879
- environmentInjector: this.applicationRef.injector,
1880
- elementInjector: this.injector,
1920
+ async show(data) {
1921
+ await this.ensureComponentCreated();
1922
+ if (this.notificationComponentRef?.instance) {
1923
+ // 使用 setTimeout 确保在下一个 Angular 周期执行
1924
+ setTimeout(() => {
1925
+ this.notificationComponentRef.instance.showNotification(data);
1926
+ });
1927
+ }
1928
+ }
1929
+ ngOnDestroy() {
1930
+ if (this.notificationComponentRef) {
1931
+ this.notificationComponentRef.destroy();
1932
+ this.notificationComponentRef = undefined;
1933
+ }
1934
+ RdNotificationService.instance = null;
1935
+ }
1936
+ // 静态方法用于快速访问
1937
+ static show(data) {
1938
+ setTimeout(() => {
1939
+ const instance = this.getInstance();
1940
+ if (instance) {
1941
+ instance.show(data);
1942
+ }
1881
1943
  });
1882
- // 添加到 DOM
1883
- const domElem = this.notificationComponent.hostView.rootNodes[0];
1884
- document.body.appendChild(domElem);
1885
- // 添加到 ApplicationRef
1886
- this.applicationRef.attachView(this.notificationComponent.hostView);
1887
- }
1888
- /**
1889
- * 显示通知
1890
- */
1891
- show(data) {
1892
- this.notificationComponent?.instance.showNotification(data);
1944
+ }
1945
+ static getInstance() {
1946
+ return this.instance;
1893
1947
  }
1894
1948
  }
1895
- RdNotificationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
1949
+ RdNotificationService.instance = null;
1950
+ RdNotificationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, deps: [{ token: i0.Injector }, { token: i0.EnvironmentInjector }], target: i0.ɵɵFactoryTarget.Injectable });
1896
1951
  RdNotificationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, providedIn: 'root' });
1897
1952
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, decorators: [{
1898
1953
  type: Injectable,
1899
1954
  args: [{
1900
1955
  providedIn: 'root',
1901
1956
  }]
1902
- }], ctorParameters: function () { return [{ type: i0.ApplicationRef }, { type: i0.Injector }]; } });
1957
+ }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.EnvironmentInjector }]; } });
1958
+
1959
+ // notification.module.ts
1960
+ class RdNotificationModule {
1961
+ constructor(parentModule) {
1962
+ if (parentModule) {
1963
+ throw new Error('RdNotificationModule is already loaded. Import it in the AppModule only');
1964
+ }
1965
+ }
1966
+ // 可选:提供配置方法
1967
+ static forRoot() {
1968
+ return {
1969
+ ngModule: RdNotificationModule,
1970
+ providers: [RdNotificationService],
1971
+ };
1972
+ }
1973
+ }
1974
+ RdNotificationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, deps: [{ token: RdNotificationModule, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.NgModule });
1975
+ RdNotificationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, declarations: [RdNotificationComponent], imports: [CommonModule, NzNotificationModule], exports: [RdNotificationComponent] });
1976
+ RdNotificationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, imports: [CommonModule, NzNotificationModule] });
1977
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, decorators: [{
1978
+ type: NgModule,
1979
+ args: [{
1980
+ imports: [CommonModule, NzNotificationModule],
1981
+ declarations: [RdNotificationComponent],
1982
+ exports: [RdNotificationComponent],
1983
+ providers: [
1984
+ // Service 已经在 @Injectable 中提供了,这里不需要重复提供
1985
+ ],
1986
+ }]
1987
+ }], ctorParameters: function () { return [{ type: RdNotificationModule, decorators: [{
1988
+ type: Optional
1989
+ }, {
1990
+ type: SkipSelf
1991
+ }] }]; } });
1903
1992
 
1904
1993
  class SearchListBaseComponent {
1905
1994
  constructor(searchStorageKey = '', isOutDatePicker = false) {