@dhccmobile/vue3-lo-form 1.1.41 → 2.0.0

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.
Files changed (165) hide show
  1. package/.env.local.bak +6 -6
  2. package/.eslintrc.js +28 -28
  3. package/README.md +70 -62
  4. package/babel.config.js +3 -3
  5. package/dist/vue3-lo-form.common.js +7700 -107778
  6. package/dist/vue3-lo-form.common.js.map +1 -1
  7. package/dist/vue3-lo-form.css +1 -1
  8. package/dist/vue3-lo-form.umd.js +7773 -107851
  9. package/dist/vue3-lo-form.umd.js.map +1 -1
  10. package/dist/vue3-lo-form.umd.min.js +1 -56
  11. package/dist/vue3-lo-form.umd.min.js.map +1 -1
  12. package/package.json +65 -61
  13. package/public/index.html +17 -17
  14. package/public/js/pinyin.ts +101 -101
  15. package/src/App.vue +741 -741
  16. package/src/components/form/DvForm.vue +642 -642
  17. package/src/components/form/DvFormLayout.vue +1569 -1569
  18. package/src/components/form/StretchText.vue +90 -90
  19. package/src/components/index.ts +3 -3
  20. package/src/constants/config/form-template.config.ts +32 -32
  21. package/src/constants/config/form.config.ts +4 -4
  22. package/src/constants/config/storage.config.ts +4 -4
  23. package/src/constants/encode-assets/svg.ts +11 -11
  24. package/src/constants/enum/builtIn-label.enum.ts +5 -5
  25. package/src/constants/enum/cache-type.enum.ts +7 -7
  26. package/src/constants/enum/control-format-type.enum.ts +9 -9
  27. package/src/constants/enum/dynamic-option-type.enum.ts +6 -6
  28. package/src/constants/enum/form-bus-attr.enum.ts +8 -8
  29. package/src/constants/enum/form-field-class.enum.ts +7 -7
  30. package/src/constants/enum/form-field-type.enum.ts +25 -25
  31. package/src/constants/enum/form-type.enum.ts +5 -5
  32. package/src/constants/enum/index.ts +19 -19
  33. package/src/constants/enum/lateral-arrangement.enum.ts +9 -9
  34. package/src/constants/enum/money-unit.enum.ts +6 -6
  35. package/src/constants/enum/option-type.enum.ts +5 -5
  36. package/src/constants/enum/submitted-type.enum.ts +32 -31
  37. package/src/constants/enum/support-upload-type.enum.ts +5 -5
  38. package/src/constants/enum/switch.enum.ts +5 -5
  39. package/src/constants/enum/upload-type.enum.ts +17 -17
  40. package/src/constants/enum/validate-rules.enum.ts +25 -25
  41. package/src/constants/enum/validate-status.enum.ts +8 -8
  42. package/src/constants/enum/vertical-arrangement.enum.ts +7 -7
  43. package/src/constants/enum/zoom-type.ts +6 -6
  44. package/src/constants/index.ts +3 -3
  45. package/src/core/FormApi.ts +1238 -1238
  46. package/src/core/index.ts +1 -1
  47. package/src/domain/AbstractControl.ts +6 -6
  48. package/src/domain/Control.ts +14 -14
  49. package/src/domain/CustomFormat.ts +6 -6
  50. package/src/domain/DesForm.ts +48 -48
  51. package/src/domain/DesFormControl.ts +241 -241
  52. package/src/domain/DesFormLayout.ts +51 -51
  53. package/src/domain/FieldChangeHistory.ts +9 -9
  54. package/src/domain/FormConfig.ts +15 -15
  55. package/src/domain/FormControl.ts +125 -125
  56. package/src/domain/FormEnum.ts +9 -9
  57. package/src/domain/FormGroup.ts +42 -42
  58. package/src/domain/FormRestfulResponse.ts +6 -6
  59. package/src/domain/ProvideInjectData.ts +10 -10
  60. package/src/domain/SysDictDetail.ts +38 -38
  61. package/src/domain/SysDictInfo.ts +40 -40
  62. package/src/domain/SysDictTreeDetail.ts +52 -52
  63. package/src/domain/index.ts +12 -12
  64. package/src/filtres/amount-capitalization.filter.ts +154 -147
  65. package/src/filtres/extract-options.filter.ts +53 -53
  66. package/src/filtres/generate-grid-column-end.filter.ts +22 -22
  67. package/src/filtres/generate-grid-template-columns.filter.ts +24 -24
  68. package/src/filtres/switch-enum-convert.filter.ts +18 -18
  69. package/src/filtres/zoom-multiple.filter.ts +32 -32
  70. package/src/index.ts +73 -73
  71. package/src/main.ts +17 -17
  72. package/src/services/api.service.ts +73 -73
  73. package/src/services/clean-local-forage.service.ts +58 -58
  74. package/src/services/date-format.service.ts +74 -74
  75. package/src/services/dict-local-forage.service.ts +58 -58
  76. package/src/services/form-bean-utils.service.ts +41 -41
  77. package/src/services/form-local-forage.service.ts +59 -59
  78. package/src/services/form-tools.service.ts +739 -659
  79. package/src/services/form-tree-node-convert.service.ts +240 -240
  80. package/src/services/form-validate.service.ts +103 -103
  81. package/src/services/index.ts +9 -9
  82. package/src/services/router.service.ts +96 -96
  83. package/src/services/validate-generator.service.ts +710 -710
  84. package/src/shims-vue.d.ts +6 -6
  85. package/src/store/dict.store.ts +63 -63
  86. package/src/store/form.store.ts +32 -32
  87. package/src/store/index.ts +2 -2
  88. package/src/styles/datePicker.scss +125 -125
  89. package/src/styles/index.scss +195 -195
  90. package/src/styles/theme1.scss +277 -277
  91. package/src/styles/theme2.scss +376 -376
  92. package/src/styles/themes.scss +9 -9
  93. package/src/types/vfForm.ts +11 -11
  94. package/tsconfig.json +40 -40
  95. package/types/components/index.d.ts +3 -3
  96. package/types/constants/config/form-template.config.d.ts +30 -30
  97. package/types/constants/config/form.config.d.ts +4 -4
  98. package/types/constants/config/storage.config.d.ts +4 -4
  99. package/types/constants/encode-assets/svg.d.ts +5 -5
  100. package/types/constants/enum/builtIn-label.enum.d.ts +7 -7
  101. package/types/constants/enum/cache-type.enum.d.ts +15 -15
  102. package/types/constants/enum/control-format-type.enum.d.ts +23 -23
  103. package/types/constants/enum/dynamic-option-type.enum.d.ts +11 -11
  104. package/types/constants/enum/form-bus-attr.enum.d.ts +19 -19
  105. package/types/constants/enum/form-field-class.enum.d.ts +18 -18
  106. package/types/constants/enum/form-field-type.enum.d.ts +111 -111
  107. package/types/constants/enum/form-type.enum.d.ts +11 -11
  108. package/types/constants/enum/index.d.ts +19 -19
  109. package/types/constants/enum/lateral-arrangement.enum.d.ts +23 -23
  110. package/types/constants/enum/money-unit.enum.d.ts +15 -15
  111. package/types/constants/enum/option-type.enum.d.ts +11 -11
  112. package/types/constants/enum/submitted-type.enum.d.ts +115 -111
  113. package/types/constants/enum/support-upload-type.enum.d.ts +11 -11
  114. package/types/constants/enum/switch.enum.d.ts +11 -11
  115. package/types/constants/enum/upload-type.enum.d.ts +59 -59
  116. package/types/constants/enum/validate-rules.enum.d.ts +2 -2
  117. package/types/constants/enum/validate-status.enum.d.ts +2 -2
  118. package/types/constants/enum/vertical-arrangement.enum.d.ts +21 -21
  119. package/types/constants/enum/zoom-type.d.ts +15 -15
  120. package/types/constants/index.d.ts +3 -3
  121. package/types/core/FormApi.d.ts +376 -376
  122. package/types/core/index.d.ts +1 -1
  123. package/types/domain/AbstractControl.d.ts +5 -5
  124. package/types/domain/Control.d.ts +13 -13
  125. package/types/domain/CustomFormat.d.ts +5 -5
  126. package/types/domain/DesForm.d.ts +32 -32
  127. package/types/domain/DesFormControl.d.ts +160 -160
  128. package/types/domain/DesFormLayout.d.ts +33 -33
  129. package/types/domain/FieldChangeHistory.d.ts +9 -9
  130. package/types/domain/FormConfig.d.ts +15 -15
  131. package/types/domain/FormControl.d.ts +60 -60
  132. package/types/domain/FormEnum.d.ts +10 -10
  133. package/types/domain/FormGroup.d.ts +27 -27
  134. package/types/domain/FormRestfulResponse.d.ts +6 -6
  135. package/types/domain/ProvideInjectData.d.ts +10 -10
  136. package/types/domain/SysDictDetail.d.ts +24 -24
  137. package/types/domain/SysDictInfo.d.ts +26 -26
  138. package/types/domain/SysDictTreeDetail.d.ts +34 -34
  139. package/types/domain/index.d.ts +12 -12
  140. package/types/filtres/amount-capitalization.filter.d.ts +7 -7
  141. package/types/filtres/extract-options.filter.d.ts +13 -13
  142. package/types/filtres/generate-grid-column-end.filter.d.ts +11 -11
  143. package/types/filtres/generate-grid-template-columns.filter.d.ts +11 -11
  144. package/types/filtres/switch-enum-convert.filter.d.ts +2 -2
  145. package/types/filtres/zoom-multiple.filter.d.ts +3 -3
  146. package/types/index.d.ts +13 -13
  147. package/types/main.d.ts +2 -2
  148. package/types/services/api.service.d.ts +25 -25
  149. package/types/services/clean-local-forage.service.d.ts +28 -28
  150. package/types/services/date-format.service.d.ts +21 -21
  151. package/types/services/dict-local-forage.service.d.ts +28 -28
  152. package/types/services/form-bean-utils.service.d.ts +23 -23
  153. package/types/services/form-local-forage.service.d.ts +28 -28
  154. package/types/services/form-tools.service.d.ts +153 -144
  155. package/types/services/form-tree-node-convert.service.d.ts +104 -104
  156. package/types/services/form-validate.service.d.ts +32 -32
  157. package/types/services/index.d.ts +9 -9
  158. package/types/services/router.service.d.ts +40 -40
  159. package/types/services/validate-generator.service.d.ts +154 -154
  160. package/types/store/dict.store.d.ts +29 -29
  161. package/types/store/form.store.d.ts +17 -17
  162. package/types/store/index.d.ts +2 -2
  163. package/types/types/vfForm.d.ts +10 -10
  164. package/vue.config.js +38 -29
  165. package/dhccmobile-vue3-lo-form-1.1.41.tgz +0 -0
