@dhccmobile/vue3-lo-form 2.0.0 → 2.0.2

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 (166) hide show
  1. package/README.md +77 -70
  2. package/dist/demo.html +1 -10
  3. package/dist/vue3-lo-form.common.js +8704 -6939
  4. package/dist/vue3-lo-form.common.js.map +1 -1
  5. package/dist/vue3-lo-form.css +1 -1
  6. package/dist/vue3-lo-form.umd.js +8715 -6949
  7. package/dist/vue3-lo-form.umd.js.map +1 -1
  8. package/dist/vue3-lo-form.umd.min.js +1 -1
  9. package/dist/vue3-lo-form.umd.min.js.map +1 -1
  10. package/package.json +72 -65
  11. package/src/App.vue +741 -741
  12. package/src/components/form/DvForm.vue +642 -642
  13. package/src/components/form/DvFormLayout.vue +1592 -1569
  14. package/src/components/form/StretchText.vue +90 -90
  15. package/src/components/index.ts +3 -3
  16. package/src/constants/config/form-template.config.ts +32 -32
  17. package/src/constants/config/form.config.ts +4 -4
  18. package/src/constants/config/storage.config.ts +4 -4
  19. package/src/constants/encode-assets/svg.ts +11 -11
  20. package/src/constants/enum/builtIn-label.enum.ts +5 -5
  21. package/src/constants/enum/cache-type.enum.ts +7 -7
  22. package/src/constants/enum/control-format-type.enum.ts +9 -9
  23. package/src/constants/enum/dynamic-option-type.enum.ts +6 -6
  24. package/src/constants/enum/form-bus-attr.enum.ts +8 -8
  25. package/src/constants/enum/form-field-class.enum.ts +7 -7
  26. package/src/constants/enum/form-field-type.enum.ts +25 -25
  27. package/src/constants/enum/form-type.enum.ts +5 -5
  28. package/src/constants/enum/index.ts +19 -19
  29. package/src/constants/enum/lateral-arrangement.enum.ts +9 -9
  30. package/src/constants/enum/money-unit.enum.ts +6 -6
  31. package/src/constants/enum/option-type.enum.ts +5 -5
  32. package/src/constants/enum/submitted-type.enum.ts +32 -32
  33. package/src/constants/enum/support-upload-type.enum.ts +5 -5
  34. package/src/constants/enum/switch.enum.ts +5 -5
  35. package/src/constants/enum/upload-type.enum.ts +17 -17
  36. package/src/constants/enum/validate-rules.enum.ts +25 -25
  37. package/src/constants/enum/validate-status.enum.ts +8 -8
  38. package/src/constants/enum/vertical-arrangement.enum.ts +7 -7
  39. package/src/constants/enum/zoom-type.ts +6 -6
  40. package/src/constants/index.ts +3 -3
  41. package/src/core/FormApi.ts +1238 -1238
  42. package/src/core/index.ts +1 -1
  43. package/src/domain/AbstractControl.ts +6 -6
  44. package/src/domain/Control.ts +14 -14
  45. package/src/domain/CustomFormat.ts +6 -6
  46. package/src/domain/DesForm.ts +48 -48
  47. package/src/domain/DesFormControl.ts +241 -241
  48. package/src/domain/DesFormLayout.ts +51 -51
  49. package/src/domain/FieldChangeHistory.ts +9 -9
  50. package/src/domain/FormConfig.ts +16 -15
  51. package/src/domain/FormControl.ts +125 -125
  52. package/src/domain/FormEnum.ts +9 -9
  53. package/src/domain/FormGroup.ts +42 -42
  54. package/src/domain/FormRestfulResponse.ts +6 -6
  55. package/src/domain/ProvideInjectData.ts +10 -10
  56. package/src/domain/SysDictDetail.ts +38 -38
  57. package/src/domain/SysDictInfo.ts +40 -40
  58. package/src/domain/SysDictTreeDetail.ts +52 -52
  59. package/src/domain/index.ts +12 -12
  60. package/src/filtres/amount-capitalization.filter.ts +154 -154
  61. package/src/filtres/extract-options.filter.ts +53 -53
  62. package/src/filtres/generate-grid-column-end.filter.ts +22 -22
  63. package/src/filtres/generate-grid-template-columns.filter.ts +24 -24
  64. package/src/filtres/switch-enum-convert.filter.ts +18 -18
  65. package/src/filtres/zoom-multiple.filter.ts +32 -32
  66. package/src/index.ts +74 -73
  67. package/src/main.ts +17 -17
  68. package/src/services/api.service.ts +73 -73
  69. package/src/services/clean-local-forage.service.ts +58 -58
  70. package/src/services/date-format.service.ts +74 -74
  71. package/src/services/dict-local-forage.service.ts +58 -58
  72. package/src/services/form-bean-utils.service.ts +41 -41
  73. package/src/services/form-local-forage.service.ts +59 -59
  74. package/src/services/form-tools.service.ts +739 -739
  75. package/src/services/form-tree-node-convert.service.ts +240 -240
  76. package/src/services/form-validate.service.ts +103 -103
  77. package/src/services/index.ts +9 -9
  78. package/src/services/router.service.ts +96 -96
  79. package/src/services/validate-generator.service.ts +710 -710
  80. package/src/shims-vue.d.ts +6 -6
  81. package/src/store/dict.store.ts +63 -63
  82. package/src/store/form.store.ts +32 -32
  83. package/src/store/index.ts +2 -2
  84. package/src/styles/datePicker.scss +125 -125
  85. package/src/styles/index.scss +195 -195
  86. package/src/styles/theme1.scss +277 -277
  87. package/src/styles/theme2.scss +376 -376
  88. package/src/styles/themes.scss +9 -9
  89. package/src/types/vfForm.ts +11 -11
  90. package/types/components/index.d.ts +3 -3
  91. package/types/constants/config/form-template.config.d.ts +30 -30
  92. package/types/constants/config/form.config.d.ts +4 -4
  93. package/types/constants/config/storage.config.d.ts +4 -4
  94. package/types/constants/encode-assets/svg.d.ts +5 -5
  95. package/types/constants/enum/builtIn-label.enum.d.ts +7 -7
  96. package/types/constants/enum/cache-type.enum.d.ts +15 -15
  97. package/types/constants/enum/control-format-type.enum.d.ts +23 -23
  98. package/types/constants/enum/dynamic-option-type.enum.d.ts +11 -11
  99. package/types/constants/enum/form-bus-attr.enum.d.ts +19 -19
  100. package/types/constants/enum/form-field-class.enum.d.ts +18 -18
  101. package/types/constants/enum/form-field-type.enum.d.ts +111 -111
  102. package/types/constants/enum/form-type.enum.d.ts +11 -11
  103. package/types/constants/enum/index.d.ts +19 -19
  104. package/types/constants/enum/lateral-arrangement.enum.d.ts +23 -23
  105. package/types/constants/enum/money-unit.enum.d.ts +15 -15
  106. package/types/constants/enum/option-type.enum.d.ts +11 -11
  107. package/types/constants/enum/submitted-type.enum.d.ts +115 -115
  108. package/types/constants/enum/support-upload-type.enum.d.ts +11 -11
  109. package/types/constants/enum/switch.enum.d.ts +11 -11
  110. package/types/constants/enum/upload-type.enum.d.ts +59 -59
  111. package/types/constants/enum/validate-rules.enum.d.ts +2 -2
  112. package/types/constants/enum/validate-status.enum.d.ts +2 -2
  113. package/types/constants/enum/vertical-arrangement.enum.d.ts +21 -21
  114. package/types/constants/enum/zoom-type.d.ts +15 -15
  115. package/types/constants/index.d.ts +3 -3
  116. package/types/core/FormApi.d.ts +376 -376
  117. package/types/core/index.d.ts +1 -1
  118. package/types/domain/AbstractControl.d.ts +5 -5
  119. package/types/domain/Control.d.ts +13 -13
  120. package/types/domain/CustomFormat.d.ts +5 -5
  121. package/types/domain/DesForm.d.ts +32 -32
  122. package/types/domain/DesFormControl.d.ts +160 -160
  123. package/types/domain/DesFormLayout.d.ts +33 -33
  124. package/types/domain/FieldChangeHistory.d.ts +9 -9
  125. package/types/domain/FormConfig.d.ts +16 -15
  126. package/types/domain/FormControl.d.ts +60 -60
  127. package/types/domain/FormEnum.d.ts +10 -10
  128. package/types/domain/FormGroup.d.ts +27 -27
  129. package/types/domain/FormRestfulResponse.d.ts +6 -6
  130. package/types/domain/ProvideInjectData.d.ts +10 -10
  131. package/types/domain/SysDictDetail.d.ts +24 -24
  132. package/types/domain/SysDictInfo.d.ts +26 -26
  133. package/types/domain/SysDictTreeDetail.d.ts +34 -34
  134. package/types/domain/index.d.ts +12 -12
  135. package/types/filtres/amount-capitalization.filter.d.ts +7 -7
  136. package/types/filtres/extract-options.filter.d.ts +13 -13
  137. package/types/filtres/generate-grid-column-end.filter.d.ts +11 -11
  138. package/types/filtres/generate-grid-template-columns.filter.d.ts +11 -11
  139. package/types/filtres/switch-enum-convert.filter.d.ts +2 -2
  140. package/types/filtres/zoom-multiple.filter.d.ts +3 -3
  141. package/types/index.d.ts +13 -13
  142. package/types/main.d.ts +2 -2
  143. package/types/services/api.service.d.ts +25 -25
  144. package/types/services/clean-local-forage.service.d.ts +28 -28
  145. package/types/services/date-format.service.d.ts +21 -21
  146. package/types/services/dict-local-forage.service.d.ts +28 -28
  147. package/types/services/form-bean-utils.service.d.ts +23 -23
  148. package/types/services/form-local-forage.service.d.ts +28 -28
  149. package/types/services/form-tools.service.d.ts +153 -153
  150. package/types/services/form-tree-node-convert.service.d.ts +104 -104
  151. package/types/services/form-validate.service.d.ts +32 -32
  152. package/types/services/index.d.ts +9 -9
  153. package/types/services/router.service.d.ts +40 -40
  154. package/types/services/validate-generator.service.d.ts +154 -154
  155. package/types/store/dict.store.d.ts +29 -29
  156. package/types/store/form.store.d.ts +17 -17
  157. package/types/store/index.d.ts +2 -2
  158. package/types/types/vfForm.d.ts +10 -10
  159. package/.env.local.bak +0 -6
  160. package/.eslintrc.js +0 -28
  161. package/babel.config.js +0 -3
  162. package/public/favicon.ico +0 -0
  163. package/public/index.html +0 -17
  164. package/public/js/pinyin.ts +0 -101
  165. package/tsconfig.json +0 -40
  166. package/vue.config.js +0 -38
