@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,642 +1,642 @@
1
- <template>
2
- <div v-if="desForm?.controls?.length" ref="formView" :class="'lo-form-container ' + ('lo-' + (edit ? 'enable' : 'disable') + '-edit') + ' lo-class-style-' + styleMode + ' lo-form-theme-' + loFormTheme">
3
- <dv-form-layout v-for="(item, i) in desForm.controls" :key="i" :control="item" :customFormats="customFormats" :linkList="linkList" @linkClick="linkClick" :index="i" @change="onChange($event)" @focus="onFocus($event)" @blur="onBlur($event)" @click="onClick($event)" @addon-before="onAddonBeforeHandler($event)" @addon-after="onAddonAfterHandler($event)" @add-item="selectAddItem($event)">
4
- <template v-for="propName in Object.keys(this.$slots)" v-slot:[propName]="slotProps">
5
- <slot :name="propName" :content="slotProps.content" :control="slotProps.control" :onChange="slotProps.onChange"></slot>
6
- </template>
7
- </dv-form-layout>
8
- </div>
9
- </template>
10
-
11
- <script lang="ts">
12
- import DvFormLayout from "./DvFormLayout.vue";
13
- import { Options, Prop, Provide, Watch, Vue } from "vue-property-decorator";
14
- import { DesForm } from "@/domain";
15
- import { FormFieldClass } from "@/constants";
16
- import { formToolsService } from "@/services";
17
- import { Control } from "@/domain";
18
- import { DesFormControl } from "@/domain";
19
- import { FormGroup } from "@/domain";
20
- import { FormControl } from "@/domain";
21
- import { formBeanUtilsService } from "@/services";
22
- import { FormApi } from "@/core";
23
- import { FormFieldType } from "@/constants";
24
- import { ProvideInjectData } from "@/domain/ProvideInjectData";
25
- import { validateGeneratorService } from "@/services";
26
- import { CustomFormat, FieldChangeHistory } from "../../domain";
27
- import { extractOptions } from "@/filtres/extract-options.filter";
28
- import { DynamicOptionType, OptionType } from "../../constants/enum";
29
- import { NzTreeNodeOptions } from "@/services";
30
-
31
- export type NfFormMode = "manual" | "auto";
32
-
33
- export type NfStyleMode = "default" | "trust" | "credit-rd";
34
-
35
- export type NfFormTheme = "default" | "gray";
36
- /**
37
- * @description: 动态表单
38
- * @author ChenRui
39
- * @date 2020/12/30 11:20
40
- */
41
- @Options({
42
- name: "DyForm",
43
- components: {
44
- DvFormLayout: DvFormLayout,
45
- },
46
- })
47
- export default class DyForm extends Vue {
48
- @Prop() formId: string | undefined;
49
- @Prop() mode: NfFormMode | undefined;
50
- @Prop({ type: String, default: "default" }) styleMode!: NfStyleMode;
51
- @Prop() srcDesForm: DesForm | undefined;
52
- @Prop({ default: false, type: Boolean }) edit!: boolean;
53
- @Prop({ default: false, type: Boolean }) colon!: boolean;
54
- @Prop({ default: "130px", type: String }) labelSpan!: string;
55
- @Prop({ default: undefined }) controlSpan!: any;
56
- @Prop({ type: Object }) formApi: FormApi | undefined;
57
- @Prop({ type: Array }) history: FieldChangeHistory | undefined;
58
- @Prop({ type: Object, default: () => ({}) }) customFormats!: {
59
- [key: string]: CustomFormat;
60
- };
61
- @Prop() refreshArguments: any; // 刷新自变量
62
- @Prop({ default: false }) widthCompatibleMode!: boolean; // 宽度计算模式
63
- @Prop({ type: String }) formTheme!: NfFormTheme; // 表单主题
64
- @Prop({ type: Array }) linkList: any | undefined; // 需要添加超链接点击事件数组 例:['cifNo', 'prodBaseNo']
65
-
66
- private metaRefresh: any = new Date().getTime(); // 刷新标识
67
- private refreshCheckFeedbackFlag = new Date().getTime(); // 刷新校验标识
68
- private sysDictDetailOptions: NzTreeNodeOptions[] = []; // 常规字典
69
- private sysDictTreeDetailOptions: NzTreeNodeOptions[] = []; // 树形字典
70
- private formValidateStateResetMark: any = new Date().getTime(); // 重置校验标识
71
-
72
- desForm: DesForm = new DesForm();
73
-
74
- @Provide() provideInjectData: ProvideInjectData = {
75
- edit: (this.$props as any).edit,
76
- labelSpan: (this.$props as any).labelSpan,
77
- controlSpan: (this.$props as any).controlSpan,
78
- colon: (this.$props as any).colon,
79
- metaRefresh: this.metaRefresh,
80
- refreshCheckFeedbackFlag: this.refreshCheckFeedbackFlag,
81
- widthCompatibleMode: (this.$props as any).widthCompatibleMode,
82
- formValidateStateResetMark: this.formValidateStateResetMark,
83
- };
84
-
85
- /**
86
- * @description: 刷新自变量监听处理
87
- * @author ChenRui
88
- * @date 2021/2/5 10:25
89
- */
90
- @Watch("refreshArguments", { immediate: true })
91
- onRefreshArgumentsHandler(newVal: any): void {
92
- this.metaRefresh = newVal;
93
- }
94
-
95
- /**
96
- * @description: 重置表单校验状态监听
97
- * @author ChenRui
98
- * @date 2022/4/6 14:17
99
- */
100
- @Watch("formValidateStateResetMark")
101
- onPropFormValidateStateResetHandler(newVal: any): void {
102
- if ((this as any)._provided) {
103
- ((this as any)._provided as any).provideInjectData.formValidateStateResetMark = this.formValidateStateResetMark;
104
- }
105
- }
106
-
107
- /**
108
- * @description: 值变更处理器
109
- * @author ChenRui
110
- * @date 2021/1/8 11:03
111
- */
112
- @Watch("edit")
113
- @Watch("labelSpan")
114
- @Watch("controlSpan")
115
- @Watch("metaRefresh")
116
- @Watch("refreshCheckFeedbackFlag")
117
- @Watch("widthCompatibleMode")
118
- onPropHandler(newVal: any): void {
119
- if (this) {
120
- this.provideInjectData.edit = this.edit;
121
- this.provideInjectData.labelSpan = this.labelSpan;
122
- this.provideInjectData.controlSpan = this.controlSpan;
123
- this.provideInjectData.metaRefresh = this.metaRefresh;
124
- this.provideInjectData.refreshCheckFeedbackFlag = this.refreshCheckFeedbackFlag;
125
- this.provideInjectData.widthCompatibleMode = this.widthCompatibleMode;
126
- }
127
- }
128
-
129
- get loFormTheme(): string {
130
- const win: any = window;
131
- const themes = ["default", "gray"];
132
- const formTheme = themes.indexOf(this.formTheme) > -1 ? this.formTheme : win.$loFormTheme;
133
- return themes.indexOf(formTheme) > -1 ? formTheme : themes[0];
134
- }
135
- /**
136
- * @Description 表单数据反显回调(data:Object { key: 元素码值, value: 元素值 })
137
- * @Author JiangTao
138
- * @Date 2023-10-07 下午 05:16
139
- */
140
- linkClick(data: any) {
141
- this.$emit("linkClick", data);
142
- }
143
-
144
- created() {
145
- this.initDict();
146
- }
147
-
148
- mounted() {
149
- if (this.formId) {
150
- this.initDesForm();
151
- } else if (this.desForm) {
152
- this.formatDesForm();
153
- }
154
- }
155
-
156
- @Watch("formId")
157
- private onFormIdChanged() {
158
- this.initDesForm();
159
- }
160
-
161
- @Watch("srcDesForm", { immediate: true })
162
- private onSrcDesFormChanged(newVal: DesForm) {
163
- if (newVal != null) {
164
- this.desForm = formBeanUtilsService.copy(newVal);
165
- this.formatDesForm();
166
- }
167
- }
168
-
169
- /**
170
- * @description: 初始化表单
171
- * @author ChenRui
172
- * @date 2020/11/23 11:19
173
- */
174
- private initDesForm(): void {
175
- if (this.formId != null && this.formId !== "") {
176
- this.desForm = formToolsService.loadResource(this.formId);
177
- this.formatDesForm();
178
- }
179
- }
180
-
181
- /**
182
- * @description: 初始化字典
183
- * @author ChenRui
184
- * @date 2021/3/12 10:12
185
- */
186
- private initDict(): void {
187
- this.sysDictDetailOptions = formToolsService.sysDictDetailOptions;
188
- this.sysDictTreeDetailOptions = formToolsService.sysDictTreeDetailOptions;
189
- }
190
-
191
- /**
192
- * @description: 格式化表单
193
- * @author ChenRui
194
- * @date 2020/11/30 16:05
195
- */
196
- private formatDesForm(isReset?: boolean): void {
197
- if (this.desForm != null && this.desForm.controls != null && this.desForm.controls.length > 0) {
198
- const model = this.analysisBindingObjects();
199
- this.desForm.formGroup = this.generateFormGroup(model);
200
- this.initControlForm(this.desForm.controls, this.desForm.formGroup);
201
- this.generateFormApi(isReset);
202
- if (this.history != null) {
203
- this.formApi?.setFieldChangeHistory(this.history);
204
- }
205
- this.$emit("complete");
206
- }
207
- }
208
- /**
209
- * @Description: 临时-该方法被取消
210
- * @author LiuBo
211
- * @date 2022/11/6
212
- * @time 17:11
213
- */
214
- private fixFormLayout() {
215
- this.$nextTick(() => {
216
- console.log("自动修改表单宽度");
217
- try {
218
- const formView: any = this.$refs.formView;
219
- const cons = formView.getElementsByClassName("lo-control-container");
220
- const len = cons.length;
221
- for (let i = 0; i < len - 1; i++) {
222
- if (cons[i].offsetLeft === cons[i + 1].offsetLeft && cons[i].clientWidth < cons[i + 1].clientWidth) {
223
- cons[i].style.width = "200%";
224
- } else {
225
- cons[i].style.width = "100%";
226
- }
227
- }
228
- if (len > 2) {
229
- const con1 = cons[len - 1];
230
- const con2 = cons[len - 2];
231
- if (con1.clientWidth === con2.clientWidth && con1.offsetLeft !== con2.offsetLeft) {
232
- con1.style.width = "200%";
233
- } else {
234
- con1.style.width = "100%";
235
- }
236
- }
237
- } catch (e) {
238
- console.error("自动修改表单宽度错误" + e);
239
- }
240
- });
241
- }
242
-
243
- /**
244
- * @description: 生成表单对象
245
- * @author ChenRui
246
- * @date 2021/1/7 20:48
247
- */
248
- private generateFormApi(isReset?: boolean): void {
249
- if (isReset) {
250
- const formApi: FormApi = new FormApi(this.formApi);
251
- formApi.dvForm = this;
252
- this.$emit("update:formApi", formApi);
253
- } else {
254
- if (this.formApi) {
255
- this.formApi.dvForm = this;
256
- this.$emit("update:formApi", this.formApi);
257
- } else {
258
- const formApi = new FormApi({ dvForm: this });
259
- this.$emit("update:formApi", formApi);
260
- }
261
- }
262
- }
263
-
264
- /**
265
- * @description: 解析对象
266
- * @author ChenRui
267
- * @date 2020/11/25 16:25
268
- */
269
- private analysisBindingObjects(): any {
270
- const models: any[] = this.objectExtraction(this.desForm!.controls);
271
- let obj: any = {};
272
- if (models != null && models.length > 0) {
273
- models.forEach((item) => {
274
- if (Object.keys(item).length > 0) {
275
- obj = this.objectMerge(obj, item[Object.keys(item)[0]]);
276
- }
277
- });
278
- }
279
- return obj;
280
- }
281
-
282
- /**
283
- * @description: 对象抽取
284
- * @author ChenRui
285
- * @date 2020/11/25 17:28
286
- */
287
- private objectExtraction(controls: Control[], models: any[] = []): any {
288
- controls.forEach((item) => {
289
- if (item.type === FormFieldClass.Layout.code) {
290
- if (item.subControls != null && item.subControls.length > 0) {
291
- return this.objectExtraction(item.subControls, models);
292
- }
293
- } else {
294
- const desFormControl: DesFormControl = item?.controlAttr as DesFormControl;
295
- const boundProperty: string = desFormControl.boundProperty;
296
- if (boundProperty) {
297
- /* 初始化字典项数据 */
298
- if (desFormControl.generalDictionary || desFormControl.treeShape) {
299
- if (desFormControl.isOptionType === OptionType.Dynamic.code) {
300
- if (desFormControl.dynamicOptionType === DynamicOptionType.GeneralDictionary.code) {
301
- desFormControl.generalDictionaryOptions = this.findDictOptions(desFormControl.generalDictionary, this.sysDictDetailOptions);
302
- } else if (desFormControl.dynamicOptionType === DynamicOptionType.TreeDictionary.code) {
303
- desFormControl.treeShapeOptions = this.findDictOptions(desFormControl.treeShape, this.sysDictTreeDetailOptions);
304
- }
305
- }
306
- }
307
- /*初始化默认值*/
308
- const propertys: string[] = boundProperty.split(".");
309
- let lastMd: any = {};
310
- const md = { lastMd };
311
- propertys.forEach((val, idx, array) => {
312
- if (idx < array.length - 1) {
313
- lastMd[val] = {};
314
- lastMd = lastMd[val];
315
- } else {
316
- const defaultValue: any = formBeanUtilsService.parse((item.controlAttr as DesFormControl).fieldDefaultValue) || "";
317
- lastMd[val] = this.securityValue(item, defaultValue);
318
- }
319
- });
320
- models.push(md.lastMd);
321
- }
322
- }
323
- });
324
- return models;
325
- }
326
-
327
- /**
328
- * @description: 查询字典
329
- * @author ChenRui
330
- * @date 2021/3/11 17:19
331
- */
332
- private findDictOptions(key: string, nzTreeNodeOptions: NzTreeNodeOptions[]): NzTreeNodeOptions[] {
333
- if (nzTreeNodeOptions != null && nzTreeNodeOptions.length > 0) {
334
- for (const item of nzTreeNodeOptions) {
335
- if (item.key === key) {
336
- (item.children || []).forEach((item) => {
337
- item.disabled = false;
338
- });
339
- return item.children || [];
340
- } else if (item.children && item.children.length > 0) {
341
- const subTtems: NzTreeNodeOptions[] = this.findDictOptions(key, item.children);
342
- if (subTtems != null && subTtems.length > 0) {
343
- return subTtems;
344
- }
345
- }
346
- }
347
- }
348
- return [];
349
- }
350
-
351
- /**
352
- * @description: 安全值处理
353
- * @author ChenRui
354
- * @date 2021/1/29 17:01
355
- */
356
- securityValue(control: Control, defaultValue: any): any {
357
- if (control.code === FormFieldType.DatePicker.code || control.code === FormFieldType.TimePicker.code) {
358
- if (defaultValue) {
359
- return defaultValue;
360
- } else {
361
- return null;
362
- }
363
- } else if (control.code === FormFieldType.TreeSelect.code) {
364
- const options = extractOptions(control.controlAttr);
365
- if (options && options.length > 0 && defaultValue) {
366
- defaultValue = this.treeSelectRecursion(defaultValue, options);
367
- }
368
- return defaultValue;
369
- } else if (control.code === FormFieldType.Upload.code) {
370
- return defaultValue || [];
371
- } else if (control.code === FormFieldType.Switch.code) {
372
- if (control.controlAttr && (control.controlAttr as DesFormControl).onOpeningValue) {
373
- return defaultValue === true || defaultValue === (control.controlAttr as DesFormControl).onOpeningValue ? true : false;
374
- } else if (control.controlAttr && (control.controlAttr as DesFormControl).whenClosedValue) {
375
- return defaultValue === false || defaultValue === (control.controlAttr as DesFormControl).whenClosedValue ? false : true;
376
- }
377
- return defaultValue;
378
- } else {
379
- return defaultValue;
380
- }
381
- }
382
-
383
- /**
384
- * @description: 树形递归
385
- * @author ChenRui
386
- * @date 2021/1/11 0:23
387
- */
388
- treeSelectRecursion(value: any, items: any[]): any {
389
- for (let i = 0; i < items.length; i++) {
390
- if (items[i].key === value) {
391
- return items[i].value;
392
- } else if (items[i].children && items[i].children.length > 0) {
393
- const subValue = this.treeSelectRecursion(value, items[i].children);
394
- if (subValue) {
395
- return subValue;
396
- }
397
- }
398
- }
399
- return "";
400
- }
401
-
402
- /**
403
- * @description: 对象合并
404
- * @author ChenRui
405
- * @date 2020/11/25 17:49
406
- */
407
- private objectMerge(modelX: any, modelY: any): any {
408
- let key;
409
- for (key in modelY) {
410
- if (modelX[key] && modelX[key].toString() === "[object Object]" && modelY[key] && modelY[key].toString() === "[object Object]") {
411
- modelX[key] = this.objectMerge(modelX[key], modelY[key]);
412
- } else {
413
- modelX[key] = modelX[key] = modelY[key];
414
- }
415
- }
416
- return modelX;
417
- }
418
-
419
- /**
420
- * @description: 生成表单对象
421
- * @author ChenRui
422
- * @date 2020/11/26 11:02
423
- */
424
- private generateFormGroup(model: any): FormGroup {
425
- const group: FormGroup = new FormGroup();
426
- if (model != null) {
427
- Object.keys(model).forEach((key) => {
428
- if (Object.prototype.toString.call(model[key]) === "[object Object]") {
429
- const subFormGroup: FormGroup = this.generateFormGroup(model[key]);
430
- subFormGroup.key = key;
431
- group.addControl(key, subFormGroup);
432
- } else {
433
- const formControl: FormControl = new FormControl(model[key]);
434
- formControl.key = key;
435
- group.addControl(key, formControl);
436
- }
437
- });
438
- }
439
- return group;
440
- }
441
-
442
- /**
443
- * @description: 创建表单对象
444
- * @author ChenRui
445
- * @date 2020/11/23 11:19
446
- */
447
- private initControlForm(controls: Control[], formGroup: FormGroup): void {
448
- controls.forEach((control) => {
449
- if (control.type === FormFieldClass.Base.code || control.type === FormFieldClass.Senior.code) {
450
- const boundProperty: string = (control.controlAttr as DesFormControl)?.boundProperty;
451
- if (boundProperty) {
452
- const propertys: string[] = boundProperty.split(".");
453
- if (propertys.length > 1 && formGroup != null) {
454
- const formControl: FormControl = this.findFormControlByProperty(propertys.slice(1, propertys.length), formGroup);
455
- formControl.code = control.code;
456
- formControl.controlAttr = control.controlAttr;
457
- validateGeneratorService.fillCheckRule(formControl, control.controlAttr as DesFormControl);
458
- control["formControl"] = formControl;
459
- }
460
- }
461
- } else if (control.type === FormFieldClass.Layout.code && control.subControls != null && control.subControls.length > 0) {
462
- this.initControlForm(control.subControls, formGroup);
463
- }
464
- });
465
- }
466
-
467
- /**
468
- * @description: 按照节点查询控件
469
- * @author ChenRui
470
- * @date 2020/11/26 15:45
471
- */
472
- private findFormControlByProperty(propertys: string[], formGroup: FormGroup): FormControl | any {
473
- let currentFormGroup = formGroup;
474
- for (let i = 0; i < propertys.length; i++) {
475
- const formObject = currentFormGroup.get(propertys[i]);
476
- if (i < propertys.length - 1 && formObject != null && formObject instanceof FormGroup) {
477
- currentFormGroup = formObject;
478
- } else {
479
- return formObject;
480
- }
481
- }
482
- }
483
-
484
- /**
485
- * @description: 控件值变化事件处理
486
- * @author ChenRui
487
- * @date 2020/12/2 14:35
488
- */
489
- onChange(event: any): void {
490
- this.$emit("change", event);
491
- }
492
-
493
- /**
494
- * @description: 下拉选项新增
495
- * @author ChenRui
496
- * @date 2021/1/14 20:05
497
- */
498
- selectAddItem(event: any): void {
499
- this.$emit("add-item", event);
500
- }
501
-
502
- /**
503
- * @description: 单击事件
504
- * @author ChenRui
505
- * @date 2021/3/4 11:39
506
- */
507
- onClick(event: any): void {
508
- this.$emit("click", event);
509
- }
510
-
511
- /**
512
- * @description: 内置前置标签事件
513
- * @author ChenRui
514
- * @date 2021/4/23 9:42
515
- */
516
- onAddonBeforeHandler(event: any): void {
517
- this.$emit("addon-before", event);
518
- }
519
-
520
- /**
521
- * @description: 内置后置标签事件
522
- * @author ChenRui
523
- * @date 2021/4/23 9:43
524
- */
525
- onAddonAfterHandler(event: any): void {
526
- this.$emit("addon-after", event);
527
- }
528
-
529
- /**
530
- * @description: 获取焦点
531
- * @author ChenRui
532
- * @date 2021/3/4 11:46
533
- */
534
- onFocus(event: Control): void {
535
- this.$emit("focus", event);
536
- }
537
-
538
- /**
539
- * @description: 失焦事件
540
- * @author ChenRui
541
- * @date 2021/3/4 11:38
542
- */
543
- onBlur(event: Control): void {
544
- this.$emit("blur", event);
545
- }
546
- }
547
- </script>
548
-
549
- <style lang="scss" scoped>
550
- .w-100 {
551
- width: 100%;
552
- }
553
- .lo-form-container {
554
- box-sizing: border-box;
555
- :deep {
556
- .ant-form-horizontal {
557
- .lo-control-container {
558
- .ant-form-item-label {
559
- padding-left: 10px;
560
- padding-right: 10px;
561
- display: flex;
562
- align-items: center;
563
- }
564
- }
565
- }
566
- }
567
- /* START 非编辑模式主题样式 */
568
- &.lo-class-style-credit-rd.lo-disable-edit,
569
- &.lo-class-style-trust.lo-disable-edit {
570
- :deep {
571
- .lo-control-container {
572
- .ant-form-item-label {
573
- padding-left: 12px;
574
- text-align: left;
575
- label {
576
- &::after {
577
- display: none;
578
- }
579
- }
580
- }
581
- }
582
- }
583
- }
584
- /* END 非编辑模式主题样式 */
585
- /* START 编辑模式主题样式 */
586
- &.lo-class-style-trust.lo-enable-edit {
587
- :deep {
588
- .ant-form-horizontal {
589
- .lo-control-container {
590
- .ant-form-item-label {
591
- label {
592
- &::after {
593
- display: none;
594
- }
595
- }
596
- }
597
- }
598
- }
599
- }
600
- }
601
- &.lo-class-style-credit-rd.lo-enable-edit,
602
- &.lo-class-style-trust.lo-enable-edit {
603
- :deep {
604
- .ant-form-horizontal {
605
- .lo-control-container {
606
- .ant-form-item-label {
607
- label {
608
- padding-left: 10px;
609
- padding-right: 5px;
610
- }
611
- }
612
- }
613
- }
614
- .lo-control-container {
615
- padding-bottom: 10px;
616
- border: 0;
617
- .ant-form-item-label {
618
- background-color: inherit;
619
- border: 0;
620
- label {
621
- color: rgba(0, 0, 0, 0.850980392156863);
622
- }
623
- }
624
- .ant-form-item-control-wrapper {
625
- .ant-form-item-children {
626
- .ant-input,
627
- .ant-select,
628
- .ant-cascader-picker-label,
629
- .ant-select-selection-selected-value,
630
- .ant-time-picker-input,
631
- .ant-radio-wrapper,
632
- .ant-checkbox-wrapper {
633
- color: #000000;
634
- }
635
- }
636
- }
637
- }
638
- }
639
- }
640
- /* END 编辑模式主题样式 */
641
- }
642
- </style>
1
+ <template>
2
+ <div v-if="desForm?.controls?.length" ref="formView" :class="'lo-form-container ' + ('lo-' + (edit ? 'enable' : 'disable') + '-edit') + ' lo-class-style-' + styleMode + ' lo-form-theme-' + loFormTheme">
3
+ <dv-form-layout v-for="(item, i) in desForm.controls" :key="i" :control="item" :customFormats="customFormats" :linkList="linkList" @linkClick="linkClick" :index="i" @change="onChange($event)" @focus="onFocus($event)" @blur="onBlur($event)" @click="onClick($event)" @addon-before="onAddonBeforeHandler($event)" @addon-after="onAddonAfterHandler($event)" @add-item="selectAddItem($event)">
4
+ <template v-for="propName in Object.keys(this.$slots)" v-slot:[propName]="slotProps">
5
+ <slot :name="propName" :content="slotProps.content" :control="slotProps.control" :onChange="slotProps.onChange"></slot>
6
+ </template>
7
+ </dv-form-layout>
8
+ </div>
9
+ </template>
10
+
11
+ <script lang="ts">
12
+ import DvFormLayout from "./DvFormLayout.vue";
13
+ import { Options, Prop, Provide, Watch, Vue } from "vue-property-decorator";
14
+ import { DesForm } from "@/domain";
15
+ import { FormFieldClass } from "@/constants";
16
+ import { formToolsService } from "@/services";
17
+ import { Control } from "@/domain";
18
+ import { DesFormControl } from "@/domain";
19
+ import { FormGroup } from "@/domain";
20
+ import { FormControl } from "@/domain";
21
+ import { formBeanUtilsService } from "@/services";
22
+ import { FormApi } from "@/core";
23
+ import { FormFieldType } from "@/constants";
24
+ import { ProvideInjectData } from "@/domain/ProvideInjectData";
25
+ import { validateGeneratorService } from "@/services";
26
+ import { CustomFormat, FieldChangeHistory } from "../../domain";
27
+ import { extractOptions } from "@/filtres/extract-options.filter";
28
+ import { DynamicOptionType, OptionType } from "../../constants/enum";
29
+ import { NzTreeNodeOptions } from "@/services";
30
+
31
+ export type NfFormMode = "manual" | "auto";
32
+
33
+ export type NfStyleMode = "default" | "trust" | "credit-rd";
34
+
35
+ export type NfFormTheme = "default" | "gray";
36
+ /**
37
+ * @description: 动态表单
38
+ * @author ChenRui
39
+ * @date 2020/12/30 11:20
40
+ */
41
+ @Options({
42
+ name: "DyForm",
43
+ components: {
44
+ DvFormLayout: DvFormLayout,
45
+ },
46
+ })
47
+ export default class DyForm extends Vue {
48
+ @Prop() formId: string | undefined;
49
+ @Prop() mode: NfFormMode | undefined;
50
+ @Prop({ type: String, default: "default" }) styleMode!: NfStyleMode;
51
+ @Prop() srcDesForm: DesForm | undefined;
52
+ @Prop({ default: false, type: Boolean }) edit!: boolean;
53
+ @Prop({ default: false, type: Boolean }) colon!: boolean;
54
+ @Prop({ default: "130px", type: String }) labelSpan!: string;
55
+ @Prop({ default: undefined }) controlSpan!: any;
56
+ @Prop({ type: Object }) formApi: FormApi | undefined;
57
+ @Prop({ type: Array }) history: FieldChangeHistory | undefined;
58
+ @Prop({ type: Object, default: () => ({}) }) customFormats!: {
59
+ [key: string]: CustomFormat;
60
+ };
61
+ @Prop() refreshArguments: any; // 刷新自变量
62
+ @Prop({ default: false }) widthCompatibleMode!: boolean; // 宽度计算模式
63
+ @Prop({ type: String }) formTheme!: NfFormTheme; // 表单主题
64
+ @Prop({ type: Array }) linkList: any | undefined; // 需要添加超链接点击事件数组 例:['cifNo', 'prodBaseNo']
65
+
66
+ private metaRefresh: any = new Date().getTime(); // 刷新标识
67
+ private refreshCheckFeedbackFlag = new Date().getTime(); // 刷新校验标识
68
+ private sysDictDetailOptions: NzTreeNodeOptions[] = []; // 常规字典
69
+ private sysDictTreeDetailOptions: NzTreeNodeOptions[] = []; // 树形字典
70
+ private formValidateStateResetMark: any = new Date().getTime(); // 重置校验标识
71
+
72
+ desForm: DesForm = new DesForm();
73
+
74
+ @Provide() provideInjectData: ProvideInjectData = {
75
+ edit: (this.$props as any).edit,
76
+ labelSpan: (this.$props as any).labelSpan,
77
+ controlSpan: (this.$props as any).controlSpan,
78
+ colon: (this.$props as any).colon,
79
+ metaRefresh: this.metaRefresh,
80
+ refreshCheckFeedbackFlag: this.refreshCheckFeedbackFlag,
81
+ widthCompatibleMode: (this.$props as any).widthCompatibleMode,
82
+ formValidateStateResetMark: this.formValidateStateResetMark,
83
+ };
84
+
85
+ /**
86
+ * @description: 刷新自变量监听处理
87
+ * @author ChenRui
88
+ * @date 2021/2/5 10:25
89
+ */
90
+ @Watch("refreshArguments", { immediate: true })
91
+ onRefreshArgumentsHandler(newVal: any): void {
92
+ this.metaRefresh = newVal;
93
+ }
94
+
95
+ /**
96
+ * @description: 重置表单校验状态监听
97
+ * @author ChenRui
98
+ * @date 2022/4/6 14:17
99
+ */
100
+ @Watch("formValidateStateResetMark")
101
+ onPropFormValidateStateResetHandler(newVal: any): void {
102
+ if ((this as any)._provided) {
103
+ ((this as any)._provided as any).provideInjectData.formValidateStateResetMark = this.formValidateStateResetMark;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * @description: 值变更处理器
109
+ * @author ChenRui
110
+ * @date 2021/1/8 11:03
111
+ */
112
+ @Watch("edit")
113
+ @Watch("labelSpan")
114
+ @Watch("controlSpan")
115
+ @Watch("metaRefresh")
116
+ @Watch("refreshCheckFeedbackFlag")
117
+ @Watch("widthCompatibleMode")
118
+ onPropHandler(newVal: any): void {
119
+ if (this) {
120
+ this.provideInjectData.edit = this.edit;
121
+ this.provideInjectData.labelSpan = this.labelSpan;
122
+ this.provideInjectData.controlSpan = this.controlSpan;
123
+ this.provideInjectData.metaRefresh = this.metaRefresh;
124
+ this.provideInjectData.refreshCheckFeedbackFlag = this.refreshCheckFeedbackFlag;
125
+ this.provideInjectData.widthCompatibleMode = this.widthCompatibleMode;
126
+ }
127
+ }
128
+
129
+ get loFormTheme(): string {
130
+ const win: any = window;
131
+ const themes = ["default", "gray"];
132
+ const formTheme = themes.indexOf(this.formTheme) > -1 ? this.formTheme : win.$loFormTheme;
133
+ return themes.indexOf(formTheme) > -1 ? formTheme : themes[0];
134
+ }
135
+ /**
136
+ * @Description 表单数据反显回调(data:Object { key: 元素码值, value: 元素值 })
137
+ * @Author JiangTao
138
+ * @Date 2023-10-07 下午 05:16
139
+ */
140
+ linkClick(data: any) {
141
+ this.$emit("linkClick", data);
142
+ }
143
+
144
+ created() {
145
+ this.initDict();
146
+ }
147
+
148
+ mounted() {
149
+ if (this.formId) {
150
+ this.initDesForm();
151
+ } else if (this.desForm) {
152
+ this.formatDesForm();
153
+ }
154
+ }
155
+
156
+ @Watch("formId")
157
+ private onFormIdChanged() {
158
+ this.initDesForm();
159
+ }
160
+
161
+ @Watch("srcDesForm", { immediate: true })
162
+ private onSrcDesFormChanged(newVal: DesForm) {
163
+ if (newVal != null) {
164
+ this.desForm = formBeanUtilsService.copy(newVal);
165
+ this.formatDesForm();
166
+ }
167
+ }
168
+
169
+ /**
170
+ * @description: 初始化表单
171
+ * @author ChenRui
172
+ * @date 2020/11/23 11:19
173
+ */
174
+ private initDesForm(): void {
175
+ if (this.formId != null && this.formId !== "") {
176
+ this.desForm = formToolsService.loadResource(this.formId);
177
+ this.formatDesForm();
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @description: 初始化字典
183
+ * @author ChenRui
184
+ * @date 2021/3/12 10:12
185
+ */
186
+ private initDict(): void {
187
+ this.sysDictDetailOptions = formToolsService.sysDictDetailOptions;
188
+ this.sysDictTreeDetailOptions = formToolsService.sysDictTreeDetailOptions;
189
+ }
190
+
191
+ /**
192
+ * @description: 格式化表单
193
+ * @author ChenRui
194
+ * @date 2020/11/30 16:05
195
+ */
196
+ private formatDesForm(isReset?: boolean): void {
197
+ if (this.desForm != null && this.desForm.controls != null && this.desForm.controls.length > 0) {
198
+ const model = this.analysisBindingObjects();
199
+ this.desForm.formGroup = this.generateFormGroup(model);
200
+ this.initControlForm(this.desForm.controls, this.desForm.formGroup);
201
+ this.generateFormApi(isReset);
202
+ if (this.history != null) {
203
+ this.formApi?.setFieldChangeHistory(this.history);
204
+ }
205
+ this.$emit("complete");
206
+ }
207
+ }
208
+ /**
209
+ * @Description: 临时-该方法被取消
210
+ * @author LiuBo
211
+ * @date 2022/11/6
212
+ * @time 17:11
213
+ */
214
+ private fixFormLayout() {
215
+ this.$nextTick(() => {
216
+ console.log("自动修改表单宽度");
217
+ try {
218
+ const formView: any = this.$refs.formView;
219
+ const cons = formView.getElementsByClassName("lo-control-container");
220
+ const len = cons.length;
221
+ for (let i = 0; i < len - 1; i++) {
222
+ if (cons[i].offsetLeft === cons[i + 1].offsetLeft && cons[i].clientWidth < cons[i + 1].clientWidth) {
223
+ cons[i].style.width = "200%";
224
+ } else {
225
+ cons[i].style.width = "100%";
226
+ }
227
+ }
228
+ if (len > 2) {
229
+ const con1 = cons[len - 1];
230
+ const con2 = cons[len - 2];
231
+ if (con1.clientWidth === con2.clientWidth && con1.offsetLeft !== con2.offsetLeft) {
232
+ con1.style.width = "200%";
233
+ } else {
234
+ con1.style.width = "100%";
235
+ }
236
+ }
237
+ } catch (e) {
238
+ console.error("自动修改表单宽度错误" + e);
239
+ }
240
+ });
241
+ }
242
+
243
+ /**
244
+ * @description: 生成表单对象
245
+ * @author ChenRui
246
+ * @date 2021/1/7 20:48
247
+ */
248
+ private generateFormApi(isReset?: boolean): void {
249
+ if (isReset) {
250
+ const formApi: FormApi = new FormApi(this.formApi);
251
+ formApi.dvForm = this;
252
+ this.$emit("update:formApi", formApi);
253
+ } else {
254
+ if (this.formApi) {
255
+ this.formApi.dvForm = this;
256
+ this.$emit("update:formApi", this.formApi);
257
+ } else {
258
+ const formApi = new FormApi({ dvForm: this });
259
+ this.$emit("update:formApi", formApi);
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * @description: 解析对象
266
+ * @author ChenRui
267
+ * @date 2020/11/25 16:25
268
+ */
269
+ private analysisBindingObjects(): any {
270
+ const models: any[] = this.objectExtraction(this.desForm!.controls);
271
+ let obj: any = {};
272
+ if (models != null && models.length > 0) {
273
+ models.forEach((item) => {
274
+ if (Object.keys(item).length > 0) {
275
+ obj = this.objectMerge(obj, item[Object.keys(item)[0]]);
276
+ }
277
+ });
278
+ }
279
+ return obj;
280
+ }
281
+
282
+ /**
283
+ * @description: 对象抽取
284
+ * @author ChenRui
285
+ * @date 2020/11/25 17:28
286
+ */
287
+ private objectExtraction(controls: Control[], models: any[] = []): any {
288
+ controls.forEach((item) => {
289
+ if (item.type === FormFieldClass.Layout.code) {
290
+ if (item.subControls != null && item.subControls.length > 0) {
291
+ return this.objectExtraction(item.subControls, models);
292
+ }
293
+ } else {
294
+ const desFormControl: DesFormControl = item?.controlAttr as DesFormControl;
295
+ const boundProperty: string = desFormControl.boundProperty;
296
+ if (boundProperty) {
297
+ /* 初始化字典项数据 */
298
+ if (desFormControl.generalDictionary || desFormControl.treeShape) {
299
+ if (desFormControl.isOptionType === OptionType.Dynamic.code) {
300
+ if (desFormControl.dynamicOptionType === DynamicOptionType.GeneralDictionary.code) {
301
+ desFormControl.generalDictionaryOptions = this.findDictOptions(desFormControl.generalDictionary, this.sysDictDetailOptions);
302
+ } else if (desFormControl.dynamicOptionType === DynamicOptionType.TreeDictionary.code) {
303
+ desFormControl.treeShapeOptions = this.findDictOptions(desFormControl.treeShape, this.sysDictTreeDetailOptions);
304
+ }
305
+ }
306
+ }
307
+ /*初始化默认值*/
308
+ const propertys: string[] = boundProperty.split(".");
309
+ let lastMd: any = {};
310
+ const md = { lastMd };
311
+ propertys.forEach((val, idx, array) => {
312
+ if (idx < array.length - 1) {
313
+ lastMd[val] = {};
314
+ lastMd = lastMd[val];
315
+ } else {
316
+ const defaultValue: any = formBeanUtilsService.parse((item.controlAttr as DesFormControl).fieldDefaultValue) || "";
317
+ lastMd[val] = this.securityValue(item, defaultValue);
318
+ }
319
+ });
320
+ models.push(md.lastMd);
321
+ }
322
+ }
323
+ });
324
+ return models;
325
+ }
326
+
327
+ /**
328
+ * @description: 查询字典
329
+ * @author ChenRui
330
+ * @date 2021/3/11 17:19
331
+ */
332
+ private findDictOptions(key: string, nzTreeNodeOptions: NzTreeNodeOptions[]): NzTreeNodeOptions[] {
333
+ if (nzTreeNodeOptions != null && nzTreeNodeOptions.length > 0) {
334
+ for (const item of nzTreeNodeOptions) {
335
+ if (item.key === key) {
336
+ (item.children || []).forEach((item) => {
337
+ item.disabled = false;
338
+ });
339
+ return item.children || [];
340
+ } else if (item.children && item.children.length > 0) {
341
+ const subTtems: NzTreeNodeOptions[] = this.findDictOptions(key, item.children);
342
+ if (subTtems != null && subTtems.length > 0) {
343
+ return subTtems;
344
+ }
345
+ }
346
+ }
347
+ }
348
+ return [];
349
+ }
350
+
351
+ /**
352
+ * @description: 安全值处理
353
+ * @author ChenRui
354
+ * @date 2021/1/29 17:01
355
+ */
356
+ securityValue(control: Control, defaultValue: any): any {
357
+ if (control.code === FormFieldType.DatePicker.code || control.code === FormFieldType.TimePicker.code) {
358
+ if (defaultValue) {
359
+ return defaultValue;
360
+ } else {
361
+ return null;
362
+ }
363
+ } else if (control.code === FormFieldType.TreeSelect.code) {
364
+ const options = extractOptions(control.controlAttr);
365
+ if (options && options.length > 0 && defaultValue) {
366
+ defaultValue = this.treeSelectRecursion(defaultValue, options);
367
+ }
368
+ return defaultValue;
369
+ } else if (control.code === FormFieldType.Upload.code) {
370
+ return defaultValue || [];
371
+ } else if (control.code === FormFieldType.Switch.code) {
372
+ if (control.controlAttr && (control.controlAttr as DesFormControl).onOpeningValue) {
373
+ return defaultValue === true || defaultValue === (control.controlAttr as DesFormControl).onOpeningValue ? true : false;
374
+ } else if (control.controlAttr && (control.controlAttr as DesFormControl).whenClosedValue) {
375
+ return defaultValue === false || defaultValue === (control.controlAttr as DesFormControl).whenClosedValue ? false : true;
376
+ }
377
+ return defaultValue;
378
+ } else {
379
+ return defaultValue;
380
+ }
381
+ }
382
+
383
+ /**
384
+ * @description: 树形递归
385
+ * @author ChenRui
386
+ * @date 2021/1/11 0:23
387
+ */
388
+ treeSelectRecursion(value: any, items: any[]): any {
389
+ for (let i = 0; i < items.length; i++) {
390
+ if (items[i].key === value) {
391
+ return items[i].value;
392
+ } else if (items[i].children && items[i].children.length > 0) {
393
+ const subValue = this.treeSelectRecursion(value, items[i].children);
394
+ if (subValue) {
395
+ return subValue;
396
+ }
397
+ }
398
+ }
399
+ return "";
400
+ }
401
+
402
+ /**
403
+ * @description: 对象合并
404
+ * @author ChenRui
405
+ * @date 2020/11/25 17:49
406
+ */
407
+ private objectMerge(modelX: any, modelY: any): any {
408
+ let key;
409
+ for (key in modelY) {
410
+ if (modelX[key] && modelX[key].toString() === "[object Object]" && modelY[key] && modelY[key].toString() === "[object Object]") {
411
+ modelX[key] = this.objectMerge(modelX[key], modelY[key]);
412
+ } else {
413
+ modelX[key] = modelX[key] = modelY[key];
414
+ }
415
+ }
416
+ return modelX;
417
+ }
418
+
419
+ /**
420
+ * @description: 生成表单对象
421
+ * @author ChenRui
422
+ * @date 2020/11/26 11:02
423
+ */
424
+ private generateFormGroup(model: any): FormGroup {
425
+ const group: FormGroup = new FormGroup();
426
+ if (model != null) {
427
+ Object.keys(model).forEach((key) => {
428
+ if (Object.prototype.toString.call(model[key]) === "[object Object]") {
429
+ const subFormGroup: FormGroup = this.generateFormGroup(model[key]);
430
+ subFormGroup.key = key;
431
+ group.addControl(key, subFormGroup);
432
+ } else {
433
+ const formControl: FormControl = new FormControl(model[key]);
434
+ formControl.key = key;
435
+ group.addControl(key, formControl);
436
+ }
437
+ });
438
+ }
439
+ return group;
440
+ }
441
+
442
+ /**
443
+ * @description: 创建表单对象
444
+ * @author ChenRui
445
+ * @date 2020/11/23 11:19
446
+ */
447
+ private initControlForm(controls: Control[], formGroup: FormGroup): void {
448
+ controls.forEach((control) => {
449
+ if (control.type === FormFieldClass.Base.code || control.type === FormFieldClass.Senior.code) {
450
+ const boundProperty: string = (control.controlAttr as DesFormControl)?.boundProperty;
451
+ if (boundProperty) {
452
+ const propertys: string[] = boundProperty.split(".");
453
+ if (propertys.length > 1 && formGroup != null) {
454
+ const formControl: FormControl = this.findFormControlByProperty(propertys.slice(1, propertys.length), formGroup);
455
+ formControl.code = control.code;
456
+ formControl.controlAttr = control.controlAttr;
457
+ validateGeneratorService.fillCheckRule(formControl, control.controlAttr as DesFormControl);
458
+ control["formControl"] = formControl;
459
+ }
460
+ }
461
+ } else if (control.type === FormFieldClass.Layout.code && control.subControls != null && control.subControls.length > 0) {
462
+ this.initControlForm(control.subControls, formGroup);
463
+ }
464
+ });
465
+ }
466
+
467
+ /**
468
+ * @description: 按照节点查询控件
469
+ * @author ChenRui
470
+ * @date 2020/11/26 15:45
471
+ */
472
+ private findFormControlByProperty(propertys: string[], formGroup: FormGroup): FormControl | any {
473
+ let currentFormGroup = formGroup;
474
+ for (let i = 0; i < propertys.length; i++) {
475
+ const formObject = currentFormGroup.get(propertys[i]);
476
+ if (i < propertys.length - 1 && formObject != null && formObject instanceof FormGroup) {
477
+ currentFormGroup = formObject;
478
+ } else {
479
+ return formObject;
480
+ }
481
+ }
482
+ }
483
+
484
+ /**
485
+ * @description: 控件值变化事件处理
486
+ * @author ChenRui
487
+ * @date 2020/12/2 14:35
488
+ */
489
+ onChange(event: any): void {
490
+ this.$emit("change", event);
491
+ }
492
+
493
+ /**
494
+ * @description: 下拉选项新增
495
+ * @author ChenRui
496
+ * @date 2021/1/14 20:05
497
+ */
498
+ selectAddItem(event: any): void {
499
+ this.$emit("add-item", event);
500
+ }
501
+
502
+ /**
503
+ * @description: 单击事件
504
+ * @author ChenRui
505
+ * @date 2021/3/4 11:39
506
+ */
507
+ onClick(event: any): void {
508
+ this.$emit("click", event);
509
+ }
510
+
511
+ /**
512
+ * @description: 内置前置标签事件
513
+ * @author ChenRui
514
+ * @date 2021/4/23 9:42
515
+ */
516
+ onAddonBeforeHandler(event: any): void {
517
+ this.$emit("addon-before", event);
518
+ }
519
+
520
+ /**
521
+ * @description: 内置后置标签事件
522
+ * @author ChenRui
523
+ * @date 2021/4/23 9:43
524
+ */
525
+ onAddonAfterHandler(event: any): void {
526
+ this.$emit("addon-after", event);
527
+ }
528
+
529
+ /**
530
+ * @description: 获取焦点
531
+ * @author ChenRui
532
+ * @date 2021/3/4 11:46
533
+ */
534
+ onFocus(event: Control): void {
535
+ this.$emit("focus", event);
536
+ }
537
+
538
+ /**
539
+ * @description: 失焦事件
540
+ * @author ChenRui
541
+ * @date 2021/3/4 11:38
542
+ */
543
+ onBlur(event: Control): void {
544
+ this.$emit("blur", event);
545
+ }
546
+ }
547
+ </script>
548
+
549
+ <style lang="scss" scoped>
550
+ .w-100 {
551
+ width: 100%;
552
+ }
553
+ .lo-form-container {
554
+ box-sizing: border-box;
555
+ :deep {
556
+ .ant-form-horizontal {
557
+ .lo-control-container {
558
+ .ant-form-item-label {
559
+ padding-left: 10px;
560
+ padding-right: 10px;
561
+ display: flex;
562
+ align-items: center;
563
+ }
564
+ }
565
+ }
566
+ }
567
+ /* START 非编辑模式主题样式 */
568
+ &.lo-class-style-credit-rd.lo-disable-edit,
569
+ &.lo-class-style-trust.lo-disable-edit {
570
+ :deep {
571
+ .lo-control-container {
572
+ .ant-form-item-label {
573
+ padding-left: 12px;
574
+ text-align: left;
575
+ label {
576
+ &::after {
577
+ display: none;
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }
583
+ }
584
+ /* END 非编辑模式主题样式 */
585
+ /* START 编辑模式主题样式 */
586
+ &.lo-class-style-trust.lo-enable-edit {
587
+ :deep {
588
+ .ant-form-horizontal {
589
+ .lo-control-container {
590
+ .ant-form-item-label {
591
+ label {
592
+ &::after {
593
+ display: none;
594
+ }
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+ }
601
+ &.lo-class-style-credit-rd.lo-enable-edit,
602
+ &.lo-class-style-trust.lo-enable-edit {
603
+ :deep {
604
+ .ant-form-horizontal {
605
+ .lo-control-container {
606
+ .ant-form-item-label {
607
+ label {
608
+ padding-left: 10px;
609
+ padding-right: 5px;
610
+ }
611
+ }
612
+ }
613
+ }
614
+ .lo-control-container {
615
+ padding-bottom: 10px;
616
+ border: 0;
617
+ .ant-form-item-label {
618
+ background-color: inherit;
619
+ border: 0;
620
+ label {
621
+ color: rgba(0, 0, 0, 0.850980392156863);
622
+ }
623
+ }
624
+ .ant-form-item-control-wrapper {
625
+ .ant-form-item-children {
626
+ .ant-input,
627
+ .ant-select,
628
+ .ant-cascader-picker-label,
629
+ .ant-select-selection-selected-value,
630
+ .ant-time-picker-input,
631
+ .ant-radio-wrapper,
632
+ .ant-checkbox-wrapper {
633
+ color: #000000;
634
+ }
635
+ }
636
+ }
637
+ }
638
+ }
639
+ }
640
+ /* END 编辑模式主题样式 */
641
+ }
642
+ </style>