@dhccmobile/vue3-lo-form 0.1.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.
- package/.eslintrc.js +29 -0
- package/README.md +62 -0
- package/babel.config.js +3 -0
- package/dist/demo.html +10 -0
- package/dist/vue3-lo-form.common.js +119725 -0
- package/dist/vue3-lo-form.common.js.map +1 -0
- package/dist/vue3-lo-form.css +1 -0
- package/dist/vue3-lo-form.umd.js +119735 -0
- package/dist/vue3-lo-form.umd.js.map +1 -0
- package/dist/vue3-lo-form.umd.min.js +38 -0
- package/dist/vue3-lo-form.umd.min.js.map +1 -0
- package/package.json +61 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +17 -0
- package/src/App.vue +715 -0
- package/src/components/form/DvForm.vue +586 -0
- package/src/components/form/DvFormLayout.vue +1568 -0
- package/src/components/form/StretchText.vue +77 -0
- package/src/components/index.ts +3 -0
- package/src/constants/config/form-template.config.ts +32 -0
- package/src/constants/config/form.config.ts +4 -0
- package/src/constants/config/storage.config.ts +4 -0
- package/src/constants/encode-assets/icons.ts +0 -0
- package/src/constants/encode-assets/svg.ts +9 -0
- package/src/constants/enum/builtIn-label.enum.ts +5 -0
- package/src/constants/enum/cache-type.enum.ts +7 -0
- package/src/constants/enum/control-format-type.enum.ts +9 -0
- package/src/constants/enum/dynamic-option-type.enum.ts +6 -0
- package/src/constants/enum/form-bus-attr.enum.ts +8 -0
- package/src/constants/enum/form-field-class.enum.ts +7 -0
- package/src/constants/enum/form-field-type.enum.ts +25 -0
- package/src/constants/enum/form-type.enum.ts +5 -0
- package/src/constants/enum/index.ts +19 -0
- package/src/constants/enum/lateral-arrangement.enum.ts +9 -0
- package/src/constants/enum/money-unit.enum.ts +6 -0
- package/src/constants/enum/option-type.enum.ts +5 -0
- package/src/constants/enum/submitted-type.enum.ts +12 -0
- package/src/constants/enum/support-upload-type.enum.ts +5 -0
- package/src/constants/enum/switch.enum.ts +5 -0
- package/src/constants/enum/upload-type.enum.ts +17 -0
- package/src/constants/enum/validate-rules.enum.ts +25 -0
- package/src/constants/enum/validate-status.enum.ts +8 -0
- package/src/constants/enum/vertical-arrangement.enum.ts +7 -0
- package/src/constants/enum/zoom-type.ts +6 -0
- package/src/constants/index.ts +3 -0
- package/src/core/FormApi.ts +865 -0
- package/src/core/index.ts +1 -0
- package/src/domain/AbstractControl.ts +6 -0
- package/src/domain/Control.ts +14 -0
- package/src/domain/CustomFormat.ts +6 -0
- package/src/domain/DesForm.ts +48 -0
- package/src/domain/DesFormControl.ts +223 -0
- package/src/domain/DesFormLayout.ts +51 -0
- package/src/domain/FieldChangeHistory.ts +9 -0
- package/src/domain/FormConfig.ts +12 -0
- package/src/domain/FormControl.ts +125 -0
- package/src/domain/FormEnum.ts +9 -0
- package/src/domain/FormGroup.ts +42 -0
- package/src/domain/FormRestfulResponse.ts +6 -0
- package/src/domain/ProvideInjectData.ts +9 -0
- package/src/domain/SysDictDetail.ts +25 -0
- package/src/domain/SysDictInfo.ts +31 -0
- package/src/domain/SysDictTreeDetail.ts +43 -0
- package/src/domain/index.ts +12 -0
- package/src/filtres/amount-capitalization.filter.ts +136 -0
- package/src/filtres/extract-options.filter.ts +53 -0
- package/src/filtres/generate-grid-column-end.filter.ts +22 -0
- package/src/filtres/generate-grid-template-columns.filter.ts +24 -0
- package/src/filtres/switch-enum-convert.filter.ts +18 -0
- package/src/filtres/zoom-multiple.filter.ts +32 -0
- package/src/index.ts +67 -0
- package/src/main.ts +17 -0
- package/src/services/api.service.ts +73 -0
- package/src/services/clean-local-forage.service.ts +58 -0
- package/src/services/dict-local-forage.service.ts +58 -0
- package/src/services/form-bean-utils.service.ts +41 -0
- package/src/services/form-local-forage.service.ts +59 -0
- package/src/services/form-tools.service.ts +497 -0
- package/src/services/form-tree-node-convert.service.ts +216 -0
- package/src/services/form-validate.service.ts +103 -0
- package/src/services/index.ts +9 -0
- package/src/services/router.service.ts +96 -0
- package/src/services/validate-generator.service.ts +710 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/store/dict.store.ts +63 -0
- package/src/store/form.store.ts +32 -0
- package/src/store/index.ts +2 -0
- package/src/styles/index.scss +167 -0
- package/src/types/vfForm.ts +11 -0
- package/tsconfig.json +40 -0
- package/types/components/index.d.ts +3 -0
- package/types/constants/config/form-template.config.d.ts +30 -0
- package/types/constants/config/form.config.d.ts +4 -0
- package/types/constants/config/storage.config.d.ts +4 -0
- package/types/constants/encode-assets/icons.d.ts +0 -0
- package/types/constants/encode-assets/svg.d.ts +5 -0
- package/types/constants/enum/builtIn-label.enum.d.ts +7 -0
- package/types/constants/enum/cache-type.enum.d.ts +15 -0
- package/types/constants/enum/control-format-type.enum.d.ts +23 -0
- package/types/constants/enum/dynamic-option-type.enum.d.ts +11 -0
- package/types/constants/enum/form-bus-attr.enum.d.ts +19 -0
- package/types/constants/enum/form-field-class.enum.d.ts +18 -0
- package/types/constants/enum/form-field-type.enum.d.ts +111 -0
- package/types/constants/enum/form-type.enum.d.ts +11 -0
- package/types/constants/enum/index.d.ts +19 -0
- package/types/constants/enum/lateral-arrangement.enum.d.ts +23 -0
- package/types/constants/enum/money-unit.enum.d.ts +15 -0
- package/types/constants/enum/option-type.enum.d.ts +11 -0
- package/types/constants/enum/submitted-type.enum.d.ts +35 -0
- package/types/constants/enum/support-upload-type.enum.d.ts +11 -0
- package/types/constants/enum/switch.enum.d.ts +11 -0
- package/types/constants/enum/upload-type.enum.d.ts +59 -0
- package/types/constants/enum/validate-rules.enum.d.ts +2 -0
- package/types/constants/enum/validate-status.enum.d.ts +2 -0
- package/types/constants/enum/vertical-arrangement.enum.d.ts +21 -0
- package/types/constants/enum/zoom-type.d.ts +15 -0
- package/types/constants/index.d.ts +3 -0
- package/types/core/FormApi.d.ts +326 -0
- package/types/core/index.d.ts +1 -0
- package/types/domain/AbstractControl.d.ts +5 -0
- package/types/domain/Control.d.ts +13 -0
- package/types/domain/CustomFormat.d.ts +5 -0
- package/types/domain/DesForm.d.ts +32 -0
- package/types/domain/DesFormControl.d.ts +148 -0
- package/types/domain/DesFormLayout.d.ts +33 -0
- package/types/domain/FieldChangeHistory.d.ts +9 -0
- package/types/domain/FormConfig.d.ts +12 -0
- package/types/domain/FormControl.d.ts +60 -0
- package/types/domain/FormEnum.d.ts +10 -0
- package/types/domain/FormGroup.d.ts +27 -0
- package/types/domain/FormRestfulResponse.d.ts +6 -0
- package/types/domain/ProvideInjectData.d.ts +9 -0
- package/types/domain/SysDictDetail.d.ts +16 -0
- package/types/domain/SysDictInfo.d.ts +20 -0
- package/types/domain/SysDictTreeDetail.d.ts +28 -0
- package/types/domain/index.d.ts +12 -0
- package/types/filtres/amount-capitalization.filter.d.ts +7 -0
- package/types/filtres/extract-options.filter.d.ts +13 -0
- package/types/filtres/generate-grid-column-end.filter.d.ts +11 -0
- package/types/filtres/generate-grid-template-columns.filter.d.ts +11 -0
- package/types/filtres/switch-enum-convert.filter.d.ts +2 -0
- package/types/filtres/zoom-multiple.filter.d.ts +3 -0
- package/types/index.d.ts +12 -0
- package/types/main.d.ts +2 -0
- package/types/services/api.service.d.ts +25 -0
- package/types/services/clean-local-forage.service.d.ts +28 -0
- package/types/services/dict-local-forage.service.d.ts +28 -0
- package/types/services/form-bean-utils.service.d.ts +23 -0
- package/types/services/form-local-forage.service.d.ts +28 -0
- package/types/services/form-tools.service.d.ts +109 -0
- package/types/services/form-tree-node-convert.service.d.ts +94 -0
- package/types/services/form-validate.service.d.ts +32 -0
- package/types/services/index.d.ts +9 -0
- package/types/services/router.service.d.ts +40 -0
- package/types/services/validate-generator.service.d.ts +154 -0
- package/types/store/dict.store.d.ts +29 -0
- package/types/store/form.store.d.ts +17 -0
- package/types/store/index.d.ts +2 -0
- package/types/types/vfForm.d.ts +10 -0
- package/vue.config.js +29 -0
|
@@ -0,0 +1,865 @@
|
|
|
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, 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 { formValidateService } from "@/services";
|
|
12
|
+
import { MathJsStatic } from "mathjs";
|
|
13
|
+
import { Vue } from "vue-property-decorator";
|
|
14
|
+
|
|
15
|
+
export type FormatType = "default" | "ebtrust";
|
|
16
|
+
|
|
17
|
+
export enum Attribute {
|
|
18
|
+
IsHideControl = "isHideControl", // 隐藏控件
|
|
19
|
+
IsRequiredValidate = "isRequiredValidate", // 是否必填
|
|
20
|
+
FormFieldDescribe = "formFieldDescribe", // 字段别名
|
|
21
|
+
FieldDefaultValue = "fieldDefaultValue", // 默认值
|
|
22
|
+
TitleWidth = "titleWidth", // 标题宽度
|
|
23
|
+
IsBoldTitle = "isBoldTitle", // 加粗标题
|
|
24
|
+
IsHideTitle = "isHideTitle", // 隐藏标题
|
|
25
|
+
TitleColor = "titleColor", // 标题颜色
|
|
26
|
+
Placeholder = "placeholder", // 预期值的提示信息
|
|
27
|
+
Tips = "tips", // 提示信息
|
|
28
|
+
IsNotEdit = "isNotEdit", // 不可编辑
|
|
29
|
+
BindingPrefix = "bindingPrefix", // 绑定前缀
|
|
30
|
+
BindingSuffix = "bindingSuffix", // 绑定后缀
|
|
31
|
+
BuiltInFrontLabel = "builtInFrontLabel", // 内置前置标签
|
|
32
|
+
BuiltInPostLabel = "builtInPostLabel", // 内置后置标签
|
|
33
|
+
ControlWidth = "controlWidth", // 控件宽度
|
|
34
|
+
IsPasswordBox = "isPasswordBox", // 是否密码框
|
|
35
|
+
InitRowHeight = "initRowHeight", // 初始行高
|
|
36
|
+
IsFixedRowHeight = "isFixedRowHeight", // 是否固定行高
|
|
37
|
+
FormatType = "formatType", // 格式化类型
|
|
38
|
+
MinValue = "minValue", // 最小值
|
|
39
|
+
MaxValue = "maxValue", // 最大值
|
|
40
|
+
Step = "step", // 步长
|
|
41
|
+
DecimalPlaces = "decimalPlaces", // 小数位
|
|
42
|
+
ThousandthPercentileFormat = "thousandthPercentileFormat", // 千分位格式化
|
|
43
|
+
Unit = "unit", // 单位
|
|
44
|
+
ZoomType = "zoomType", // 缩放类型
|
|
45
|
+
ZoomMultiple = "zoomMultiple", // 缩放倍数
|
|
46
|
+
IsShowCapitalization = "isShowCapitalization", // 展示大写
|
|
47
|
+
IsLineFeedDisplay = "isLineFeedDisplay", // 换行显示
|
|
48
|
+
IsOptionType = "isOptionType", // 类型选项
|
|
49
|
+
OptionConfig = "optionConfig", // 自定义字典项
|
|
50
|
+
DateFormat = "dateFormat", // 日期格式
|
|
51
|
+
TimeFormat = "timeFormat", // 时间格式
|
|
52
|
+
IsSupportMultiple = "isSupportMultiple", // 是否支持多选
|
|
53
|
+
MaxUploadNumber = "maxUploadNumber", // 最多上传个数"
|
|
54
|
+
LimitSize = "limitSize", // 上传大小限制
|
|
55
|
+
SupportUploadType = "supportUploadType", // 扩展类型
|
|
56
|
+
CustomUploadType = "customUploadType", // 自定义类型
|
|
57
|
+
ExtendUploadType = "extendUploadType", // 扩展类型
|
|
58
|
+
AttachmentExtendProperties = "attachmentExtendProperties", // 附件扩展属性
|
|
59
|
+
IsMultipleChoice = "isMultipleChoice", // 是否可多选
|
|
60
|
+
IsSearchable = "isSearchable", // 是否可搜索
|
|
61
|
+
CanAddEntry = "canAddEntry", // 是否可新增条目
|
|
62
|
+
IsClearButton = "isClearButton", // 显示清除按钮
|
|
63
|
+
OnOpeningValue = "onOpeningValue", // 打开时的值
|
|
64
|
+
WhenClosedValue = "whenClosedValue", // 关闭时的值
|
|
65
|
+
OnOpeningText = "onOpeningText", // 打开时的文字描述
|
|
66
|
+
WhenClosedText = "whenClosedText", // 关闭时的文字描述
|
|
67
|
+
CustomFieldName = "customFieldName", // 自定义字段名
|
|
68
|
+
TextFold = "textFold", // 文本折叠
|
|
69
|
+
HiddenDropdown = "hiddenDropdown", // 隐藏下拉面板
|
|
70
|
+
BusAttr = "busAttr", // 业务属性
|
|
71
|
+
EnableAutoComplete = "enableAutoComplete", // 开启自动完成功能
|
|
72
|
+
AutoCompleteOptions = "autoCompleteOptions", // 自动完成列表数据
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @description: 表单基础类,聚合常用api
|
|
77
|
+
* @author ChenRui
|
|
78
|
+
* @date 2020/11/28 23:27
|
|
79
|
+
*/
|
|
80
|
+
export class FormApi {
|
|
81
|
+
id?: any; // api编号
|
|
82
|
+
dvForm: Vue | any; // form组件实例
|
|
83
|
+
edit: boolean | undefined; // 编辑状态
|
|
84
|
+
formatType: FormatType; // 数据格式化模式
|
|
85
|
+
momentUtil = moment; // 时间工具包
|
|
86
|
+
apiMetaRefresh: any; // api内部刷新标识
|
|
87
|
+
[key: string]: any; // 任一扩展属性
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @description: 获取表单对象
|
|
91
|
+
* @author ChenRui
|
|
92
|
+
* @date 2020/11/28 23:29
|
|
93
|
+
*/
|
|
94
|
+
constructor(
|
|
95
|
+
options: {
|
|
96
|
+
id?: any;
|
|
97
|
+
dvForm?: Vue;
|
|
98
|
+
edit?: boolean;
|
|
99
|
+
formatType?: FormatType;
|
|
100
|
+
} = {}
|
|
101
|
+
) {
|
|
102
|
+
this.id = options.id || this.getUuid();
|
|
103
|
+
this.dvForm = options.dvForm || new Vue(DvForm);
|
|
104
|
+
this.edit = options.edit;
|
|
105
|
+
this.formatType = options.formatType || "default";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get mathjs(): MathJsStatic {
|
|
109
|
+
if ((window as any).$app.config.globalProperties.$mathjs) {
|
|
110
|
+
return (window as any).$app.config.globalProperties.$mathjs;
|
|
111
|
+
}
|
|
112
|
+
return {} as MathJsStatic;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @description: 获取表单值
|
|
117
|
+
* @author ChenRui
|
|
118
|
+
* @date 2021/2/4 10:36
|
|
119
|
+
*/
|
|
120
|
+
get formData(): any {
|
|
121
|
+
this.apiMetaRefresh = this.dvForm.metaRefresh;
|
|
122
|
+
if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
|
|
123
|
+
return this.generateData(this.dvForm.desForm.formGroup);
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description: 编码表单对象
|
|
130
|
+
* @author ChenRui
|
|
131
|
+
* @date 2021/4/25 16:41
|
|
132
|
+
*/
|
|
133
|
+
get encodedFormData(): any {
|
|
134
|
+
this.apiMetaRefresh = this.dvForm.metaRefresh;
|
|
135
|
+
if (this.dvForm.desForm && this.dvForm.desForm.formGroup) {
|
|
136
|
+
const data = this.generateData(this.dvForm.desForm.formGroup);
|
|
137
|
+
return this.jsonToFormData(data);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @description: 设置表单值
|
|
144
|
+
* @author ChenRui
|
|
145
|
+
* @date 2021/2/4 10:37
|
|
146
|
+
*/
|
|
147
|
+
setFormData(srcData: any, isDefault = false, validate = false): void {
|
|
148
|
+
if (this.dvForm.desForm.formGroup) {
|
|
149
|
+
this.setFormDataInner(srcData, isDefault, validate);
|
|
150
|
+
} else {
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
this.setFormDataInner(srcData, isDefault, validate);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @description: 获取控件对象
|
|
159
|
+
* @author ChenRui
|
|
160
|
+
* @date 2021/1/29 10:08
|
|
161
|
+
*/
|
|
162
|
+
getControl(key: string, control?: AbstractControl, showError = true): AbstractControl | any {
|
|
163
|
+
if (key) {
|
|
164
|
+
if (control == null) {
|
|
165
|
+
if (this.dvForm.desForm.formGroup) {
|
|
166
|
+
control = this.dvForm.desForm.formGroup.controls;
|
|
167
|
+
} else if (showError) {
|
|
168
|
+
console.log("表单对象尚未初始化完成...");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (control && Object.keys(control).length > 0) {
|
|
172
|
+
for (const propName of Object.keys(control)) {
|
|
173
|
+
if (propName === key) {
|
|
174
|
+
return control[propName];
|
|
175
|
+
}
|
|
176
|
+
if (control[propName].controls && Object.keys(control[propName].controls).length > 0) {
|
|
177
|
+
const subControl: AbstractControl = this.getControl(key, control[propName].controls);
|
|
178
|
+
if (subControl != null) {
|
|
179
|
+
return subControl;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @description: 获取值
|
|
190
|
+
* @author ChenRui
|
|
191
|
+
* @date 2021/1/29 14:57
|
|
192
|
+
*/
|
|
193
|
+
getValue(key: string): any {
|
|
194
|
+
const control: AbstractControl = this.getControl(key);
|
|
195
|
+
if (control && control instanceof FormControl) {
|
|
196
|
+
return this.decodeData(control, false);
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @description: 设置值
|
|
203
|
+
* @author ChenRui
|
|
204
|
+
* @date 2021/1/29 16:23
|
|
205
|
+
*/
|
|
206
|
+
setValue(key: string, val: any, isDefault = false, validate = true): void {
|
|
207
|
+
let control: AbstractControl = this.getControl(key);
|
|
208
|
+
if (control == null) {
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
control = this.getControl(key);
|
|
211
|
+
this.setControlValue(control, key, val, isDefault, validate);
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
this.setControlValue(control, key, val, isDefault, validate);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @description: 重置表单
|
|
220
|
+
* @author ChenRui
|
|
221
|
+
* @date 2021/2/22 17:40
|
|
222
|
+
*/
|
|
223
|
+
resetValue(): void {
|
|
224
|
+
this.dvForm.formatDesForm(true);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @description: 获取文本内容
|
|
229
|
+
* @author ChenRui
|
|
230
|
+
* @date 2021/1/29 15:03
|
|
231
|
+
*/
|
|
232
|
+
getText(key: string): any {
|
|
233
|
+
const control: AbstractControl = this.getControl(key);
|
|
234
|
+
if (control && control instanceof FormControl) {
|
|
235
|
+
return control.text();
|
|
236
|
+
}
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @description: 获取可选项
|
|
242
|
+
* @author ChenRui
|
|
243
|
+
* @date 2021/1/29 16:11
|
|
244
|
+
*/
|
|
245
|
+
getOptions(key: string): any[] {
|
|
246
|
+
const control: AbstractControl = this.getControl(key);
|
|
247
|
+
if (control && control instanceof FormControl && control.controlAttr) {
|
|
248
|
+
return extractOptions(control.controlAttr);
|
|
249
|
+
}
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @description: 设置可选项
|
|
255
|
+
* @author ChenRui
|
|
256
|
+
* @date 2021/1/29 16:15
|
|
257
|
+
*/
|
|
258
|
+
setOptions(key: string, data: any[], defaultVal?: any): void {
|
|
259
|
+
let control: AbstractControl = this.getControl(key);
|
|
260
|
+
if (control == null) {
|
|
261
|
+
setTimeout(() => {
|
|
262
|
+
control = this.getControl(key);
|
|
263
|
+
this.setControlOptions(control, key, data, defaultVal);
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
this.setControlOptions(control, key, data, defaultVal);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @description: 获取常规属性
|
|
272
|
+
* @author ChenRui
|
|
273
|
+
* @date 2021/1/29 17:21
|
|
274
|
+
*/
|
|
275
|
+
getAttribute(key: string, attribute: Attribute): any {
|
|
276
|
+
const control: AbstractControl = this.getControl(key);
|
|
277
|
+
if (control && control instanceof FormControl && control.controlAttr) {
|
|
278
|
+
return control.controlAttr[attribute];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @description: 设置常规属性
|
|
283
|
+
* @author ChenRui
|
|
284
|
+
* @date 2021/1/29 17:21
|
|
285
|
+
*/
|
|
286
|
+
setAttribute(key: string, attribute: Attribute, data: any): void {
|
|
287
|
+
let control: AbstractControl = this.getControl(key);
|
|
288
|
+
if (control == null) {
|
|
289
|
+
setTimeout(() => {
|
|
290
|
+
control = this.getControl(key);
|
|
291
|
+
this.setControlAttribute(control, attribute, data);
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
this.setControlAttribute(control, attribute, data);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @description: 根据name获取校验
|
|
300
|
+
* @author ChenRui
|
|
301
|
+
* @date 2021/1/30 11:46
|
|
302
|
+
*/
|
|
303
|
+
getValidate(key: string, name: string): any {
|
|
304
|
+
const control: AbstractControl = this.getControl(key);
|
|
305
|
+
if (control && control instanceof FormControl) {
|
|
306
|
+
return control.getValidate(name);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @description: 移除校验
|
|
312
|
+
* @author ChenRui
|
|
313
|
+
* @date 2021/4/1 21:30
|
|
314
|
+
*/
|
|
315
|
+
removeValidate(key: string, validateName: string): void {
|
|
316
|
+
const control: AbstractControl = this.getControl(key);
|
|
317
|
+
if (control && control instanceof FormControl) {
|
|
318
|
+
const validates: Validate[] = control.validates;
|
|
319
|
+
if (validates && validates.length > 0) {
|
|
320
|
+
const index = validates.findIndex((item) => item.name === validateName);
|
|
321
|
+
if (index !== -1) {
|
|
322
|
+
validates.splice(index, 1);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* @description: 移除所有校验
|
|
330
|
+
* @author ChenRui
|
|
331
|
+
* @date 2021/4/1 21:48
|
|
332
|
+
*/
|
|
333
|
+
removeAllValidates(key: string): void {
|
|
334
|
+
const control: AbstractControl = this.getControl(key);
|
|
335
|
+
if (control && control instanceof FormControl) {
|
|
336
|
+
control.validates = [];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @description: 获取校验集合
|
|
342
|
+
* @author ChenRui
|
|
343
|
+
* @date 2021/1/30 11:40
|
|
344
|
+
*/
|
|
345
|
+
getValidates(key: string): Validate[] {
|
|
346
|
+
const control: AbstractControl = this.getControl(key);
|
|
347
|
+
if (control && control instanceof FormControl) {
|
|
348
|
+
return control.validates;
|
|
349
|
+
}
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @Description: 设置必输校验
|
|
354
|
+
* @author GuoXuHui
|
|
355
|
+
* @date 2022-05-25
|
|
356
|
+
* @time 10:09
|
|
357
|
+
*/
|
|
358
|
+
setRequiredValidate(key: string, data: boolean) {
|
|
359
|
+
if (data) {
|
|
360
|
+
this.setValidate(key, { ruleType: ValidateRules.Required.code });
|
|
361
|
+
} else {
|
|
362
|
+
this.removeValidate(key, ValidateRules.Required.code); // 清除必填校验
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @description: 设置校验
|
|
368
|
+
* @author ChenRui
|
|
369
|
+
* @date 2021/1/30 11:54
|
|
370
|
+
*/
|
|
371
|
+
setValidate(key: string, validate: Validate | Validate[] | Rule, isCover = false): void {
|
|
372
|
+
let control: AbstractControl = this.getControl(key);
|
|
373
|
+
if (control == null) {
|
|
374
|
+
setTimeout(() => {
|
|
375
|
+
control = this.getControl(key);
|
|
376
|
+
if (control && control instanceof FormControl) {
|
|
377
|
+
this.setValidateInner(control, validate, isCover);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
} else {
|
|
381
|
+
this.setValidateInner(control, validate, isCover);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @description: 校验提示
|
|
387
|
+
* @author ChenRui
|
|
388
|
+
* @date 2021/8/18 17:40
|
|
389
|
+
*/
|
|
390
|
+
validateTips(scrollView?: any): boolean {
|
|
391
|
+
return formValidateService.validateTips(this, scrollView);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @description: 全局校验报告
|
|
396
|
+
* @author ChenRui
|
|
397
|
+
* @date 2021/2/5 11:48
|
|
398
|
+
*/
|
|
399
|
+
validateReport(formGroup?: AbstractControl, validateReports?: ValidateReport[], refreshFeedback = true): ValidateReport[] {
|
|
400
|
+
if (validateReports == null) {
|
|
401
|
+
validateReports = [];
|
|
402
|
+
}
|
|
403
|
+
if (formGroup == null) {
|
|
404
|
+
formGroup = this.dvForm.desForm.formGroup;
|
|
405
|
+
if (refreshFeedback) {
|
|
406
|
+
this.dvForm.refreshCheckFeedbackFlag = new Date().getTime();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (formGroup != null) {
|
|
410
|
+
for (const propName of Object.keys(formGroup.controls)) {
|
|
411
|
+
if (formGroup.controls[propName] instanceof FormGroup) {
|
|
412
|
+
this.validateReport(formGroup.controls[propName], validateReports);
|
|
413
|
+
} else if (formGroup.controls[propName] instanceof FormControl && !formGroup.controls[propName].controlAttr.isHideControl) {
|
|
414
|
+
const validateResult: ValidateResult = formGroup.controls[propName].validate();
|
|
415
|
+
if (validateResult.validateStatus === ValidateStatus.Error.code) {
|
|
416
|
+
validateReports.push({
|
|
417
|
+
key: formGroup.controls[propName].key,
|
|
418
|
+
name: formGroup.controls[propName].controlAttr.formFieldDescribe,
|
|
419
|
+
errorMsg: validateResult.errorMsg,
|
|
420
|
+
controlType: formGroup.controls[propName].controlAttr.controlType,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return validateReports;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* @description: 表单全局校验
|
|
431
|
+
* @author ChenRui
|
|
432
|
+
* @date 2021/2/5 14:11
|
|
433
|
+
*/
|
|
434
|
+
validate(refreshFeedback = true): boolean {
|
|
435
|
+
const validateReports: ValidateReport[] = this.validateReport(undefined, undefined, refreshFeedback);
|
|
436
|
+
return !(validateReports.length > 0);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* @description: 刷新校验
|
|
441
|
+
* @author ChenRui
|
|
442
|
+
* @date 2021/6/4 19:32
|
|
443
|
+
*/
|
|
444
|
+
refreshValidate(key: string): void {
|
|
445
|
+
let control: AbstractControl = this.getControl(key);
|
|
446
|
+
if (control == null) {
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
control = this.getControl(key);
|
|
449
|
+
control["refreshValidate"] = new Date().getTime();
|
|
450
|
+
});
|
|
451
|
+
} else {
|
|
452
|
+
control["refreshValidate"] = new Date().getTime();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @description: 重置表单校验
|
|
458
|
+
* @author ChenRui
|
|
459
|
+
* @date 2022/4/6 11:51
|
|
460
|
+
*/
|
|
461
|
+
resetFormValidateState(): void {
|
|
462
|
+
this.dvForm.formValidateStateResetMark = new Date().getTime();
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @description: 设置格式化显示和输出函数
|
|
467
|
+
* @author ChenRui
|
|
468
|
+
* @date 2021/2/4 19:44
|
|
469
|
+
*/
|
|
470
|
+
setFormatDisplayAndOutput(key: string, customFormat: CustomFormat): void {
|
|
471
|
+
if (key) {
|
|
472
|
+
this.dvForm.customFormats[key] = customFormat;
|
|
473
|
+
}
|
|
474
|
+
this.refreshAndUpdateData();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* @description: 刷新数据
|
|
479
|
+
* @author ChenRui
|
|
480
|
+
* @date 2021/2/4 20:22
|
|
481
|
+
*/
|
|
482
|
+
refreshAndUpdateData(): void {
|
|
483
|
+
this.dvForm.onRefreshArgumentsHandler(new Date().getTime());
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @description: 获取控件dom对象
|
|
488
|
+
* @author ChenRui
|
|
489
|
+
* @date 2021/2/26 17:12
|
|
490
|
+
*/
|
|
491
|
+
getControlEl(key: string): any {
|
|
492
|
+
const control: AbstractControl = this.getControl(key);
|
|
493
|
+
if (control != null && control.controlAttr) {
|
|
494
|
+
const els: HTMLCollectionOf<any> = document.getElementsByClassName("form-model-item-" + control.controlAttr.boundProperty);
|
|
495
|
+
if (els != null && els.length > 0) {
|
|
496
|
+
return els[0];
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* @description: 检查是否包含上传控件
|
|
504
|
+
* @author ChenRui
|
|
505
|
+
* @date 2021/4/23 11:30
|
|
506
|
+
*/
|
|
507
|
+
checkHasUploadControl(abstractControl: AbstractControl): boolean {
|
|
508
|
+
if (abstractControl instanceof FormGroup) {
|
|
509
|
+
const formGroup: FormGroup = abstractControl as FormGroup;
|
|
510
|
+
for (const propName of Object.keys(formGroup.controls)) {
|
|
511
|
+
if (formGroup.controls[propName] instanceof FormGroup) {
|
|
512
|
+
const judge = this.checkHasUploadControl(formGroup.controls[propName]);
|
|
513
|
+
if (judge) {
|
|
514
|
+
return judge;
|
|
515
|
+
}
|
|
516
|
+
} else if (formGroup.controls[propName] instanceof FormControl) {
|
|
517
|
+
if (formGroup.controls[propName].code === FormFieldType.Upload.code) {
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* @description: json格式转表单格式
|
|
528
|
+
* @author ChenRui
|
|
529
|
+
* @date 2020/8/28 15:20
|
|
530
|
+
*/
|
|
531
|
+
jsonToFormData(params: any): FormData {
|
|
532
|
+
const formData = new FormData();
|
|
533
|
+
if (params != null) {
|
|
534
|
+
Object.keys(params).forEach((key) => {
|
|
535
|
+
if (params[key] != null && params[key] instanceof Array && params[key].length > 0 && params[key][0] instanceof File) {
|
|
536
|
+
params[key].forEach((item: any) => {
|
|
537
|
+
formData.append(key, item);
|
|
538
|
+
});
|
|
539
|
+
} else {
|
|
540
|
+
formData.append(key, params[key]);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
return formData;
|
|
544
|
+
}
|
|
545
|
+
return formData;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @description: 设置变更历史记录
|
|
550
|
+
* @author ChenRui
|
|
551
|
+
* @date 2021/4/25 15:55
|
|
552
|
+
*/
|
|
553
|
+
setFieldChangeHistory(fieldChangeHistory: FieldChangeHistory): void {
|
|
554
|
+
fieldChangeHistory = fieldChangeHistory || {};
|
|
555
|
+
for (const propertyName of Object.keys(fieldChangeHistory)) {
|
|
556
|
+
let control: AbstractControl = this.getControl(propertyName, undefined, false);
|
|
557
|
+
if (control == null) {
|
|
558
|
+
setTimeout(() => {
|
|
559
|
+
control = this.getControl(propertyName, undefined, false);
|
|
560
|
+
if (control && control instanceof FormControl) {
|
|
561
|
+
const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
|
|
562
|
+
const aTime = new Date(a.time).getTime();
|
|
563
|
+
const bTime = new Date(b.time).getTime();
|
|
564
|
+
return bTime - aTime;
|
|
565
|
+
});
|
|
566
|
+
control.history = history;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
} else {
|
|
570
|
+
control = this.getControl(propertyName, undefined, false);
|
|
571
|
+
if (control && control instanceof FormControl) {
|
|
572
|
+
const history = (fieldChangeHistory[propertyName] || []).sort((a, b) => {
|
|
573
|
+
const aTime = new Date(a.time).getTime();
|
|
574
|
+
const bTime = new Date(b.time).getTime();
|
|
575
|
+
return bTime - aTime;
|
|
576
|
+
});
|
|
577
|
+
control.history = history;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @description: 隐藏布局
|
|
585
|
+
* @author ChenRui
|
|
586
|
+
* @date 2021/11/16 0:01
|
|
587
|
+
*/
|
|
588
|
+
hideLayout(layoutName: string, mark = true): void {
|
|
589
|
+
if (layoutName) {
|
|
590
|
+
const nodes: any = document.getElementsByClassName("lo-form-layout-" + layoutName);
|
|
591
|
+
if (nodes && nodes.length > 0) {
|
|
592
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
593
|
+
nodes[i].style.display = mark ? "none" : "grid";
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* @description: 设置表单值
|
|
601
|
+
* @author ChenRui
|
|
602
|
+
* @date 2021/8/16 9:29
|
|
603
|
+
*/
|
|
604
|
+
private setFormDataInner(srcData: any, isDefault: boolean, validate: boolean): void {
|
|
605
|
+
if (srcData) {
|
|
606
|
+
for (const propName of Object.keys(srcData)) {
|
|
607
|
+
if (typeof srcData[propName] === "string" || typeof srcData[propName] === "number") {
|
|
608
|
+
this.setValue(propName, srcData[propName], isDefault, false);
|
|
609
|
+
} else {
|
|
610
|
+
this.setFormData(srcData[propName], isDefault, validate);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (validate) {
|
|
615
|
+
this.validate();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* @description: 设置控件值
|
|
621
|
+
* @author ChenRui
|
|
622
|
+
* @date 2021/4/13 12:50
|
|
623
|
+
*/
|
|
624
|
+
private setControlValue(control: AbstractControl, key: string, val: any, isDefault?: boolean, validate = true): void {
|
|
625
|
+
if (control && control instanceof FormControl) {
|
|
626
|
+
switch (control.code) {
|
|
627
|
+
case FormFieldType.InputNumber.code:
|
|
628
|
+
if (val && control.controlAttr.zoomMultiple) {
|
|
629
|
+
if (control.controlAttr.zoomType === ZoomType.enlarge.code) {
|
|
630
|
+
val = this.mathjs.format(this.mathjs.evaluate(`${val} / ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
|
|
631
|
+
} else if (control.controlAttr.zoomType === ZoomType.narrow.code) {
|
|
632
|
+
val = this.mathjs.format(this.mathjs.evaluate(`${val} * ${control.controlAttr.zoomMultiple}`), { notation: "fixed" });
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (val != undefined) {
|
|
636
|
+
control.value = val;
|
|
637
|
+
} else {
|
|
638
|
+
control.value = "";
|
|
639
|
+
}
|
|
640
|
+
break;
|
|
641
|
+
case FormFieldType.Select.code:
|
|
642
|
+
if (control.controlAttr.isMultipleChoice) {
|
|
643
|
+
if (!val) {
|
|
644
|
+
val = [];
|
|
645
|
+
} else if (typeof val === "string") {
|
|
646
|
+
val = val.split(",");
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
control.value = val;
|
|
650
|
+
break;
|
|
651
|
+
case FormFieldType.Checkbox.code:
|
|
652
|
+
case FormFieldType.Cascader.code:
|
|
653
|
+
if (val) {
|
|
654
|
+
val = val.split(",");
|
|
655
|
+
} else {
|
|
656
|
+
val = [];
|
|
657
|
+
}
|
|
658
|
+
control.value = val;
|
|
659
|
+
break;
|
|
660
|
+
case FormFieldType.Switch.code:
|
|
661
|
+
if (control.controlAttr.onOpeningValue) {
|
|
662
|
+
val = val === true || val === control.controlAttr.onOpeningValue;
|
|
663
|
+
} else if (control.controlAttr.whenClosedValue) {
|
|
664
|
+
val = !(val === false || val === control.controlAttr.whenClosedValue);
|
|
665
|
+
}
|
|
666
|
+
control.value = val;
|
|
667
|
+
break;
|
|
668
|
+
case FormFieldType.TimePicker.code:
|
|
669
|
+
if (val) {
|
|
670
|
+
if (typeof val === "string") {
|
|
671
|
+
val = this.momentUtil(new Date(this.nowDateStr() + " " + val));
|
|
672
|
+
} else if (val instanceof Date) {
|
|
673
|
+
val = this.momentUtil(val);
|
|
674
|
+
}
|
|
675
|
+
control.value = val;
|
|
676
|
+
} else {
|
|
677
|
+
control.value = null;
|
|
678
|
+
}
|
|
679
|
+
break;
|
|
680
|
+
case FormFieldType.DatePicker.code:
|
|
681
|
+
if (val) {
|
|
682
|
+
if (typeof val === "string") {
|
|
683
|
+
val = this.momentUtil(val, "YYYY-MM-DD");
|
|
684
|
+
} else if (val instanceof Date) {
|
|
685
|
+
val = this.momentUtil(val);
|
|
686
|
+
}
|
|
687
|
+
control.value = val;
|
|
688
|
+
} else {
|
|
689
|
+
control.value = null;
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
default: {
|
|
693
|
+
control.value = val;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
if (isDefault) {
|
|
697
|
+
this.setAttribute(key, Attribute.FieldDefaultValue, JSON.stringify(control.value));
|
|
698
|
+
}
|
|
699
|
+
if (validate) {
|
|
700
|
+
control["refreshValidate"] = new Date().getTime();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* @description: 设置控件可选项
|
|
707
|
+
* @author ChenRui
|
|
708
|
+
* @date 2021/4/13 15:09
|
|
709
|
+
*/
|
|
710
|
+
private setControlOptions(control: AbstractControl, key: string, data: any[], defaultVal?: any): void {
|
|
711
|
+
if (control && control instanceof FormControl && control.controlAttr) {
|
|
712
|
+
storageOptions(control.controlAttr, data);
|
|
713
|
+
this.setAttribute(key, Attribute.IsOptionType, OptionType.Fixed.code);
|
|
714
|
+
this.setAttribute(key, Attribute.OptionConfig, data);
|
|
715
|
+
}
|
|
716
|
+
if (defaultVal) {
|
|
717
|
+
this.setValue(key, defaultVal, true);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* @description: 设置控件常规属性
|
|
723
|
+
* @author ChenRui
|
|
724
|
+
* @date 2021/4/13 15:11
|
|
725
|
+
*/
|
|
726
|
+
private setControlAttribute(control: AbstractControl, attribute: Attribute, data: any): void {
|
|
727
|
+
if (control && control instanceof FormControl && attribute) {
|
|
728
|
+
control.controlAttr[attribute] = data;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @description: 设置校验内部函数
|
|
734
|
+
* @author ChenRui
|
|
735
|
+
* @date 2021/7/19 17:51
|
|
736
|
+
*/
|
|
737
|
+
private setValidateInner(control: AbstractControl, validate: Validate | Validate[] | Rule, isCover = false): void {
|
|
738
|
+
if (validate != null && (validate as Rule).ruleType) {
|
|
739
|
+
validate = validateGeneratorService.getBuiltInValidationRules(validate as Rule, control.controlAttr) as any;
|
|
740
|
+
}
|
|
741
|
+
if (validate != null) {
|
|
742
|
+
if (isCover) {
|
|
743
|
+
control.validates = [];
|
|
744
|
+
}
|
|
745
|
+
control.addValidate(validate);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* @description: 生成数据信息
|
|
751
|
+
* @author ChenRui
|
|
752
|
+
* @date 2021/1/29 10:06
|
|
753
|
+
*/
|
|
754
|
+
private generateData(abstractControl: AbstractControl, obj: any = {}): any {
|
|
755
|
+
if (abstractControl instanceof FormGroup) {
|
|
756
|
+
const formGroup: FormGroup = abstractControl as FormGroup;
|
|
757
|
+
for (const propName of Object.keys(formGroup.controls)) {
|
|
758
|
+
if (formGroup.controls[propName] instanceof FormGroup) {
|
|
759
|
+
obj[propName] = this.generateData(formGroup.controls[propName], obj[propName]);
|
|
760
|
+
} else if (formGroup.controls[propName] instanceof FormControl) {
|
|
761
|
+
obj[propName] = this.decodeData(formGroup.controls[propName] as FormControl);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return obj;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* @description: 数据解码输出
|
|
770
|
+
* @author ChenRui
|
|
771
|
+
* @date 2021/5/29 23:03
|
|
772
|
+
*/
|
|
773
|
+
private decodeData(formControl: FormControl, isFinal = true): any {
|
|
774
|
+
let data = formControl.value || "";
|
|
775
|
+
switch (formControl.code) {
|
|
776
|
+
case FormFieldType.InputNumber.code:
|
|
777
|
+
if (data && formControl.controlAttr.zoomMultiple) {
|
|
778
|
+
if (formControl.controlAttr.zoomType === ZoomType.enlarge.code) {
|
|
779
|
+
data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
|
|
780
|
+
} else if (formControl.controlAttr.zoomType === ZoomType.narrow.code) {
|
|
781
|
+
data = this.mathjs.format(this.mathjs.evaluate(`${data} / ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
|
|
782
|
+
} else if (formControl.controlAttr.zoomType === ZoomType.automatic.code) {
|
|
783
|
+
data = this.mathjs.format(this.mathjs.evaluate(`${data} * ${formControl.controlAttr.zoomMultiple}`), { notation: "fixed" });
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
if (formControl.value === 0) {
|
|
787
|
+
data = 0;
|
|
788
|
+
}
|
|
789
|
+
break;
|
|
790
|
+
case FormFieldType.Select.code:
|
|
791
|
+
if (formControl.controlAttr.isMultipleChoice && data && Array.isArray(data)) {
|
|
792
|
+
data = data.join(",");
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
case FormFieldType.Checkbox.code:
|
|
796
|
+
if (data && isFinal) {
|
|
797
|
+
data = data.join(",");
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
800
|
+
case FormFieldType.TimePicker.code:
|
|
801
|
+
if (data) {
|
|
802
|
+
data = moment(data).format(formControl.controlAttr.timeFormat || "LTS");
|
|
803
|
+
}
|
|
804
|
+
break;
|
|
805
|
+
case FormFieldType.DatePicker.code:
|
|
806
|
+
if (data) {
|
|
807
|
+
data = moment(data).format(formControl.controlAttr.dateFormat || "YYYY-MM-DD");
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
case FormFieldType.Cascader.code:
|
|
811
|
+
if (data) {
|
|
812
|
+
data = data.join(",");
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
case FormFieldType.Switch.code:
|
|
816
|
+
data = !!data;
|
|
817
|
+
if (formControl.controlAttr) {
|
|
818
|
+
if (data === true && formControl.controlAttr.onOpeningValue != undefined && formControl.controlAttr.onOpeningValue !== "") {
|
|
819
|
+
data = formControl.controlAttr.onOpeningValue;
|
|
820
|
+
} else if (data === false && formControl.controlAttr.whenClosedValue != undefined && formControl.controlAttr.whenClosedValue !== "") {
|
|
821
|
+
data = formControl.controlAttr.whenClosedValue;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
break;
|
|
825
|
+
case FormFieldType.Custom.code:
|
|
826
|
+
if (formControl.controlAttr && formControl.controlAttr.customFieldName) {
|
|
827
|
+
const customFormat: CustomFormat = this.dvForm.customFormats[formControl.controlAttr.customFieldName];
|
|
828
|
+
if (customFormat && customFormat.output) {
|
|
829
|
+
data = customFormat.output(data, formControl.controlAttr);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return data;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* @description: 获取当前日期字符串
|
|
838
|
+
* @author ChenRui
|
|
839
|
+
* @date 2021/2/4 11:43
|
|
840
|
+
*/
|
|
841
|
+
private nowDateStr(): string {
|
|
842
|
+
const time = new Date();
|
|
843
|
+
const day = ("0" + time.getDate()).slice(-2);
|
|
844
|
+
const month = ("0" + (time.getMonth() + 1)).slice(-2);
|
|
845
|
+
return time.getFullYear() + "/" + month + "/" + day;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* @description: uuid生成器
|
|
850
|
+
* @author ChenRui
|
|
851
|
+
* @date 2021/7/20 11:14
|
|
852
|
+
*/
|
|
853
|
+
private getUuid(): string {
|
|
854
|
+
const s: any[] = [];
|
|
855
|
+
const hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
856
|
+
for (let i = 0; i < 36; i++) {
|
|
857
|
+
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
858
|
+
}
|
|
859
|
+
s[14] = "4";
|
|
860
|
+
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
|
|
861
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
862
|
+
const uuid = s.join("");
|
|
863
|
+
return uuid;
|
|
864
|
+
}
|
|
865
|
+
}
|