@@ -1,1238 +1,1238 @@
1
- import { FormGroup } from "@/domain";
2
- import { AbstractControl } from "@/domain/AbstractControl";
3
- import { FormControl, Validate, ValidateReport, ValidateResult } from "../domain/FormControl";
4
- import DvForm from "../components/form/DvForm.vue";
5
- import { FormFieldType, OptionType, SubmittedType, ValidateRules, ValidateStatus } from "../constants/enum";
6
- // import moment from "moment";
7
- import { ZoomType } from "@/constants";
8
- import { extractOptions, storageOptions } from "@/filtres/extract-options.filter";
9
- import { CustomFormat, FieldChangeHistory } from "../domain";
10
- import { Rule, validateGeneratorService } from "../services/validate-generator.service";
11
- import { formToolsService, formTreeNodeConvertService, formValidateService } from "@/services";
12
- import { MathJsStatic } from "mathjs";
13
- import { Vue } from "vue-property-decorator";
14
- import dayjs from "dayjs";
15
- import { dateFormat } from "@/services/date-format.service";
16
- export type FormatType = "default" | "ebtrust";
17
-
18
- export enum Attribute {
19
- IsHideControl = "isHideControl", // 隐藏控件
20
- IsRequiredValidate = "isRequiredValidate", // 是否必填
21
- FormFieldDescribe = "formFieldDescribe", // 字段别名
22
- FieldDefaultValue = "fieldDefaultValue", // 默认值
23
- TitleWidth = "titleWidth", // 标题宽度
24
- IsBoldTitle = "isBoldTitle", // 加粗标题
25
- IsHideTitle = "isHideTitle", // 隐藏标题
26
- TitleColor = "titleColor", // 标题颜色
27
- Placeholder = "placeholder", // 预期值的提示信息
28
- Tips = "tips", // 提示信息
29
- IsNotEdit = "isNotEdit", // 不可编辑
30
- BindingPrefix = "bindingPrefix", // 绑定前缀
31
- BindingSuffix = "bindingSuffix", // 绑定后缀
32
- BuiltInFrontLabel = "builtInFrontLabel", // 内置前置标签
33
- BuiltInPostLabel = "builtInPostLabel", // 内置后置标签
34
- ControlWidth = "controlWidth", // 控件宽度
35
- IsPasswordBox = "isPasswordBox", // 是否密码框
36
- InitRowHeight = "initRowHeight", // 初始行高
37
- IsFixedRowHeight = "isFixedRowHeight", // 是否固定行高
38
- FormatType = "formatType", // 格式化类型
39
- MinValue = "minValue", // 最小值
40
- MaxValue = "maxValue", // 最大值
41
- Step = "step", // 步长
42
- DecimalPlaces = "decimalPlaces", // 小数位
43
- ThousandthPercentileFormat = "thousandthPercentileFormat", // 千分位格式化
44
- Unit = "unit", // 单位
45
- ZoomType = "zoomType", // 缩放类型
46
- ZoomMultiple = "zoomMultiple", // 缩放倍数
47
- IsShowCapitalization = "isShowCapitalization", // 展示大写
48
- IsLineFeedDisplay = "isLineFeedDisplay", // 换行显示
49
- IsOptionType = "isOptionType", // 类型选项
50
- OptionConfig = "optionConfig", // 自定义字典项
51
- DateFormat = "dateFormat", // 日期格式
52
- TimeFormat = "timeFormat", // 时间格式
53
- IsSupportMultiple = "isSupportMultiple", // 是否支持多选
54
- MaxUploadNumber = "maxUploadNumber", // 最多上传个数"
55
- LimitSize = "limitSize", // 上传大小限制
56
- SupportUploadType = "supportUploadType", // 扩展类型
57
- CustomUploadType = "customUploadType", // 自定义类型
58
- ExtendUploadType = "extendUploadType", // 扩展类型
59
- AttachmentExtendProperties = "attachmentExtendProperties", // 附件扩展属性
60
- IsMultipleChoice = "isMultipleChoice", // 是否可多选
61
- IsSearchable = "isSearchable", // 是否可搜索
62
- CanAddEntry = "canAddEntry", // 是否可新增条目
63
- IsClearButton = "isClearButton", // 显示清除按钮
64
- OnOpeningValue = "onOpeningValue", // 打开时的值
65
- WhenClosedValue = "whenClosedValue", // 关闭时的值
66
- OnOpeningText = "onOpeningText", // 打开时的文字描述
67
- WhenClosedText = "whenClosedText", // 关闭时的文字描述
68
- CustomFieldName = "customFieldName", // 自定义字段名
69
- TextFold = "textFold", // 文本折叠
70
- HiddenDropdown = "hiddenDropdown", // 隐藏下拉面板
71
- BusAttr = "busAttr", // 业务属性
72
- EnableAutoComplete = "enableAutoComplete", // 开启自动完成功能
73
- AutoCompleteOptions = "autoCompleteOptions", // 自动完成列表数据
74
- IsTreeOpen = "isTreeOpen", // 树形选择框是否展开
75
- CheckboxStyle = "checkboxStyle", // 多选器选项标签样式
76
- ItemWidth = "itemWidth",
77
- ChangeOnSelect = "changeOnSelect", // 是否允许级联选择框只选中父级选项
78
- TextareaRows = "textareaRows", // 设置textarea组件默认展示行数
79
- IsShowHoliday = "isShowHoliday", // 是否展示节假日
80
- }
81
-
82
- /**
83
- * @description: 表单基础类,聚合常用api
84
- * @author ChenRui
85
- * @date 2020/11/28 23:27
86
- */
87
- export class FormApi {
88
- id?: any; // api编号
89
- dvForm: Vue | any; // form组件实例
90
- edit: boolean | undefined; // 编辑状态
91
- formatType: FormatType; // 数据格式化模式
92
- apiMetaRefresh: any; // api内部刷新标识
93
- [key: string]: any; // 任一扩展属性
94
- oldVal: any; //修改前数据
95
-
96
- /**
97
- * @description: 获取表单对象
98
- * @author ChenRui
99
- * @date 2020/11/28 23:29
100
- */
101
- constructor(
102
- options: {
103
- id?: any;
104
- dvForm?: Vue;
105
- edit?: boolean;
106
- formatType?: FormatType;
107
- } = {}
108
- ) {
109
- this.id = options.id || this.getUuid();
110
- this.dvForm = options.dvForm || new Vue(DvForm);
111
- this.edit = options.edit;
112
- this.formatType = options.formatType || "default";
113
- }
114
-
115
- get mathjs(): MathJsStatic {
116
- if ((window as any).$app.config.globalProperties.$mathjs) {
117
- return (window as any).$app.config.globalProperties.$mathjs;
118
- }
119
- return {} as MathJsStatic;
120
- }
121
-
122
- /**
123
- * @description: 获取表单值
124
- * @author ChenRui
125
- * @date 2021/2/4 10:36
126
- */
127
- get formData(): any {
128
- this.apiMetaRefresh = this.dvForm.metaRefresh;
129
- if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
130
- let obj: any = this.generateData(this.dvForm.desForm.formGroup);
131
- if (this.oldVal) {
132
- obj = this.contrast(this.oldVal, obj);
133
- if (!Object.keys(obj).length) {
134
- obj = null;
135
- }
136
- }
137
- return obj;
138
- }
139
- return null;
140
- }
141
-
142
- /**
143
- * @Description 获取表单全部值
144
- * @Author JiangTao
145
- * @Date 2023-12-22 下午 02:50
146
- */
147
- get formAllData(): any {
148
- this.apiMetaRefresh = this.dvForm.metaRefresh;
149
- if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
150
- const obj: any = this.generateData(this.dvForm.desForm.formGroup);
151
- return obj;
152
- }
153
- return null;
154
- }
155
-
156
- /**
157
- * @description: 编码表单对象
158
- * @author ChenRui
159
- * @date 2021/4/25 16:41
160
- */
161
- get encodedFormData(): any {
162
- this.apiMetaRefresh = this.dvForm.metaRefresh;
163
- if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
164
- const data = this.generateData(this.dvForm.desForm.formGroup);
165
- return this.jsonToFormData(data);
166
- }
167
- return null;
168
- }
169
-
170
- /**
171
- * @description: 设置表单值
172
- * @author ChenRui
173
- * @date 2021/2/4 10:37
174
- */
175
- setFormData(srcData: any, isDefault = false, validate = false, oldVal?: any): void {
176
- if (this.dvForm.desForm.formGroup) {
177
- this.setFormDataInner(srcData, isDefault, validate);
178
- } else {
179
- setTimeout(() => {
180
- this.setFormDataInner(srcData, isDefault, validate);
181
- });
182
- }
183
- if (oldVal) this.oldVal = oldVal;
184
- }
185
-
186
- /**
187
- * @description: 获取控件对象
188
- * @author ChenRui
189
- * @date 2021/1/29 10:08
190
- */
191
- getControl(key: string, control?: AbstractControl, showError = true): AbstractControl | any {
192
- if (key) {
193
- if (control == null) {
194
- if (this.dvForm.desForm.formGroup) {
195
- control = this.dvForm.desForm.formGroup.controls;
196
- } else if (showError) {
197
- console.log("表单对象尚未初始化完成...");
198
- }
199
- }
200
- if (control && Object.keys(control).length > 0) {
201
- for (const propName of Object.keys(control)) {
202
- if (propName === key) {
203
- return control[propName];
204
- }
205
- if (control[propName].controls && Object.keys(control[propName].controls).length > 0) {
206
- const subControl: AbstractControl = this.getControl(key, control[propName].controls);
207
- if (subControl != null) {
208
- return subControl;
209
- }
210
- }
211
- }
212
- }
213
- }
214
- return null;
215
- }
216
-
217
- /**
218
- * @description: 获取值
219
- * @author ChenRui
220
- * @date 2021/1/29 14:57
221
- */
222
- getValue(key: string): any {
223
- const control: AbstractControl = this.getControl(key);
224
- if (control) {
225
- // && control instanceof FormControl
226
- return this.decodeData(control as FormControl, false);
227
- }
228
- return null;
229
- }
230
-
231
- /**
232
- * @description: 设置值
233
- * @author ChenRui
234
- * @date 2021/1/29 16:23
235
- */
236
- setValue(key: string, val: any, isDefault = false, validate = true): void {
237
- let control: AbstractControl = this.getControl(key);
238
- if (control == null) {
239
- setTimeout(() => {
240
- control = this.getControl(key);
241
- this.setControlValue(control, key, val, isDefault, validate);
242
- });
243
- } else {
244
- this.setControlValue(control, key, val, isDefault, validate);
245
- }
246
- }
247
-
248
- /**
249
- * @description: 重置表单
250
- * @author ChenRui
251
- * @date 2021/2/22 17:40
252
- */
253
- resetValue(): void {
254
- this.dvForm.formatDesForm(true);
255
- }
256
-
257
- /**
258
- * @description: 获取文本内容
259
- * @author ChenRui
260
- * @date 2021/1/29 15:03
261
- */
262
- getText(key: string): any {
263
- const control: AbstractControl = this.getControl(key);
264
- if (control) {
265
- //control && control instanceof FormControl
266
- return control.text();
267
- }
268
- return "";
269
- }
270
-
271
- /**
272
- * @description: 获取可选项
273
- * @author ChenRui
274
- * @date 2021/1/29 16:11
275
- */
276
- getOptions(key: string): any[] {
277
- const control: AbstractControl = this.getControl(key);
278
- if (control && control.controlAttr) {
279
- //control && control instanceof FormControl && control.controlAttr
280
- return extractOptions(control.controlAttr);
281
- }
282
- return [];
283
- }
284
-
285
- /**
286
- * @description: 设置可选项
287
- * @author ChenRui
288
- * @date 2021/1/29 16:15
289
- */
290
- setOptions(key: string, data: any[], defaultVal?: any): void {
291
- let control: AbstractControl = this.getControl(key);
292
- if (control == null) {
293
- setTimeout(() => {
294
- control = this.getControl(key);
295
- this.setControlOptions(control, key, data, defaultVal);
296
- });
297
- } else {
298
- this.setControlOptions(control, key, data, defaultVal);
299
- }
300
- }
301
-
302
- /**
303
- * @description: 获取常规属性
304
- * @author ChenRui
305
- * @date 2021/1/29 17:21
306
- */
307
- getAttribute(key: string, attribute: Attribute): any {
308
- const control: AbstractControl = this.getControl(key);
309
- if (control && control.controlAttr) {
310
- //control && control instanceof FormControl && control.controlAttr
311
- return control.controlAttr[attribute];
312
- }
313
- }
314
- /**
315
- * @description: 设置常规属性
316
- * @author ChenRui
317
- * @date 2021/1/29 17:21
318
- */
319
- setAttribute(key: string, attribute: Attribute, data: any): void {
320
- let control: AbstractControl = this.getControl(key);
321
- if (control == null) {
322
- setTimeout(() => {
323
- control = this.getControl(key);
324
- this.setControlAttribute(control, attribute, data);
325
- });
326
- } else {
327
- this.setControlAttribute(control, attribute, data);
328
- }
329
- }
330
-
331
- /**
332
- * @description: 根据name获取校验
333
- * @author ChenRui
334
- * @date 2021/1/30 11:46
335
- */
336
- getValidate(key: string, name: string): any {
337
- const control: AbstractControl = this.getControl(key);
338
- if (control) {
339
- //control && control instanceof FormControl
340
- return control.getValidate(name);
341
- }
342
- }
343
-
344
- /**
345
- * @description: 移除校验
346
- * @author ChenRui
347
- * @date 2021/4/1 21:30
348
- */
349
- removeValidate(key: string, validateName: string): void {
350
- const control: AbstractControl = this.getControl(key);
351
- if (control) {
352
- //control && control instanceof FormControl
353
- const validates: Validate[] = control.validates;
354
- if (validates && validates.length > 0) {
355
- const index = validates.findIndex((item) => item.name === validateName);
356
- if (index !== -1) {
357
- validates.splice(index, 1);
358
- }
359
- }
360
- }
361
- }
362
-
363
- /**
364
- * @description: 移除所有校验
365
- * @author ChenRui
366
- * @date 2021/4/1 21:48
367
- */
368
- removeAllValidates(key: string): void {
369
- const control: AbstractControl = this.getControl(key);
370
- if (control) {
371
- //control && control instanceof FormControl
372
- control.validates = [];
373
- }
374
- }
375
-
376
- /**
377
- * @description: 获取校验集合
378
- * @author ChenRui
379
- * @date 2021/1/30 11:40
380
- */
381
- getValidates(key: string): Validate[] {
382
- const control: AbstractControl = this.getControl(key);
383
- if (control) {
384
- //control && control instanceof FormControl
385
- return control.validates;
386
- }
387
- return [];
388
- }
389
- /**
390
- * @Description: 设置必输校验
391
- * @author GuoXuHui
392
- * @date 2022-05-25
393
- * @time 10:09
394
- */
395
- setRequiredValidate(key: string, data: boolean) {
396
- if (data) {
397
- this.setValidate(key, { ruleType: ValidateRules.Required.code });
398
- } else {
399
- this.removeValidate(key, ValidateRules.Required.code); // 清除必填校验
400
- }
401
- }
402
-
403
- /**
404
- * @description: 设置校验
405
- * @author ChenRui
406
- * @date 2021/1/30 11:54
407
- */
408
- setValidate(key: string, validate: Validate | Validate[] | Rule, isCover = false): void {
409
- let control: AbstractControl = this.getControl(key);
410
- if (control == null) {
411
- setTimeout(() => {
412
- control = this.getControl(key);
413
- if (control) {
414
- //control && control instanceof FormControl
415
- this.setValidateInner(control, validate, isCover);
416
- }
417
- });
418
- } else {
419
- this.setValidateInner(control, validate, isCover);
420
- }
421
- }
422
-
423
- /**
424
- * @description: 校验提示
425
- * @author ChenRui
426
- * @date 2021/8/18 17:40
427
- */
428
- validateTips(scrollView?: any): boolean {
429
- return formValidateService.validateTips(this, scrollView);
430
- }
431
-
432
- /**
433
- * @description: 全局校验报告
434
- * @author ChenRui
435
- * @date 2021/2/5 11:48
436
- */
437
- validateReport(formGroup?: AbstractControl, validateReports?: ValidateReport[], refreshFeedback = true): ValidateReport[] {
438
- if (validateReports == null) {
439
- validateReports = [];
440
- }
441
- if (formGroup == null) {
442
- formGroup = this.dvForm.desForm.formGroup;
443
- if (refreshFeedback) {
444
- this.dvForm.refreshCheckFeedbackFlag = new Date().getTime();
445
- }
446
- }
447
- if (formGroup != null) {
448
- for (const propName of Object.keys(formGroup.controls)) {
449
- if (formGroup.controls[propName] instanceof FormGroup) {
450
- this.validateReport(formGroup.controls[propName], validateReports);
451
- } else if (formGroup.controls[propName] instanceof FormControl && !formGroup.controls[propName].controlAttr.isHideControl) {
452
- const validateResult: ValidateResult = formGroup.controls[propName].validate();
453
- if (validateResult.validateStatus === ValidateStatus.Error.code) {
454
- validateReports.push({
455
- key: formGroup.controls[propName].key,
456
- name: formGroup.controls[propName].controlAttr.formFieldDescribe,
457
- errorMsg: validateResult.errorMsg,
458
- controlType: formGroup.controls[propName].controlAttr.controlType,
459
- });
460
- }
461
- }
462
- }
463
- }
464
- return validateReports;
465
- }
466
-
467
- /**
468
- * @description: 表单全局校验
469
- * @author ChenRui
470
- * @date 2021/2/5 14:11
471
- */
472
- validate(refreshFeedback = true): boolean {
473
- const validateReports: ValidateReport[] = this.validateReport(undefined, undefined, refreshFeedback);
474
- return !(validateReports.length > 0);
475
- }
476
-
477
- /**
478
- * @description: 刷新校验
479
- * @author ChenRui
480
- * @date 2021/6/4 19:32
481
- */
482
- refreshValidate(key: string): void {
483
- let control: AbstractControl = this.getControl(key);
484
- if (control == null) {
485
- setTimeout(() => {
486
- control = this.getControl(key);
487
- control["refreshValidate"] = new Date().getTime();
488
- });
489
- } else {
490
- control["refreshValidate"] = new Date().getTime();
491
- }
492
- }
493
-
494
- /**
495
- * @description: 重置表单校验
496
- * @author ChenRui
497
- * @date 2022/4/6 11:51
498
- */
499
- resetFormValidateState(): void {
500
- this.dvForm.formValidateStateResetMark = new Date().getTime();
501
- }
502
-
503
- /**
504
- * @description: 设置格式化显示和输出函数
505
- * @author ChenRui
506
- * @date 2021/2/4 19:44
507
- */
508
- setFormatDisplayAndOutput(key: string, customFormat: CustomFormat): void {
509
- if (key) {
510
- this.dvForm.customFormats[key] = customFormat;
511
- }
512
- this.refreshAndUpdateData();
513
- }
514
-
515
- /**
516
- * @description: 刷新数据
517
- * @author ChenRui
518
- * @date 2021/2/4 20:22
519
- */
520
- refreshAndUpdateData(): void {
521
- this.dvForm.onRefreshArgumentsHandler(new Date().getTime());
522
- }
523
-
524
- /**
525
- * @description: 获取控件dom对象
526
- * @author ChenRui
527
- * @date 2021/2/26 17:12
528
- */
529
- getControlEl(key: string): any {
530
- const control: AbstractControl = this.getControl(key);
531
- if (control != null && control.controlAttr) {
532
- const els: HTMLCollectionOf<any> = document.getElementsByClassName("form-model-item-" + control.controlAttr.boundProperty);
533
- if (els != null && els.length > 0) {
534
- return els[0];
535
- }
536
- }
537
- return null;
538
- }
539
-
540
- /**
541
- * @description: 检查是否包含上传控件
542
- * @author ChenRui
543
- * @date 2021/4/23 11:30
544
- */
545
- checkHasUploadControl(abstractControl: AbstractControl): boolean {
546
- if (abstractControl instanceof FormGroup) {
547
- const formGroup: FormGroup = abstractControl as FormGroup;
548
- for (const propName of Object.keys(formGroup.controls)) {
549
- if (formGroup.controls[propName] instanceof FormGroup) {
550
- const judge = this.checkHasUploadControl(formGroup.controls[propName]);
551
- if (judge) {
552
- return judge;
553
- }
554
- } else if (formGroup.controls[propName] instanceof FormControl) {
555
- if (formGroup.controls[propName].code === FormFieldType.Upload.code) {
556
- return true;
557
- }
558
- }
559
- }
560
- }
561
- return false;
562
- }
563
-
564
- /**
565
- * @description: json格式转表单格式
566
- * @author ChenRui
567
- * @date 2020/8/28 15:20
568
- */
569
- jsonToFormData(params: any): FormData {
570
- const formData = new FormData();
571
- if (params != null) {
572
- Object.keys(params).forEach((key) => {
573
- if (params[key] != null && params[key] instanceof Array && params[key].length > 0 && params[key][0] instanceof File) {
574
- params[key].forEach((item: any) => {
575
- formData.append(key, item);
576
- });
577
- } else {
578
- formData.append(key, params[key]);
579
- }
580
- });
581
- return formData;
582
- }
583
- return formData;
584
- }
585
-
586
- /**
587
- * @description: 设置变更历史记录
588
- * @author ChenRui
589
- * @date 2021/4/25 15:55
590
- */
591
- setFieldChangeHistory(fieldChangeHistory: FieldChangeHistory): void {
592
- fieldChangeHistory = fieldChangeHistory || {};
593
- for (const propertyName of Object.keys(fieldChangeHistory)) {
594
- let control: AbstractControl = this.getControl(propertyName, undefined, false);
595
- if (control == null) {
596
- setTimeout(() => {
597
- control = this.getControl(propertyName, undefined, false);
598
- if (control) {
599
- //control && control instanceof FormControl
600
- const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
601
- const aTime = new Date(a.time).getTime();
602
- const bTime = new Date(b.time).getTime();
603
- return bTime - aTime;
604
- });
605
- control.history = history;
606
- }
607
- });
608
- } else {
609
- control = this.getControl(propertyName, undefined, false);
610
- if (control) {
611
- //control && control instanceof FormControl
612
- const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
613
- const aTime = new Date(a.time).getTime();
614
- const bTime = new Date(b.time).getTime();
615
- return bTime - aTime;
616
- });
617
- control.history = history;
618
- }
619
- }
620
- }
621
- }
622
-
623
- /**
624
- * @description: 隐藏布局
625
- * @author ChenRui
626
- * @date 2021/11/16 0:01
627
- */
628
- hideLayout(layoutName: string, mark = true): void {
629
- if (layoutName) {
630
- const nodes: any = document.getElementsByClassName("lo-form-layout-" + layoutName);
631
- if (nodes && nodes.length > 0) {
632
- for (let i = 0; i < nodes.length; i++) {
633
- nodes[i].style.display = mark ? "none" : "grid";
634
- }
635
- }
636
- }
637
- }
638
-
639
- /**
640
- * @description: 设置表单值
641
- * @author ChenRui
642
- * @date 2021/8/16 9:29
643
- */
644
- private setFormDataInner(srcData: any, isDefault: boolean, validate: boolean): void {
645
- if (srcData) {
646
- for (const propName of Object.keys(srcData)) {
647
- if (typeof srcData[propName] === "string" || typeof srcData[propName] === "number") {
648
- this.setValue(propName, srcData[propName], isDefault, false);
649
- } else {
650
- this.setFormData(srcData[propName], isDefault, validate);
651
- }
652
- }
653
- }
654
- if (validate) {
655
- this.validate();
656
- }
657
- }
658
-
659
- /**
660
- * @description: 设置控件值
661
- * @author ChenRui
662
- * @date 2021/4/13 12:50
663
- */
664
- private setControlValue(control: AbstractControl, key: string, val: any, isDefault?: boolean, validate = true): void {
665
- if (control) {
666
- // && control instanceof FormControl
667
- switch (control.code) {
668
- case FormFieldType.InputNumber.code:
669
- if (val && control.controlAttr.zoomMultiple) {
670
- if (control.controlAttr.zoomType === ZoomType.enlarge.code) {
671
- val = this.mathjs.format(this.mathjs.evaluate(`${val} / ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
672
- } else if (control.controlAttr.zoomType === ZoomType.narrow.code) {
673
- val = this.mathjs.format(this.mathjs.evaluate(`${val} * ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
674
- }
675
- }
676
- if (val != undefined) {
677
- control.value = val;
678
- } else {
679
- control.value = "";
680
- }
681
- break;
682
- case FormFieldType.Select.code:
683
- if (control.controlAttr.isMultipleChoice) {
684
- if (!val) {
685
- val = [];
686
- } else if (typeof val === "string") {
687
- val = val.split(",");
688
- }
689
- }
690
- control.value = val;
691
- break;
692
- case FormFieldType.Checkbox.code:
693
- case FormFieldType.Cascader.code:
694
- if (val) {
695
- val = val.split(",");
696
- } else {
697
- val = [];
698
- }
699
- control.value = val;
700
- break;
701
- case FormFieldType.Switch.code:
702
- if (control.controlAttr.onOpeningValue) {
703
- val = val === true || val === control.controlAttr.onOpeningValue;
704
- } else if (control.controlAttr.whenClosedValue) {
705
- val = !(val === false || val === control.controlAttr.whenClosedValue);
706
- }
707
- control.value = val;
708
- break;
709
- case FormFieldType.TimePicker.code:
710
- if (val) {
711
- if (typeof val === "string") {
712
- val = dayjs(new Date(this.nowDateStr() + " " + val));
713
- } else if (val instanceof Date) {
714
- val = dayjs(val);
715
- }
716
- control.value = val;
717
- } else {
718
- control.value = null;
719
- }
720
- break;
721
- case FormFieldType.DatePicker.code:
722
- if (val) {
723
- if (typeof val === "string") {
724
- val = dayjs(val, control.dateFormat);
725
- } else if (val instanceof Date) {
726
- val = dayjs(val);
727
- }
728
- control.value = val;
729
- } else {
730
- control.value = null;
731
- }
732
- break;
733
- default: {
734
- control.value = val;
735
- }
736
- }
737
- if (isDefault) {
738
- this.setAttribute(key, Attribute.FieldDefaultValue, JSON.stringify(control.value));
739
- }
740
- if (validate) {
741
- control["refreshValidate"] = new Date().getTime();
742
- }
743
- }
744
- }
745
-
746
- /**
747
- * @description: 设置控件可选项
748
- * @author ChenRui
749
- * @date 2021/4/13 15:09
750
- */
751
- private setControlOptions(control: AbstractControl, key: string, data: any[], defaultVal?: any): void {
752
- if (control && control.controlAttr) {
753
- //control && control instanceof FormControl && control.controlAttr)
754
- storageOptions(control.controlAttr, data);
755
- this.setAttribute(key, Attribute.IsOptionType, OptionType.Fixed.code);
756
- this.setAttribute(key, Attribute.OptionConfig, data);
757
- }
758
- if (defaultVal) {
759
- this.setValue(key, defaultVal, true);
760
- }
761
- }
762
-
763
- /**
764
- * @description: 设置控件常规属性
765
- * @author ChenRui
766
- * @date 2021/4/13 15:11
767
- */
768
- private setControlAttribute(control: AbstractControl, attribute: Attribute, data: any): void {
769
- if (control && attribute) {
770
- //control && control instanceof FormControl && attribute
771
- control.controlAttr[attribute] = data;
772
- }
773
- }
774
-
775
- /**
776
- * @description: 设置校验内部函数
777
- * @author ChenRui
778
- * @date 2021/7/19 17:51
779
- */
780
- private setValidateInner(control: AbstractControl, validate: Validate | Validate[] | Rule, isCover = false): void {
781
- if (validate != null && (validate as Rule).ruleType) {
782
- validate = validateGeneratorService.getBuiltInValidationRules(validate as Rule, control.controlAttr) as any;
783
- }
784
- if (validate != null) {
785
- if (isCover) {
786
- control.validates = [];
787
- }
788
- control.addValidate(validate);
789
- }
790
- }
791
-
792
- /**
793
- * @description: 生成数据信息
794
- * @author ChenRui
795
- * @date 2021/1/29 10:06
796
- */
797
- private generateData(abstractControl: AbstractControl, obj: any = {}): any {
798
- if (abstractControl instanceof FormGroup) {
799
- const formGroup: FormGroup = abstractControl as FormGroup;
800
- for (const propName of Object.keys(formGroup.controls)) {
801
- if (formGroup.controls[propName] instanceof FormGroup) {
802
- obj[propName] = this.generateData(formGroup.controls[propName], obj[propName]);
803
- } else if (formGroup.controls[propName] instanceof FormControl) {
804
- obj[propName] = this.decodeData(formGroup.controls[propName] as FormControl);
805
- }
806
- }
807
- }
808
- return obj;
809
- }
810
-
811
- /**
812
- * @description: 数据解码输出
813
- * @author ChenRui
814
- * @date 2021/5/29 23:03
815
- */
816
- private decodeData(formControl: FormControl, isFinal = true): any {
817
- let data = formControl.value || "";
818
- switch (formControl.code) {
819
- case FormFieldType.InputNumber.code:
820
- if (data && formControl.controlAttr.zoomMultiple) {
821
- if (formControl.controlAttr.zoomType === ZoomType.enlarge.code) {
822
- data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
823
- } else if (formControl.controlAttr.zoomType === ZoomType.narrow.code) {
824
- data = this.mathjs.format(this.mathjs.evaluate(`${data} / ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
825
- } else if (formControl.controlAttr.zoomType === ZoomType.automatic.code) {
826
- data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
827
- }
828
- }
829
- if (formControl.value === 0) {
830
- data = 0;
831
- }
832
- break;
833
- case FormFieldType.Select.code:
834
- if (formControl.controlAttr.isMultipleChoice && data && Array.isArray(data)) {
835
- data = data.join(",");
836
- }
837
- break;
838
- case FormFieldType.Checkbox.code:
839
- if (data && isFinal) {
840
- data = data.join(",");
841
- }
842
- break;
843
- case FormFieldType.TimePicker.code:
844
- if (data) {
845
- data = dayjs(data).format(formControl.controlAttr.timeFormat || "LTS");
846
- }
847
- break;
848
- case FormFieldType.DatePicker.code:
849
- if (data) {
850
- data = dayjs(data).format(formControl.controlAttr.dateFormat || "YYYY-MM-DD");
851
- }
852
- break;
853
- case FormFieldType.Cascader.code:
854
- if (data) {
855
- data = data.join(",");
856
- }
857
- break;
858
- case FormFieldType.Switch.code:
859
- data = !!data;
860
- if (formControl.controlAttr) {
861
- if (data === true && formControl.controlAttr.onOpeningValue != undefined && formControl.controlAttr.onOpeningValue !== "") {
862
- data = formControl.controlAttr.onOpeningValue;
863
- } else if (data === false && formControl.controlAttr.whenClosedValue != undefined && formControl.controlAttr.whenClosedValue !== "") {
864
- data = formControl.controlAttr.whenClosedValue;
865
- }
866
- }
867
- break;
868
- case FormFieldType.Custom.code:
869
- if (formControl.controlAttr && formControl.controlAttr.customFieldName) {
870
- const customFormat: CustomFormat = this.dvForm.customFormats[formControl.controlAttr.customFieldName];
871
- if (customFormat && customFormat.output) {
872
- data = customFormat.output(data, formControl.controlAttr);
873
- }
874
- }
875
- }
876
- return data;
877
- }
878
-
879
- /**
880
- * @description: 获取当前日期字符串
881
- * @author ChenRui
882
- * @date 2021/2/4 11:43
883
- */
884
- private nowDateStr(): string {
885
- const time = new Date();
886
- const day = ("0" + time.getDate()).slice(-2);
887
- const month = ("0" + (time.getMonth() + 1)).slice(-2);
888
- return time.getFullYear() + "/" + month + "/" + day;
889
- }
890
-
891
- /**
892
- * @description: uuid生成器
893
- * @author ChenRui
894
- * @date 2021/7/20 11:14
895
- */
896
- private getUuid(): string {
897
- const s: any[] = [];
898
- const hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
899
- for (let i = 0; i < 36; i++) {
900
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
901
- }
902
- s[14] = "4";
903
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
904
- s[8] = s[13] = s[18] = s[23] = "-";
905
- const uuid = s.join("");
906
- return uuid;
907
- }
908
-
909
- /**
910
- * @Description: 对比新旧表单值
911
- * @author lzs
912
- * @date 2022/9/3
913
- * @time 21:49
914
- */
915
- private contrast(objectA: any, objectB: any): any {
916
- const object: any = {};
917
- const data: any = {};
918
- const fieldInfoArr: any = [];
919
- if (!objectB || !objectA) {
920
- object.changeLog = "必传参数不存在";
921
- return object;
922
- }
923
- const handlerFlag = objectA.handlerFlag;
924
- // console.log("======", this.dvForm.desForm.formGroup.controls);
925
- for (const key in this.dvForm.desForm.formGroup.controls) {
926
- if (!objectA[key] && !objectB[key]) {
927
- continue;
928
- }
929
- const control: AbstractControl = this.getControl(key);
930
- if (!control) {
931
- continue;
932
- }
933
- if (this.getChangedInfo(control, objectA[key], objectB[key])) {
934
- let oldValue = objectA[key]; // 记录新值
935
- const newValue = objectB[key]; // 记录旧值
936
- const fieldInfo: any = {}; //日志信息
937
- if (control.code !== FormFieldType.Custom.code) {
938
- fieldInfo.field_cd = key; //字段英文
939
- const name = control.controlAttr.formFieldDescribe;
940
- fieldInfo.field_nm = name; //字段中文
941
- fieldInfo.field_key = newValue; //当前值
942
-
943
- const newDict = this.translateDictionaries(control, key, newValue); // 新值描述
944
- fieldInfo.field_value = newDict; //当前值描述
945
-
946
- fieldInfo.is_change = "1"; //是否变动
947
-
948
- fieldInfo.field_old_key = oldValue; //旧值
949
- const oldDict = this.translateDictionaries(control, key, oldValue); //旧值描述
950
- fieldInfo.field_old_value = oldDict; //field_old_value
951
- object[key] = newValue;
952
-
953
- fieldInfoArr.push(fieldInfo);
954
- if (oldValue === "null" || oldValue === "undefined") {
955
- oldValue = "";
956
- }
957
- const oldName = oldValue ? oldDict : "空";
958
- const newName = newValue ? newDict : "空";
959
- //除自定义组件均记录日志
960
- object.changeLog = object.changeLog ? object.changeLog + "," : "";
961
- if (handlerFlag === "add") {
962
- object.changeLog = object.changeLog + "新增【" + name + "】" + "为“" + newName + "”";
963
- } else {
964
- object.changeLog = object.changeLog + "修改【" + name + "】" + "由“" + oldName + "”修改为“" + newName + "”";
965
- }
966
- } else {
967
- object[key] = newValue;
968
- }
969
- }
970
- }
971
- object.fieldInfoArr = fieldInfoArr;
972
- return object;
973
- }
974
- /**
975
- * @Description: 获取表单值更改信息
976
- * @author lzs
977
- * @date 2022/10/11
978
- * @time 09:53
979
- */
980
- getChangedInfo(control: any, oldValue: any, newValue: any): boolean {
981
- oldValue = oldValue + "";
982
- newValue = newValue + "";
983
- if (oldValue === "null" || oldValue === "undefined") {
984
- return true;
985
- }
986
- let flag = true;
987
- switch (control.code) {
988
- case FormFieldType.Input.code:
989
- if (oldValue === newValue) flag = false;
990
- break;
991
- case FormFieldType.InputNumber.code:
992
- if (oldValue === newValue) flag = false;
993
- break;
994
- case FormFieldType.Textarea.code:
995
- if (oldValue === newValue) flag = false;
996
- break;
997
- case FormFieldType.Slider.code:
998
- if (oldValue === newValue) flag = false;
999
- break;
1000
- case FormFieldType.Rate.code:
1001
- if (oldValue === newValue) flag = false;
1002
- break;
1003
- case FormFieldType.Select.code:
1004
- if (oldValue === newValue) flag = false;
1005
- break;
1006
- case FormFieldType.Checkbox.code:
1007
- if (oldValue === newValue) flag = false;
1008
- break;
1009
- case FormFieldType.Radio.code:
1010
- if (oldValue === newValue) flag = false;
1011
- break;
1012
- case FormFieldType.TimePicker.code:
1013
- if (oldValue === newValue) flag = false;
1014
- break;
1015
- case FormFieldType.DatePicker.code:
1016
- oldValue = dateFormat.formatDateTime(oldValue, "YYYY-MM-dd");
1017
- newValue = dateFormat.formatDateTime(newValue, "YYYY-MM-dd");
1018
- if (oldValue === newValue) flag = false;
1019
- break;
1020
- case FormFieldType.Cascader.code:
1021
- if (oldValue === newValue) flag = false;
1022
- break;
1023
- case FormFieldType.TreeSelect.code:
1024
- if (oldValue === newValue) flag = false;
1025
- break;
1026
- case FormFieldType.Switch.code:
1027
- if (oldValue === newValue) flag = false;
1028
- break;
1029
- case FormFieldType.Custom.code:
1030
- break;
1031
- }
1032
- return flag;
1033
- }
1034
- /**
1035
- * @Description: 翻译字典项
1036
- * @author lzs
1037
- * @date 2022/9/6
1038
- * @time 11:54
1039
- */
1040
- translateDictionaries(control: any, key: any, value: any): string {
1041
- let str = value;
1042
- switch (control.code) {
1043
- case FormFieldType.Input.code:
1044
- break;
1045
- case FormFieldType.InputNumber.code:
1046
- break;
1047
- case FormFieldType.Textarea.code:
1048
- break;
1049
- case FormFieldType.Slider.code:
1050
- break;
1051
- case FormFieldType.Rate.code:
1052
- break;
1053
- case FormFieldType.Select.code:
1054
- if (control.controlAttr.generalDictionaryOptions) {
1055
- control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1056
- if (item.value === value) {
1057
- str = item.title;
1058
- }
1059
- });
1060
- } else {
1061
- control.controlAttr.optionConfig.forEach((item: any) => {
1062
- if (item.value === value) {
1063
- str = item.title;
1064
- }
1065
- });
1066
- }
1067
- break;
1068
- case FormFieldType.Checkbox.code:
1069
- str = "";
1070
- if (value) {
1071
- if (control.controlAttr.generalDictionaryOptions) {
1072
- control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1073
- value.split(",").forEach((index: any) => {
1074
- if (item.value === index) {
1075
- str = str + item.title + ",";
1076
- }
1077
- });
1078
- });
1079
- } else {
1080
- control.controlAttr.optionConfig.forEach((item: any) => {
1081
- value.split(",").forEach((index: any) => {
1082
- if (item.value === index) {
1083
- str = str + item.title + ",";
1084
- }
1085
- });
1086
- });
1087
- }
1088
- str = str.substring(0, str.length - 1);
1089
- }
1090
- break;
1091
- case FormFieldType.Radio.code:
1092
- if (control.controlAttr.generalDictionaryOptions) {
1093
- control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1094
- if (item.value === value) {
1095
- str = item.title;
1096
- }
1097
- });
1098
- } else {
1099
- control.controlAttr.optionConfig.forEach((item: any) => {
1100
- if (item.value === value) {
1101
- str = item.title;
1102
- }
1103
- });
1104
- }
1105
- break;
1106
- case FormFieldType.TimePicker.code:
1107
- break;
1108
- case FormFieldType.DatePicker.code:
1109
- str = dateFormat.formatDateTime(value, "YYYY-MM-dd");
1110
- break;
1111
- case FormFieldType.Cascader.code:
1112
- str = "";
1113
- if (value) {
1114
- formTreeNodeConvertService.treeNodeConvertToArray(control.controlAttr.treeShapeOptions, [], "children").forEach((item: any) => {
1115
- value.split(",").forEach((index: any) => {
1116
- if (item.value === index) {
1117
- str = str + item.title + ",";
1118
- }
1119
- });
1120
- });
1121
- str = str.substring(0, str.length - 1);
1122
- } else {
1123
- str = "";
1124
- }
1125
- break;
1126
- case FormFieldType.TreeSelect.code:
1127
- str = "";
1128
- formTreeNodeConvertService.treeNodeConvertToArray(control.controlAttr.treeShapeOptions, [], "children").forEach((item: any) => {
1129
- if (item.value === value) {
1130
- str = str + item.title;
1131
- }
1132
- });
1133
- break;
1134
- case FormFieldType.Switch.code:
1135
- str = value ? "开" : "关";
1136
- break;
1137
- case FormFieldType.Custom.code:
1138
- break;
1139
- default:
1140
- str = value;
1141
- break;
1142
- }
1143
- return str;
1144
- }
1145
-
1146
- /**
1147
- * @Description 根据报送类型返回需要隐藏的表单字段
1148
- * @Author JiangTao
1149
- * @Date 2024-01-30 上午 09:33
1150
- */
1151
- getFormSubmittedType(form: any, code: any) {
1152
- const strArr = code && code.length > 0 ? code : [];
1153
- const list: any = this.dvForm.desForm.controls[0].subControls;
1154
- const subControlsList: any = formToolsService.loadResource(this.dvForm.desForm.formId).controls[0].subControls;
1155
- const submittedTypeList: any = [];
1156
- if (strArr.length > 0) {
1157
- // 遍历组件实例
1158
- list.forEach((item: any, index: any) => {
1159
- if (item.formControl) {
1160
- // 校验当前字段是否已隐藏,已隐藏的字段不做处理
1161
- if (!form.getAttribute(item.formControl.key, Attribute.IsHideControl)) {
1162
- // 处理普通表单控件
1163
- submittedTypeList.push(item.formControl.key);
1164
- // 初始化字段是否隐藏属性
1165
- form.setAttribute(item.formControl.key, Attribute.IsHideControl, subControlsList[index].controlAttr.isHideControl);
1166
- // 筛选报送类型字段数据处理
1167
- this.handleSubmittedData(submittedTypeList, strArr, item);
1168
- }
1169
- } else if (item.subControls) {
1170
- // 处理栅格中表单控件
1171
- // 遍历栅格中控件
1172
- item.subControls.forEach((control: any, num: any) => {
1173
- // 校验当前字段是否已隐藏,已隐藏的字段不做处理
1174
- if (!form.getAttribute(control.formControl.key, Attribute.IsHideControl)) {
1175
- submittedTypeList.push(control.formControl.key);
1176
- // 初始化字段是否隐藏属性
1177
- form.setAttribute(control.formControl.key, Attribute.IsHideControl, subControlsList[index].subControls[num].controlAttr.isHideControl);
1178
- // 筛选报送类型字段数据处理
1179
- this.handleSubmittedData(submittedTypeList, strArr, control);
1180
- }
1181
- });
1182
- }
1183
- });
1184
- // 隐藏无需展示的表单字段
1185
- submittedTypeList.forEach((item: any) => {
1186
- form.setAttribute(item, Attribute.IsHideControl, true);
1187
- });
1188
- } else {
1189
- // 默认展示全部字段
1190
- list.forEach((item: any, index: any) => {
1191
- if (item.formControl) {
1192
- form.setAttribute(item.formControl.key, Attribute.IsHideControl, subControlsList[index].controlAttr.isHideControl);
1193
- } else if (item.subControls) {
1194
- item.subControls.forEach((control: any, num: any) => {
1195
- form.setAttribute(control.formControl.key, Attribute.IsHideControl, subControlsList[index].subControls[num].controlAttr.isHideControl);
1196
- });
1197
- }
1198
- });
1199
- }
1200
- }
1201
-
1202
- /**
1203
- * @Description 筛选报送类型字段数据处理
1204
- * @Author JiangTao
1205
- * @Date 2024-01-30 下午 08:50
1206
- */
1207
- private handleSubmittedData(submittedTypeList: any, codeArr: any, submittedData: any): void {
1208
- let submittedType: any = [];
1209
- if (JSON.parse(submittedData.formControl.controlAttr.busAttr).submittedType !== "") {
1210
- // 获取字段报送类型
1211
- submittedType = JSON.parse(submittedData.formControl.controlAttr.busAttr).submittedType.split(",");
1212
- // 遍历查询报送类型
1213
- for (let i = 0; i < codeArr.length; i++) {
1214
- // 判断是否为查询的报送类型字段
1215
- if (submittedType.filter((type: any) => type === codeArr[i]).length > 0 && submittedTypeList.indexOf(submittedData.formControl.key) >= 0) {
1216
- submittedTypeList.splice(submittedTypeList.indexOf(submittedData.formControl.key), 1);
1217
- break;
1218
- }
1219
- }
1220
- }
1221
- }
1222
-
1223
- /**
1224
- * @Description 获取报送类型枚举(数组)
1225
- * @Author JiangTao
1226
- * @Date 2024-01-30 下午 03:30
1227
- */
1228
- getSubmittedType() {
1229
- const list: any = [];
1230
- Object.values(SubmittedType).forEach((item: any) => {
1231
- list.push({
1232
- value: item.code,
1233
- label: item.name,
1234
- });
1235
- });
1236
- return list;
1237
- }
1238
- }
1
+ import { FormGroup } from "@/domain";
2
+ import { AbstractControl } from "@/domain/AbstractControl";
3
+ import { FormControl, Validate, ValidateReport, ValidateResult } from "../domain/FormControl";
4
+ import DvForm from "../components/form/DvForm.vue";
5
+ import { FormFieldType, OptionType, SubmittedType, ValidateRules, ValidateStatus } from "../constants/enum";
6
+ // import moment from "moment";
7
+ import { ZoomType } from "@/constants";
8
+ import { extractOptions, storageOptions } from "@/filtres/extract-options.filter";
9
+ import { CustomFormat, FieldChangeHistory } from "../domain";
10
+ import { Rule, validateGeneratorService } from "../services/validate-generator.service";
11
+ import { formToolsService, formTreeNodeConvertService, formValidateService } from "@/services";
12
+ import { MathJsStatic } from "mathjs";
13
+ import { Vue } from "vue-property-decorator";
14
+ import dayjs from "dayjs";
15
+ import { dateFormat } from "@/services/date-format.service";
16
+ export type FormatType = "default" | "ebtrust";
17
+
18
+ export enum Attribute {
19
+ IsHideControl = "isHideControl", // 隐藏控件
20
+ IsRequiredValidate = "isRequiredValidate", // 是否必填
21
+ FormFieldDescribe = "formFieldDescribe", // 字段别名
22
+ FieldDefaultValue = "fieldDefaultValue", // 默认值
23
+ TitleWidth = "titleWidth", // 标题宽度
24
+ IsBoldTitle = "isBoldTitle", // 加粗标题
25
+ IsHideTitle = "isHideTitle", // 隐藏标题
26
+ TitleColor = "titleColor", // 标题颜色
27
+ Placeholder = "placeholder", // 预期值的提示信息
28
+ Tips = "tips", // 提示信息
29
+ IsNotEdit = "isNotEdit", // 不可编辑
30
+ BindingPrefix = "bindingPrefix", // 绑定前缀
31
+ BindingSuffix = "bindingSuffix", // 绑定后缀
32
+ BuiltInFrontLabel = "builtInFrontLabel", // 内置前置标签
33
+ BuiltInPostLabel = "builtInPostLabel", // 内置后置标签
34
+ ControlWidth = "controlWidth", // 控件宽度
35
+ IsPasswordBox = "isPasswordBox", // 是否密码框
36
+ InitRowHeight = "initRowHeight", // 初始行高
37
+ IsFixedRowHeight = "isFixedRowHeight", // 是否固定行高
38
+ FormatType = "formatType", // 格式化类型
39
+ MinValue = "minValue", // 最小值
40
+ MaxValue = "maxValue", // 最大值
41
+ Step = "step", // 步长
42
+ DecimalPlaces = "decimalPlaces", // 小数位
43
+ ThousandthPercentileFormat = "thousandthPercentileFormat", // 千分位格式化
44
+ Unit = "unit", // 单位
45
+ ZoomType = "zoomType", // 缩放类型
46
+ ZoomMultiple = "zoomMultiple", // 缩放倍数
47
+ IsShowCapitalization = "isShowCapitalization", // 展示大写
48
+ IsLineFeedDisplay = "isLineFeedDisplay", // 换行显示
49
+ IsOptionType = "isOptionType", // 类型选项
50
+ OptionConfig = "optionConfig", // 自定义字典项
51
+ DateFormat = "dateFormat", // 日期格式
52
+ TimeFormat = "timeFormat", // 时间格式
53
+ IsSupportMultiple = "isSupportMultiple", // 是否支持多选
54
+ MaxUploadNumber = "maxUploadNumber", // 最多上传个数"
55
+ LimitSize = "limitSize", // 上传大小限制
56
+ SupportUploadType = "supportUploadType", // 扩展类型
57
+ CustomUploadType = "customUploadType", // 自定义类型
58
+ ExtendUploadType = "extendUploadType", // 扩展类型
59
+ AttachmentExtendProperties = "attachmentExtendProperties", // 附件扩展属性
60
+ IsMultipleChoice = "isMultipleChoice", // 是否可多选
61
+ IsSearchable = "isSearchable", // 是否可搜索
62
+ CanAddEntry = "canAddEntry", // 是否可新增条目
63
+ IsClearButton = "isClearButton", // 显示清除按钮
64
+ OnOpeningValue = "onOpeningValue", // 打开时的值
65
+ WhenClosedValue = "whenClosedValue", // 关闭时的值
66
+ OnOpeningText = "onOpeningText", // 打开时的文字描述
67
+ WhenClosedText = "whenClosedText", // 关闭时的文字描述
68
+ CustomFieldName = "customFieldName", // 自定义字段名
69
+ TextFold = "textFold", // 文本折叠
70
+ HiddenDropdown = "hiddenDropdown", // 隐藏下拉面板
71
+ BusAttr = "busAttr", // 业务属性
72
+ EnableAutoComplete = "enableAutoComplete", // 开启自动完成功能
73
+ AutoCompleteOptions = "autoCompleteOptions", // 自动完成列表数据
74
+ IsTreeOpen = "isTreeOpen", // 树形选择框是否展开
75
+ CheckboxStyle = "checkboxStyle", // 多选器选项标签样式
76
+ ItemWidth = "itemWidth",
77
+ ChangeOnSelect = "changeOnSelect", // 是否允许级联选择框只选中父级选项
78
+ TextareaRows = "textareaRows", // 设置textarea组件默认展示行数
79
+ IsShowHoliday = "isShowHoliday", // 是否展示节假日
80
+ }
81
+
82
+ /**
83
+ * @description: 表单基础类,聚合常用api
84
+ * @author ChenRui
85
+ * @date 2020/11/28 23:27
86
+ */
87
+ export class FormApi {
88
+ id?: any; // api编号
89
+ dvForm: Vue | any; // form组件实例
90
+ edit: boolean | undefined; // 编辑状态
91
+ formatType: FormatType; // 数据格式化模式
92
+ apiMetaRefresh: any; // api内部刷新标识
93
+ [key: string]: any; // 任一扩展属性
94
+ oldVal: any; //修改前数据
95
+
96
+ /**
97
+ * @description: 获取表单对象
98
+ * @author ChenRui
99
+ * @date 2020/11/28 23:29
100
+ */
101
+ constructor(
102
+ options: {
103
+ id?: any;
104
+ dvForm?: Vue;
105
+ edit?: boolean;
106
+ formatType?: FormatType;
107
+ } = {}
108
+ ) {
109
+ this.id = options.id || this.getUuid();
110
+ this.dvForm = options.dvForm || new Vue(DvForm);
111
+ this.edit = options.edit;
112
+ this.formatType = options.formatType || "default";
113
+ }
114
+
115
+ get mathjs(): MathJsStatic {
116
+ if ((window as any).$app.config.globalProperties.$mathjs) {
117
+ return (window as any).$app.config.globalProperties.$mathjs;
118
+ }
119
+ return {} as MathJsStatic;
120
+ }
121
+
122
+ /**
123
+ * @description: 获取表单值
124
+ * @author ChenRui
125
+ * @date 2021/2/4 10:36
126
+ */
127
+ get formData(): any {
128
+ this.apiMetaRefresh = this.dvForm.metaRefresh;
129
+ if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
130
+ let obj: any = this.generateData(this.dvForm.desForm.formGroup);
131
+ if (this.oldVal) {
132
+ obj = this.contrast(this.oldVal, obj);
133
+ if (!Object.keys(obj).length) {
134
+ obj = null;
135
+ }
136
+ }
137
+ return obj;
138
+ }
139
+ return null;
140
+ }
141
+
142
+ /**
143
+ * @Description 获取表单全部值
144
+ * @Author JiangTao
145
+ * @Date 2023-12-22 下午 02:50
146
+ */
147
+ get formAllData(): any {
148
+ this.apiMetaRefresh = this.dvForm.metaRefresh;
149
+ if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
150
+ const obj: any = this.generateData(this.dvForm.desForm.formGroup);
151
+ return obj;
152
+ }
153
+ return null;
154
+ }
155
+
156
+ /**
157
+ * @description: 编码表单对象
158
+ * @author ChenRui
159
+ * @date 2021/4/25 16:41
160
+ */
161
+ get encodedFormData(): any {
162
+ this.apiMetaRefresh = this.dvForm.metaRefresh;
163
+ if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
164
+ const data = this.generateData(this.dvForm.desForm.formGroup);
165
+ return this.jsonToFormData(data);
166
+ }
167
+ return null;
168
+ }
169
+
170
+ /**
171
+ * @description: 设置表单值
172
+ * @author ChenRui
173
+ * @date 2021/2/4 10:37
174
+ */
175
+ setFormData(srcData: any, isDefault = false, validate = false, oldVal?: any): void {
176
+ if (this.dvForm.desForm.formGroup) {
177
+ this.setFormDataInner(srcData, isDefault, validate);
178
+ } else {
179
+ setTimeout(() => {
180
+ this.setFormDataInner(srcData, isDefault, validate);
181
+ });
182
+ }
183
+ if (oldVal) this.oldVal = oldVal;
184
+ }
185
+
186
+ /**
187
+ * @description: 获取控件对象
188
+ * @author ChenRui
189
+ * @date 2021/1/29 10:08
190
+ */
191
+ getControl(key: string, control?: AbstractControl, showError = true): AbstractControl | any {
192
+ if (key) {
193
+ if (control == null) {
194
+ if (this.dvForm.desForm.formGroup) {
195
+ control = this.dvForm.desForm.formGroup.controls;
196
+ } else if (showError) {
197
+ console.log("表单对象尚未初始化完成...");
198
+ }
199
+ }
200
+ if (control && Object.keys(control).length > 0) {
201
+ for (const propName of Object.keys(control)) {
202
+ if (propName === key) {
203
+ return control[propName];
204
+ }
205
+ if (control[propName].controls && Object.keys(control[propName].controls).length > 0) {
206
+ const subControl: AbstractControl = this.getControl(key, control[propName].controls);
207
+ if (subControl != null) {
208
+ return subControl;
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ return null;
215
+ }
216
+
217
+ /**
218
+ * @description: 获取值
219
+ * @author ChenRui
220
+ * @date 2021/1/29 14:57
221
+ */
222
+ getValue(key: string): any {
223
+ const control: AbstractControl = this.getControl(key);
224
+ if (control) {
225
+ // && control instanceof FormControl
226
+ return this.decodeData(control as FormControl, false);
227
+ }
228
+ return null;
229
+ }
230
+
231
+ /**
232
+ * @description: 设置值
233
+ * @author ChenRui
234
+ * @date 2021/1/29 16:23
235
+ */
236
+ setValue(key: string, val: any, isDefault = false, validate = true): void {
237
+ let control: AbstractControl = this.getControl(key);
238
+ if (control == null) {
239
+ setTimeout(() => {
240
+ control = this.getControl(key);
241
+ this.setControlValue(control, key, val, isDefault, validate);
242
+ });
243
+ } else {
244
+ this.setControlValue(control, key, val, isDefault, validate);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * @description: 重置表单
250
+ * @author ChenRui
251
+ * @date 2021/2/22 17:40
252
+ */
253
+ resetValue(): void {
254
+ this.dvForm.formatDesForm(true);
255
+ }
256
+
257
+ /**
258
+ * @description: 获取文本内容
259
+ * @author ChenRui
260
+ * @date 2021/1/29 15:03
261
+ */
262
+ getText(key: string): any {
263
+ const control: AbstractControl = this.getControl(key);
264
+ if (control) {
265
+ //control && control instanceof FormControl
266
+ return control.text();
267
+ }
268
+ return "";
269
+ }
270
+
271
+ /**
272
+ * @description: 获取可选项
273
+ * @author ChenRui
274
+ * @date 2021/1/29 16:11
275
+ */
276
+ getOptions(key: string): any[] {
277
+ const control: AbstractControl = this.getControl(key);
278
+ if (control && control.controlAttr) {
279
+ //control && control instanceof FormControl && control.controlAttr
280
+ return extractOptions(control.controlAttr);
281
+ }
282
+ return [];
283
+ }
284
+
285
+ /**
286
+ * @description: 设置可选项
287
+ * @author ChenRui
288
+ * @date 2021/1/29 16:15
289
+ */
290
+ setOptions(key: string, data: any[], defaultVal?: any): void {
291
+ let control: AbstractControl = this.getControl(key);
292
+ if (control == null) {
293
+ setTimeout(() => {
294
+ control = this.getControl(key);
295
+ this.setControlOptions(control, key, data, defaultVal);
296
+ });
297
+ } else {
298
+ this.setControlOptions(control, key, data, defaultVal);
299
+ }
300
+ }
301
+
302
+ /**
303
+ * @description: 获取常规属性
304
+ * @author ChenRui
305
+ * @date 2021/1/29 17:21
306
+ */
307
+ getAttribute(key: string, attribute: Attribute): any {
308
+ const control: AbstractControl = this.getControl(key);
309
+ if (control && control.controlAttr) {
310
+ //control && control instanceof FormControl && control.controlAttr
311
+ return control.controlAttr[attribute];
312
+ }
313
+ }
314
+ /**
315
+ * @description: 设置常规属性
316
+ * @author ChenRui
317
+ * @date 2021/1/29 17:21
318
+ */
319
+ setAttribute(key: string, attribute: Attribute, data: any): void {
320
+ let control: AbstractControl = this.getControl(key);
321
+ if (control == null) {
322
+ setTimeout(() => {
323
+ control = this.getControl(key);
324
+ this.setControlAttribute(control, attribute, data);
325
+ });
326
+ } else {
327
+ this.setControlAttribute(control, attribute, data);
328
+ }
329
+ }
330
+
331
+ /**
332
+ * @description: 根据name获取校验
333
+ * @author ChenRui
334
+ * @date 2021/1/30 11:46
335
+ */
336
+ getValidate(key: string, name: string): any {
337
+ const control: AbstractControl = this.getControl(key);
338
+ if (control) {
339
+ //control && control instanceof FormControl
340
+ return control.getValidate(name);
341
+ }
342
+ }
343
+
344
+ /**
345
+ * @description: 移除校验
346
+ * @author ChenRui
347
+ * @date 2021/4/1 21:30
348
+ */
349
+ removeValidate(key: string, validateName: string): void {
350
+ const control: AbstractControl = this.getControl(key);
351
+ if (control) {
352
+ //control && control instanceof FormControl
353
+ const validates: Validate[] = control.validates;
354
+ if (validates && validates.length > 0) {
355
+ const index = validates.findIndex((item) => item.name === validateName);
356
+ if (index !== -1) {
357
+ validates.splice(index, 1);
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ /**
364
+ * @description: 移除所有校验
365
+ * @author ChenRui
366
+ * @date 2021/4/1 21:48
367
+ */
368
+ removeAllValidates(key: string): void {
369
+ const control: AbstractControl = this.getControl(key);
370
+ if (control) {
371
+ //control && control instanceof FormControl
372
+ control.validates = [];
373
+ }
374
+ }
375
+
376
+ /**
377
+ * @description: 获取校验集合
378
+ * @author ChenRui
379
+ * @date 2021/1/30 11:40
380
+ */
381
+ getValidates(key: string): Validate[] {
382
+ const control: AbstractControl = this.getControl(key);
383
+ if (control) {
384
+ //control && control instanceof FormControl
385
+ return control.validates;
386
+ }
387
+ return [];
388
+ }
389
+ /**
390
+ * @Description: 设置必输校验
391
+ * @author GuoXuHui
392
+ * @date 2022-05-25
393
+ * @time 10:09
394
+ */
395
+ setRequiredValidate(key: string, data: boolean) {
396
+ if (data) {
397
+ this.setValidate(key, { ruleType: ValidateRules.Required.code });
398
+ } else {
399
+ this.removeValidate(key, ValidateRules.Required.code); // 清除必填校验
400
+ }
401
+ }
402
+
403
+ /**
404
+ * @description: 设置校验
405
+ * @author ChenRui
406
+ * @date 2021/1/30 11:54
407
+ */
408
+ setValidate(key: string, validate: Validate | Validate[] | Rule, isCover = false): void {
409
+ let control: AbstractControl = this.getControl(key);
410
+ if (control == null) {
411
+ setTimeout(() => {
412
+ control = this.getControl(key);
413
+ if (control) {
414
+ //control && control instanceof FormControl
415
+ this.setValidateInner(control, validate, isCover);
416
+ }
417
+ });
418
+ } else {
419
+ this.setValidateInner(control, validate, isCover);
420
+ }
421
+ }
422
+
423
+ /**
424
+ * @description: 校验提示
425
+ * @author ChenRui
426
+ * @date 2021/8/18 17:40
427
+ */
428
+ validateTips(scrollView?: any): boolean {
429
+ return formValidateService.validateTips(this, scrollView);
430
+ }
431
+
432
+ /**
433
+ * @description: 全局校验报告
434
+ * @author ChenRui
435
+ * @date 2021/2/5 11:48
436
+ */
437
+ validateReport(formGroup?: AbstractControl, validateReports?: ValidateReport[], refreshFeedback = true): ValidateReport[] {
438
+ if (validateReports == null) {
439
+ validateReports = [];
440
+ }
441
+ if (formGroup == null) {
442
+ formGroup = this.dvForm.desForm.formGroup;
443
+ if (refreshFeedback) {
444
+ this.dvForm.refreshCheckFeedbackFlag = new Date().getTime();
445
+ }
446
+ }
447
+ if (formGroup != null) {
448
+ for (const propName of Object.keys(formGroup.controls)) {
449
+ if (formGroup.controls[propName] instanceof FormGroup) {
450
+ this.validateReport(formGroup.controls[propName], validateReports);
451
+ } else if (formGroup.controls[propName] instanceof FormControl && !formGroup.controls[propName].controlAttr.isHideControl) {
452
+ const validateResult: ValidateResult = formGroup.controls[propName].validate();
453
+ if (validateResult.validateStatus === ValidateStatus.Error.code) {
454
+ validateReports.push({
455
+ key: formGroup.controls[propName].key,
456
+ name: formGroup.controls[propName].controlAttr.formFieldDescribe,
457
+ errorMsg: validateResult.errorMsg,
458
+ controlType: formGroup.controls[propName].controlAttr.controlType,
459
+ });
460
+ }
461
+ }
462
+ }
463
+ }
464
+ return validateReports;
465
+ }
466
+
467
+ /**
468
+ * @description: 表单全局校验
469
+ * @author ChenRui
470
+ * @date 2021/2/5 14:11
471
+ */
472
+ validate(refreshFeedback = true): boolean {
473
+ const validateReports: ValidateReport[] = this.validateReport(undefined, undefined, refreshFeedback);
474
+ return !(validateReports.length > 0);
475
+ }
476
+
477
+ /**
478
+ * @description: 刷新校验
479
+ * @author ChenRui
480
+ * @date 2021/6/4 19:32
481
+ */
482
+ refreshValidate(key: string): void {
483
+ let control: AbstractControl = this.getControl(key);
484
+ if (control == null) {
485
+ setTimeout(() => {
486
+ control = this.getControl(key);
487
+ control["refreshValidate"] = new Date().getTime();
488
+ });
489
+ } else {
490
+ control["refreshValidate"] = new Date().getTime();
491
+ }
492
+ }
493
+
494
+ /**
495
+ * @description: 重置表单校验
496
+ * @author ChenRui
497
+ * @date 2022/4/6 11:51
498
+ */
499
+ resetFormValidateState(): void {
500
+ this.dvForm.formValidateStateResetMark = new Date().getTime();
501
+ }
502
+
503
+ /**
504
+ * @description: 设置格式化显示和输出函数
505
+ * @author ChenRui
506
+ * @date 2021/2/4 19:44
507
+ */
508
+ setFormatDisplayAndOutput(key: string, customFormat: CustomFormat): void {
509
+ if (key) {
510
+ this.dvForm.customFormats[key] = customFormat;
511
+ }
512
+ this.refreshAndUpdateData();
513
+ }
514
+
515
+ /**
516
+ * @description: 刷新数据
517
+ * @author ChenRui
518
+ * @date 2021/2/4 20:22
519
+ */
520
+ refreshAndUpdateData(): void {
521
+ this.dvForm.onRefreshArgumentsHandler(new Date().getTime());
522
+ }
523
+
524
+ /**
525
+ * @description: 获取控件dom对象
526
+ * @author ChenRui
527
+ * @date 2021/2/26 17:12
528
+ */
529
+ getControlEl(key: string): any {
530
+ const control: AbstractControl = this.getControl(key);
531
+ if (control != null && control.controlAttr) {
532
+ const els: HTMLCollectionOf<any> = document.getElementsByClassName("form-model-item-" + control.controlAttr.boundProperty);
533
+ if (els != null && els.length > 0) {
534
+ return els[0];
535
+ }
536
+ }
537
+ return null;
538
+ }
539
+
540
+ /**
541
+ * @description: 检查是否包含上传控件
542
+ * @author ChenRui
543
+ * @date 2021/4/23 11:30
544
+ */
545
+ checkHasUploadControl(abstractControl: AbstractControl): boolean {
546
+ if (abstractControl instanceof FormGroup) {
547
+ const formGroup: FormGroup = abstractControl as FormGroup;
548
+ for (const propName of Object.keys(formGroup.controls)) {
549
+ if (formGroup.controls[propName] instanceof FormGroup) {
550
+ const judge = this.checkHasUploadControl(formGroup.controls[propName]);
551
+ if (judge) {
552
+ return judge;
553
+ }
554
+ } else if (formGroup.controls[propName] instanceof FormControl) {
555
+ if (formGroup.controls[propName].code === FormFieldType.Upload.code) {
556
+ return true;
557
+ }
558
+ }
559
+ }
560
+ }
561
+ return false;
562
+ }
563
+
564
+ /**
565
+ * @description: json格式转表单格式
566
+ * @author ChenRui
567
+ * @date 2020/8/28 15:20
568
+ */
569
+ jsonToFormData(params: any): FormData {
570
+ const formData = new FormData();
571
+ if (params != null) {
572
+ Object.keys(params).forEach((key) => {
573
+ if (params[key] != null && params[key] instanceof Array && params[key].length > 0 && params[key][0] instanceof File) {
574
+ params[key].forEach((item: any) => {
575
+ formData.append(key, item);
576
+ });
577
+ } else {
578
+ formData.append(key, params[key]);
579
+ }
580
+ });
581
+ return formData;
582
+ }
583
+ return formData;
584
+ }
585
+
586
+ /**
587
+ * @description: 设置变更历史记录
588
+ * @author ChenRui
589
+ * @date 2021/4/25 15:55
590
+ */
591
+ setFieldChangeHistory(fieldChangeHistory: FieldChangeHistory): void {
592
+ fieldChangeHistory = fieldChangeHistory || {};
593
+ for (const propertyName of Object.keys(fieldChangeHistory)) {
594
+ let control: AbstractControl = this.getControl(propertyName, undefined, false);
595
+ if (control == null) {
596
+ setTimeout(() => {
597
+ control = this.getControl(propertyName, undefined, false);
598
+ if (control) {
599
+ //control && control instanceof FormControl
600
+ const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
601
+ const aTime = new Date(a.time).getTime();
602
+ const bTime = new Date(b.time).getTime();
603
+ return bTime - aTime;
604
+ });
605
+ control.history = history;
606
+ }
607
+ });
608
+ } else {
609
+ control = this.getControl(propertyName, undefined, false);
610
+ if (control) {
611
+ //control && control instanceof FormControl
612
+ const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
613
+ const aTime = new Date(a.time).getTime();
614
+ const bTime = new Date(b.time).getTime();
615
+ return bTime - aTime;
616
+ });
617
+ control.history = history;
618
+ }
619
+ }
620
+ }
621
+ }
622
+
623
+ /**
624
+ * @description: 隐藏布局
625
+ * @author ChenRui
626
+ * @date 2021/11/16 0:01
627
+ */
628
+ hideLayout(layoutName: string, mark = true): void {
629
+ if (layoutName) {
630
+ const nodes: any = document.getElementsByClassName("lo-form-layout-" + layoutName);
631
+ if (nodes && nodes.length > 0) {
632
+ for (let i = 0; i < nodes.length; i++) {
633
+ nodes[i].style.display = mark ? "none" : "grid";
634
+ }
635
+ }
636
+ }
637
+ }
638
+
639
+ /**
640
+ * @description: 设置表单值
641
+ * @author ChenRui
642
+ * @date 2021/8/16 9:29
643
+ */
644
+ private setFormDataInner(srcData: any, isDefault: boolean, validate: boolean): void {
645
+ if (srcData) {
646
+ for (const propName of Object.keys(srcData)) {
647
+ if (typeof srcData[propName] === "string" || typeof srcData[propName] === "number") {
648
+ this.setValue(propName, srcData[propName], isDefault, false);
649
+ } else {
650
+ this.setFormData(srcData[propName], isDefault, validate);
651
+ }
652
+ }
653
+ }
654
+ if (validate) {
655
+ this.validate();
656
+ }
657
+ }
658
+
659
+ /**
660
+ * @description: 设置控件值
661
+ * @author ChenRui
662
+ * @date 2021/4/13 12:50
663
+ */
664
+ private setControlValue(control: AbstractControl, key: string, val: any, isDefault?: boolean, validate = true): void {
665
+ if (control) {
666
+ // && control instanceof FormControl
667
+ switch (control.code) {
668
+ case FormFieldType.InputNumber.code:
669
+ if (val && control.controlAttr.zoomMultiple) {
670
+ if (control.controlAttr.zoomType === ZoomType.enlarge.code) {
671
+ val = this.mathjs.format(this.mathjs.evaluate(`${val} / ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
672
+ } else if (control.controlAttr.zoomType === ZoomType.narrow.code) {
673
+ val = this.mathjs.format(this.mathjs.evaluate(`${val} * ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
674
+ }
675
+ }
676
+ if (val != undefined) {
677
+ control.value = val;
678
+ } else {
679
+ control.value = "";
680
+ }
681
+ break;
682
+ case FormFieldType.Select.code:
683
+ if (control.controlAttr.isMultipleChoice) {
684
+ if (!val) {
685
+ val = [];
686
+ } else if (typeof val === "string") {
687
+ val = val.split(",");
688
+ }
689
+ }
690
+ control.value = val;
691
+ break;
692
+ case FormFieldType.Checkbox.code:
693
+ case FormFieldType.Cascader.code:
694
+ if (val) {
695
+ val = val.split(",");
696
+ } else {
697
+ val = [];
698
+ }
699
+ control.value = val;
700
+ break;
701
+ case FormFieldType.Switch.code:
702
+ if (control.controlAttr.onOpeningValue) {
703
+ val = val === true || val === control.controlAttr.onOpeningValue;
704
+ } else if (control.controlAttr.whenClosedValue) {
705
+ val = !(val === false || val === control.controlAttr.whenClosedValue);
706
+ }
707
+ control.value = val;
708
+ break;
709
+ case FormFieldType.TimePicker.code:
710
+ if (val) {
711
+ if (typeof val === "string") {
712
+ val = dayjs(new Date(this.nowDateStr() + " " + val));
713
+ } else if (val instanceof Date) {
714
+ val = dayjs(val);
715
+ }
716
+ control.value = val;
717
+ } else {
718
+ control.value = null;
719
+ }
720
+ break;
721
+ case FormFieldType.DatePicker.code:
722
+ if (val) {
723
+ if (typeof val === "string") {
724
+ val = dayjs(val, control.dateFormat);
725
+ } else if (val instanceof Date) {
726
+ val = dayjs(val);
727
+ }
728
+ control.value = val;
729
+ } else {
730
+ control.value = null;
731
+ }
732
+ break;
733
+ default: {
734
+ control.value = val;
735
+ }
736
+ }
737
+ if (isDefault) {
738
+ this.setAttribute(key, Attribute.FieldDefaultValue, JSON.stringify(control.value));
739
+ }
740
+ if (validate) {
741
+ control["refreshValidate"] = new Date().getTime();
742
+ }
743
+ }
744
+ }
745
+
746
+ /**
747
+ * @description: 设置控件可选项
748
+ * @author ChenRui
749
+ * @date 2021/4/13 15:09
750
+ */
751
+ private setControlOptions(control: AbstractControl, key: string, data: any[], defaultVal?: any): void {
752
+ if (control && control.controlAttr) {
753
+ //control && control instanceof FormControl && control.controlAttr)
754
+ storageOptions(control.controlAttr, data);
755
+ this.setAttribute(key, Attribute.IsOptionType, OptionType.Fixed.code);
756
+ this.setAttribute(key, Attribute.OptionConfig, data);
757
+ }
758
+ if (defaultVal) {
759
+ this.setValue(key, defaultVal, true);
760
+ }
761
+ }
762
+
763
+ /**
764
+ * @description: 设置控件常规属性
765
+ * @author ChenRui
766
+ * @date 2021/4/13 15:11
767
+ */
768
+ private setControlAttribute(control: AbstractControl, attribute: Attribute, data: any): void {
769
+ if (control && attribute) {
770
+ //control && control instanceof FormControl && attribute
771
+ control.controlAttr[attribute] = data;
772
+ }
773
+ }
774
+
775
+ /**
776
+ * @description: 设置校验内部函数
777
+ * @author ChenRui
778
+ * @date 2021/7/19 17:51
779
+ */
780
+ private setValidateInner(control: AbstractControl, validate: Validate | Validate[] | Rule, isCover = false): void {
781
+ if (validate != null && (validate as Rule).ruleType) {
782
+ validate = validateGeneratorService.getBuiltInValidationRules(validate as Rule, control.controlAttr) as any;
783
+ }
784
+ if (validate != null) {
785
+ if (isCover) {
786
+ control.validates = [];
787
+ }
788
+ control.addValidate(validate);
789
+ }
790
+ }
791
+
792
+ /**
793
+ * @description: 生成数据信息
794
+ * @author ChenRui
795
+ * @date 2021/1/29 10:06
796
+ */
797
+ private generateData(abstractControl: AbstractControl, obj: any = {}): any {
798
+ if (abstractControl instanceof FormGroup) {
799
+ const formGroup: FormGroup = abstractControl as FormGroup;
800
+ for (const propName of Object.keys(formGroup.controls)) {
801
+ if (formGroup.controls[propName] instanceof FormGroup) {
802
+ obj[propName] = this.generateData(formGroup.controls[propName], obj[propName]);
803
+ } else if (formGroup.controls[propName] instanceof FormControl) {
804
+ obj[propName] = this.decodeData(formGroup.controls[propName] as FormControl);
805
+ }
806
+ }
807
+ }
808
+ return obj;
809
+ }
810
+
811
+ /**
812
+ * @description: 数据解码输出
813
+ * @author ChenRui
814
+ * @date 2021/5/29 23:03
815
+ */
816
+ private decodeData(formControl: FormControl, isFinal = true): any {
817
+ let data = formControl.value || "";
818
+ switch (formControl.code) {
819
+ case FormFieldType.InputNumber.code:
820
+ if (data && formControl.controlAttr.zoomMultiple) {
821
+ if (formControl.controlAttr.zoomType === ZoomType.enlarge.code) {
822
+ data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
823
+ } else if (formControl.controlAttr.zoomType === ZoomType.narrow.code) {
824
+ data = this.mathjs.format(this.mathjs.evaluate(`${data} / ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
825
+ } else if (formControl.controlAttr.zoomType === ZoomType.automatic.code) {
826
+ data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
827
+ }
828
+ }
829
+ if (formControl.value === 0) {
830
+ data = 0;
831
+ }
832
+ break;
833
+ case FormFieldType.Select.code:
834
+ if (formControl.controlAttr.isMultipleChoice && data && Array.isArray(data)) {
835
+ data = data.join(",");
836
+ }
837
+ break;
838
+ case FormFieldType.Checkbox.code:
839
+ if (data && isFinal) {
840
+ data = data.join(",");
841
+ }
842
+ break;
843
+ case FormFieldType.TimePicker.code:
844
+ if (data) {
845
+ data = dayjs(data).format(formControl.controlAttr.timeFormat || "LTS");
846
+ }
847
+ break;
848
+ case FormFieldType.DatePicker.code:
849
+ if (data) {
850
+ data = dayjs(data).format(formControl.controlAttr.dateFormat || "YYYY-MM-DD");
851
+ }
852
+ break;
853
+ case FormFieldType.Cascader.code:
854
+ if (data) {
855
+ data = data.join(",");
856
+ }
857
+ break;
858
+ case FormFieldType.Switch.code:
859
+ data = !!data;
860
+ if (formControl.controlAttr) {
861
+ if (data === true && formControl.controlAttr.onOpeningValue != undefined && formControl.controlAttr.onOpeningValue !== "") {
862
+ data = formControl.controlAttr.onOpeningValue;
863
+ } else if (data === false && formControl.controlAttr.whenClosedValue != undefined && formControl.controlAttr.whenClosedValue !== "") {
864
+ data = formControl.controlAttr.whenClosedValue;
865
+ }
866
+ }
867
+ break;
868
+ case FormFieldType.Custom.code:
869
+ if (formControl.controlAttr && formControl.controlAttr.customFieldName) {
870
+ const customFormat: CustomFormat = this.dvForm.customFormats[formControl.controlAttr.customFieldName];
871
+ if (customFormat && customFormat.output) {
872
+ data = customFormat.output(data, formControl.controlAttr);
873
+ }
874
+ }
875
+ }
876
+ return data;
877
+ }
878
+
879
+ /**
880
+ * @description: 获取当前日期字符串
881
+ * @author ChenRui
882
+ * @date 2021/2/4 11:43
883
+ */
884
+ private nowDateStr(): string {
885
+ const time = new Date();
886
+ const day = ("0" + time.getDate()).slice(-2);
887
+ const month = ("0" + (time.getMonth() + 1)).slice(-2);
888
+ return time.getFullYear() + "/" + month + "/" + day;
889
+ }
890
+
891
+ /**
892
+ * @description: uuid生成器
893
+ * @author ChenRui
894
+ * @date 2021/7/20 11:14
895
+ */
896
+ private getUuid(): string {
897
+ const s: any[] = [];
898
+ const hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
899
+ for (let i = 0; i < 36; i++) {
900
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
901
+ }
902
+ s[14] = "4";
903
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
904
+ s[8] = s[13] = s[18] = s[23] = "-";
905
+ const uuid = s.join("");
906
+ return uuid;
907
+ }
908
+
909
+ /**
910
+ * @Description: 对比新旧表单值
911
+ * @author lzs
912
+ * @date 2022/9/3
913
+ * @time 21:49
914
+ */
915
+ private contrast(objectA: any, objectB: any): any {
916
+ const object: any = {};
917
+ const data: any = {};
918
+ const fieldInfoArr: any = [];
919
+ if (!objectB || !objectA) {
920
+ object.changeLog = "必传参数不存在";
921
+ return object;
922
+ }
923
+ const handlerFlag = objectA.handlerFlag;
924
+ // console.log("======", this.dvForm.desForm.formGroup.controls);
925
+ for (const key in this.dvForm.desForm.formGroup.controls) {
926
+ if (!objectA[key] && !objectB[key]) {
927
+ continue;
928
+ }
929
+ const control: AbstractControl = this.getControl(key);
930
+ if (!control) {
931
+ continue;
932
+ }
933
+ if (this.getChangedInfo(control, objectA[key], objectB[key])) {
934
+ let oldValue = objectA[key]; // 记录新值
935
+ const newValue = objectB[key]; // 记录旧值
936
+ const fieldInfo: any = {}; //日志信息
937
+ if (control.code !== FormFieldType.Custom.code) {
938
+ fieldInfo.field_cd = key; //字段英文
939
+ const name = control.controlAttr.formFieldDescribe;
940
+ fieldInfo.field_nm = name; //字段中文
941
+ fieldInfo.field_key = newValue; //当前值
942
+
943
+ const newDict = this.translateDictionaries(control, key, newValue); // 新值描述
944
+ fieldInfo.field_value = newDict; //当前值描述
945
+
946
+ fieldInfo.is_change = "1"; //是否变动
947
+
948
+ fieldInfo.field_old_key = oldValue; //旧值
949
+ const oldDict = this.translateDictionaries(control, key, oldValue); //旧值描述
950
+ fieldInfo.field_old_value = oldDict; //field_old_value
951
+ object[key] = newValue;
952
+
953
+ fieldInfoArr.push(fieldInfo);
954
+ if (oldValue === "null" || oldValue === "undefined") {
955
+ oldValue = "";
956
+ }
957
+ const oldName = oldValue ? oldDict : "空";
958
+ const newName = newValue ? newDict : "空";
959
+ //除自定义组件均记录日志
960
+ object.changeLog = object.changeLog ? object.changeLog + "," : "";
961
+ if (handlerFlag === "add") {
962
+ object.changeLog = object.changeLog + "新增【" + name + "】" + "为“" + newName + "”";
963
+ } else {
964
+ object.changeLog = object.changeLog + "修改【" + name + "】" + "由“" + oldName + "”修改为“" + newName + "”";
965
+ }
966
+ } else {
967
+ object[key] = newValue;
968
+ }
969
+ }
970
+ }
971
+ object.fieldInfoArr = fieldInfoArr;
972
+ return object;
973
+ }
974
+ /**
975
+ * @Description: 获取表单值更改信息
976
+ * @author lzs
977
+ * @date 2022/10/11
978
+ * @time 09:53
979
+ */
980
+ getChangedInfo(control: any, oldValue: any, newValue: any): boolean {
981
+ oldValue = oldValue + "";
982
+ newValue = newValue + "";
983
+ if (oldValue === "null" || oldValue === "undefined") {
984
+ return true;
985
+ }
986
+ let flag = true;
987
+ switch (control.code) {
988
+ case FormFieldType.Input.code:
989
+ if (oldValue === newValue) flag = false;
990
+ break;
991
+ case FormFieldType.InputNumber.code:
992
+ if (oldValue === newValue) flag = false;
993
+ break;
994
+ case FormFieldType.Textarea.code:
995
+ if (oldValue === newValue) flag = false;
996
+ break;
997
+ case FormFieldType.Slider.code:
998
+ if (oldValue === newValue) flag = false;
999
+ break;
1000
+ case FormFieldType.Rate.code:
1001
+ if (oldValue === newValue) flag = false;
1002
+ break;
1003
+ case FormFieldType.Select.code:
1004
+ if (oldValue === newValue) flag = false;
1005
+ break;
1006
+ case FormFieldType.Checkbox.code:
1007
+ if (oldValue === newValue) flag = false;
1008
+ break;
1009
+ case FormFieldType.Radio.code:
1010
+ if (oldValue === newValue) flag = false;
1011
+ break;
1012
+ case FormFieldType.TimePicker.code:
1013
+ if (oldValue === newValue) flag = false;
1014
+ break;
1015
+ case FormFieldType.DatePicker.code:
1016
+ oldValue = dateFormat.formatDateTime(oldValue, "YYYY-MM-dd");
1017
+ newValue = dateFormat.formatDateTime(newValue, "YYYY-MM-dd");
1018
+ if (oldValue === newValue) flag = false;
1019
+ break;
1020
+ case FormFieldType.Cascader.code:
1021
+ if (oldValue === newValue) flag = false;
1022
+ break;
1023
+ case FormFieldType.TreeSelect.code:
1024
+ if (oldValue === newValue) flag = false;
1025
+ break;
1026
+ case FormFieldType.Switch.code:
1027
+ if (oldValue === newValue) flag = false;
1028
+ break;
1029
+ case FormFieldType.Custom.code:
1030
+ break;
1031
+ }
1032
+ return flag;
1033
+ }
1034
+ /**
1035
+ * @Description: 翻译字典项
1036
+ * @author lzs
1037
+ * @date 2022/9/6
1038
+ * @time 11:54
1039
+ */
1040
+ translateDictionaries(control: any, key: any, value: any): string {
1041
+ let str = value;
1042
+ switch (control.code) {
1043
+ case FormFieldType.Input.code:
1044
+ break;
1045
+ case FormFieldType.InputNumber.code:
1046
+ break;
1047
+ case FormFieldType.Textarea.code:
1048
+ break;
1049
+ case FormFieldType.Slider.code:
1050
+ break;
1051
+ case FormFieldType.Rate.code:
1052
+ break;
1053
+ case FormFieldType.Select.code:
1054
+ if (control.controlAttr.generalDictionaryOptions) {
1055
+ control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1056
+ if (item.value === value) {
1057
+ str = item.title;
1058
+ }
1059
+ });
1060
+ } else {
1061
+ control.controlAttr.optionConfig.forEach((item: any) => {
1062
+ if (item.value === value) {
1063
+ str = item.title;
1064
+ }
1065
+ });
1066
+ }
1067
+ break;
1068
+ case FormFieldType.Checkbox.code:
1069
+ str = "";
1070
+ if (value) {
1071
+ if (control.controlAttr.generalDictionaryOptions) {
1072
+ control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1073
+ value.split(",").forEach((index: any) => {
1074
+ if (item.value === index) {
1075
+ str = str + item.title + ",";
1076
+ }
1077
+ });
1078
+ });
1079
+ } else {
1080
+ control.controlAttr.optionConfig.forEach((item: any) => {
1081
+ value.split(",").forEach((index: any) => {
1082
+ if (item.value === index) {
1083
+ str = str + item.title + ",";
1084
+ }
1085
+ });
1086
+ });
1087
+ }
1088
+ str = str.substring(0, str.length - 1);
1089
+ }
1090
+ break;
1091
+ case FormFieldType.Radio.code:
1092
+ if (control.controlAttr.generalDictionaryOptions) {
1093
+ control.controlAttr.generalDictionaryOptions.forEach((item: any) => {
1094
+ if (item.value === value) {
1095
+ str = item.title;
1096
+ }
1097
+ });
1098
+ } else {
1099
+ control.controlAttr.optionConfig.forEach((item: any) => {
1100
+ if (item.value === value) {
1101
+ str = item.title;
1102
+ }
1103
+ });
1104
+ }
1105
+ break;
1106
+ case FormFieldType.TimePicker.code:
1107
+ break;
1108
+ case FormFieldType.DatePicker.code:
1109
+ str = dateFormat.formatDateTime(value, "YYYY-MM-dd");
1110
+ break;
1111
+ case FormFieldType.Cascader.code:
1112
+ str = "";
1113
+ if (value) {
1114
+ formTreeNodeConvertService.treeNodeConvertToArray(control.controlAttr.treeShapeOptions, [], "children").forEach((item: any) => {
1115
+ value.split(",").forEach((index: any) => {
1116
+ if (item.value === index) {
1117
+ str = str + item.title + ",";
1118
+ }
1119
+ });
1120
+ });
1121
+ str = str.substring(0, str.length - 1);
1122
+ } else {
1123
+ str = "";
1124
+ }
1125
+ break;
1126
+ case FormFieldType.TreeSelect.code:
1127
+ str = "";
1128
+ formTreeNodeConvertService.treeNodeConvertToArray(control.controlAttr.treeShapeOptions, [], "children").forEach((item: any) => {
1129
+ if (item.value === value) {
1130
+ str = str + item.title;
1131
+ }
1132
+ });
1133
+ break;
1134
+ case FormFieldType.Switch.code:
1135
+ str = value ? "开" : "关";
1136
+ break;
1137
+ case FormFieldType.Custom.code:
1138
+ break;
1139
+ default:
1140
+ str = value;
1141
+ break;
1142
+ }
1143
+ return str;
1144
+ }
1145
+
1146
+ /**
1147
+ * @Description 根据报送类型返回需要隐藏的表单字段
1148
+ * @Author JiangTao
1149
+ * @Date 2024-01-30 上午 09:33
1150
+ */
1151
+ getFormSubmittedType(form: any, code: any) {
1152
+ const strArr = code && code.length > 0 ? code : [];
1153
+ const list: any = this.dvForm.desForm.controls[0].subControls;
1154
+ const subControlsList: any = formToolsService.loadResource(this.dvForm.desForm.formId).controls[0].subControls;
1155
+ const submittedTypeList: any = [];
1156
+ if (strArr.length > 0) {
1157
+ // 遍历组件实例
1158
+ list.forEach((item: any, index: any) => {
1159
+ if (item.formControl) {
1160
+ // 校验当前字段是否已隐藏,已隐藏的字段不做处理
1161
+ if (!form.getAttribute(item.formControl.key, Attribute.IsHideControl)) {
1162
+ // 处理普通表单控件
1163
+ submittedTypeList.push(item.formControl.key);
1164
+ // 初始化字段是否隐藏属性
1165
+ form.setAttribute(item.formControl.key, Attribute.IsHideControl, subControlsList[index].controlAttr.isHideControl);
1166
+ // 筛选报送类型字段数据处理
1167
+ this.handleSubmittedData(submittedTypeList, strArr, item);
1168
+ }
1169
+ } else if (item.subControls) {
1170
+ // 处理栅格中表单控件
1171
+ // 遍历栅格中控件
1172
+ item.subControls.forEach((control: any, num: any) => {
1173
+ // 校验当前字段是否已隐藏,已隐藏的字段不做处理
1174
+ if (!form.getAttribute(control.formControl.key, Attribute.IsHideControl)) {
1175
+ submittedTypeList.push(control.formControl.key);
1176
+ // 初始化字段是否隐藏属性
1177
+ form.setAttribute(control.formControl.key, Attribute.IsHideControl, subControlsList[index].subControls[num].controlAttr.isHideControl);
1178
+ // 筛选报送类型字段数据处理
1179
+ this.handleSubmittedData(submittedTypeList, strArr, control);
1180
+ }
1181
+ });
1182
+ }
1183
+ });
1184
+ // 隐藏无需展示的表单字段
1185
+ submittedTypeList.forEach((item: any) => {
1186
+ form.setAttribute(item, Attribute.IsHideControl, true);
1187
+ });
1188
+ } else {
1189
+ // 默认展示全部字段
1190
+ list.forEach((item: any, index: any) => {
1191
+ if (item.formControl) {
1192
+ form.setAttribute(item.formControl.key, Attribute.IsHideControl, subControlsList[index].controlAttr.isHideControl);
1193
+ } else if (item.subControls) {
1194
+ item.subControls.forEach((control: any, num: any) => {
1195
+ form.setAttribute(control.formControl.key, Attribute.IsHideControl, subControlsList[index].subControls[num].controlAttr.isHideControl);
1196
+ });
1197
+ }
1198
+ });
1199
+ }
1200
+ }
1201
+
1202
+ /**
1203
+ * @Description 筛选报送类型字段数据处理
1204
+ * @Author JiangTao
1205
+ * @Date 2024-01-30 下午 08:50
1206
+ */
1207
+ private handleSubmittedData(submittedTypeList: any, codeArr: any, submittedData: any): void {
1208
+ let submittedType: any = [];
1209
+ if (JSON.parse(submittedData.formControl.controlAttr.busAttr).submittedType !== "") {
1210
+ // 获取字段报送类型
1211
+ submittedType = JSON.parse(submittedData.formControl.controlAttr.busAttr).submittedType.split(",");
1212
+ // 遍历查询报送类型
1213
+ for (let i = 0; i < codeArr.length; i++) {
1214
+ // 判断是否为查询的报送类型字段
1215
+ if (submittedType.filter((type: any) => type === codeArr[i]).length > 0 && submittedTypeList.indexOf(submittedData.formControl.key) >= 0) {
1216
+ submittedTypeList.splice(submittedTypeList.indexOf(submittedData.formControl.key), 1);
1217
+ break;
1218
+ }
1219
+ }
1220
+ }
1221
+ }
1222
+
1223
+ /**
1224
+ * @Description 获取报送类型枚举(数组)
1225
+ * @Author JiangTao
1226
+ * @Date 2024-01-30 下午 03:30
1227
+ */
1228
+ getSubmittedType() {
1229
+ const list: any = [];
1230
+ Object.values(SubmittedType).forEach((item: any) => {
1231
+ list.push({
1232
+ value: item.code,
1233
+ label: item.name,
1234
+ });
1235
+ });
1236
+ return list;
1237
+ }
1238
+ }