@@ -1,659 +1,739 @@
1
- import { FormConfig } from "../domain/FormConfig";
2
- import { FormRestfulResponse } from "../domain/FormRestfulResponse";
3
- import { DesForm } from "../domain/DesForm";
4
- import { DesFormControl } from "../domain/DesFormControl";
5
- import { DesFormLayout } from "../domain/DesFormLayout";
6
- import { FormFieldClass } from "../constants/enum/form-field-class.enum";
7
- import { Control } from "../domain/Control";
8
- import { FormFieldType } from "../constants/enum/form-field-type.enum";
9
- import { Switch } from "../constants/enum/switch.enum";
10
- import { formTreeNodeConvertService, MapNodeOptions, NodeContrast, NzNodeContrast, NzTreeNodeOptions } from "./form-tree-node-convert.service";
11
- import { formBeanUtilsService } from "./form-bean-utils.service";
12
- import { apiService } from "./api.service";
13
- import { formStore } from "../store/form.store";
14
- import { DynamicOptionType } from "../constants/enum/dynamic-option-type.enum";
15
- import { dictStore } from "../store";
16
- import { SysDictInfo } from "../domain/SysDictInfo";
17
- import { DEFAULT_DICT_URL, DEFAULT_FORM_FILE_NAME } from "../constants/config/form.config";
18
- import { CacheType } from "../constants/enum/cache-type.enum";
19
- import { routerService } from "./router.service";
20
- import { FormApi } from "../core/FormApi";
21
- import { formValidateService } from "./form-validate.service";
22
-
23
- interface DictionaryFormatCollection {
24
- sysDictDetailOptions?: NzTreeNodeOptions[];
25
- sysDictTreeDetailOptions?: NzTreeNodeOptions[];
26
- mapSysDictDetailOptions?: MapNodeOptions;
27
- mapSysDictTreeDetailOptions?: MapNodeOptions;
28
- }
29
-
30
- class FormToolsService {
31
- private static readonly LOAD_SUCCESS = { code: 1, msg: "加载成功" }; // 操作成功提示
32
- private static readonly LOAD_FAIL = { code: 1, msg: "加载失败" }; // 操作失败提示
33
- private static IS_FIRST_LOADED = false; // 是否经过首次初始化
34
- private nodeContrast: NodeContrast = { id: "layoutId", parentId: "parentLayoutId", children: "subDesFormLayout" };
35
- private dictDetailsContrast: NodeContrast = { id: "dicEntryPk", parentId: "suprDicPk", children: "children" };
36
- private nzDictDetailsContrastContrast: NzNodeContrast = { key: "dicEntryPk", title: "dicValue", children: "children", value: "dicKey" };
37
- private dictTreeDetailsContrast: NodeContrast = { id: "dicEntryPk", parentId: "suprDicPk", children: "children" };
38
- private nzDictTreeDetailsContrastContrast: NzNodeContrast = { key: "dicEntryPk", title: "dicValue", children: "children", value: "dicKey" };
39
- private desForms: DesForm[] = []; // 表单配置缓存
40
-
41
- sysDictDetailOptions: NzTreeNodeOptions[] = [];
42
- sysDictTreeDetailOptions: NzTreeNodeOptions[] = [];
43
- mapSysDictDetailOptions: MapNodeOptions | undefined;
44
- mapSysDictTreeDetailOptions: MapNodeOptions | undefined;
45
-
46
- constructor() {}
47
-
48
- get formConfig(): Partial<FormConfig> {
49
- if ((window as any).$app.config.globalProperties.$qlForm != null) {
50
- return (window as any).$app.config.globalProperties.$qlForm;
51
- }
52
- return {};
53
- }
54
-
55
- /**
56
- * @description: 检查是否经过首次初始化并初始化
57
- * @author ChenRui
58
- * @date 2021/1/5 23:04
59
- */
60
- checkFirstLoadAndInitDesign(): Promise<FormRestfulResponse> {
61
- if (FormToolsService.IS_FIRST_LOADED) {
62
- return Promise.resolve({
63
- code: 1,
64
- msg: "检查到已经过首次加载,不在执行加载逻辑",
65
- });
66
- } else {
67
- return this.init().then((res: FormRestfulResponse) => {
68
- FormToolsService.IS_FIRST_LOADED = true;
69
- return res;
70
- });
71
- }
72
- }
73
-
74
- /**
75
- * @description: 初始化
76
- * @author ChenRui
77
- * @date 2021/3/12 11:02
78
- */
79
- init(): Promise<FormRestfulResponse> {
80
- return Promise.all([this.initDesign(), this.initDict(), this.selectHolidays()]).then(([designRes, dictRes]: any) => {
81
- const code = designRes.code === 1 && dictRes.code === 1 ? 1 : 0;
82
- return { code, msg: designRes.msg + "; " + dictRes.msg };
83
- });
84
- }
85
-
86
- /**
87
- * @Description 初始化节假日数据
88
- * @Author JiangTao
89
- * @Date 2024-04-16 下午 04:11
90
- */
91
- selectHolidays(): Promise<FormRestfulResponse> {
92
- if (this.formConfig.url) {
93
- const url = this.formConfig.url + "/ms-loong/api/v1/basic-form-weekday/query-all-by-year";
94
- return this.fetch(url, {}, undefined, "POST").then((res: FormRestfulResponse) => {
95
- if (res != null && (res.code === 1 || String(res.code) === String(200))) {
96
- if (res.data != null) {
97
- localStorage.setItem("traddayList", JSON.stringify(res.data.traddayList)); // 交易日集合
98
- localStorage.setItem("weekdayList", JSON.stringify(res.data.weekdayList)); // 节假日集合
99
- localStorage.setItem("workdayList", JSON.stringify(res.data.workdayList)); // 工作日集合
100
- }
101
- }
102
- return Promise.resolve(FormToolsService.LOAD_SUCCESS);
103
- });
104
- }
105
- return Promise.resolve(FormToolsService.LOAD_SUCCESS);
106
- }
107
-
108
- /**
109
- * @description: 初始化表单设计
110
- * @author ChenRui
111
- * @date 2020/11/20 10:55
112
- */
113
- initDesign(): Promise<FormRestfulResponse> {
114
- return Promise.all([formStore.getForms(), formStore.getVersion()]).then(([forms, formVersion]: any[]) => {
115
- if (this.formConfig.loadMode === "static") {
116
- if (forms != null) {
117
- this.desForms = forms;
118
- return Promise.resolve(FormToolsService.LOAD_SUCCESS);
119
- } else {
120
- return this.loadDesign([this.formConfig.url || DEFAULT_FORM_FILE_NAME]);
121
- }
122
- } else if (this.formConfig.loadMode === "dynamic") {
123
- if (this.formConfig.appId != null && this.formConfig.appId !== "") {
124
- const query = {
125
- appId: this.formConfig.appId,
126
- cacheType: CacheType.FORM.code,
127
- };
128
- const url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-cacheversion-by-appid-cachetype";
129
- return this.fetch(url!, query).then((res: FormRestfulResponse) => {
130
- if (res != null && res.code === 1) {
131
- if (res.data != null && res.data.desCacheVersion != null) {
132
- if (String(formVersion) !== String(res.data.desCacheVersion.cacheVersionNumber)) {
133
- const formUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + res.data.desCacheVersion.storageAddress;
134
- return this.loadDesign([formUrl]).then((resEx: FormRestfulResponse) => {
135
- if (resEx.code === 1) {
136
- formStore.setVersion(res.data.desCacheVersion.cacheVersionNumber);
137
- }
138
- return resEx;
139
- });
140
- } else {
141
- if (forms != null) {
142
- this.desForms = forms;
143
- }
144
- console.log(this.desForms);
145
- return Promise.resolve(FormToolsService.LOAD_SUCCESS);
146
- }
147
- } else {
148
- return Promise.resolve({ code: 1, msg: "暂无版本数据" });
149
- }
150
- } else {
151
- return Promise.resolve(FormToolsService.LOAD_FAIL);
152
- }
153
- });
154
- } else {
155
- return Promise.resolve({
156
- code: 0,
157
- msg: "动态加载需指定当前系统编号(appId)",
158
- });
159
- }
160
- } else if (this.formConfig.loadMode === "merge") {
161
- if (this.formConfig.urls) {
162
- return new Promise((resolve) => {
163
- this.loadDesign(this.formConfig.urls || []).then(() => {
164
- resolve(FormToolsService.LOAD_SUCCESS);
165
- });
166
- });
167
- } else {
168
- return this.mergeUrlByType(CacheType.FORM.code).then((response: any) => {
169
- if (formVersion === response.cacheVersionNumber) {
170
- if (forms) {
171
- this.desForms = forms;
172
- }
173
- return Promise.resolve(FormToolsService.LOAD_SUCCESS);
174
- } else {
175
- return new Promise((resolve) => {
176
- this.loadDesign(response.storageAddress).then(() => {
177
- formStore.setVersion(response.cacheVersionNumber);
178
- resolve(FormToolsService.LOAD_SUCCESS);
179
- });
180
- });
181
- }
182
- });
183
- }
184
- }
185
- return Promise.resolve(FormToolsService.LOAD_FAIL);
186
- });
187
- }
188
-
189
- /**
190
- * @description: 获取表单或字典数据地址
191
- * @author ZPFly
192
- * @date 2022/10/18 20:43
193
- */
194
- private mergeUrlByType(type: string): Promise<any> {
195
- const url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-batch-appids-cachetype";
196
- const downloadUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=";
197
- const query = {
198
- appIds: this.formConfig.appId,
199
- cacheType: type,
200
- };
201
- return this.fetch(url!, query).then((resp: any) => {
202
- const response: any = {};
203
- const address: string[] = [];
204
- const cacheVersionNumber: any[] = [];
205
- const cacheVersionMap: any = {};
206
- resp?.data?.forEach((item: any) => {
207
- // 数据下载地址
208
- if (item.cacheType == type && item.desCacheVersion?.storageAddress && query.appIds && query.appIds.indexOf(item.appId) > -1) {
209
- cacheVersionMap[item.appId] = item.desCacheVersion.cacheVersionNumber;
210
- address.push(downloadUrl + item.desCacheVersion.storageAddress);
211
- }
212
- });
213
- query.appIds?.split(",").forEach((appId) => {
214
- cacheVersionNumber.push(cacheVersionMap[appId]);
215
- });
216
- response.cacheVersionNumber = cacheVersionNumber.join(",");
217
- response.storageAddress = address;
218
- return response;
219
- });
220
- }
221
-
222
- /**
223
- * @description: 加载远程表单配置
224
- * @author ChenRui
225
- * @date 2020/11/20 17:30
226
- */
227
- private loadDesign(urls: string[]): Promise<FormRestfulResponse> {
228
- return this.mergeFetchDesign(urls).then((desForms: DesForm[]) => {
229
- const newDesForms: DesForm[] = [];
230
- if (desForms != null && desForms.length > 0) {
231
- desForms
232
- .filter((item) => item.desFormLayouts != null && item.desFormLayouts.length > 0)
233
- .forEach((item) => {
234
- const newDesForm: DesForm | undefined = this.formatDesForm(item);
235
- if (newDesForm != null) {
236
- newDesForms.push(newDesForm);
237
- }
238
- });
239
- }
240
- this.desForms = newDesForms;
241
- formStore.setForms(this.desForms);
242
- return FormToolsService.LOAD_SUCCESS;
243
- });
244
- }
245
-
246
- /**
247
- * @description: 合并多个应用表单
248
- * @author ZPFly
249
- * @date 2022/10/17 15:39
250
- */
251
- private mergeFetchDesign(urls: string[]) {
252
- const onlySimpleLoadConfig = !!this.formConfig.onlySimpleLoadConfig;
253
- const headers = this.createFileDownloadAuthorizationHeader();
254
- const fetches: any = [];
255
- urls.forEach((url: string) => {
256
- fetches.push(this.fetch(url, {}, undefined, "GET", headers, onlySimpleLoadConfig));
257
- });
258
- return Promise.all(fetches).then((desForms: DesForm[]) => {
259
- let newDesForms: DesForm[] = [];
260
- desForms?.forEach((desForm: any) => {
261
- newDesForms = newDesForms.concat(desForm);
262
- });
263
- return newDesForms;
264
- });
265
- }
266
-
267
- /**
268
- * @description: 初始化字典
269
- * @author ChenRui
270
- * @date 2021/3/11 14:32
271
- */
272
- initDict(): Promise<FormRestfulResponse> {
273
- return Promise.all([dictStore.getDicts(), dictStore.getTreeDicts(), dictStore.getMapDicts(), dictStore.getMapTreeDicts(), dictStore.getVersion()]).then(([dicts, treeDicts, mapDicts, mapTreeDicts, dictVersion]: any[]) => {
274
- if (this.formConfig.loadMode === "static") {
275
- const url = this.formConfig.dictUrl ? this.formConfig.dictUrl : DEFAULT_DICT_URL;
276
- if (dicts != null || treeDicts != null) {
277
- this.sysDictDetailOptions = dicts;
278
- this.sysDictTreeDetailOptions = treeDicts;
279
- this.mapSysDictDetailOptions = mapDicts;
280
- this.mapSysDictTreeDetailOptions = mapTreeDicts;
281
- return FormToolsService.LOAD_SUCCESS;
282
- } else {
283
- return this.loadDict([url]);
284
- }
285
- } else if (this.formConfig.loadMode === "dynamic") {
286
- if (this.formConfig.appId) {
287
- const url1 = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-cacheversion-by-appid-cachetype";
288
- const url: string = this.formConfig.dictUrl ? this.formConfig.dictUrl : url1 || "";
289
- const path: string = routerService.getPathFromUrl(url);
290
- let query: any = routerService.getParamsFromUrl(url) || {};
291
- query.appId = query.appId ? query.appId : this.formConfig.appId;
292
- query.cacheType = query.cacheType ? query.cacheType : CacheType.DICT.code;
293
- query = this.formConfig.dictRestLoadOnlyBody ? {} : query;
294
- const body: any = (this.formConfig.dictRestLoadMode || "GET").toLocaleUpperCase() === "GET" ? undefined : this.formConfig.dictRestLoadBody;
295
- let headers: any = this.formConfig.dictRestLoadHeaders;
296
- if (headers != null && typeof headers === "function") {
297
- headers = (headers as any)();
298
- }
299
- return this.fetch(path, query, body, this.formConfig.dictRestLoadMode, headers).then((res: FormRestfulResponse) => {
300
- if (res != null && (res.code === 1 || String(res.code) === String(200))) {
301
- if (res.data != null) {
302
- let desCacheVersion: any = res.data.desCacheVersion;
303
- if (res.data && res.data instanceof Array && res.data.length > 0) {
304
- desCacheVersion = res.data[0].desCacheVersion;
305
- }
306
- const distUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + desCacheVersion.storageAddress;
307
- if (String(dictVersion) !== String(desCacheVersion.cacheVersionNumber)) {
308
- return this.loadDict([distUrl]).then((resEx: FormRestfulResponse) => {
309
- if (resEx.code === 1) {
310
- dictStore.setVersion(desCacheVersion.cacheVersionNumber);
311
- }
312
- return resEx;
313
- });
314
- } else {
315
- if (dicts != null || treeDicts != null) {
316
- this.sysDictDetailOptions = dicts;
317
- this.sysDictTreeDetailOptions = treeDicts;
318
- this.mapSysDictDetailOptions = mapDicts;
319
- this.mapSysDictTreeDetailOptions = mapTreeDicts;
320
- }
321
- return FormToolsService.LOAD_SUCCESS;
322
- }
323
- } else {
324
- return { code: 1, msg: "暂无版本数据" };
325
- }
326
- } else {
327
- return FormToolsService.LOAD_FAIL;
328
- }
329
- });
330
- } else {
331
- return { code: 0, msg: "动态加载需指定当前系统编号(appId)" };
332
- }
333
- } else if (this.formConfig.loadMode === "merge") {
334
- return this.mergeUrlByType(CacheType.DICT.code).then((response: any) => {
335
- if (dictVersion === response.cacheVersionNumber) {
336
- if (dicts != null || treeDicts != null) {
337
- this.sysDictDetailOptions = dicts;
338
- this.sysDictTreeDetailOptions = treeDicts;
339
- this.mapSysDictDetailOptions = mapDicts;
340
- this.mapSysDictTreeDetailOptions = mapTreeDicts;
341
- }
342
- return FormToolsService.LOAD_SUCCESS;
343
- } else {
344
- return new Promise((resolve) => {
345
- this.loadDict(response.storageAddress).then(() => {
346
- dictStore.setVersion(response.cacheVersionNumber);
347
- resolve(FormToolsService.LOAD_SUCCESS);
348
- });
349
- });
350
- }
351
- });
352
- }
353
- return FormToolsService.LOAD_FAIL;
354
- });
355
- }
356
-
357
- /**
358
- * @description: 加载远程字典配置
359
- * @author ChenRui
360
- * @date 2020/11/20 17:30
361
- */
362
- private loadDict(urls: string[]): Promise<FormRestfulResponse> {
363
- return this.mergeFetchDict(urls).then((sysDictInfos: any) => {
364
- if (sysDictInfos != null) {
365
- // 数据格式化
366
- const dictionaryFormatCollection: DictionaryFormatCollection = this.inidDictOptions(sysDictInfos);
367
- this.sysDictDetailOptions = dictionaryFormatCollection.sysDictDetailOptions || [];
368
- this.sysDictTreeDetailOptions = dictionaryFormatCollection.sysDictTreeDetailOptions || [];
369
- this.mapSysDictDetailOptions = dictionaryFormatCollection.mapSysDictDetailOptions;
370
- this.mapSysDictTreeDetailOptions = dictionaryFormatCollection.mapSysDictTreeDetailOptions;
371
- // 字典本地存储
372
- if (dictionaryFormatCollection.sysDictDetailOptions && dictionaryFormatCollection.sysDictDetailOptions.length > 0) {
373
- dictStore.setDicts(dictionaryFormatCollection.sysDictDetailOptions);
374
- }
375
- if (dictionaryFormatCollection.sysDictTreeDetailOptions && dictionaryFormatCollection.sysDictTreeDetailOptions.length > 0) {
376
- dictStore.setTreeDicts(dictionaryFormatCollection.sysDictTreeDetailOptions);
377
- }
378
- dictStore.setMapDicts(dictionaryFormatCollection.mapSysDictDetailOptions || null);
379
- dictStore.setMapTreeDicts(dictionaryFormatCollection.mapSysDictTreeDetailOptions || null);
380
- }
381
- return FormToolsService.LOAD_SUCCESS;
382
- });
383
- // const onlySimpleLoadConfig = !!this.formConfig.onlySimpleLoadConfig;
384
- // let sysDictInfos: SysDictInfo[] = [];
385
- // if (loadMode === "dynamic") {
386
- // const headers = this.createFileDownloadAuthorizationHeader();
387
- // url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + url;
388
- // return this.fetch(url, {}, undefined, "GET", headers, onlySimpleLoadConfig).then((res: any) => {
389
- // sysDictInfos = res;
390
- // if (sysDictInfos != null && sysDictInfos.length > 0) {
391
- // // 数据格式化
392
- // const dictionaryFormatCollection: DictionaryFormatCollection = this.inidDictOptions(sysDictInfos);
393
- // this.sysDictDetailOptions = dictionaryFormatCollection.sysDictDetailOptions || [];
394
- // this.sysDictTreeDetailOptions = dictionaryFormatCollection.sysDictTreeDetailOptions || [];
395
- // this.mapSysDictDetailOptions = dictionaryFormatCollection.mapSysDictDetailOptions;
396
- // this.mapSysDictTreeDetailOptions = dictionaryFormatCollection.mapSysDictTreeDetailOptions;
397
- // // 字典本地存储
398
- // if (dictionaryFormatCollection.sysDictDetailOptions && dictionaryFormatCollection.sysDictDetailOptions.length > 0) {
399
- // dictStore.setDicts(dictionaryFormatCollection.sysDictDetailOptions);
400
- // }
401
- // if (dictionaryFormatCollection.sysDictTreeDetailOptions && dictionaryFormatCollection.sysDictTreeDetailOptions.length > 0) {
402
- // dictStore.setTreeDicts(dictionaryFormatCollection.sysDictTreeDetailOptions);
403
- // }
404
- // dictStore.setMapDicts(dictionaryFormatCollection.mapSysDictDetailOptions || null);
405
- // dictStore.setMapTreeDicts(dictionaryFormatCollection.mapSysDictTreeDetailOptions || null);
406
- // }
407
- // return FormToolsService.LOAD_SUCCESS;
408
- // });
409
- // }
410
- }
411
-
412
- /**
413
- * @description: 合并多个应用字典
414
- * @author ZPFly
415
- * @date 2022/10/17 15:39
416
- */
417
- private mergeFetchDict(dictUrl: string[]) {
418
- const fetchDicts: any = [];
419
- dictUrl.forEach((url: string) => {
420
- fetchDicts.push(this.fetch(url, {}, undefined, "GET", undefined, !!this.formConfig.onlySimpleLoadConfig));
421
- });
422
- return Promise.all(fetchDicts).then((dictInfos: SysDictInfo[]) => {
423
- let newDictInfos: SysDictInfo[] = [];
424
- const empObj: any = {};
425
- const filterDist: SysDictInfo[] = [];
426
- dictInfos?.forEach((desForm: any) => {
427
- newDictInfos = newDictInfos.concat(desForm);
428
- });
429
- // 去除重复字典
430
- newDictInfos.forEach((item: SysDictInfo) => {
431
- if (!empObj[item.dictId]) {
432
- filterDist.push(item);
433
- empObj[item.dictId] = true;
434
- }
435
- });
436
- return filterDist;
437
- });
438
- }
439
- /**
440
- * @description: 初始化字典可选项
441
- * @author ChenRui
442
- * @date 2020/11/10 20:38
443
- */
444
- public inidDictOptions(sysDictInfos: SysDictInfo[]): DictionaryFormatCollection {
445
- const sysDictDetailOptions: NzTreeNodeOptions[] = [];
446
- const sysDictTreeDetailOptions: NzTreeNodeOptions[] = [];
447
- sysDictInfos.forEach((sysDictInfo) => {
448
- const node: NzTreeNodeOptions = {
449
- key: sysDictInfo.dictId,
450
- value: sysDictInfo.dictCd,
451
- title: sysDictInfo.dictNm,
452
- isLeaf: true,
453
- expanded: false,
454
- children: [],
455
- };
456
- if (sysDictInfo.dictTp === DynamicOptionType.GeneralDictionary.code) {
457
- node.isLeaf = false;
458
- node.children = formTreeNodeConvertService.arrayConvertToNzTreeNode(
459
- sysDictInfo.comDictKeyValues.filter((it) => !!it.dictId),
460
- this.dictDetailsContrast,
461
- this.nzDictDetailsContrastContrast,
462
- true
463
- );
464
- sysDictDetailOptions.push(node);
465
- } else if (sysDictInfo.dictTp === DynamicOptionType.TreeDictionary.code) {
466
- if (sysDictInfo.treeDictKeyValues != null && sysDictInfo.treeDictKeyValues.length > 0) {
467
- node.isLeaf = false;
468
- sysDictInfo.treeDictKeyValues.forEach((item) => {
469
- if (item.suprDicPk === "0") {
470
- item.suprDicPk = "";
471
- }
472
- });
473
- node.children = formTreeNodeConvertService.arrayConvertToNzTreeNode(
474
- sysDictInfo.treeDictKeyValues.filter((it) => !!it.dictId),
475
- this.dictTreeDetailsContrast,
476
- this.nzDictTreeDetailsContrastContrast,
477
- true
478
- );
479
- }
480
- sysDictTreeDetailOptions.push(node);
481
- }
482
- });
483
- const mapNodeOptions: MapNodeOptions | undefined = formTreeNodeConvertService.nzTreeNodeConvertToMap(sysDictDetailOptions);
484
- const mapTreeNodeOptions: MapNodeOptions | undefined = formTreeNodeConvertService.nzTreeNodeConvertToMap(sysDictTreeDetailOptions);
485
- return {
486
- sysDictDetailOptions: sysDictDetailOptions,
487
- sysDictTreeDetailOptions: sysDictTreeDetailOptions,
488
- mapSysDictDetailOptions: mapNodeOptions,
489
- mapSysDictTreeDetailOptions: mapTreeNodeOptions,
490
- };
491
- }
492
-
493
- /**
494
- * @description: 格式化表单
495
- * @author ChenRui
496
- * @date 2020/11/30 15:48
497
- */
498
- formatDesForm(sourceDesForm: DesForm): DesForm | undefined {
499
- if (sourceDesForm != null) {
500
- const newDesForm: DesForm = new DesForm(sourceDesForm);
501
- const desFormLayouts: DesFormLayout[] = formTreeNodeConvertService.arrayConvertToTreeNode(sourceDesForm.desFormLayouts, this.nodeContrast);
502
- const controls = this.recursionFormatForm([], desFormLayouts);
503
- this.sortControls(controls);
504
- newDesForm.desFormLayouts = [];
505
- newDesForm.controls = controls;
506
- return newDesForm;
507
- }
508
- }
509
-
510
- /**
511
- * @description: 递归格式化
512
- * @author ChenRui
513
- * @date 2020/11/17 10:16
514
- */
515
- private recursionFormatForm(desFormControls: DesFormControl[], desFormLayouts: DesFormLayout[]): Control[] {
516
- const controls: Control[] = [];
517
- if (desFormControls != null && desFormControls.length > 0) {
518
- desFormControls
519
- .filter((item) => !!item.formFieldId)
520
- .forEach((desFormControl) => {
521
- const control: Control = {
522
- code: desFormControl.controlType,
523
- name: (Object.values(FormFieldType).find((item) => item.code === desFormControl.controlType) || {}).name || "",
524
- type: Number(desFormControl.controlType) < 50 ? FormFieldClass.Base.code : FormFieldClass.Senior.code,
525
- active: false,
526
- subControls: undefined,
527
- controlAttr: desFormControl,
528
- };
529
- const controlAttr = control.controlAttr as DesFormControl;
530
- controlAttr.isBoldTitle = desFormControl.isBoldTitle === Switch.Enable.code;
531
- controlAttr.isHideTitle = desFormControl.isHideTitle === Switch.Enable.code;
532
- controlAttr.isNotEdit = desFormControl.isNotEdit === Switch.Enable.code;
533
- controlAttr.isShowHoliday = desFormControl.isShowHoliday === Switch.Enable.code;
534
- controlAttr.isHideControl = desFormControl.isHideControl === Switch.Enable.code;
535
- controlAttr.isPasswordBox = desFormControl.isPasswordBox === Switch.Enable.code;
536
- controlAttr.enableAutoComplete = desFormControl.enableAutoComplete === Switch.Enable.code;
537
- controlAttr.isFixedRowHeight = desFormControl.isFixedRowHeight === Switch.Enable.code;
538
- controlAttr.thousandthPercentileFormat = desFormControl.thousandthPercentileFormat === Switch.Enable.code;
539
- controlAttr.isShowCapitalization = desFormControl.isShowCapitalization === Switch.Enable.code;
540
- controlAttr.isLineFeedDisplay = desFormControl.isLineFeedDisplay === Switch.Enable.code;
541
- controlAttr.optionConfig = formBeanUtilsService.parse(desFormControl.optionConfig);
542
- controlAttr.generalDictionaryOptions = formBeanUtilsService.parse(desFormControl.generalDictionaryOptions);
543
- controlAttr.treeShapeOptions = formBeanUtilsService.parse(desFormControl.treeShapeOptions);
544
- controlAttr.isSupportMultiple = desFormControl.isSupportMultiple === Switch.Enable.code;
545
- if (Array.isArray(desFormControl.customUploadType) && desFormControl.customUploadType.length > 0) {
546
- controlAttr.customUploadType = desFormControl.customUploadType.join(",");
547
- }
548
- controlAttr.isMultipleChoice = desFormControl.isMultipleChoice === Switch.Enable.code;
549
- controlAttr.isSearchable = desFormControl.isSearchable === Switch.Enable.code;
550
- controlAttr.canAddEntry = desFormControl.canAddEntry === Switch.Enable.code;
551
- controlAttr.isClearButton = desFormControl.isClearButton === Switch.Enable.code;
552
- controlAttr.hiddenDropdown = desFormControl.hiddenDropdown === Switch.Enable.code;
553
- controlAttr.textFold = desFormControl.textFold === Switch.Enable.code;
554
- controlAttr.verificationRules = formBeanUtilsService.parse(desFormControl.verificationRules);
555
- controls.push(control);
556
- });
557
- }
558
- if (desFormLayouts != null && desFormLayouts.length > 0) {
559
- desFormLayouts
560
- .filter((item) => !!item.layoutId)
561
- .forEach((desFormLayout) => {
562
- const layoutControl: Control = {
563
- code: desFormLayout.layoutType,
564
- name: (Object.values(FormFieldType).find((item) => item.code === desFormLayout.layoutType) || {}).name || "",
565
- type: FormFieldClass.Layout.code,
566
- active: false,
567
- subControls: [],
568
- controlAttr: new DesFormLayout(desFormLayout),
569
- };
570
- const controlAttr = layoutControl.controlAttr as DesFormLayout;
571
- controlAttr.gridColumnConfig = formBeanUtilsService.parse(desFormLayout.gridColumnConfig);
572
- controlAttr.desFormControls = [];
573
- controlAttr.subDesFormLayout = [];
574
- if ((desFormLayout.subDesFormLayout != null && desFormLayout.subDesFormLayout.length > 0) || (desFormLayout.desFormControls != null && desFormLayout.desFormControls.length > 0)) {
575
- layoutControl.subControls = this.recursionFormatForm(desFormLayout.desFormControls, desFormLayout.subDesFormLayout);
576
- }
577
- controls.push(layoutControl);
578
- });
579
- }
580
- return controls;
581
- }
582
-
583
- /**
584
- * @description: 控件排序
585
- * @author ChenRui
586
- * @date 2020/11/17 11:59
587
- */
588
- private sortControls(controls: Control[]): void {
589
- controls.sort((controlA, controlB) => {
590
- let x = 0;
591
- let y = 0;
592
- if (controlA.type === FormFieldClass.Layout.code) {
593
- x = Number((controlA.controlAttr as DesFormLayout).layoutOrder);
594
- } else {
595
- x = Number((controlA.controlAttr as DesFormControl).tableFieldOrder);
596
- }
597
- if (controlB.type === FormFieldClass.Layout.code) {
598
- y = Number((controlB.controlAttr as DesFormLayout).layoutOrder);
599
- } else {
600
- y = Number((controlB.controlAttr as DesFormControl).tableFieldOrder);
601
- }
602
- return x - y;
603
- });
604
- controls.forEach((item) => {
605
- if (item.subControls != null && item.subControls.length > 0) {
606
- this.sortControls(item.subControls);
607
- }
608
- });
609
- }
610
-
611
- /**
612
- * @description: 加载资源
613
- * @author ChenRui
614
- * @date 2020/11/23 11:00
615
- */
616
- loadResource(formId: string): DesForm {
617
- const desForm: DesForm | undefined = this.desForms.find((item) => item.formId === formId);
618
- if (desForm != null) {
619
- return formBeanUtilsService.copy(desForm);
620
- } else {
621
- return new DesForm({ formId: formId });
622
- }
623
- }
624
-
625
- /**
626
- * @description: rest客户端
627
- * @author ChenRui
628
- * @date 2020/11/19 21:02
629
- */
630
- private fetch(path: string, params: { [key: string]: any }, body?: any, method = "GET", headers?: any, simple = false): Promise<any> {
631
- headers = headers ? headers : apiService.createBasicHeaders();
632
- return simple ? fetch(path).then((response) => response.json()) : apiService.fetch(path, params, body, method, headers);
633
- }
634
-
635
- /**
636
- * @description: 校验提示
637
- * @author ChenRui
638
- * @date 2021/8/18 17:14
639
- */
640
- validateTips(formApis: FormApi | FormApi[], scrollView?: any): boolean {
641
- return formValidateService.validateTips(formApis, scrollView);
642
- }
643
-
644
- /**
645
- * @description: 创建认证下载消息头
646
- * @author ChenRui
647
- * @date 2020/8/28 15:18
648
- */
649
- createFileDownloadAuthorizationHeader() {
650
- return {
651
- headers: {
652
- "Content-Type": "application/json",
653
- },
654
- responseType: "blob",
655
- };
656
- }
657
- }
658
- const formToolsService: FormToolsService = new FormToolsService();
659
- export { formToolsService, FormToolsService, DictionaryFormatCollection };
1
+ import { FormConfig } from "../domain/FormConfig";
2
+ import { FormRestfulResponse } from "../domain/FormRestfulResponse";
3
+ import { DesForm } from "../domain/DesForm";
4
+ import { DesFormControl } from "../domain/DesFormControl";
5
+ import { DesFormLayout } from "../domain/DesFormLayout";
6
+ import { FormFieldClass } from "../constants/enum/form-field-class.enum";
7
+ import { Control } from "../domain/Control";
8
+ import { FormFieldType } from "../constants/enum/form-field-type.enum";
9
+ import { Switch } from "../constants/enum/switch.enum";
10
+ import { formTreeNodeConvertService, MapNodeOptions, NodeContrast, NzNodeContrast, NzTreeNodeOptions } from "./form-tree-node-convert.service";
11
+ import { formBeanUtilsService } from "./form-bean-utils.service";
12
+ import { apiService } from "./api.service";
13
+ import { formStore } from "../store/form.store";
14
+ import { DynamicOptionType } from "../constants/enum/dynamic-option-type.enum";
15
+ import { dictStore } from "../store";
16
+ import { SysDictInfo } from "../domain/SysDictInfo";
17
+ import { DEFAULT_DICT_URL, DEFAULT_FORM_FILE_NAME } from "../constants/config/form.config";
18
+ import { CacheType } from "../constants/enum/cache-type.enum";
19
+ import { routerService } from "./router.service";
20
+ import { FormApi } from "../core/FormApi";
21
+ import { formValidateService } from "./form-validate.service";
22
+
23
+ interface DictionaryFormatCollection {
24
+ sysDictDetailOptions?: NzTreeNodeOptions[];
25
+ sysDictTreeDetailOptions?: NzTreeNodeOptions[];
26
+ mapSysDictDetailOptions?: MapNodeOptions;
27
+ mapSysDictTreeDetailOptions?: MapNodeOptions;
28
+ }
29
+
30
+ class FormToolsService {
31
+ private static readonly LOAD_SUCCESS = { code: 1, msg: "加载成功" }; // 操作成功提示
32
+ private static readonly LOAD_FAIL = { code: 1, msg: "加载失败" }; // 操作失败提示
33
+ private static IS_FIRST_LOADED = false; // 是否经过首次初始化
34
+ private nodeContrast: NodeContrast = { id: "layoutId", parentId: "parentLayoutId", children: "subDesFormLayout" };
35
+ private dictDetailsContrast: NodeContrast = { id: "dicEntryPk", parentId: "suprDicPk", children: "children" };
36
+ private nzDictDetailsContrastContrast: NzNodeContrast = { key: "dicEntryPk", title: "dicValue", children: "children", value: "dicKey" };
37
+ private dictTreeDetailsContrast: NodeContrast = { id: "dicEntryPk", parentId: "suprDicPk", children: "children" };
38
+ private nzDictTreeDetailsContrastContrast: NzNodeContrast = { key: "dicEntryPk", title: "dicValue", children: "children", value: "dicKey" };
39
+ private desForms: DesForm[] = []; // 表单配置缓存
40
+
41
+ sysDictDetailOptions: NzTreeNodeOptions[] = [];
42
+ sysDictTreeDetailOptions: NzTreeNodeOptions[] = [];
43
+ mapSysDictDetailOptions: MapNodeOptions | undefined;
44
+ mapSysDictTreeDetailOptions: MapNodeOptions | undefined;
45
+
46
+ supHoliday?: boolean = false; // 节假日支持
47
+
48
+ constructor() {}
49
+
50
+ get formConfig(): Partial<FormConfig> {
51
+ if ((window as any).$app.config.globalProperties.$qlForm != null) {
52
+ return (window as any).$app.config.globalProperties.$qlForm;
53
+ }
54
+ return {};
55
+ }
56
+
57
+ setSupHoliday(bool: boolean) {
58
+ this.supHoliday = bool;
59
+ }
60
+
61
+ setFormDisabledColor(color = "#f0f0f0") {
62
+ document.body.style.setProperty("--lo-form-disabled", color);
63
+ }
64
+
65
+ /**
66
+ * @description: 检查是否经过首次初始化并初始化
67
+ * @author ChenRui
68
+ * @date 2021/1/5 23:04
69
+ */
70
+ checkFirstLoadAndInitDesign(): Promise<FormRestfulResponse> {
71
+ if (FormToolsService.IS_FIRST_LOADED) {
72
+ return Promise.resolve({
73
+ code: 1,
74
+ msg: "检查到已经过首次加载,不在执行加载逻辑",
75
+ });
76
+ } else {
77
+ return this.init().then((res: FormRestfulResponse) => {
78
+ FormToolsService.IS_FIRST_LOADED = true;
79
+ return res;
80
+ });
81
+ }
82
+ }
83
+
84
+ /**
85
+ * @description: 初始化
86
+ * @author ChenRui
87
+ * @date 2021/3/12 11:02
88
+ */
89
+ init(): Promise<FormRestfulResponse> {
90
+ return Promise.all([this.initDesign(), this.initDict(), this.selectHolidays()]).then(([designRes, dictRes]: any) => {
91
+ const code = designRes.code === 1 && dictRes.code === 1 ? 1 : 0;
92
+ return { code, msg: designRes.msg + "; " + dictRes.msg };
93
+ });
94
+ }
95
+
96
+ /**
97
+ * @Description 初始化节假日数据
98
+ * @Author JiangTao
99
+ * @Date 2024-04-16 下午 04:11
100
+ */
101
+ selectHolidays(): Promise<FormRestfulResponse> {
102
+ if (this.formConfig.url && this.supHoliday) {
103
+ const url = this.formConfig.url + "/ms-loong/api/v1/basic-form-weekday/query-all-by-year";
104
+ return this.fetch(url, {}, undefined, "POST").then((res: FormRestfulResponse) => {
105
+ if (res != null && (res.code === 1 || String(res.code) === String(200))) {
106
+ if (res.data != null) {
107
+ localStorage.setItem("traddayList", JSON.stringify(res.data.traddayList)); // 交易日集合
108
+ localStorage.setItem("weekdayList", JSON.stringify(res.data.weekdayList)); // 节假日集合
109
+ localStorage.setItem("workdayList", JSON.stringify(res.data.workdayList)); // 工作日集合
110
+ }
111
+ }
112
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
113
+ });
114
+ }
115
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
116
+ }
117
+
118
+ /**
119
+ * @description: 初始化表单设计
120
+ * @author ChenRui
121
+ * @date 2020/11/20 10:55
122
+ */
123
+ initDesign(): Promise<FormRestfulResponse> {
124
+ return Promise.all([formStore.getForms(), formStore.getVersion()]).then(([forms, formVersion]: any[]) => {
125
+ if (this.formConfig.loadMode === "static") {
126
+ if (forms != null) {
127
+ this.desForms = forms;
128
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
129
+ } else {
130
+ return this.loadDesign([this.formConfig.url || DEFAULT_FORM_FILE_NAME]);
131
+ }
132
+ } else if (this.formConfig.loadMode === "dynamic") {
133
+ if (this.formConfig.appId != null && this.formConfig.appId !== "") {
134
+ const query = {
135
+ appId: this.formConfig.appId,
136
+ cacheType: CacheType.FORM.code,
137
+ };
138
+ const url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-cacheversion-by-appid-cachetype";
139
+ return this.fetch(url!, query).then((res: FormRestfulResponse) => {
140
+ if (res != null && res.code === 1) {
141
+ if (res.data != null && res.data.desCacheVersion != null) {
142
+ if (String(formVersion) !== String(res.data.desCacheVersion.cacheVersionNumber)) {
143
+ const formUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + res.data.desCacheVersion.storageAddress;
144
+ return this.loadDesign([formUrl]).then((resEx: FormRestfulResponse) => {
145
+ if (resEx.code === 1) {
146
+ formStore.setVersion(res.data.desCacheVersion.cacheVersionNumber);
147
+ }
148
+ return resEx;
149
+ });
150
+ } else {
151
+ if (forms != null) {
152
+ this.desForms = forms;
153
+ }
154
+ console.log(this.desForms);
155
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
156
+ }
157
+ } else {
158
+ return Promise.resolve({ code: 1, msg: "暂无版本数据" });
159
+ }
160
+ } else {
161
+ return Promise.resolve(FormToolsService.LOAD_FAIL);
162
+ }
163
+ });
164
+ } else {
165
+ return Promise.resolve({
166
+ code: 0,
167
+ msg: "动态加载需指定当前系统编号(appId)",
168
+ });
169
+ }
170
+ } else if (this.formConfig.loadMode === "merge") {
171
+ if (this.formConfig.urls) {
172
+ return new Promise((resolve) => {
173
+ this.loadDesign(this.formConfig.urls || []).then(() => {
174
+ resolve(FormToolsService.LOAD_SUCCESS);
175
+ });
176
+ });
177
+ } else {
178
+ return this.mergeUrlByType(CacheType.FORM.code).then((response: any) => {
179
+ if (formVersion === response.cacheVersionNumber) {
180
+ if (forms) {
181
+ this.desForms = forms;
182
+ }
183
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
184
+ } else {
185
+ return new Promise((resolve) => {
186
+ this.loadDesign(response.storageAddress).then(() => {
187
+ formStore.setVersion(response.cacheVersionNumber);
188
+ resolve(FormToolsService.LOAD_SUCCESS);
189
+ });
190
+ });
191
+ }
192
+ });
193
+ }
194
+ } else if (this.formConfig.loadMode === "merge_cacheId") {
195
+ // 按照缓存编号查询表单数据,2024年8月15日14:03:24
196
+ return this.mergeUrlByCacheId(CacheType.FORM.code).then((response: any) => {
197
+ if (formVersion === response.cacheVersionNumber) {
198
+ if (forms) {
199
+ this.desForms = forms;
200
+ }
201
+ return Promise.resolve(FormToolsService.LOAD_SUCCESS);
202
+ } else {
203
+ return new Promise((resolve) => {
204
+ this.loadDesign(response.storageAddress).then(() => {
205
+ formStore.setVersion(response.cacheVersionNumber);
206
+ resolve(FormToolsService.LOAD_SUCCESS);
207
+ });
208
+ });
209
+ }
210
+ });
211
+ }
212
+ return Promise.resolve(FormToolsService.LOAD_FAIL);
213
+ });
214
+ }
215
+
216
+ /**
217
+ * @description: 获取表单或字典数据地址
218
+ * @author ZPFly
219
+ * @date 2022/10/18 20:43
220
+ */
221
+ private mergeUrlByType(type: string): Promise<any> {
222
+ const url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-batch-appids-cachetype";
223
+ const downloadUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=";
224
+ const query = {
225
+ appIds: this.formConfig.appId,
226
+ cacheType: type,
227
+ };
228
+ return this.fetch(url!, query).then((resp: any) => {
229
+ const response: any = {};
230
+ const address: string[] = [];
231
+ const cacheVersionNumber: any[] = [];
232
+ const cacheVersionMap: any = {};
233
+ resp?.data?.forEach((item: any) => {
234
+ // 数据下载地址
235
+ if (item.cacheType == type && item.desCacheVersion?.storageAddress && query.appIds && query.appIds.indexOf(item.appId) > -1) {
236
+ cacheVersionMap[item.appId] = item.desCacheVersion.cacheVersionNumber;
237
+ address.push(downloadUrl + item.desCacheVersion.storageAddress);
238
+ }
239
+ });
240
+ query.appIds?.split(",").forEach((appId) => {
241
+ cacheVersionNumber.push(cacheVersionMap[appId]);
242
+ });
243
+ response.cacheVersionNumber = cacheVersionNumber.join(",");
244
+ response.storageAddress = address;
245
+ return response;
246
+ });
247
+ }
248
+ /**
249
+ * @description: 获取表单或字典数据地址-按照缓存版本号查询字典/表单
250
+ * @author ZPFly
251
+ * @date 2022/10/18 20:43
252
+ */
253
+ private mergeUrlByCacheId(type: string): Promise<any> {
254
+ const url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-batch-appids-cachetype";
255
+ const downloadUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/downloadById?cacheVersionId=";
256
+ const query = {
257
+ appIds: this.formConfig.appId,
258
+ cacheType: type,
259
+ };
260
+ const appIds: string[] = query.appIds?.split(",") || [];
261
+ return this.fetch(url!, query).then((resp: any) => {
262
+ const response: any = {};
263
+ const address: string[] = [];
264
+ const cacheVersionNumber: any[] = [];
265
+ const cacheVersionMap: any = {};
266
+ resp?.data?.forEach((item: any) => {
267
+ // 数据下载地址
268
+ if (item.cacheType == type && item.desCacheVersion?.cacheVersionId && query.appIds && appIds.indexOf(item.appId) > -1) {
269
+ cacheVersionMap[item.appId] = item.desCacheVersion.cacheVersionNumber;
270
+ address.push(downloadUrl + item.desCacheVersion.cacheVersionId + "&appId=" + item.appId + "&cacheType=" + type);
271
+ }
272
+ });
273
+ query.appIds?.split(",").forEach((appId) => {
274
+ cacheVersionNumber.push(cacheVersionMap[appId]);
275
+ });
276
+ response.cacheVersionNumber = cacheVersionNumber.join(",");
277
+ response.storageAddress = address;
278
+ return response;
279
+ });
280
+ }
281
+
282
+ /**
283
+ * @description: 加载远程表单配置
284
+ * @author ChenRui
285
+ * @date 2020/11/20 17:30
286
+ */
287
+ private loadDesign(urls: string[]): Promise<FormRestfulResponse> {
288
+ return this.mergeFetchDesign(urls).then((desForms: DesForm[]) => {
289
+ const newDesForms: DesForm[] = [];
290
+ if (desForms != null && desForms.length > 0) {
291
+ desForms
292
+ .filter((item) => item.desFormLayouts != null && item.desFormLayouts.length > 0)
293
+ .forEach((item) => {
294
+ const newDesForm: DesForm | undefined = this.formatDesForm(item);
295
+ if (newDesForm != null) {
296
+ newDesForms.push(newDesForm);
297
+ }
298
+ });
299
+ }
300
+ this.desForms = newDesForms;
301
+ formStore.setForms(this.desForms);
302
+ return FormToolsService.LOAD_SUCCESS;
303
+ });
304
+ }
305
+
306
+ /**
307
+ * @description: 合并多个应用表单
308
+ * @author ZPFly
309
+ * @date 2022/10/17 15:39
310
+ */
311
+ private mergeFetchDesign(urls: string[]) {
312
+ const onlySimpleLoadConfig = !!this.formConfig.onlySimpleLoadConfig;
313
+ const headers = this.createFileDownloadAuthorizationHeader();
314
+ const fetches: any = [];
315
+ urls.forEach((url: string) => {
316
+ fetches.push(this.fetch(url, {}, undefined, "GET", headers, onlySimpleLoadConfig));
317
+ });
318
+ return Promise.all(fetches).then((desForms: DesForm[]) => {
319
+ let newDesForms: DesForm[] = [];
320
+ desForms?.forEach((desForm: any) => {
321
+ newDesForms = newDesForms.concat(desForm);
322
+ });
323
+ return newDesForms;
324
+ });
325
+ }
326
+
327
+ /**
328
+ * @description: 初始化字典
329
+ * @author ChenRui
330
+ * @date 2021/3/11 14:32
331
+ */
332
+ initDict(): Promise<FormRestfulResponse> {
333
+ return Promise.all([dictStore.getDicts(), dictStore.getTreeDicts(), dictStore.getMapDicts(), dictStore.getMapTreeDicts(), dictStore.getVersion()]).then(([dicts, treeDicts, mapDicts, mapTreeDicts, dictVersion]: any[]) => {
334
+ if (this.formConfig.loadMode === "static") {
335
+ const url = this.formConfig.dictUrl ? this.formConfig.dictUrl : DEFAULT_DICT_URL;
336
+ if (dicts != null || treeDicts != null) {
337
+ this.sysDictDetailOptions = dicts;
338
+ this.sysDictTreeDetailOptions = treeDicts;
339
+ this.mapSysDictDetailOptions = mapDicts;
340
+ this.mapSysDictTreeDetailOptions = mapTreeDicts;
341
+ return FormToolsService.LOAD_SUCCESS;
342
+ } else {
343
+ return this.loadDict([url]);
344
+ }
345
+ } else if (this.formConfig.loadMode === "dynamic") {
346
+ if (this.formConfig.appId) {
347
+ const url1 = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/query-cacheversion-by-appid-cachetype";
348
+ const url: string = this.formConfig.dictUrl ? this.formConfig.dictUrl : url1 || "";
349
+ const path: string = routerService.getPathFromUrl(url);
350
+ let query: any = routerService.getParamsFromUrl(url) || {};
351
+ query.appId = query.appId ? query.appId : this.formConfig.appId;
352
+ query.cacheType = query.cacheType ? query.cacheType : CacheType.DICT.code;
353
+ query = this.formConfig.dictRestLoadOnlyBody ? {} : query;
354
+ const body: any = (this.formConfig.dictRestLoadMode || "GET").toLocaleUpperCase() === "GET" ? undefined : this.formConfig.dictRestLoadBody;
355
+ let headers: any = this.formConfig.dictRestLoadHeaders;
356
+ if (headers != null && typeof headers === "function") {
357
+ headers = (headers as any)();
358
+ }
359
+ return this.fetch(path, query, body, this.formConfig.dictRestLoadMode, headers).then((res: FormRestfulResponse) => {
360
+ if (res != null && (res.code === 1 || String(res.code) === String(200))) {
361
+ if (res.data != null) {
362
+ let desCacheVersion: any = res.data.desCacheVersion;
363
+ if (res.data && res.data instanceof Array && res.data.length > 0) {
364
+ desCacheVersion = res.data[0].desCacheVersion;
365
+ }
366
+ const distUrl = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + desCacheVersion.storageAddress;
367
+ if (String(dictVersion) !== String(desCacheVersion.cacheVersionNumber)) {
368
+ return this.loadDict([distUrl]).then((resEx: FormRestfulResponse) => {
369
+ if (resEx.code === 1) {
370
+ dictStore.setVersion(desCacheVersion.cacheVersionNumber);
371
+ }
372
+ return resEx;
373
+ });
374
+ } else {
375
+ if (dicts != null || treeDicts != null) {
376
+ this.sysDictDetailOptions = dicts;
377
+ this.sysDictTreeDetailOptions = treeDicts;
378
+ this.mapSysDictDetailOptions = mapDicts;
379
+ this.mapSysDictTreeDetailOptions = mapTreeDicts;
380
+ }
381
+ return FormToolsService.LOAD_SUCCESS;
382
+ }
383
+ } else {
384
+ return { code: 1, msg: "暂无版本数据" };
385
+ }
386
+ } else {
387
+ return FormToolsService.LOAD_FAIL;
388
+ }
389
+ });
390
+ } else {
391
+ return { code: 0, msg: "动态加载需指定当前系统编号(appId)" };
392
+ }
393
+ } else if (this.formConfig.loadMode === "merge") {
394
+ return this.mergeUrlByType(CacheType.DICT.code).then((response: any) => {
395
+ if (dictVersion === response.cacheVersionNumber) {
396
+ if (dicts != null || treeDicts != null) {
397
+ this.sysDictDetailOptions = dicts;
398
+ this.sysDictTreeDetailOptions = treeDicts;
399
+ this.mapSysDictDetailOptions = mapDicts;
400
+ this.mapSysDictTreeDetailOptions = mapTreeDicts;
401
+ }
402
+ return FormToolsService.LOAD_SUCCESS;
403
+ } else {
404
+ return new Promise((resolve) => {
405
+ this.loadDict(response.storageAddress).then(() => {
406
+ dictStore.setVersion(response.cacheVersionNumber);
407
+ resolve(FormToolsService.LOAD_SUCCESS);
408
+ });
409
+ });
410
+ }
411
+ });
412
+ } else if (this.formConfig.loadMode === "merge_cacheId") {
413
+ // 按照缓存编号查询表单数据,2024年8月15日14:03:24
414
+ return this.mergeUrlByCacheId(CacheType.DICT.code).then((response: any) => {
415
+ if (dictVersion === response.cacheVersionNumber) {
416
+ if (dicts != null || treeDicts != null) {
417
+ this.sysDictDetailOptions = dicts;
418
+ this.sysDictTreeDetailOptions = treeDicts;
419
+ this.mapSysDictDetailOptions = mapDicts;
420
+ this.mapSysDictTreeDetailOptions = mapTreeDicts;
421
+ }
422
+ return FormToolsService.LOAD_SUCCESS;
423
+ } else {
424
+ return new Promise((resolve) => {
425
+ this.loadDict(response.storageAddress).then(() => {
426
+ dictStore.setVersion(response.cacheVersionNumber);
427
+ resolve(FormToolsService.LOAD_SUCCESS);
428
+ });
429
+ });
430
+ }
431
+ });
432
+ }
433
+ return FormToolsService.LOAD_FAIL;
434
+ });
435
+ }
436
+
437
+ /**
438
+ * @description: 加载远程字典配置
439
+ * @author ChenRui
440
+ * @date 2020/11/20 17:30
441
+ */
442
+ private loadDict(urls: string[]): Promise<FormRestfulResponse> {
443
+ return this.mergeFetchDict(urls).then((sysDictInfos: any) => {
444
+ if (sysDictInfos != null) {
445
+ // 数据格式化
446
+ const dictionaryFormatCollection: DictionaryFormatCollection = this.inidDictOptions(sysDictInfos);
447
+ this.sysDictDetailOptions = dictionaryFormatCollection.sysDictDetailOptions || [];
448
+ this.sysDictTreeDetailOptions = dictionaryFormatCollection.sysDictTreeDetailOptions || [];
449
+ this.mapSysDictDetailOptions = dictionaryFormatCollection.mapSysDictDetailOptions;
450
+ this.mapSysDictTreeDetailOptions = dictionaryFormatCollection.mapSysDictTreeDetailOptions;
451
+ // 字典本地存储
452
+ if (dictionaryFormatCollection.sysDictDetailOptions && dictionaryFormatCollection.sysDictDetailOptions.length > 0) {
453
+ dictStore.setDicts(dictionaryFormatCollection.sysDictDetailOptions);
454
+ }
455
+ if (dictionaryFormatCollection.sysDictTreeDetailOptions && dictionaryFormatCollection.sysDictTreeDetailOptions.length > 0) {
456
+ dictStore.setTreeDicts(dictionaryFormatCollection.sysDictTreeDetailOptions);
457
+ }
458
+ dictStore.setMapDicts(dictionaryFormatCollection.mapSysDictDetailOptions || null);
459
+ dictStore.setMapTreeDicts(dictionaryFormatCollection.mapSysDictTreeDetailOptions || null);
460
+ }
461
+ return FormToolsService.LOAD_SUCCESS;
462
+ });
463
+ // const onlySimpleLoadConfig = !!this.formConfig.onlySimpleLoadConfig;
464
+ // let sysDictInfos: SysDictInfo[] = [];
465
+ // if (loadMode === "dynamic") {
466
+ // const headers = this.createFileDownloadAuthorizationHeader();
467
+ // url = this.formConfig.url + "/ms-loong/api/v1/des-cache-info/permit_endpoint/download?storageAddress=" + url;
468
+ // return this.fetch(url, {}, undefined, "GET", headers, onlySimpleLoadConfig).then((res: any) => {
469
+ // sysDictInfos = res;
470
+ // if (sysDictInfos != null && sysDictInfos.length > 0) {
471
+ // // 数据格式化
472
+ // const dictionaryFormatCollection: DictionaryFormatCollection = this.inidDictOptions(sysDictInfos);
473
+ // this.sysDictDetailOptions = dictionaryFormatCollection.sysDictDetailOptions || [];
474
+ // this.sysDictTreeDetailOptions = dictionaryFormatCollection.sysDictTreeDetailOptions || [];
475
+ // this.mapSysDictDetailOptions = dictionaryFormatCollection.mapSysDictDetailOptions;
476
+ // this.mapSysDictTreeDetailOptions = dictionaryFormatCollection.mapSysDictTreeDetailOptions;
477
+ // // 字典本地存储
478
+ // if (dictionaryFormatCollection.sysDictDetailOptions && dictionaryFormatCollection.sysDictDetailOptions.length > 0) {
479
+ // dictStore.setDicts(dictionaryFormatCollection.sysDictDetailOptions);
480
+ // }
481
+ // if (dictionaryFormatCollection.sysDictTreeDetailOptions && dictionaryFormatCollection.sysDictTreeDetailOptions.length > 0) {
482
+ // dictStore.setTreeDicts(dictionaryFormatCollection.sysDictTreeDetailOptions);
483
+ // }
484
+ // dictStore.setMapDicts(dictionaryFormatCollection.mapSysDictDetailOptions || null);
485
+ // dictStore.setMapTreeDicts(dictionaryFormatCollection.mapSysDictTreeDetailOptions || null);
486
+ // }
487
+ // return FormToolsService.LOAD_SUCCESS;
488
+ // });
489
+ // }
490
+ }
491
+
492
+ /**
493
+ * @description: 合并多个应用字典
494
+ * @author ZPFly
495
+ * @date 2022/10/17 15:39
496
+ */
497
+ private mergeFetchDict(dictUrl: string[]) {
498
+ const fetchDicts: any = [];
499
+ dictUrl.forEach((url: string) => {
500
+ fetchDicts.push(this.fetch(url, {}, undefined, "GET", undefined, !!this.formConfig.onlySimpleLoadConfig));
501
+ });
502
+ return Promise.all(fetchDicts).then((dictInfos: SysDictInfo[]) => {
503
+ let newDictInfos: SysDictInfo[] = [];
504
+ const empObj: any = {};
505
+ const filterDist: SysDictInfo[] = [];
506
+ dictInfos?.forEach((desForm: any) => {
507
+ newDictInfos = newDictInfos.concat(desForm);
508
+ });
509
+ // 去除重复字典
510
+ newDictInfos.forEach((item: SysDictInfo) => {
511
+ if (!empObj[item.dictId]) {
512
+ filterDist.push(item);
513
+ empObj[item.dictId] = true;
514
+ }
515
+ });
516
+ return filterDist;
517
+ });
518
+ }
519
+ /**
520
+ * @description: 初始化字典可选项
521
+ * @author ChenRui
522
+ * @date 2020/11/10 20:38
523
+ */
524
+ public inidDictOptions(sysDictInfos: SysDictInfo[]): DictionaryFormatCollection {
525
+ const sysDictDetailOptions: NzTreeNodeOptions[] = [];
526
+ const sysDictTreeDetailOptions: NzTreeNodeOptions[] = [];
527
+ sysDictInfos.forEach((sysDictInfo) => {
528
+ const node: NzTreeNodeOptions = {
529
+ key: sysDictInfo.dictId,
530
+ value: sysDictInfo.dictCd,
531
+ title: sysDictInfo.dictNm,
532
+ isLeaf: true,
533
+ expanded: false,
534
+ children: [],
535
+ };
536
+ if (sysDictInfo.dictTp === DynamicOptionType.GeneralDictionary.code) {
537
+ node.isLeaf = false;
538
+ node.children = formTreeNodeConvertService.arrayConvertToNzTreeNode(
539
+ sysDictInfo.comDictKeyValues.filter((it) => !!it.dictId),
540
+ this.dictDetailsContrast,
541
+ this.nzDictDetailsContrastContrast,
542
+ true
543
+ );
544
+ sysDictDetailOptions.push(node);
545
+ } else if (sysDictInfo.dictTp === DynamicOptionType.TreeDictionary.code) {
546
+ if (sysDictInfo.treeDictKeyValues != null && sysDictInfo.treeDictKeyValues.length > 0) {
547
+ node.isLeaf = false;
548
+ sysDictInfo.treeDictKeyValues.forEach((item) => {
549
+ if (item.suprDicPk === "0") {
550
+ item.suprDicPk = "";
551
+ }
552
+ });
553
+ node.children = formTreeNodeConvertService.arrayConvertToNzTreeNode(
554
+ sysDictInfo.treeDictKeyValues.filter((it) => !!it.dictId),
555
+ this.dictTreeDetailsContrast,
556
+ this.nzDictTreeDetailsContrastContrast,
557
+ true
558
+ );
559
+ }
560
+ sysDictTreeDetailOptions.push(node);
561
+ }
562
+ });
563
+ const mapNodeOptions: MapNodeOptions | undefined = formTreeNodeConvertService.nzTreeNodeConvertToMap(sysDictDetailOptions);
564
+ const mapTreeNodeOptions: MapNodeOptions | undefined = formTreeNodeConvertService.nzTreeNodeConvertToMap(sysDictTreeDetailOptions);
565
+ return {
566
+ sysDictDetailOptions: sysDictDetailOptions,
567
+ sysDictTreeDetailOptions: sysDictTreeDetailOptions,
568
+ mapSysDictDetailOptions: mapNodeOptions,
569
+ mapSysDictTreeDetailOptions: mapTreeNodeOptions,
570
+ };
571
+ }
572
+
573
+ /**
574
+ * @description: 格式化表单
575
+ * @author ChenRui
576
+ * @date 2020/11/30 15:48
577
+ */
578
+ formatDesForm(sourceDesForm: DesForm): DesForm | undefined {
579
+ if (sourceDesForm != null) {
580
+ const newDesForm: DesForm = new DesForm(sourceDesForm);
581
+ const desFormLayouts: DesFormLayout[] = formTreeNodeConvertService.arrayConvertToTreeNode(sourceDesForm.desFormLayouts, this.nodeContrast);
582
+ const controls = this.recursionFormatForm([], desFormLayouts);
583
+ this.sortControls(controls);
584
+ newDesForm.desFormLayouts = [];
585
+ newDesForm.controls = controls;
586
+ return newDesForm;
587
+ }
588
+ }
589
+
590
+ /**
591
+ * @description: 递归格式化
592
+ * @author ChenRui
593
+ * @date 2020/11/17 10:16
594
+ */
595
+ private recursionFormatForm(desFormControls: DesFormControl[], desFormLayouts: DesFormLayout[]): Control[] {
596
+ const controls: Control[] = [];
597
+ if (desFormControls != null && desFormControls.length > 0) {
598
+ desFormControls
599
+ .filter((item) => !!item.formFieldId)
600
+ .forEach((desFormControl) => {
601
+ const control: Control = {
602
+ code: desFormControl.controlType,
603
+ name: (Object.values(FormFieldType).find((item) => item.code === desFormControl.controlType) || {}).name || "",
604
+ type: Number(desFormControl.controlType) < 50 ? FormFieldClass.Base.code : FormFieldClass.Senior.code,
605
+ active: false,
606
+ subControls: undefined,
607
+ controlAttr: desFormControl,
608
+ };
609
+ const controlAttr = control.controlAttr as DesFormControl;
610
+ controlAttr.isBoldTitle = desFormControl.isBoldTitle === Switch.Enable.code;
611
+ controlAttr.isHideTitle = desFormControl.isHideTitle === Switch.Enable.code;
612
+ controlAttr.isNotEdit = desFormControl.isNotEdit === Switch.Enable.code;
613
+ controlAttr.isShowHoliday = desFormControl.isShowHoliday === Switch.Enable.code;
614
+ controlAttr.isHideControl = desFormControl.isHideControl === Switch.Enable.code;
615
+ controlAttr.isPasswordBox = desFormControl.isPasswordBox === Switch.Enable.code;
616
+ controlAttr.enableAutoComplete = desFormControl.enableAutoComplete === Switch.Enable.code;
617
+ controlAttr.isFixedRowHeight = desFormControl.isFixedRowHeight === Switch.Enable.code;
618
+ controlAttr.thousandthPercentileFormat = desFormControl.thousandthPercentileFormat === Switch.Enable.code;
619
+ controlAttr.isShowCapitalization = desFormControl.isShowCapitalization === Switch.Enable.code;
620
+ controlAttr.isLineFeedDisplay = desFormControl.isLineFeedDisplay === Switch.Enable.code;
621
+ controlAttr.optionConfig = formBeanUtilsService.parse(desFormControl.optionConfig);
622
+ controlAttr.generalDictionaryOptions = formBeanUtilsService.parse(desFormControl.generalDictionaryOptions);
623
+ controlAttr.treeShapeOptions = formBeanUtilsService.parse(desFormControl.treeShapeOptions);
624
+ controlAttr.isSupportMultiple = desFormControl.isSupportMultiple === Switch.Enable.code;
625
+ if (Array.isArray(desFormControl.customUploadType) && desFormControl.customUploadType.length > 0) {
626
+ controlAttr.customUploadType = desFormControl.customUploadType.join(",");
627
+ }
628
+ controlAttr.isMultipleChoice = desFormControl.isMultipleChoice === Switch.Enable.code;
629
+ controlAttr.isSearchable = desFormControl.isSearchable === Switch.Enable.code;
630
+ controlAttr.canAddEntry = desFormControl.canAddEntry === Switch.Enable.code;
631
+ controlAttr.isClearButton = desFormControl.isClearButton === Switch.Enable.code;
632
+ controlAttr.hiddenDropdown = desFormControl.hiddenDropdown === Switch.Enable.code;
633
+ controlAttr.textFold = desFormControl.textFold === Switch.Enable.code;
634
+ controlAttr.verificationRules = formBeanUtilsService.parse(desFormControl.verificationRules);
635
+ controls.push(control);
636
+ });
637
+ }
638
+ if (desFormLayouts != null && desFormLayouts.length > 0) {
639
+ desFormLayouts
640
+ .filter((item) => !!item.layoutId)
641
+ .forEach((desFormLayout) => {
642
+ const layoutControl: Control = {
643
+ code: desFormLayout.layoutType,
644
+ name: (Object.values(FormFieldType).find((item) => item.code === desFormLayout.layoutType) || {}).name || "",
645
+ type: FormFieldClass.Layout.code,
646
+ active: false,
647
+ subControls: [],
648
+ controlAttr: new DesFormLayout(desFormLayout),
649
+ };
650
+ const controlAttr = layoutControl.controlAttr as DesFormLayout;
651
+ controlAttr.gridColumnConfig = formBeanUtilsService.parse(desFormLayout.gridColumnConfig);
652
+ controlAttr.desFormControls = [];
653
+ controlAttr.subDesFormLayout = [];
654
+ if ((desFormLayout.subDesFormLayout != null && desFormLayout.subDesFormLayout.length > 0) || (desFormLayout.desFormControls != null && desFormLayout.desFormControls.length > 0)) {
655
+ layoutControl.subControls = this.recursionFormatForm(desFormLayout.desFormControls, desFormLayout.subDesFormLayout);
656
+ }
657
+ controls.push(layoutControl);
658
+ });
659
+ }
660
+ return controls;
661
+ }
662
+
663
+ /**
664
+ * @description: 控件排序
665
+ * @author ChenRui
666
+ * @date 2020/11/17 11:59
667
+ */
668
+ private sortControls(controls: Control[]): void {
669
+ controls.sort((controlA, controlB) => {
670
+ let x = 0;
671
+ let y = 0;
672
+ if (controlA.type === FormFieldClass.Layout.code) {
673
+ x = Number((controlA.controlAttr as DesFormLayout).layoutOrder);
674
+ } else {
675
+ x = Number((controlA.controlAttr as DesFormControl).tableFieldOrder);
676
+ }
677
+ if (controlB.type === FormFieldClass.Layout.code) {
678
+ y = Number((controlB.controlAttr as DesFormLayout).layoutOrder);
679
+ } else {
680
+ y = Number((controlB.controlAttr as DesFormControl).tableFieldOrder);
681
+ }
682
+ return x - y;
683
+ });
684
+ controls.forEach((item) => {
685
+ if (item.subControls != null && item.subControls.length > 0) {
686
+ this.sortControls(item.subControls);
687
+ }
688
+ });
689
+ }
690
+
691
+ /**
692
+ * @description: 加载资源
693
+ * @author ChenRui
694
+ * @date 2020/11/23 11:00
695
+ */
696
+ loadResource(formId: string): DesForm {
697
+ const desForm: DesForm | undefined = this.desForms.find((item) => item.formId === formId);
698
+ if (desForm != null) {
699
+ return formBeanUtilsService.copy(desForm);
700
+ } else {
701
+ return new DesForm({ formId: formId });
702
+ }
703
+ }
704
+
705
+ /**
706
+ * @description: rest客户端
707
+ * @author ChenRui
708
+ * @date 2020/11/19 21:02
709
+ */
710
+ private fetch(path: string, params: { [key: string]: any }, body?: any, method = "GET", headers?: any, simple = false): Promise<any> {
711
+ headers = headers ? headers : apiService.createBasicHeaders();
712
+ return simple ? fetch(path).then((response) => response.json()) : apiService.fetch(path, params, body, method, headers);
713
+ }
714
+
715
+ /**
716
+ * @description: 校验提示
717
+ * @author ChenRui
718
+ * @date 2021/8/18 17:14
719
+ */
720
+ validateTips(formApis: FormApi | FormApi[], scrollView?: any): boolean {
721
+ return formValidateService.validateTips(formApis, scrollView);
722
+ }
723
+
724
+ /**
725
+ * @description: 创建认证下载消息头
726
+ * @author ChenRui
727
+ * @date 2020/8/28 15:18
728
+ */
729
+ createFileDownloadAuthorizationHeader() {
730
+ return {
731
+ headers: {
732
+ "Content-Type": "application/json",
733
+ },
734
+ responseType: "blob",
735
+ };
736
+ }
737
+ }
738
+ const formToolsService: FormToolsService = new FormToolsService();
739
+ export { formToolsService, FormToolsService, DictionaryFormatCollection };