@ebuilding/form 2.4.0 → 2.4.1

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.
@@ -0,0 +1,214 @@
1
+ import * as i0 from '@angular/core';
2
+ import { ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
3
+ import { CommonModule } from '@angular/common';
4
+ import * as i1$1 from '@ebuilding-form/core';
5
+ import { FieldType, FormlyModule } from '@ebuilding-form/core';
6
+ import { DeonNzFormFieldModule } from '@ebuilding/form/form-field';
7
+ import { ReactiveFormsModule } from '@angular/forms';
8
+ import * as i3 from 'ng-zorro-antd/upload';
9
+ import { NzUploadModule } from 'ng-zorro-antd/upload';
10
+ import * as i4 from 'ng-zorro-antd/icon';
11
+ import { NzIconModule } from 'ng-zorro-antd/icon';
12
+ import { NzModalModule } from 'ng-zorro-antd/modal';
13
+ import { ModuleAPI } from '@ebuilding/base/shared.var/shared.constant';
14
+ import * as i1 from '@delon/theme';
15
+ import * as i2 from 'ng-zorro-antd/message';
16
+
17
+ class DeonNzFieldAttachment extends FieldType {
18
+ http;
19
+ msg;
20
+ fileList = [];
21
+ previewImage;
22
+ previewVisible = false;
23
+ constructor(http, msg) {
24
+ super();
25
+ this.http = http;
26
+ this.msg = msg;
27
+ }
28
+ /** 是否多图 */
29
+ get isMultiple() {
30
+ return this.to?.selectType === 'multiple';
31
+ }
32
+ /** 最大数量 */
33
+ get maxCount() {
34
+ if (!this.isMultiple)
35
+ return 1;
36
+ return this.to?.max || 8;
37
+ }
38
+ ngOnInit() {
39
+ this.initValue();
40
+ /** 解决页面渲染后赋值 */
41
+ this.formControl.valueChanges.subscribe(() => {
42
+ if (this.fileList.length === 0) {
43
+ this.initValue();
44
+ }
45
+ });
46
+ }
47
+ /**
48
+ * 初始化回显
49
+ */
50
+ initValue() {
51
+ const value = this.formControl.value;
52
+ if (!value)
53
+ return;
54
+ const arr = Array.isArray(value) ? value : [value];
55
+ this.fileList = arr.map((item, index) => ({
56
+ uid: item.id || String(index),
57
+ name: item.fileName,
58
+ status: 'done',
59
+ url: item.fileUrl,
60
+ thumbUrl: item.fileUrl
61
+ }));
62
+ }
63
+ /**
64
+ * 上传前
65
+ */
66
+ beforeUpload = (file) => {
67
+ const realFile = file;
68
+ if (!realFile)
69
+ return false;
70
+ /** 限制 50MB */
71
+ const isLt5M = realFile.size / 1024 / 1024 < 50;
72
+ if (!isLt5M) {
73
+ this.msg.warning('附件不能超过50MB');
74
+ return false;
75
+ }
76
+ const reader = new FileReader();
77
+ reader.onload = () => {
78
+ const target = this.fileList.find(f => f.uid === file.uid);
79
+ if (target) {
80
+ target.thumbUrl = reader.result;
81
+ this.fileList = [...this.fileList];
82
+ }
83
+ };
84
+ reader.readAsDataURL(realFile);
85
+ return true;
86
+ };
87
+ /**
88
+ * 上传
89
+ */
90
+ uploadRequest = (item) => {
91
+ const file = item.file;
92
+ const realFile = file.originFileObj ||
93
+ item.file;
94
+ const formData = new FormData();
95
+ formData.append('type', 'OTHER');
96
+ formData.append('multipartFile', realFile);
97
+ return this.http
98
+ .post(`${ModuleAPI.system}/user/comm/uploadFile`, formData)
99
+ .subscribe({
100
+ next: (res) => {
101
+ if (res && res?.result) {
102
+ const data = res.result;
103
+ file.status = 'done';
104
+ file.url = data.fileUrl;
105
+ file.thumbUrl = data.fileUrl;
106
+ /** 保存 id */
107
+ file.id = data.id;
108
+ if (!this.isMultiple) {
109
+ this.fileList = [file];
110
+ }
111
+ else {
112
+ this.fileList = [...this.fileList];
113
+ }
114
+ this.updateModel();
115
+ item.onSuccess?.(res, file, null);
116
+ }
117
+ else {
118
+ file.status = 'error';
119
+ item.onError?.(res, file);
120
+ }
121
+ },
122
+ error: err => {
123
+ file.status = 'error';
124
+ item.onError?.(err, file);
125
+ }
126
+ });
127
+ };
128
+ /**
129
+ * 删除
130
+ */
131
+ remove = (file) => {
132
+ const index = this.fileList.indexOf(file);
133
+ if (index > -1) {
134
+ this.fileList.splice(index, 1);
135
+ }
136
+ this.updateModel();
137
+ return true;
138
+ };
139
+ fileChange(e) { }
140
+ /**
141
+ * 写回 model
142
+ */
143
+ updateModel() {
144
+ let arr = [];
145
+ if (this.fileList && this.fileList.length > 0) {
146
+ this.fileList.forEach((item) => {
147
+ if (item && item["status"] === 'done' && item["url"]) {
148
+ arr.push({
149
+ id: item.id,
150
+ fileName: item.name,
151
+ fileUrl: item.url
152
+ });
153
+ }
154
+ });
155
+ }
156
+ if (this.isMultiple) {
157
+ this.formControl.setValue(arr);
158
+ }
159
+ else {
160
+ this.formControl.setValue(arr[0] || null);
161
+ }
162
+ }
163
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldAttachment, deps: [{ token: i1._HttpClient }, { token: i2.NzMessageService }], target: i0.ɵɵFactoryTarget.Component });
164
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.15", type: DeonNzFieldAttachment, isStandalone: true, selector: "deon-nz-field-attachment", usesInheritance: true, ngImport: i0, template: "<nz-upload nzType=\"drag\" [nzLimit]=\"1\" [nzShowButton]=\"fileList.length < maxCount\" [nzMultiple]=\"isMultiple\"\r\n [nzDisabled]=\"fileList && fileList.length>=maxCount\" [(nzFileList)]=\"fileList\" [nzBeforeUpload]=\"beforeUpload\"\r\n [nzRemove]=\"remove\" [nzCustomRequest]=\"uploadRequest\" [(nzFileList)]=\"fileList\">\r\n <p class=\"ant-upload-drag-icon\">\r\n <i nz-icon nzType=\"inbox\"></i>\r\n </p>\r\n <p class=\"ant-upload-text\">\u5355\u51FB\u6216\u62D6\u52A8\u6587\u4EF6\u5230\u6B64\u533A\u57DF\u4EE5\u4E0A\u4F20</p>\r\n <p class=\"ant-upload-hint\">\u5355\u4E2A\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC750MB\uFF08\u6700\u591A\u53EF\u4EE5\u4E0A\u4F20{{maxCount}}\u4E2A\u6587\u4EF6\uFF09</p>\r\n</nz-upload>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "ngmodule", type: FormlyModule }, { kind: "ngmodule", type: NzUploadModule }, { kind: "component", type: i3.NzUploadComponent, selector: "nz-upload", inputs: ["nzType", "nzLimit", "nzSize", "nzFileType", "nzAccept", "nzAction", "nzDirectory", "nzOpenFileDialogOnClick", "nzBeforeUpload", "nzCustomRequest", "nzData", "nzFilter", "nzFileList", "nzDisabled", "nzHeaders", "nzListType", "nzMultiple", "nzName", "nzShowUploadList", "nzShowButton", "nzWithCredentials", "nzRemove", "nzPreview", "nzPreviewFile", "nzPreviewIsImage", "nzTransformFile", "nzDownload", "nzIconRender", "nzFileListRender"], outputs: ["nzChange", "nzFileListChange"], exportAs: ["nzUpload"] }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i4.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzModalModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
165
+ }
166
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldAttachment, decorators: [{
167
+ type: Component,
168
+ args: [{ selector: 'deon-nz-field-attachment', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
169
+ CommonModule,
170
+ ReactiveFormsModule,
171
+ FormlyModule,
172
+ NzUploadModule,
173
+ NzIconModule,
174
+ NzModalModule
175
+ ], template: "<nz-upload nzType=\"drag\" [nzLimit]=\"1\" [nzShowButton]=\"fileList.length < maxCount\" [nzMultiple]=\"isMultiple\"\r\n [nzDisabled]=\"fileList && fileList.length>=maxCount\" [(nzFileList)]=\"fileList\" [nzBeforeUpload]=\"beforeUpload\"\r\n [nzRemove]=\"remove\" [nzCustomRequest]=\"uploadRequest\" [(nzFileList)]=\"fileList\">\r\n <p class=\"ant-upload-drag-icon\">\r\n <i nz-icon nzType=\"inbox\"></i>\r\n </p>\r\n <p class=\"ant-upload-text\">\u5355\u51FB\u6216\u62D6\u52A8\u6587\u4EF6\u5230\u6B64\u533A\u57DF\u4EE5\u4E0A\u4F20</p>\r\n <p class=\"ant-upload-hint\">\u5355\u4E2A\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC750MB\uFF08\u6700\u591A\u53EF\u4EE5\u4E0A\u4F20{{maxCount}}\u4E2A\u6587\u4EF6\uFF09</p>\r\n</nz-upload>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"] }]
176
+ }], ctorParameters: () => [{ type: i1._HttpClient }, { type: i2.NzMessageService }] });
177
+
178
+ function withFormlyFieldAttachment() {
179
+ return {
180
+ types: [
181
+ {
182
+ name: 'attachment',
183
+ component: DeonNzFieldAttachment,
184
+ wrappers: ['formly-form-field'],
185
+ }
186
+ ],
187
+ };
188
+ }
189
+
190
+ class DeonNzAttachmentModule {
191
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzAttachmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
192
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: DeonNzAttachmentModule, imports: [CommonModule,
193
+ DeonNzFormFieldModule, i1$1.FormlyModule] });
194
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzAttachmentModule, imports: [CommonModule,
195
+ DeonNzFormFieldModule,
196
+ FormlyModule.forChild(withFormlyFieldAttachment())] });
197
+ }
198
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzAttachmentModule, decorators: [{
199
+ type: NgModule,
200
+ args: [{
201
+ imports: [
202
+ CommonModule,
203
+ DeonNzFormFieldModule,
204
+ FormlyModule.forChild(withFormlyFieldAttachment()),
205
+ ],
206
+ }]
207
+ }] });
208
+
209
+ /**
210
+ * Generated bundle index. Do not edit.
211
+ */
212
+
213
+ export { DeonNzAttachmentModule, DeonNzFieldAttachment, withFormlyFieldAttachment };
214
+ //# sourceMappingURL=type.attachment.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.attachment.mjs","sources":["../../../../packages/form/attachment/src/default/index.ts","../../../../packages/form/attachment/src/default/index.html","../../../../packages/form/attachment/src/attachment.config.ts","../../../../packages/form/attachment/src/attachment.module.ts","../../../../packages/form/attachment/type.attachment.ts"],"sourcesContent":["import {\r\n Component,\r\n ChangeDetectionStrategy\r\n} from '@angular/core';\r\n\r\nimport { CommonModule } from '@angular/common';\r\nimport { ReactiveFormsModule } from '@angular/forms';\r\nimport { _HttpClient } from '@delon/theme';\r\n\r\nimport {\r\n FormlyModule,\r\n FieldType,\r\n FieldTypeConfig\r\n} from '@ebuilding-form/core';\r\n\r\nimport {\r\n NzUploadFile,\r\n NzUploadModule,\r\n NzUploadXHRArgs\r\n} from 'ng-zorro-antd/upload';\r\n\r\nimport { NzIconModule } from 'ng-zorro-antd/icon';\r\nimport { NzModalModule } from 'ng-zorro-antd/modal';\r\nimport { NzMessageService } from 'ng-zorro-antd/message';\r\nimport { Subscription } from 'rxjs';\r\n\r\nimport { ModuleAPI } from '@ebuilding/base/shared.var/shared.constant';\r\n\r\n@Component({\r\n selector: 'deon-nz-field-attachment',\r\n templateUrl: './index.html',\r\n styleUrls: ['./index.less'],\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n standalone: true,\r\n imports: [\r\n CommonModule,\r\n ReactiveFormsModule,\r\n FormlyModule,\r\n NzUploadModule,\r\n NzIconModule,\r\n NzModalModule\r\n ]\r\n})\r\nexport class DeonNzFieldAttachment extends FieldType<FieldTypeConfig> {\r\n\r\n fileList: NzUploadFile[] = [];\r\n\r\n previewImage?: string;\r\n previewVisible = false;\r\n\r\n constructor(private http: _HttpClient, private msg: NzMessageService) {\r\n super();\r\n }\r\n\r\n /** 是否多图 */\r\n get isMultiple(): boolean {\r\n return this.to?.selectType === 'multiple';\r\n }\r\n\r\n /** 最大数量 */\r\n get maxCount(): number {\r\n if (!this.isMultiple) return 1;\r\n return this.to?.max || 8;\r\n }\r\n\r\n ngOnInit(): void {\r\n this.initValue();\r\n /** 解决页面渲染后赋值 */\r\n this.formControl.valueChanges.subscribe(() => {\r\n if (this.fileList.length === 0) {\r\n this.initValue();\r\n }\r\n\r\n });\r\n\r\n }\r\n\r\n /**\r\n * 初始化回显\r\n */\r\n initValue() {\r\n const value = this.formControl.value;\r\n if (!value) return;\r\n const arr = Array.isArray(value) ? value : [value];\r\n this.fileList = arr.map((item: any, index: number) => ({\r\n uid: item.id || String(index),\r\n name: item.fileName,\r\n status: 'done',\r\n url: item.fileUrl,\r\n thumbUrl: item.fileUrl\r\n }));\r\n }\r\n\r\n /**\r\n * 上传前\r\n */\r\n beforeUpload = (file: NzUploadFile): boolean => {\r\n const realFile = file as unknown as File\r\n if (!realFile) return false;\r\n /** 限制 50MB */\r\n const isLt5M = realFile.size / 1024 / 1024 < 50;\r\n if (!isLt5M) {\r\n this.msg.warning('附件不能超过50MB');\r\n return false;\r\n }\r\n const reader = new FileReader();\r\n reader.onload = () => {\r\n const target = this.fileList.find(f => f.uid === file.uid);\r\n if (target) {\r\n target.thumbUrl = reader.result as string;\r\n this.fileList = [...this.fileList];\r\n }\r\n };\r\n\r\n reader.readAsDataURL(realFile);\r\n\r\n return true;\r\n\r\n };\r\n\r\n /**\r\n * 上传\r\n */\r\n uploadRequest = (item: NzUploadXHRArgs): Subscription => {\r\n\r\n const file = item.file as NzUploadFile;\r\n\r\n const realFile =\r\n file.originFileObj ||\r\n (item.file as unknown as File);\r\n\r\n const formData = new FormData();\r\n\r\n formData.append('type', 'OTHER');\r\n formData.append('multipartFile', realFile);\r\n\r\n return this.http\r\n .post(`${ModuleAPI.system}/user/comm/uploadFile`, formData)\r\n .subscribe({\r\n\r\n next: (res: any) => {\r\n if (res && res?.result) {\r\n const data: any = res.result;\r\n\r\n file.status = 'done';\r\n file.url = data.fileUrl;\r\n file.thumbUrl = data.fileUrl;\r\n\r\n /** 保存 id */\r\n (file as any).id = data.id;\r\n\r\n if (!this.isMultiple) {\r\n this.fileList = [file];\r\n } else {\r\n this.fileList = [...this.fileList];\r\n }\r\n this.updateModel();\r\n item.onSuccess?.(res, file, null);\r\n } else {\r\n file.status = 'error';\r\n item.onError?.(res, file);\r\n }\r\n },\r\n error: err => {\r\n file.status = 'error';\r\n item.onError?.(err, file);\r\n }\r\n });\r\n };\r\n\r\n /**\r\n * 删除\r\n */\r\n remove = (file: NzUploadFile): boolean => {\r\n const index = this.fileList.indexOf(file);\r\n if (index > -1) {\r\n this.fileList.splice(index, 1);\r\n }\r\n this.updateModel();\r\n return true;\r\n\r\n };\r\n\r\n\r\n fileChange(e: any) { }\r\n\r\n\r\n /**\r\n * 写回 model\r\n */\r\n updateModel() {\r\n let arr: any[] = [];\r\n if (this.fileList && this.fileList.length > 0) {\r\n this.fileList.forEach((item: any) => {\r\n if (item && item[\"status\"] === 'done' && item[\"url\"]) {\r\n arr.push({\r\n id: item.id,\r\n fileName: item.name,\r\n fileUrl: item.url\r\n });\r\n }\r\n })\r\n }\r\n\r\n if (this.isMultiple) {\r\n this.formControl.setValue(arr);\r\n } else {\r\n this.formControl.setValue(arr[0] || null);\r\n }\r\n }\r\n\r\n}","<nz-upload nzType=\"drag\" [nzLimit]=\"1\" [nzShowButton]=\"fileList.length < maxCount\" [nzMultiple]=\"isMultiple\"\r\n [nzDisabled]=\"fileList && fileList.length>=maxCount\" [(nzFileList)]=\"fileList\" [nzBeforeUpload]=\"beforeUpload\"\r\n [nzRemove]=\"remove\" [nzCustomRequest]=\"uploadRequest\" [(nzFileList)]=\"fileList\">\r\n <p class=\"ant-upload-drag-icon\">\r\n <i nz-icon nzType=\"inbox\"></i>\r\n </p>\r\n <p class=\"ant-upload-text\">单击或拖动文件到此区域以上传</p>\r\n <p class=\"ant-upload-hint\">单个文件大小不能超过50MB(最多可以上传{{maxCount}}个文件)</p>\r\n</nz-upload>","import { ConfigOption } from '@ebuilding-form/core';\nimport { DeonNzFieldAttachment } from './default/index';\n\nexport function withFormlyFieldAttachment(): ConfigOption {\n return {\n types: [\n {\n name: 'attachment',\n component: DeonNzFieldAttachment,\n wrappers: ['formly-form-field'],\n }\n ],\n };\n}\n","import { NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { FormlyModule } from '@ebuilding-form/core';\nimport { DeonNzFormFieldModule } from '@ebuilding/form/form-field';\nimport { withFormlyFieldAttachment } from './attachment.config';\n\n@NgModule({\n imports: [\n CommonModule,\n DeonNzFormFieldModule,\n FormlyModule.forChild(withFormlyFieldAttachment()),\n ],\n})\nexport class DeonNzAttachmentModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1"],"mappings":";;;;;;;;;;;;;;;;AA2CM,MAAO,qBAAsB,SAAQ,SAA0B,CAAA;AAO/C,IAAA,IAAA;AAA2B,IAAA,GAAA;IAL/C,QAAQ,GAAmB,EAAE;AAE7B,IAAA,YAAY;IACZ,cAAc,GAAG,KAAK;IAEtB,WAAoB,CAAA,IAAiB,EAAU,GAAqB,EAAA;AAClE,QAAA,KAAK,EAAE;QADW,IAAI,CAAA,IAAA,GAAJ,IAAI;QAAuB,IAAG,CAAA,GAAA,GAAH,GAAG;;;AAKlD,IAAA,IAAI,UAAU,GAAA;AACZ,QAAA,OAAO,IAAI,CAAC,EAAE,EAAE,UAAU,KAAK,UAAU;;;AAI3C,IAAA,IAAI,QAAQ,GAAA;QACV,IAAI,CAAC,IAAI,CAAC,UAAU;AAAE,YAAA,OAAO,CAAC;AAC9B,QAAA,OAAO,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC;;IAG1B,QAAQ,GAAA;QACN,IAAI,CAAC,SAAS,EAAE;;QAEhB,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,MAAK;YAC3C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC9B,IAAI,CAAC,SAAS,EAAE;;AAGpB,SAAC,CAAC;;AAIJ;;AAEG;IACH,SAAS,GAAA;AACP,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK;AACpC,QAAA,IAAI,CAAC,KAAK;YAAE;AACZ,QAAA,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,C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,YAAY,CAAC,QAAQ,CAAC,yBAAyB,EAAE,CAAC,CAAA,EAAA,CAAA;;4FAGzC,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBAPlC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,OAAO,EAAE;wBACP,YAAY;wBACZ,qBAAqB;AACrB,wBAAA,YAAY,CAAC,QAAQ,CAAC,yBAAyB,EAAE,CAAC;AACnD,qBAAA;AACF,iBAAA;;;ACZD;;AAEG;;;;"}
@@ -0,0 +1,403 @@
1
+ import * as i0 from '@angular/core';
2
+ import { ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
3
+ import { CommonModule } from '@angular/common';
4
+ import * as i1$1 from '@ebuilding-form/core';
5
+ import { FieldType, FormlyModule } from '@ebuilding-form/core';
6
+ import { DeonNzFormFieldModule } from '@ebuilding/form/form-field';
7
+ import { ReactiveFormsModule } from '@angular/forms';
8
+ import * as i3 from 'ng-zorro-antd/upload';
9
+ import { NzUploadModule } from 'ng-zorro-antd/upload';
10
+ import * as i4 from 'ng-zorro-antd/icon';
11
+ import { NzIconModule } from 'ng-zorro-antd/icon';
12
+ import * as i5 from 'ng-zorro-antd/modal';
13
+ import { NzModalModule } from 'ng-zorro-antd/modal';
14
+ import { ModuleAPI } from '@ebuilding/base/shared.var/shared.constant';
15
+ import * as i1 from '@delon/theme';
16
+ import * as i2 from 'ng-zorro-antd/message';
17
+
18
+ class DeonNzFieldCardFront extends FieldType {
19
+ http;
20
+ msg;
21
+ fileList = [];
22
+ maxCount = 1;
23
+ previewImage;
24
+ previewVisible = false;
25
+ isMultiple = false;
26
+ constructor(http, msg) {
27
+ super();
28
+ this.http = http;
29
+ this.msg = msg;
30
+ }
31
+ ngOnInit() {
32
+ this.initValue();
33
+ /** 解决页面渲染后赋值 */
34
+ this.formControl.valueChanges.subscribe(() => {
35
+ if (this.fileList.length === 0) {
36
+ this.initValue();
37
+ }
38
+ });
39
+ }
40
+ /**
41
+ * 初始化回显
42
+ */
43
+ initValue() {
44
+ const value = this.formControl.value;
45
+ if (!value)
46
+ return;
47
+ const arr = Array.isArray(value) ? value : [value];
48
+ this.fileList = arr.map((item, index) => ({
49
+ uid: item.id || String(index),
50
+ name: item.fileName,
51
+ status: 'done',
52
+ url: item.fileUrl,
53
+ thumbUrl: item.fileUrl
54
+ }));
55
+ }
56
+ /**
57
+ * 上传前
58
+ */
59
+ beforeUpload = (file) => {
60
+ const realFile = file;
61
+ if (!realFile)
62
+ return false;
63
+ /** 限制 5MB */
64
+ const isLt5M = realFile.size / 1024 / 1024 < 5;
65
+ if (!isLt5M) {
66
+ this.msg.warning('图片不能超过5MB');
67
+ return false;
68
+ }
69
+ const reader = new FileReader();
70
+ reader.onload = () => {
71
+ const target = this.fileList.find(f => f.uid === file.uid);
72
+ if (target) {
73
+ target.thumbUrl = reader.result;
74
+ this.fileList = [...this.fileList];
75
+ }
76
+ };
77
+ reader.readAsDataURL(realFile);
78
+ return true;
79
+ };
80
+ /**
81
+ * 上传
82
+ */
83
+ uploadRequest = (item) => {
84
+ const file = item.file;
85
+ const realFile = file.originFileObj ||
86
+ item.file;
87
+ const formData = new FormData();
88
+ formData.append('type', 'CARD_FRONT');
89
+ formData.append('multipartFile', realFile);
90
+ let url = `${ModuleAPI.system}/user/comm/uploadFile`;
91
+ if (this.to && this.to["ocr"] == true) {
92
+ url = `${ModuleAPI.system}/user/comm/uploadFileOCR`;
93
+ }
94
+ return this.http.post(url, formData)
95
+ .subscribe({
96
+ next: (res) => {
97
+ if (res && res?.result) {
98
+ const data = res.result;
99
+ file.status = 'done';
100
+ file.url = data.fileUrl;
101
+ file.thumbUrl = data.fileUrl;
102
+ /** 保存 id */
103
+ file.id = data.id;
104
+ if (!this.isMultiple) {
105
+ this.fileList = [file];
106
+ }
107
+ else {
108
+ this.fileList = [...this.fileList];
109
+ }
110
+ this.updateModel(data);
111
+ item.onSuccess?.(res, file, null);
112
+ }
113
+ else {
114
+ file.status = 'error';
115
+ item.onError?.(res, file);
116
+ }
117
+ },
118
+ error: err => {
119
+ file.status = 'error';
120
+ item.onError?.(err, file);
121
+ }
122
+ });
123
+ };
124
+ /**
125
+ * 删除
126
+ */
127
+ remove = (file) => {
128
+ const index = this.fileList.indexOf(file);
129
+ if (index > -1) {
130
+ this.fileList.splice(index, 1);
131
+ }
132
+ this.updateModel(null);
133
+ return true;
134
+ };
135
+ /**
136
+ * 预览
137
+ */
138
+ handlePreview = async (file) => {
139
+ if (!file.url && !file.preview) {
140
+ const realFile = file.originFileObj;
141
+ if (realFile) {
142
+ file.preview = await this.getBase64(realFile);
143
+ }
144
+ }
145
+ this.previewImage = file.url || file.preview;
146
+ this.previewVisible = true;
147
+ };
148
+ getBase64(file) {
149
+ return new Promise((resolve, reject) => {
150
+ const reader = new FileReader();
151
+ reader.readAsDataURL(file);
152
+ reader.onload = () => resolve(reader.result);
153
+ reader.onerror = reject;
154
+ });
155
+ }
156
+ /**
157
+ * 写回 model
158
+ */
159
+ updateModel(e) {
160
+ let arr = [];
161
+ if (this.fileList && this.fileList.length > 0) {
162
+ this.fileList.forEach((item) => {
163
+ if (item?.originFileObj && item?.originFileObj["status"] === 'done' && item?.originFileObj["url"]) {
164
+ let obj = item?.originFileObj;
165
+ arr.push({
166
+ id: obj.id,
167
+ fileName: obj.name,
168
+ fileUrl: obj.url
169
+ });
170
+ }
171
+ });
172
+ }
173
+ this.formControl.setValue(arr[0] || null);
174
+ }
175
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldCardFront, deps: [{ token: i1._HttpClient }, { token: i2.NzMessageService }], target: i0.ɵɵFactoryTarget.Component });
176
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.15", type: DeonNzFieldCardFront, isStandalone: true, selector: "deon-nz-field-card-front", usesInheritance: true, ngImport: i0, template: "<nz-upload nzListType=\"picture-card\" [(nzFileList)]=\"fileList\" [nzShowButton]=\"fileList.length < maxCount\"\r\n [nzPreview]=\"handlePreview\" [nzBeforeUpload]=\"beforeUpload\" [nzCustomRequest]=\"uploadRequest\" [nzRemove]=\"remove\"\r\n nzAccept=\"image/*\" [nzMultiple]=\"isMultiple\">\r\n <div class=\"upload-empty-box\">\r\n <span nz-icon nzType=\"plus\"></span>\r\n <div style=\"margin-top: 8px\">\u70B9\u51FB\u4E0A\u4F20</div>\r\n </div>\r\n</nz-upload>\r\n\r\n<nz-modal [nzVisible]=\"previewVisible\" [nzFooter]=\"null\" (nzOnCancel)=\"previewVisible = false\">\r\n <img [src]=\"previewImage\" style=\"width: 100%\" />\r\n</nz-modal>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "ngmodule", type: FormlyModule }, { kind: "ngmodule", type: NzUploadModule }, { kind: "component", type: i3.NzUploadComponent, selector: "nz-upload", inputs: ["nzType", "nzLimit", "nzSize", "nzFileType", "nzAccept", "nzAction", "nzDirectory", "nzOpenFileDialogOnClick", "nzBeforeUpload", "nzCustomRequest", "nzData", "nzFilter", "nzFileList", "nzDisabled", "nzHeaders", "nzListType", "nzMultiple", "nzName", "nzShowUploadList", "nzShowButton", "nzWithCredentials", "nzRemove", "nzPreview", "nzPreviewFile", "nzPreviewIsImage", "nzTransformFile", "nzDownload", "nzIconRender", "nzFileListRender"], outputs: ["nzChange", "nzFileListChange"], exportAs: ["nzUpload"] }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i4.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzModalModule }, { kind: "component", type: i5.NzModalComponent, selector: "nz-modal", inputs: ["nzMask", "nzMaskClosable", "nzCloseOnNavigation", "nzVisible", "nzClosable", "nzOkLoading", "nzOkDisabled", "nzCancelDisabled", "nzCancelLoading", "nzKeyboard", "nzNoAnimation", "nzCentered", "nzDraggable", "nzContent", "nzFooter", "nzZIndex", "nzWidth", "nzWrapClassName", "nzClassName", "nzStyle", "nzTitle", "nzCloseIcon", "nzMaskStyle", "nzBodyStyle", "nzOkText", "nzCancelText", "nzOkType", "nzOkDanger", "nzIconType", "nzModalType", "nzAutofocus", "nzOnOk", "nzOnCancel"], outputs: ["nzOnOk", "nzOnCancel", "nzAfterOpen", "nzAfterClose", "nzVisibleChange"], exportAs: ["nzModal"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
177
+ }
178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldCardFront, decorators: [{
179
+ type: Component,
180
+ args: [{ selector: 'deon-nz-field-card-front', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
181
+ CommonModule,
182
+ ReactiveFormsModule,
183
+ FormlyModule,
184
+ NzUploadModule,
185
+ NzIconModule,
186
+ NzModalModule
187
+ ], template: "<nz-upload nzListType=\"picture-card\" [(nzFileList)]=\"fileList\" [nzShowButton]=\"fileList.length < maxCount\"\r\n [nzPreview]=\"handlePreview\" [nzBeforeUpload]=\"beforeUpload\" [nzCustomRequest]=\"uploadRequest\" [nzRemove]=\"remove\"\r\n nzAccept=\"image/*\" [nzMultiple]=\"isMultiple\">\r\n <div class=\"upload-empty-box\">\r\n <span nz-icon nzType=\"plus\"></span>\r\n <div style=\"margin-top: 8px\">\u70B9\u51FB\u4E0A\u4F20</div>\r\n </div>\r\n</nz-upload>\r\n\r\n<nz-modal [nzVisible]=\"previewVisible\" [nzFooter]=\"null\" (nzOnCancel)=\"previewVisible = false\">\r\n <img [src]=\"previewImage\" style=\"width: 100%\" />\r\n</nz-modal>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"] }]
188
+ }], ctorParameters: () => [{ type: i1._HttpClient }, { type: i2.NzMessageService }] });
189
+
190
+ class DeonNzFieldCardBack extends FieldType {
191
+ http;
192
+ msg;
193
+ fileList = [];
194
+ maxCount = 1;
195
+ previewImage;
196
+ previewVisible = false;
197
+ isMultiple = false;
198
+ constructor(http, msg) {
199
+ super();
200
+ this.http = http;
201
+ this.msg = msg;
202
+ }
203
+ ngOnInit() {
204
+ this.initValue();
205
+ /** 解决页面渲染后赋值 */
206
+ this.formControl.valueChanges.subscribe(() => {
207
+ if (this.fileList.length === 0) {
208
+ this.initValue();
209
+ }
210
+ });
211
+ }
212
+ /**
213
+ * 初始化回显
214
+ */
215
+ initValue() {
216
+ const value = this.formControl.value;
217
+ if (!value)
218
+ return;
219
+ const arr = Array.isArray(value) ? value : [value];
220
+ this.fileList = arr.map((item, index) => ({
221
+ uid: item.id || String(index),
222
+ name: item.fileName,
223
+ status: 'done',
224
+ url: item.fileUrl,
225
+ thumbUrl: item.fileUrl
226
+ }));
227
+ }
228
+ /**
229
+ * 上传前
230
+ */
231
+ beforeUpload = (file) => {
232
+ const realFile = file;
233
+ if (!realFile)
234
+ return false;
235
+ /** 限制 5MB */
236
+ const isLt5M = realFile.size / 1024 / 1024 < 5;
237
+ if (!isLt5M) {
238
+ this.msg.warning('图片不能超过5MB');
239
+ return false;
240
+ }
241
+ const reader = new FileReader();
242
+ reader.onload = () => {
243
+ const target = this.fileList.find(f => f.uid === file.uid);
244
+ if (target) {
245
+ target.thumbUrl = reader.result;
246
+ this.fileList = [...this.fileList];
247
+ }
248
+ };
249
+ reader.readAsDataURL(realFile);
250
+ return true;
251
+ };
252
+ /**
253
+ * 上传
254
+ */
255
+ uploadRequest = (item) => {
256
+ const file = item.file;
257
+ const realFile = file.originFileObj ||
258
+ item.file;
259
+ const formData = new FormData();
260
+ formData.append('type', 'CARD_BACK');
261
+ formData.append('multipartFile', realFile);
262
+ let url = `${ModuleAPI.system}/user/comm/uploadFile`;
263
+ if (this.to && this.to["ocr"] == true) {
264
+ url = `${ModuleAPI.system}/user/comm/uploadFileOCR`;
265
+ }
266
+ return this.http.post(url, formData)
267
+ .subscribe({
268
+ next: (res) => {
269
+ if (res && res?.result) {
270
+ const data = res.result;
271
+ file.status = 'done';
272
+ file.url = data.fileUrl;
273
+ file.thumbUrl = data.fileUrl;
274
+ /** 保存 id */
275
+ file.id = data.id;
276
+ if (!this.isMultiple) {
277
+ this.fileList = [file];
278
+ }
279
+ else {
280
+ this.fileList = [...this.fileList];
281
+ }
282
+ this.updateModel(data);
283
+ item.onSuccess?.(res, file, null);
284
+ }
285
+ else {
286
+ file.status = 'error';
287
+ item.onError?.(res, file);
288
+ }
289
+ },
290
+ error: err => {
291
+ file.status = 'error';
292
+ item.onError?.(err, file);
293
+ }
294
+ });
295
+ };
296
+ /**
297
+ * 删除
298
+ */
299
+ remove = (file) => {
300
+ const index = this.fileList.indexOf(file);
301
+ if (index > -1) {
302
+ this.fileList.splice(index, 1);
303
+ }
304
+ this.updateModel(null);
305
+ return true;
306
+ };
307
+ /**
308
+ * 预览
309
+ */
310
+ handlePreview = async (file) => {
311
+ if (!file.url && !file.preview) {
312
+ const realFile = file.originFileObj;
313
+ if (realFile) {
314
+ file.preview = await this.getBase64(realFile);
315
+ }
316
+ }
317
+ this.previewImage = file.url || file.preview;
318
+ this.previewVisible = true;
319
+ };
320
+ getBase64(file) {
321
+ return new Promise((resolve, reject) => {
322
+ const reader = new FileReader();
323
+ reader.readAsDataURL(file);
324
+ reader.onload = () => resolve(reader.result);
325
+ reader.onerror = reject;
326
+ });
327
+ }
328
+ /**
329
+ * 写回 model
330
+ */
331
+ updateModel(e) {
332
+ let arr = [];
333
+ if (this.fileList && this.fileList.length > 0) {
334
+ this.fileList.forEach((item) => {
335
+ if (item?.originFileObj && item?.originFileObj["status"] === 'done' && item?.originFileObj["url"]) {
336
+ let obj = item?.originFileObj;
337
+ arr.push({
338
+ id: obj.id,
339
+ fileName: obj.name,
340
+ fileUrl: obj.url
341
+ });
342
+ }
343
+ });
344
+ }
345
+ this.formControl.setValue(arr[0] || null);
346
+ }
347
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldCardBack, deps: [{ token: i1._HttpClient }, { token: i2.NzMessageService }], target: i0.ɵɵFactoryTarget.Component });
348
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.15", type: DeonNzFieldCardBack, isStandalone: true, selector: "deon-nz-field-card-back", usesInheritance: true, ngImport: i0, template: "<nz-upload nzListType=\"picture-card\" [(nzFileList)]=\"fileList\" [nzShowButton]=\"fileList.length < maxCount\"\r\n [nzPreview]=\"handlePreview\" [nzBeforeUpload]=\"beforeUpload\" [nzCustomRequest]=\"uploadRequest\" [nzRemove]=\"remove\"\r\n nzAccept=\"image/*\" [nzMultiple]=\"isMultiple\">\r\n <div class=\"upload-empty-box\">\r\n <span nz-icon nzType=\"plus\"></span>\r\n <div style=\"margin-top: 8px\">\u70B9\u51FB\u4E0A\u4F20</div>\r\n </div>\r\n</nz-upload>\r\n\r\n<nz-modal [nzVisible]=\"previewVisible\" [nzFooter]=\"null\" (nzOnCancel)=\"previewVisible = false\">\r\n <img [src]=\"previewImage\" style=\"width: 100%\" />\r\n</nz-modal>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "ngmodule", type: FormlyModule }, { kind: "ngmodule", type: NzUploadModule }, { kind: "component", type: i3.NzUploadComponent, selector: "nz-upload", inputs: ["nzType", "nzLimit", "nzSize", "nzFileType", "nzAccept", "nzAction", "nzDirectory", "nzOpenFileDialogOnClick", "nzBeforeUpload", "nzCustomRequest", "nzData", "nzFilter", "nzFileList", "nzDisabled", "nzHeaders", "nzListType", "nzMultiple", "nzName", "nzShowUploadList", "nzShowButton", "nzWithCredentials", "nzRemove", "nzPreview", "nzPreviewFile", "nzPreviewIsImage", "nzTransformFile", "nzDownload", "nzIconRender", "nzFileListRender"], outputs: ["nzChange", "nzFileListChange"], exportAs: ["nzUpload"] }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i4.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzModalModule }, { kind: "component", type: i5.NzModalComponent, selector: "nz-modal", inputs: ["nzMask", "nzMaskClosable", "nzCloseOnNavigation", "nzVisible", "nzClosable", "nzOkLoading", "nzOkDisabled", "nzCancelDisabled", "nzCancelLoading", "nzKeyboard", "nzNoAnimation", "nzCentered", "nzDraggable", "nzContent", "nzFooter", "nzZIndex", "nzWidth", "nzWrapClassName", "nzClassName", "nzStyle", "nzTitle", "nzCloseIcon", "nzMaskStyle", "nzBodyStyle", "nzOkText", "nzCancelText", "nzOkType", "nzOkDanger", "nzIconType", "nzModalType", "nzAutofocus", "nzOnOk", "nzOnCancel"], outputs: ["nzOnOk", "nzOnCancel", "nzAfterOpen", "nzAfterClose", "nzVisibleChange"], exportAs: ["nzModal"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
349
+ }
350
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzFieldCardBack, decorators: [{
351
+ type: Component,
352
+ args: [{ selector: 'deon-nz-field-card-back', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
353
+ CommonModule,
354
+ ReactiveFormsModule,
355
+ FormlyModule,
356
+ NzUploadModule,
357
+ NzIconModule,
358
+ NzModalModule
359
+ ], template: "<nz-upload nzListType=\"picture-card\" [(nzFileList)]=\"fileList\" [nzShowButton]=\"fileList.length < maxCount\"\r\n [nzPreview]=\"handlePreview\" [nzBeforeUpload]=\"beforeUpload\" [nzCustomRequest]=\"uploadRequest\" [nzRemove]=\"remove\"\r\n nzAccept=\"image/*\" [nzMultiple]=\"isMultiple\">\r\n <div class=\"upload-empty-box\">\r\n <span nz-icon nzType=\"plus\"></span>\r\n <div style=\"margin-top: 8px\">\u70B9\u51FB\u4E0A\u4F20</div>\r\n </div>\r\n</nz-upload>\r\n\r\n<nz-modal [nzVisible]=\"previewVisible\" [nzFooter]=\"null\" (nzOnCancel)=\"previewVisible = false\">\r\n <img [src]=\"previewImage\" style=\"width: 100%\" />\r\n</nz-modal>", styles: [":host ::ng-deep .upload-empty-box{font-size:12px}:host ::ng-deep .ant-upload-list{display:inline-block}:host ::ng-deep .ant-upload-list-picture-card-container{width:80px;height:80px;margin:0 8px 8px 0}:host ::ng-deep .ant-upload.ant-upload-select-picture-card{width:80px;height:80px}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item{width:80px;height:80px;padding:0}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail{width:100%;height:100%}:host ::ng-deep .ant-upload-list-picture-card .ant-upload-list-item-thumbnail img{width:100%;height:100%;object-fit:cover}:host ::ng-deep .ant-upload-list-item-name{font-size:12px}:host ::ng-deep .ant-upload-list-item-uploading{font-size:12px}:host ::ng-deep .ant-upload-list-item-progress{font-size:12px}\n"] }]
360
+ }], ctorParameters: () => [{ type: i1._HttpClient }, { type: i2.NzMessageService }] });
361
+
362
+ function withFormlyFieldIdCard() {
363
+ return {
364
+ types: [
365
+ {
366
+ name: 'card_front',
367
+ component: DeonNzFieldCardFront,
368
+ wrappers: ['formly-form-field'],
369
+ },
370
+ {
371
+ name: 'card_back',
372
+ component: DeonNzFieldCardBack,
373
+ wrappers: ['formly-form-field'],
374
+ }
375
+ ],
376
+ };
377
+ }
378
+
379
+ class DeonNzIdCardModule {
380
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzIdCardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
381
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: DeonNzIdCardModule, imports: [CommonModule,
382
+ DeonNzFormFieldModule, i1$1.FormlyModule] });
383
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzIdCardModule, imports: [CommonModule,
384
+ DeonNzFormFieldModule,
385
+ FormlyModule.forChild(withFormlyFieldIdCard())] });
386
+ }
387
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: DeonNzIdCardModule, decorators: [{
388
+ type: NgModule,
389
+ args: [{
390
+ imports: [
391
+ CommonModule,
392
+ DeonNzFormFieldModule,
393
+ FormlyModule.forChild(withFormlyFieldIdCard()),
394
+ ],
395
+ }]
396
+ }] });
397
+
398
+ /**
399
+ * Generated bundle index. Do not edit.
400
+ */
401
+
402
+ export { DeonNzFieldCardBack, DeonNzFieldCardFront, DeonNzIdCardModule, withFormlyFieldIdCard };
403
+ //# sourceMappingURL=type.idCard.mjs.map