form-driver 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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/m3.css +310 -0
- package/dist/m3.js +1 -0
- package/es/m3.css +310 -0
- package/es/m3.js +20919 -0
- package/lib/m3.css +310 -0
- package/lib/m3.js +20959 -0
- package/package.json +132 -0
- package/src/.DS_Store +0 -0
- package/src/framework/Ajax.ts +96 -0
- package/src/framework/Assembly.tsx +165 -0
- package/src/framework/Init.tsx +196 -0
- package/src/framework/M3.tsx +94 -0
- package/src/framework/MContext.ts +15 -0
- package/src/framework/MFieldViewer.tsx +32 -0
- package/src/framework/MUtil.tsx +653 -0
- package/src/framework/MViewer.less +128 -0
- package/src/framework/MViewer.tsx +180 -0
- package/src/framework/MViewerDebug.tsx +95 -0
- package/src/framework/Persistant.ts +90 -0
- package/src/framework/Schema.ts +386 -0
- package/src/framework/SchemaFunc.ts +30 -0
- package/src/framework/Validator.ts +160 -0
- package/src/framework/editorMap.ts +109 -0
- package/src/index.ts +33 -0
- package/src/types/MArrayType.ts +73 -0
- package/src/types/MCascadeType.ts +35 -0
- package/src/types/MCnAddressType.ts +54 -0
- package/src/types/MDateRangeType.ts +52 -0
- package/src/types/MDateTimeType.ts +53 -0
- package/src/types/MDecorationType.ts +6 -0
- package/src/types/MEnumType.ts +65 -0
- package/src/types/MExperienceType.ts +81 -0
- package/src/types/MFloatType.ts +10 -0
- package/src/types/MGB2260Type.ts +56 -0
- package/src/types/MIntDiffType.ts +6 -0
- package/src/types/MIntType.ts +44 -0
- package/src/types/MKvSetType.ts +50 -0
- package/src/types/MMatrixType.ts +52 -0
- package/src/types/MObjectType.ts +89 -0
- package/src/types/MSetType.ts +220 -0
- package/src/types/MStringType.ts +27 -0
- package/src/types/MTelType.ts +14 -0
- package/src/types/MType.ts +77 -0
- package/src/types/MVLPairType.ts +35 -0
- package/src/types/gb2260.json +1 -0
- package/src/ui/BaseViewer.tsx +110 -0
- package/src/ui/editor/.DS_Store +0 -0
- package/src/ui/editor/basic/.DS_Store +0 -0
- package/src/ui/editor/basic/ACascadePicker.tsx +114 -0
- package/src/ui/editor/basic/ACheckBox.tsx +104 -0
- package/src/ui/editor/basic/ADatetimePicker.tsx +76 -0
- package/src/ui/editor/basic/AGB2260.tsx +52 -0
- package/src/ui/editor/basic/AInputBox.tsx +59 -0
- package/src/ui/editor/basic/AIntBox.tsx +39 -0
- package/src/ui/editor/basic/AKvSet.less +9 -0
- package/src/ui/editor/basic/AKvSet.tsx +90 -0
- package/src/ui/editor/basic/ARadio.tsx +86 -0
- package/src/ui/editor/basic/ARangePicker.tsx +129 -0
- package/src/ui/editor/basic/ARate.less +8 -0
- package/src/ui/editor/basic/ARate.tsx +37 -0
- package/src/ui/editor/basic/ARemoteSelector.tsx +116 -0
- package/src/ui/editor/basic/ASelector.tsx +88 -0
- package/src/ui/editor/basic/ASetSelector.tsx +65 -0
- package/src/ui/editor/basic/ASpecInputBox.tsx +20 -0
- package/src/ui/editor/basic/ATreeSelect.tsx +41 -0
- package/src/ui/editor/basic/AUpload.tsx +119 -0
- package/src/ui/editor/basic/NPS.less +21 -0
- package/src/ui/editor/basic/NPS.tsx +47 -0
- package/src/ui/editor/complex/AArray.less +10 -0
- package/src/ui/editor/complex/AArray.tsx +104 -0
- package/src/ui/editor/complex/AArrayGrid.tsx +115 -0
- package/src/ui/editor/complex/ACnAddress.less +15 -0
- package/src/ui/editor/complex/ACnAddress.tsx +61 -0
- package/src/ui/editor/complex/ADialogForm.tsx +45 -0
- package/src/ui/editor/complex/AExperience.tsx +85 -0
- package/src/ui/editor/complex/AForm.less +35 -0
- package/src/ui/editor/complex/AForm.tsx +340 -0
- package/src/ui/editor/complex/AIntDiff.tsx +77 -0
- package/src/ui/editor/complex/AMatrix.less +18 -0
- package/src/ui/editor/complex/AMatrix.tsx +242 -0
- package/src/ui/editor/complex/ATable.less +4 -0
- package/src/ui/editor/complex/ATable.tsx +33 -0
- package/src/ui/editor/complex/JsonEditor.tsx +37 -0
- package/src/ui/readable/A.tsx +33 -0
- package/src/ui/readable/ArrayViewer.tsx +46 -0
- package/src/ui/readable/DecorationViewer.tsx +76 -0
- package/src/ui/readable/DivViewer.tsx +11 -0
- package/src/ui/widget/Collapsible.tsx +156 -0
- package/src/ui/widget/Segment.less +39 -0
- package/src/ui/widget/Segment.tsx +40 -0
- package/src/ui/widget/SegmentEditSwitch.tsx +46 -0
- package/src/ui/widget/SelectBox.tsx +43 -0
- package/src/ui/widget/UnderlineInputBox.less +47 -0
- package/src/ui/widget/UnderlineInputBox.tsx +10 -0
- package/types/framework/Ajax.d.ts +5 -0
- package/types/framework/Assembly.d.ts +59 -0
- package/types/framework/Init.d.ts +4 -0
- package/types/framework/M3.d.ts +6 -0
- package/types/framework/MContext.d.ts +11 -0
- package/types/framework/MFieldViewer.d.ts +8 -0
- package/types/framework/MUtil.d.ts +180 -0
- package/types/framework/MViewer.d.ts +75 -0
- package/types/framework/MViewerDebug.d.ts +11 -0
- package/types/framework/Persistant.d.ts +17 -0
- package/types/framework/Schema.d.ts +306 -0
- package/types/framework/SchemaFunc.d.ts +14 -0
- package/types/framework/Validator.d.ts +53 -0
- package/types/framework/editorMap.d.ts +107 -0
- package/types/index.d.ts +21 -0
- package/types/types/MArrayType.d.ts +2 -0
- package/types/types/MCascadeType.d.ts +11 -0
- package/types/types/MCnAddressType.d.ts +2 -0
- package/types/types/MDateRangeType.d.ts +7 -0
- package/types/types/MDateTimeType.d.ts +11 -0
- package/types/types/MDecorationType.d.ts +7 -0
- package/types/types/MEnumType.d.ts +2 -0
- package/types/types/MExperienceType.d.ts +5 -0
- package/types/types/MFloatType.d.ts +2 -0
- package/types/types/MGB2260Type.d.ts +9 -0
- package/types/types/MIntDiffType.d.ts +2 -0
- package/types/types/MIntType.d.ts +2 -0
- package/types/types/MKvSetType.d.ts +11 -0
- package/types/types/MMatrixType.d.ts +5 -0
- package/types/types/MObjectType.d.ts +11 -0
- package/types/types/MSetType.d.ts +7 -0
- package/types/types/MStringType.d.ts +2 -0
- package/types/types/MTelType.d.ts +4 -0
- package/types/types/MType.d.ts +46 -0
- package/types/types/MVLPairType.d.ts +5 -0
- package/types/ui/BaseViewer.d.ts +45 -0
- package/types/ui/editor/basic/ACascadePicker.d.ts +11 -0
- package/types/ui/editor/basic/ACheckBox.d.ts +17 -0
- package/types/ui/editor/basic/ADatetimePicker.d.ts +15 -0
- package/types/ui/editor/basic/AGB2260.d.ts +10 -0
- package/types/ui/editor/basic/AInputBox.d.ts +8 -0
- package/types/ui/editor/basic/AIntBox.d.ts +9 -0
- package/types/ui/editor/basic/AKvSet.d.ts +19 -0
- package/types/ui/editor/basic/ARadio.d.ts +14 -0
- package/types/ui/editor/basic/ARangePicker.d.ts +30 -0
- package/types/ui/editor/basic/ARate.d.ts +13 -0
- package/types/ui/editor/basic/ARemoteSelector.d.ts +15 -0
- package/types/ui/editor/basic/ASelector.d.ts +14 -0
- package/types/ui/editor/basic/ASetSelector.d.ts +10 -0
- package/types/ui/editor/basic/ASpecInputBox.d.ts +9 -0
- package/types/ui/editor/basic/ATreeSelect.d.ts +18 -0
- package/types/ui/editor/basic/AUpload.d.ts +33 -0
- package/types/ui/editor/basic/NPS.d.ts +13 -0
- package/types/ui/editor/complex/AArray.d.ts +11 -0
- package/types/ui/editor/complex/AArrayGrid.d.ts +13 -0
- package/types/ui/editor/complex/ACnAddress.d.ts +10 -0
- package/types/ui/editor/complex/ADialogForm.d.ts +11 -0
- package/types/ui/editor/complex/AExperience.d.ts +16 -0
- package/types/ui/editor/complex/AForm.d.ts +46 -0
- package/types/ui/editor/complex/AIntDiff.d.ts +14 -0
- package/types/ui/editor/complex/AMatrix.d.ts +48 -0
- package/types/ui/editor/complex/ATable.d.ts +9 -0
- package/types/ui/editor/complex/JsonEditor.d.ts +9 -0
- package/types/ui/readable/A.d.ts +5 -0
- package/types/ui/readable/ArrayViewer.d.ts +5 -0
- package/types/ui/readable/DecorationViewer.d.ts +3 -0
- package/types/ui/readable/DivViewer.d.ts +5 -0
- package/types/ui/widget/Collapsible.d.ts +46 -0
- package/types/ui/widget/Segment.d.ts +18 -0
- package/types/ui/widget/SegmentEditSwitch.d.ts +20 -0
- package/types/ui/widget/SelectBox.d.ts +13 -0
- package/types/ui/widget/UnderlineInputBox.d.ts +6 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { MORPH, VIEWER, Assembly } from './Assembly';
|
|
2
|
+
|
|
3
|
+
export type ValueConst = string | boolean | number;
|
|
4
|
+
export interface MEnumField {
|
|
5
|
+
// 展示选项时,html > label > value
|
|
6
|
+
|
|
7
|
+
/** 选项文案 */
|
|
8
|
+
label?: string,
|
|
9
|
+
/** 选项html */
|
|
10
|
+
html?: string,
|
|
11
|
+
/** 选项的showIf */
|
|
12
|
+
showIf?: boolean,
|
|
13
|
+
/** 选项html */
|
|
14
|
+
value: ValueConst,
|
|
15
|
+
// 排他选项。
|
|
16
|
+
// 只对多选有效,exclusive不同(exclusive都是undefined的两个选项,也算相同)的两个选项,不能同时选中
|
|
17
|
+
// 应用场景:有些多选中有 "以上都没有" 这类选项,选中时,其他选项都要取消掉
|
|
18
|
+
exclusive?: string,
|
|
19
|
+
// 选项分值
|
|
20
|
+
score?: number,
|
|
21
|
+
|
|
22
|
+
children?: MEnumField[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 匿名的MFieldSchema,没有name字段 */
|
|
26
|
+
export type MFieldSchemaAnonymity = Omit<MFieldSchema, "name">
|
|
27
|
+
|
|
28
|
+
/** JS表达式 */
|
|
29
|
+
export type JSEXPR = string;
|
|
30
|
+
|
|
31
|
+
/** 如何适配屏幕 */
|
|
32
|
+
export type SCREEN_ADAPTION =
|
|
33
|
+
/** 强制使用适应大屏的控件 */
|
|
34
|
+
"big" |
|
|
35
|
+
/** 强制使用适应小屏的控件 */
|
|
36
|
+
"phone"
|
|
37
|
+
|
|
38
|
+
/** M3 单元的 schema */
|
|
39
|
+
export interface MFieldSchema {
|
|
40
|
+
type?: string,
|
|
41
|
+
name: string,
|
|
42
|
+
label?: string,
|
|
43
|
+
|
|
44
|
+
/** 编辑器,editor:<viewer名字> 是 viewerFor: {morph:"editor", name:<viewer名字>} 的简写 */
|
|
45
|
+
editor?: string | VIEWER,
|
|
46
|
+
|
|
47
|
+
/** 查看器,readable:<viewer名字> 是 viewerFor: {morph:"readable", name:<viewer名字>} 的简写 */
|
|
48
|
+
readable?: string | VIEWER,
|
|
49
|
+
|
|
50
|
+
/** 选项 */
|
|
51
|
+
option?: MEnumField[] | string;
|
|
52
|
+
|
|
53
|
+
/** @deprecated 旧版本字段,新版本用 options */
|
|
54
|
+
enumFields?: string | MEnumField[];
|
|
55
|
+
|
|
56
|
+
/** @deprecated 旧版本字段,新版本用 options */
|
|
57
|
+
setFields?: string | MEnumField[];
|
|
58
|
+
|
|
59
|
+
/** 如果选项是不完全的,要设置这个值,允许用户自己输入 */
|
|
60
|
+
openOption?: MFieldSchemaAnonymity;
|
|
61
|
+
|
|
62
|
+
/** @deprecated 旧版本字段,新版本用 openOption */
|
|
63
|
+
enumOpen?: MFieldSchemaAnonymity;
|
|
64
|
+
|
|
65
|
+
/** @deprecated 旧版本字段,新版本用 openOption */
|
|
66
|
+
setOpen?: MFieldSchemaAnonymity;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 默认值
|
|
70
|
+
* object上设置defaultValue后,其字段的defaultValue就无效了
|
|
71
|
+
*/
|
|
72
|
+
defaultValue?: ValueConst,
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 表单控件的属性(对应 antd 组件的 api)
|
|
76
|
+
*/
|
|
77
|
+
props?: any,
|
|
78
|
+
|
|
79
|
+
/** 最多输入多少行,默认1,表示单行字符串 */
|
|
80
|
+
stringLines?: number;
|
|
81
|
+
|
|
82
|
+
/** 最小值/最小长度/至少选几项 (include) */
|
|
83
|
+
min?: number;
|
|
84
|
+
|
|
85
|
+
/** 最大值/最大长度/最多选几项 (include) */
|
|
86
|
+
max?: number;
|
|
87
|
+
|
|
88
|
+
/** 是否是必选项 */
|
|
89
|
+
required?: boolean;
|
|
90
|
+
|
|
91
|
+
/** 当表达式成立时认为表单中有这个字段,不成立时字段不展示,也不会输出数据 */
|
|
92
|
+
showIf?: JSEXPR;
|
|
93
|
+
|
|
94
|
+
/** 分栏数 */
|
|
95
|
+
column?: number;
|
|
96
|
+
|
|
97
|
+
/** 展示前格式化值。
|
|
98
|
+
* string=js模板字符串,可用变量包括:
|
|
99
|
+
* value是数据值
|
|
100
|
+
* _ 是lodash
|
|
101
|
+
* readable是原来默认的toReadable函数转换后的字符串
|
|
102
|
+
* READABLE_UNKNOWN/READABLE_BLANK/READABLE_INVALID/READABLE_ERROR:这些值参考MTheme
|
|
103
|
+
* 函数=就不用解释了,自己可以随意发挥了
|
|
104
|
+
*/
|
|
105
|
+
toReadable?: string | ((v: any, parent: any, assembly: Assembly) => string),
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* true表示值不是严格匹配
|
|
109
|
+
* 例如枚举的value是number时,传入字符串也可以匹配
|
|
110
|
+
*/
|
|
111
|
+
tolerate?: boolean;
|
|
112
|
+
|
|
113
|
+
/** 是否强制使用大屏或者小屏的控件,默认是自动 */
|
|
114
|
+
screenAdaption?: SCREEN_ADAPTION
|
|
115
|
+
|
|
116
|
+
/** 展示时显示的后缀 */
|
|
117
|
+
postfix?: string,
|
|
118
|
+
|
|
119
|
+
/** 会展示为一个问号图标,点击弹出提示 */
|
|
120
|
+
popoverDesc?: React.ReactNode;
|
|
121
|
+
|
|
122
|
+
/** undefined表示 这个字段不是必填的,否则表示此字段不填时的提示信息*/
|
|
123
|
+
requiredMessage?: string;
|
|
124
|
+
|
|
125
|
+
/** 有的字段是多个框,可能需要多个placeholder */
|
|
126
|
+
placeholder?: string | string[];
|
|
127
|
+
|
|
128
|
+
objectFields?: MFieldSchema[];
|
|
129
|
+
/** 对象类型中,哪些字段作为标题展示成readable,默认是第一个字段 */
|
|
130
|
+
objectLabelFields?: string[];
|
|
131
|
+
|
|
132
|
+
/** 字符串是不是允许全部填空格/t/n,默认不允许 */
|
|
133
|
+
stringAllowSpaceOnly?: boolean;
|
|
134
|
+
|
|
135
|
+
/** 矩阵类型的配置 */
|
|
136
|
+
matrix?: {
|
|
137
|
+
/** 矩阵的横轴选项 */
|
|
138
|
+
x: string | MEnumField[];
|
|
139
|
+
|
|
140
|
+
/** 矩阵的纵轴选项 */
|
|
141
|
+
y: string | MEnumField[];
|
|
142
|
+
|
|
143
|
+
/** 每行最多选几个,默认1 */
|
|
144
|
+
maxX?: number,
|
|
145
|
+
|
|
146
|
+
/** 每行最少选几个,默认1 */
|
|
147
|
+
minX?: number,
|
|
148
|
+
|
|
149
|
+
/** 每列最多选几个,默认无限多个 */
|
|
150
|
+
maxY?: number,
|
|
151
|
+
|
|
152
|
+
/** 每列最少选几个,默认1 */
|
|
153
|
+
minY?: number,
|
|
154
|
+
|
|
155
|
+
/** 开放项的配置,开放项是y轴最后一个选项 */
|
|
156
|
+
open?: {
|
|
157
|
+
label: string
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** 数组成员类型 */
|
|
162
|
+
arrayMember?: MFieldSchemaAnonymity;
|
|
163
|
+
|
|
164
|
+
/** 数组增加一项的按钮文案 */
|
|
165
|
+
arrayAddLabel?: string;
|
|
166
|
+
|
|
167
|
+
/** experience类型配置 */
|
|
168
|
+
experience?: {
|
|
169
|
+
/** 除了起始时间,至今选项外,还要有什么字段 */
|
|
170
|
+
members: MFieldSchema[];
|
|
171
|
+
/** 允许时间段重叠,默认是不能重叠 */
|
|
172
|
+
overlap?: boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** dateRange 类型配置 */
|
|
176
|
+
dateRange?: {
|
|
177
|
+
/** 是否隐藏至今按钮 */
|
|
178
|
+
hideTillNow?: boolean;
|
|
179
|
+
/** 是否能选择时间 */
|
|
180
|
+
showTime?: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 数据格式 */
|
|
184
|
+
dataFormat?:
|
|
185
|
+
"x" | "YYYYMMDD" | /** 用于时间日期类型字段的数据格式,参考moment,例如x表示数据是时间戳,YYYYMMDD表示数据是形如19990130的字符串 */
|
|
186
|
+
string;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 例如:
|
|
190
|
+
* 4.5 与去年同期(2019 年 1 月初-6 月底)相比,您的收入
|
|
191
|
+
* (1)增长了约___万元 (2)下降了约___万元 (3)基本没有变化
|
|
192
|
+
*/
|
|
193
|
+
intDiff?: {
|
|
194
|
+
incLabel: string; // 增长了约
|
|
195
|
+
incLabelPostfix: string; // 万元
|
|
196
|
+
decLabel: string; // 下降了约
|
|
197
|
+
decLabelPostfix: string; // 万元
|
|
198
|
+
keep: string; // 基本没有变化
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/** 可以自己写个样式,会作用于antd元素上 */
|
|
202
|
+
css?: any;
|
|
203
|
+
|
|
204
|
+
/** 删除这个字段数据时的提示,不写会直接删除,不提示 */
|
|
205
|
+
removeConfirm?: string;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* most case size 字段通常有多少个字符(string)/项(array),或者用css写长度
|
|
209
|
+
* 布局器会尽量让小于mcs的值可以不需要滚动就展示出来
|
|
210
|
+
* string/ 最好配上
|
|
211
|
+
* 不完全enum/不完全set,可以配,默认是最长的候选值的字符数
|
|
212
|
+
* 完全enum/完全set,不用配
|
|
213
|
+
*/
|
|
214
|
+
mcs?: number | string;
|
|
215
|
+
|
|
216
|
+
/** ui规约 */
|
|
217
|
+
uispec?: M3UISpec;
|
|
218
|
+
|
|
219
|
+
/** 用于hpOrg类型*/
|
|
220
|
+
hpOrg?: {
|
|
221
|
+
/** 空格表示根 */
|
|
222
|
+
rootId: string
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
ossFile?: {
|
|
226
|
+
type: "HP_GO" | "HP_SECOBJ",
|
|
227
|
+
/** 预览大小,单位像素 */
|
|
228
|
+
previewSize?: number,
|
|
229
|
+
arguments:
|
|
230
|
+
{ genName: boolean, ossKeyPath: string, permissionPolicyOr: string } // HPHOM_SECOBJ的参数,也就是/academy/oss/secObject的参数
|
|
231
|
+
| { appName: string } // HPHOM_GO的参数,也就是/academy/go/upload的参数
|
|
232
|
+
| any;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 装饰物的html */
|
|
236
|
+
decoration?: {
|
|
237
|
+
subType?: "rich" | "segmentLabel" | "submitBar" | "operations", // 子类型
|
|
238
|
+
HTML?: string, // html片段
|
|
239
|
+
submitLabel?: string, // 提交按钮
|
|
240
|
+
segmentLabel?: string, // 分段标题
|
|
241
|
+
operations?: { label: React.ReactNode, handler: (data) => void }[] // 操作
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 来自远程的数据,用于下拉搜索框.
|
|
246
|
+
* 例如对于如下远程数据
|
|
247
|
+
* {
|
|
248
|
+
"data": {
|
|
249
|
+
"pagination": {
|
|
250
|
+
...
|
|
251
|
+
},
|
|
252
|
+
"list": [
|
|
253
|
+
{ "id": 33219, "name": "张媛", "brief": "掌阅科技股份有限公司" },
|
|
254
|
+
{ "id": 86576, "name": "张步镇", "brief": "广州速道信息科技有限公司" }
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
remote配置示例:
|
|
259
|
+
remote:{
|
|
260
|
+
url: ... ,
|
|
261
|
+
dataPath: "data.list",
|
|
262
|
+
valuePath: "id",
|
|
263
|
+
labelExpr: "name + '(' + brief + ')'"
|
|
264
|
+
}
|
|
265
|
+
*/
|
|
266
|
+
remote?: {
|
|
267
|
+
/** 数据url,可以用${q}引用用户输入的查询关键字 */
|
|
268
|
+
url: string,
|
|
269
|
+
/** url返回的json中,数据list的路径 */
|
|
270
|
+
dataPath: string,
|
|
271
|
+
|
|
272
|
+
/** 在dataPath下,值字段路径 */
|
|
273
|
+
valuePath: JSEXPR,
|
|
274
|
+
|
|
275
|
+
/** 在dataPath下,标题字段的表达式 */
|
|
276
|
+
labelExpr: JSEXPR,
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
a?: {
|
|
280
|
+
urlExpr?: ((value: any, parent: any) => React.ReactNode) | JSEXPR;
|
|
281
|
+
labelExpr?: ((value: any, parent: any) => React.ReactNode) | JSEXPR;
|
|
282
|
+
onClick?: (value: any, parent: any) => void;
|
|
283
|
+
/** 在当前页面打开 */
|
|
284
|
+
currentPage?: boolean;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** 元素的style */
|
|
288
|
+
style?: React.CSSProperties
|
|
289
|
+
|
|
290
|
+
/** 布局方式,垂直(vertical)、水平(horizontal) */
|
|
291
|
+
layoutHint?: "v" | "h";
|
|
292
|
+
|
|
293
|
+
/** 其他插件的配置 */
|
|
294
|
+
options?: any;
|
|
295
|
+
|
|
296
|
+
/** 业务数据 */
|
|
297
|
+
bizData?: any;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 数据变化时回调
|
|
302
|
+
* final=true表示回调是因为类似失去焦点导致的,此后不会再有变化回调
|
|
303
|
+
* final=false表示回调是因为用户操作导致的,不处理的话也不会导致最终数据不一致,因为后续会有final=true的回调。
|
|
304
|
+
* 对于暂存表单等比较重的操作,应该仅在final=true时触发,以减少调用次数
|
|
305
|
+
*/
|
|
306
|
+
export type AFTER_CHANGE_CALLBACK = (path: string, v: any, final: boolean) => void;
|
|
307
|
+
|
|
308
|
+
export interface MProp {
|
|
309
|
+
/** database的数据描述 */
|
|
310
|
+
schema: MFieldSchemaAnonymity,
|
|
311
|
+
|
|
312
|
+
/** json格式数据 */
|
|
313
|
+
database: any,
|
|
314
|
+
|
|
315
|
+
/** 编辑database中的字段路径 */
|
|
316
|
+
path: string,
|
|
317
|
+
|
|
318
|
+
/** 元素形态 */
|
|
319
|
+
morph: MORPH;
|
|
320
|
+
|
|
321
|
+
/** database有任何变化时回调 */
|
|
322
|
+
afterChange?: AFTER_CHANGE_CALLBACK,
|
|
323
|
+
|
|
324
|
+
/** @deprecated 直接上层。有时parent是谁,会影响渲染字段 */
|
|
325
|
+
parent?: MFieldSchemaAnonymity,
|
|
326
|
+
|
|
327
|
+
/** 强制展示校验信息 */
|
|
328
|
+
forceValid?: boolean,
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 要求元素展示删除按钮
|
|
332
|
+
* true=父元素是array(或object),要求子元素展示删除按钮
|
|
333
|
+
* false=父元素是array(或object),子元素可以展示删除按钮,但disable
|
|
334
|
+
* undefined=子元素不能展示删除按钮
|
|
335
|
+
*/
|
|
336
|
+
removeButton?: boolean,
|
|
337
|
+
|
|
338
|
+
/** 禁用元素 */
|
|
339
|
+
disable?: boolean,
|
|
340
|
+
|
|
341
|
+
/** 是否隐藏边框,例如在表格中就不需要边框 */
|
|
342
|
+
hideBorder?: boolean,
|
|
343
|
+
|
|
344
|
+
/** 额外的控件,比如AArrayGrid里加个按钮 */
|
|
345
|
+
extra?: JSX.Element;
|
|
346
|
+
|
|
347
|
+
// 以下都是向下传递到html元素的
|
|
348
|
+
style?: React.CSSProperties,
|
|
349
|
+
className?: string
|
|
350
|
+
}
|
|
351
|
+
export interface M3UISpecSegmentItem {
|
|
352
|
+
label: string,
|
|
353
|
+
fields: string[],
|
|
354
|
+
showIf?: string,
|
|
355
|
+
name?: string,
|
|
356
|
+
|
|
357
|
+
/** 如果要支持分段编辑提交,要设置此回调 */
|
|
358
|
+
onSubmit?: (segment: M3UISpecSegmentItem, segmentData: any, done: () => void) => void;
|
|
359
|
+
|
|
360
|
+
/** 设置分段根元素的style */
|
|
361
|
+
style?: React.CSSProperties,
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export interface M3UISpec {
|
|
365
|
+
type: "segmentForm" | "stepForm" | "flowForm",
|
|
366
|
+
layout: "horizontal" | "vertical",
|
|
367
|
+
comma?: string,
|
|
368
|
+
labelAlign?: "left" | "right"
|
|
369
|
+
segments?: M3UISpecSegmentItem[];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface MValidationFail {
|
|
373
|
+
/** 错误信息,空字符串表示因为子元素错误导致的,因为子元素已经展示错误了,父元素就不需要再展示了 */
|
|
374
|
+
message: string;
|
|
375
|
+
|
|
376
|
+
/** 数据的路径 */
|
|
377
|
+
path: string;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 校验结果
|
|
382
|
+
* MValidationFail: 校验直接失败,不再经过下一个校验器
|
|
383
|
+
* pass: 直接通过校验,不再经过下一个校验器了(例如 required=false时,数值是nil, 可以直接pass,否则之后的校验器都要处理nil)
|
|
384
|
+
* undefined: 表示让下一个校验器再校验
|
|
385
|
+
*/
|
|
386
|
+
export type MValidationResult = MValidationFail | "pass" | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { ValueConst } from './Schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* schema里可以使用的函数都定义在这里
|
|
6
|
+
*/
|
|
7
|
+
export const SchemaFunc = {
|
|
8
|
+
/**
|
|
9
|
+
* 是否选中shouldSelected中的某个选项.
|
|
10
|
+
*
|
|
11
|
+
* @param v 适用于enum/set/string/int
|
|
12
|
+
* @param shouldSelected 选中值
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
is(v:any|any[], shouldSelected:ValueConst | ValueConst[]) {
|
|
16
|
+
if(_.isArray(v)) {
|
|
17
|
+
if(_.isArray(shouldSelected)) {
|
|
18
|
+
return _.intersection(v, shouldSelected).length > 0
|
|
19
|
+
} else {
|
|
20
|
+
return _.indexOf(v, shouldSelected) >= 0
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
if(_.isArray(shouldSelected)) {
|
|
24
|
+
return _.indexOf(shouldSelected, v) >= 0
|
|
25
|
+
} else {
|
|
26
|
+
return v === shouldSelected
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { Assembly, assembly } from './Assembly';
|
|
3
|
+
import { MFieldSchemaAnonymity, MValidationResult} from './Schema';
|
|
4
|
+
|
|
5
|
+
export type VALIDATOR = (a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string)=> MValidationResult;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 非空校验,数据不能是null/undefined/""/NaN/[]
|
|
9
|
+
* 要在其他条件之前,以便required=false时短路掉nil的数据,否则后面的校验全都得处理nil
|
|
10
|
+
* @param a
|
|
11
|
+
* @param schema
|
|
12
|
+
* @param value
|
|
13
|
+
* @param path
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export function validateRequired(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
17
|
+
if(schema.required){
|
|
18
|
+
if(_.isNil(value) || value === "" || _.isNaN(value) || (_.isArray(value) && value.length == 0)) {
|
|
19
|
+
return {message:'您还没有填完这一项', path};
|
|
20
|
+
}
|
|
21
|
+
// 凡是总有例外
|
|
22
|
+
if(schema.type === "set" && schema.openOption) {
|
|
23
|
+
if(value.length === 1 && !value[0]){
|
|
24
|
+
return {message:'您还没有填完这一项', path}; // 开放set,只勾了开放选项,没有填内容,也要算空
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
if(_.isNil(value)) {
|
|
29
|
+
return "pass";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 和validateRequired相同,但不短路 */
|
|
36
|
+
export function validateRequiredNS(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
37
|
+
const v = validateRequired(a, schema, value, path);
|
|
38
|
+
if(v === "pass"){
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function validateDateMinMax(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
44
|
+
if(schema.min){
|
|
45
|
+
if(!value || value < schema.min) {
|
|
46
|
+
return {message: `请选择${schema.min}之后的时间`, path};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if(schema.max){
|
|
50
|
+
if(!value || value > schema.max) {
|
|
51
|
+
return {message: `请选择${schema.min}之前的时间`, path};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 数组项数不超过[min, max]
|
|
59
|
+
* @param schema
|
|
60
|
+
* @param value 应该是个数组
|
|
61
|
+
*/
|
|
62
|
+
export function validateArrayItemMinMax(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
63
|
+
if(schema.min){
|
|
64
|
+
if(!value || value.length < schema.min) {
|
|
65
|
+
return {message: `至少选择${schema.min}项`, path};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if(schema.max){
|
|
69
|
+
if(!value || value.length > schema.max) {
|
|
70
|
+
return {message: `最多选择${schema.max}项`, path};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 字符串长度不超过[min, max]
|
|
78
|
+
* @param schema
|
|
79
|
+
* @param value 应该是个字符串
|
|
80
|
+
*/
|
|
81
|
+
export function validateStringMinMax(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
82
|
+
if(schema.min){
|
|
83
|
+
if(!value || value.length < schema.min) {
|
|
84
|
+
return {message: `至少${schema.min}个字`, path};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if(schema.max){
|
|
88
|
+
if(value && value.length > schema.max) {
|
|
89
|
+
return {message: `最多${schema.max}个字`, path};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 数字不超过[min, max]
|
|
97
|
+
* @param schema
|
|
98
|
+
* @param value 应该是个数字
|
|
99
|
+
*/
|
|
100
|
+
export function validateNumberMinMax(a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
101
|
+
const temp = Number(value)
|
|
102
|
+
if(!_.isNil(schema.max)){
|
|
103
|
+
if(!_.isFinite(temp) || temp > schema.max) {
|
|
104
|
+
return {message: `最多${schema.max}`, path};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if(!_.isNil(schema.min)){
|
|
108
|
+
if(!_.isFinite(temp) || temp < schema.min) {
|
|
109
|
+
return {message: `最少${schema.min}`, path};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function generateRegexValidate(regex:RegExp, mismatchMsg:string):VALIDATOR {
|
|
116
|
+
return function (a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
117
|
+
const asstr = _.toString(value);
|
|
118
|
+
if( !regex.test(asstr) ){
|
|
119
|
+
return {message: mismatchMsg, path};
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 数据用Object.prototype.toString.call返回的类型是预期的
|
|
127
|
+
* 可以用Object.prototype.toString.call(<预期的类型>)来查看你想要的数据类型的expectType
|
|
128
|
+
* @param expectType 预期类型,例如:"[object Object]" "[object Null]" "[object Number]" "[object Date]" "[object Array]"
|
|
129
|
+
* @param mismatchMsg 如果不匹配,提示的错误信息
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
export function generateJsPrototypeValidate(expectType:string, mismatchMsg:string = "数据有误,请重填此项"):VALIDATOR {
|
|
133
|
+
return function (a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
134
|
+
if(Object.prototype.toString.call(value) == expectType){
|
|
135
|
+
return undefined
|
|
136
|
+
} else {
|
|
137
|
+
return {message: mismatchMsg, path};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function generateSchemaValidate(valueSchema:MFieldSchemaAnonymity, mismatchMsg?:string):VALIDATOR {
|
|
143
|
+
return function (a:Assembly, schema:MFieldSchemaAnonymity, value:any, path:string): MValidationResult {
|
|
144
|
+
const r = assembly.validate(valueSchema,value, "");
|
|
145
|
+
if(!r){
|
|
146
|
+
return r;
|
|
147
|
+
} else {
|
|
148
|
+
return {message: mismatchMsg ?? r.message, path};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default {
|
|
154
|
+
validateRequired,
|
|
155
|
+
validateRequiredNS,
|
|
156
|
+
validateDateMinMax,
|
|
157
|
+
validateStringMinMax,
|
|
158
|
+
validateNumberMinMax,
|
|
159
|
+
generateRegexValidate
|
|
160
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// 所有表单控件(type + editor)的枚举
|
|
2
|
+
const editorMap = {
|
|
3
|
+
AInputBox: {
|
|
4
|
+
editor: "AInputBox",
|
|
5
|
+
type: "string",
|
|
6
|
+
},
|
|
7
|
+
ARate: {
|
|
8
|
+
editor: "ARate",
|
|
9
|
+
type: "int",
|
|
10
|
+
},
|
|
11
|
+
NPS: {
|
|
12
|
+
editor: "NPS",
|
|
13
|
+
type: "int",
|
|
14
|
+
},
|
|
15
|
+
AIntBox: {
|
|
16
|
+
editor: "AIntBox",
|
|
17
|
+
type: "int",
|
|
18
|
+
},
|
|
19
|
+
AFloatBox: {
|
|
20
|
+
editor: "AIntBox",
|
|
21
|
+
type: "float",
|
|
22
|
+
},
|
|
23
|
+
ARadio: {
|
|
24
|
+
editor: 'ARadio',
|
|
25
|
+
type: 'enum',
|
|
26
|
+
},
|
|
27
|
+
ASelector: {
|
|
28
|
+
editor: 'ASelector',
|
|
29
|
+
type: 'enum',
|
|
30
|
+
},
|
|
31
|
+
ASetSelector: {
|
|
32
|
+
editor: 'ASetSelector',
|
|
33
|
+
type: 'array',
|
|
34
|
+
},
|
|
35
|
+
ARemoteSelector: {
|
|
36
|
+
editor: 'ARemoteSelector',
|
|
37
|
+
type: 'array',
|
|
38
|
+
},
|
|
39
|
+
AArrayGrid: {
|
|
40
|
+
editor: 'AArrayGrid',
|
|
41
|
+
type: 'array',
|
|
42
|
+
},
|
|
43
|
+
ACascadePicker: {
|
|
44
|
+
editor: 'ACascadePicker',
|
|
45
|
+
type: 'cascade',
|
|
46
|
+
},
|
|
47
|
+
AGB2260: {
|
|
48
|
+
editor: 'AGB2260',
|
|
49
|
+
type: 'gb2260',
|
|
50
|
+
},
|
|
51
|
+
ARangePicker: {
|
|
52
|
+
editor: 'ARangePicker',
|
|
53
|
+
type: 'dateRange',
|
|
54
|
+
},
|
|
55
|
+
ADatetimePicker: {
|
|
56
|
+
editor: 'ADatetimePicker',
|
|
57
|
+
type: 'datetime',
|
|
58
|
+
},
|
|
59
|
+
AYearPicker: {
|
|
60
|
+
editor: 'ADatetimePicker',
|
|
61
|
+
type: 'year',
|
|
62
|
+
},
|
|
63
|
+
AYearMonthPicker: {
|
|
64
|
+
editor: 'ADatetimePicker',
|
|
65
|
+
type: 'yearMonth',
|
|
66
|
+
},
|
|
67
|
+
AYearMonthDayPicker: {
|
|
68
|
+
editor: 'ADatetimePicker',
|
|
69
|
+
type: 'yearMonthDay',
|
|
70
|
+
},
|
|
71
|
+
ACheckBox: {
|
|
72
|
+
editor: "ACheckBox",
|
|
73
|
+
type: "set",
|
|
74
|
+
},
|
|
75
|
+
AArray: {
|
|
76
|
+
editor: "AArray",
|
|
77
|
+
type: 'array',
|
|
78
|
+
},
|
|
79
|
+
AMatrix: {
|
|
80
|
+
editor: "AMatrix",
|
|
81
|
+
type: "matrix",
|
|
82
|
+
},
|
|
83
|
+
AExperience: {
|
|
84
|
+
editor: "AExperience",
|
|
85
|
+
type: "experience",
|
|
86
|
+
},
|
|
87
|
+
AKvSet: {
|
|
88
|
+
editor: "AKvSet",
|
|
89
|
+
type: "kvSet",
|
|
90
|
+
},
|
|
91
|
+
ACnAddress: {
|
|
92
|
+
editor: "ACnAddress",
|
|
93
|
+
type: "cnAddress",
|
|
94
|
+
},
|
|
95
|
+
ATelBox: {
|
|
96
|
+
editor: 'ASpecInputBox',
|
|
97
|
+
type: 'tel',
|
|
98
|
+
},
|
|
99
|
+
AEmailBox: {
|
|
100
|
+
editor: 'ASpecInputBox',
|
|
101
|
+
type: 'email',
|
|
102
|
+
},
|
|
103
|
+
DecorationViewer: {
|
|
104
|
+
editor: 'DecorationViewer',
|
|
105
|
+
type: 'decoration',
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default editorMap
|