Skip to content

Commit a408cbb

Browse files
authoredNov 11, 2022
feat(abc:exception): add typeDict of global config (#1551)
1 parent 4ed1aa4 commit a408cbb

File tree

7 files changed

+48
-34
lines changed

7 files changed

+48
-34
lines changed
 

‎packages/abc/exception/demo/403.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import { Component } from '@angular/core';
1010

1111
@Component({
1212
selector: 'app-demo',
13-
template: ` <exception [type]="403">
13+
template: `
14+
<exception [type]="403">
1415
<button nz-button [nzType]="'primary'">回到首页</button>
1516
<button nz-button>查看详情</button>
16-
</exception>`,
17+
</exception>
18+
`,
1719
})
1820
export class DemoComponent {}
1921
```

‎packages/abc/exception/exception.component.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Subject, takeUntil } from 'rxjs';
1616

1717
import { DelonLocaleService, LocaleData } from '@delon/theme';
1818
import { isEmpty } from '@delon/util/browser';
19+
import { AlainConfigService } from '@delon/util/config';
1920
import { NzSafeAny } from 'ng-zorro-antd/core/types';
2021

2122
export type ExceptionType = 403 | 404 | 500;
@@ -46,24 +47,11 @@ export class ExceptionComponent implements OnInit, OnDestroy {
4647
_img: SafeUrl = '';
4748
_title: SafeHtml = '';
4849
_desc: SafeHtml = '';
50+
private typeDict!: { [key: number | string]: { img: string; title: string; desc?: string } };
4951

5052
@Input()
5153
set type(value: ExceptionType) {
52-
const item: { img: string; title: string } = {
53-
403: {
54-
img: 'https://gw.alipayobjects.com/zos/rmsportal/wZcnGqRDyhPOEYFcZDnb.svg',
55-
title: '403'
56-
},
57-
404: {
58-
img: 'https://gw.alipayobjects.com/zos/rmsportal/KpnpchXsobRgLElEozzI.svg',
59-
title: '404'
60-
},
61-
500: {
62-
img: 'https://gw.alipayobjects.com/zos/rmsportal/RVRUAYdCGeYNBWoKiIwB.svg',
63-
title: '500'
64-
}
65-
}[value];
66-
54+
const item = this.typeDict[value];
6755
if (!item) return;
6856

6957
this.fixImg(item.img);
@@ -101,9 +89,27 @@ export class ExceptionComponent implements OnInit, OnDestroy {
10189
constructor(
10290
private i18n: DelonLocaleService,
10391
private dom: DomSanitizer,
92+
configSrv: AlainConfigService,
10493
@Optional() private directionality: Directionality,
10594
private cdr: ChangeDetectorRef
106-
) {}
95+
) {
96+
configSrv.attach(this, 'exception', {
97+
typeDict: {
98+
403: {
99+
img: 'https://gw.alipayobjects.com/zos/rmsportal/wZcnGqRDyhPOEYFcZDnb.svg',
100+
title: '403'
101+
},
102+
404: {
103+
img: 'https://gw.alipayobjects.com/zos/rmsportal/KpnpchXsobRgLElEozzI.svg',
104+
title: '404'
105+
},
106+
500: {
107+
img: 'https://gw.alipayobjects.com/zos/rmsportal/RVRUAYdCGeYNBWoKiIwB.svg',
108+
title: '500'
109+
}
110+
}
111+
});
112+
}
107113

108114
ngOnInit(): void {
109115
this.dir = this.directionality.value;

‎packages/abc/exception/index.en-US.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Exceptions page is used to provide feedback on specific abnormal state. Usually,
1212

1313
### exception
1414

15-
| Property | Description | Type | Default |
16-
|----------|-------------|------|---------|
17-
| `[type]` | type of exception, the corresponding default `title`, `desc`, `img` will be given if set, which can be overridden by explicit setting of `title`, `desc`, `img` | `'403','404','500'` | - |
18-
| `[title]` | title | `string` | - |
19-
| `[desc]` | supplementary description | `string` | - |
20-
| `[img]` | the url of background image | `string` | - |
21-
| `[backRouterLink]` | Back of router link | `string, any[]` | `/` |
22-
| `ng-content` | suggested operations, a default 'Home' link will show if not set | `TemplateRef<void>` | - |
15+
| Property | Description | Type | Default | Global Config |
16+
|----------|-------------|------|---------|---------------|
17+
| `[type]` | type of exception, the corresponding default `title`, `desc`, `img` will be given if set, which can be overridden by explicit setting of `title`, `desc`, `img` | `'403','404','500'` | - ||
18+
| `[title]` | title | `string` | - | - |
19+
| `[desc]` | supplementary description | `string` | - | - |
20+
| `[img]` | the url of background image | `string` | - | - |
21+
| `[backRouterLink]` | Back of router link | `string, any[]` | `/` | - |
22+
| `ng-content` | suggested operations, a default 'Home' link will show if not set | `TemplateRef<void>` | - | - |

‎packages/abc/exception/index.zh-CN.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ module: import { ExceptionModule } from '@delon/abc/exception';
1212

1313
### exception
1414

15-
| 成员 | 说明 | 类型 | 默认值 |
16-
|----|----|----|-----|
17-
| `[type]` | 页面类型,若配置,则自带对应类型默认的 `title``desc``img`,此默认设置可以被 `title``desc``img` 覆盖 | `'403','404','500'` | - |
18-
| `[title]` | 标题 | `string` | - |
19-
| `[desc]` | 补充描述 | `string` | - |
20-
| `[img]` | 背景图片地址 | `string` | - |
21-
| `[backRouterLink]` | 后退路由链接 | `string, any[]` | `/` |
22-
| `ng-content` | 建议操作,配置此属性时默认的『返回首页』按钮不生效 | `TemplateRef<void>` | - |
15+
| 成员 | 说明 | 类型 | 默认值 | 全局配置 |
16+
|----|----|----|-----|------|
17+
| `[type]` | 页面类型,若配置,则自带对应类型默认的 `title``desc``img`,此默认设置可以被 `title``desc``img` 覆盖 | `'403','404','500'` | - ||
18+
| `[title]` | 标题 | `string` | - | - |
19+
| `[desc]` | 补充描述 | `string` | - | - |
20+
| `[img]` | 背景图片地址 | `string` | - | - |
21+
| `[backRouterLink]` | 后退路由链接 | `string, any[]` | `/` | - |
22+
| `ng-content` | 建议操作,配置此属性时默认的『返回首页』按钮不生效 | `TemplateRef<void>` | - | - |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface AlainExceptionType {
2+
typeDict?: { [key: number | string]: { img: string; title: string; desc?: string } };
3+
}

‎packages/util/config/abc/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './zip.type';
1414
export * from './media.type';
1515
export * from './pdf.type';
1616
export * from './onboarding.type';
17+
export * from './exception.type';

‎packages/util/config/config.types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { InjectionToken } from '@angular/core';
33
import {
44
AlainDateRangePickerConfig,
55
AlainErrorCollectConfig,
6+
AlainExceptionType,
67
AlainImageConfig,
78
AlainLoadingConfig,
89
AlainLodopConfig,
@@ -30,6 +31,7 @@ import { AlainUtilCurrencyConfig } from './util/currency.type';
3031

3132
export interface AlainConfig {
3233
dataRange?: AlainDateRangePickerConfig;
34+
exception?: AlainExceptionType;
3335
errorCollect?: AlainErrorCollectConfig;
3436
image?: AlainImageConfig;
3537
loading?: AlainLoadingConfig;

0 commit comments

Comments
 (0)
Please sign in to comment.