rd-outer-component 0.0.67 → 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.
- package/esm2020/lib/modules/rd-notification/notification.component.mjs +24 -7
- package/esm2020/lib/modules/rd-notification/notification.module.mjs +30 -9
- package/esm2020/lib/modules/rd-notification/notification.service.mjs +90 -23
- package/fesm2015/rd-outer-component.mjs +150 -43
- package/fesm2015/rd-outer-component.mjs.map +1 -1
- package/fesm2020/rd-outer-component.mjs +147 -42
- package/fesm2020/rd-outer-component.mjs.map +1 -1
- package/lib/modules/rd-notification/notification.component.d.ts +6 -3
- package/lib/modules/rd-notification/notification.module.d.ts +9 -4
- package/lib/modules/rd-notification/notification.service.d.ts +12 -10
- package/package.json +1 -1
|
@@ -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';
|
|
@@ -32,8 +32,8 @@ import { NzPaginationModule } from 'ng-zorro-antd/pagination';
|
|
|
32
32
|
import * as i5 from 'ng-zorro-antd/grid';
|
|
33
33
|
import { NzGridModule } from 'ng-zorro-antd/grid';
|
|
34
34
|
import * as i1$1 from 'ng-zorro-antd/notification';
|
|
35
|
+
import { NzNotificationModule } from 'ng-zorro-antd/notification';
|
|
35
36
|
import * as i2$3 from '@angular/platform-browser';
|
|
36
|
-
import { RouterModule } from '@angular/router';
|
|
37
37
|
import { Subject, isObservable, of } from 'rxjs';
|
|
38
38
|
import { debounceTime, filter, switchMap } from 'rxjs/operators';
|
|
39
39
|
|
|
@@ -1785,6 +1785,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
1785
1785
|
}]
|
|
1786
1786
|
}] });
|
|
1787
1787
|
|
|
1788
|
+
// notification.component.ts
|
|
1788
1789
|
const borderColorMap = {
|
|
1789
1790
|
success: '#bbf7e0',
|
|
1790
1791
|
warn: '#fef0c3',
|
|
@@ -1794,14 +1795,16 @@ class RdNotificationComponent {
|
|
|
1794
1795
|
constructor(notificationService, sanitizer) {
|
|
1795
1796
|
this.notificationService = notificationService;
|
|
1796
1797
|
this.sanitizer = sanitizer;
|
|
1798
|
+
this.notifications = new Map();
|
|
1797
1799
|
}
|
|
1798
1800
|
showNotification(data) {
|
|
1799
|
-
|
|
1801
|
+
const notificationId = this.generateId();
|
|
1802
|
+
const notification = this.notificationService.template(this.notificationTpl, {
|
|
1800
1803
|
nzData: data,
|
|
1801
1804
|
nzDuration: data.duration || 8 * 1000,
|
|
1802
1805
|
nzStyle: {
|
|
1803
1806
|
borderRadius: '4px',
|
|
1804
|
-
border: `1px solid ${borderColorMap[data?.type]}`,
|
|
1807
|
+
border: `1px solid ${borderColorMap[data?.type] || '#e5e7eb'}`,
|
|
1805
1808
|
boxShadow: '0px 8px 16px 0px rgba(31, 41, 55, 0.08)',
|
|
1806
1809
|
display: 'flex',
|
|
1807
1810
|
padding: '0',
|
|
@@ -1810,20 +1813,34 @@ class RdNotificationComponent {
|
|
|
1810
1813
|
},
|
|
1811
1814
|
nzClass: 'custom-wallet-notification',
|
|
1812
1815
|
nzCloseIcon: this.closeTpl,
|
|
1816
|
+
nzKey: notificationId, // 添加唯一 key
|
|
1813
1817
|
});
|
|
1818
|
+
this.notifications.set(notificationId, notification);
|
|
1819
|
+
// 自动清理
|
|
1820
|
+
setTimeout(() => {
|
|
1821
|
+
this.notifications.delete(notificationId);
|
|
1822
|
+
}, data.duration || 8000);
|
|
1814
1823
|
}
|
|
1815
1824
|
getDesc(desc) {
|
|
1816
1825
|
return this.sanitizer.bypassSecurityTrustHtml(desc);
|
|
1817
1826
|
}
|
|
1818
1827
|
onClick(data) {
|
|
1819
|
-
if (this.notification?.messageId) {
|
|
1820
|
-
this.notificationService.remove(this.notification?.messageId);
|
|
1821
|
-
}
|
|
1822
1828
|
if (data.onLinkClick) {
|
|
1823
|
-
// 明确检查存在性
|
|
1824
1829
|
data.onLinkClick();
|
|
1825
1830
|
}
|
|
1826
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
|
+
}
|
|
1827
1844
|
}
|
|
1828
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 });
|
|
1829
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"] }] });
|
|
@@ -1838,52 +1855,140 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
1838
1855
|
args: ['closeTpl', { static: true }]
|
|
1839
1856
|
}] } });
|
|
1840
1857
|
|
|
1841
|
-
|
|
1842
|
-
}
|
|
1843
|
-
RdNotificationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1844
|
-
RdNotificationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, declarations: [RdNotificationComponent], imports: [CommonModule, RouterModule, FormsModule, ReactiveFormsModule] });
|
|
1845
|
-
RdNotificationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, imports: [CommonModule, RouterModule, FormsModule, ReactiveFormsModule] });
|
|
1846
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationModule, decorators: [{
|
|
1847
|
-
type: NgModule,
|
|
1848
|
-
args: [{
|
|
1849
|
-
declarations: [RdNotificationComponent],
|
|
1850
|
-
imports: [CommonModule, RouterModule, FormsModule, ReactiveFormsModule],
|
|
1851
|
-
}]
|
|
1852
|
-
}] });
|
|
1853
|
-
|
|
1858
|
+
// notification.service.ts
|
|
1854
1859
|
class RdNotificationService {
|
|
1855
|
-
constructor(
|
|
1856
|
-
|
|
1860
|
+
constructor(injector, environmentInjector // 添加 EnvironmentInjector
|
|
1861
|
+
) {
|
|
1857
1862
|
this.injector = injector;
|
|
1858
|
-
this.
|
|
1863
|
+
this.environmentInjector = environmentInjector;
|
|
1864
|
+
this.isCreating = false;
|
|
1865
|
+
// 防止重复实例化
|
|
1866
|
+
if (RdNotificationService.instance) {
|
|
1867
|
+
return RdNotificationService.instance;
|
|
1868
|
+
}
|
|
1869
|
+
RdNotificationService.instance = this;
|
|
1859
1870
|
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
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
|
+
});
|
|
1919
|
+
}
|
|
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
|
+
}
|
|
1865
1943
|
});
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
// 添加到 ApplicationRef
|
|
1870
|
-
this.applicationRef.attachView(this.notificationComponent.hostView);
|
|
1871
|
-
}
|
|
1872
|
-
/**
|
|
1873
|
-
* 显示通知
|
|
1874
|
-
*/
|
|
1875
|
-
show(data) {
|
|
1876
|
-
this.notificationComponent?.instance.showNotification(data);
|
|
1944
|
+
}
|
|
1945
|
+
static getInstance() {
|
|
1946
|
+
return this.instance;
|
|
1877
1947
|
}
|
|
1878
1948
|
}
|
|
1879
|
-
RdNotificationService
|
|
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 });
|
|
1880
1951
|
RdNotificationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, providedIn: 'root' });
|
|
1881
1952
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: RdNotificationService, decorators: [{
|
|
1882
1953
|
type: Injectable,
|
|
1883
1954
|
args: [{
|
|
1884
1955
|
providedIn: 'root',
|
|
1885
1956
|
}]
|
|
1886
|
-
}], ctorParameters: function () { return [{ type: i0.
|
|
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
|
+
}] }]; } });
|
|
1887
1992
|
|
|
1888
1993
|
class SearchListBaseComponent {
|
|
1889
1994
|
constructor(searchStorageKey = '', isOutDatePicker = false) {
|