@wibetter/json-utils 1.3.2 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.esm.js +189 -334
- package/dist/index.esm.min.js +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +7 -0
- package/package.json +9 -30
- package/dist/index.umd.js +0 -8
package/dist/index.esm.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import { cloneDeep, isEqual as isEqual$1 } from 'lodash';
|
|
2
|
+
|
|
1
3
|
/** js对象数据深拷贝,避免数据联动 */
|
|
2
4
|
function objClone(targetObj) {
|
|
3
|
-
|
|
4
|
-
return JSON.parse(newObj);
|
|
5
|
+
// const newObj = JSON.stringify(targetObj);
|
|
6
|
+
// return JSON.parse(newObj);
|
|
7
|
+
return cloneDeep(targetObj);
|
|
5
8
|
}
|
|
6
|
-
/** 对比两个json数据是否相等 */
|
|
7
9
|
|
|
10
|
+
/** 对比两个json数据是否相等 */
|
|
8
11
|
function isEqual(targetObj, nextTargetObj) {
|
|
9
|
-
return JSON.stringify(targetObj) === JSON.stringify(nextTargetObj);
|
|
12
|
+
// return JSON.stringify(targetObj) === JSON.stringify(nextTargetObj);
|
|
13
|
+
return isEqual$1(targetObj, nextTargetObj);
|
|
10
14
|
}
|
|
15
|
+
|
|
11
16
|
/** 判断当前属性是否存在
|
|
12
17
|
* 备注:要识别boolean类型的数值 */
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// targetPropertie 等于""、0、false时均认为是存在的属性
|
|
19
|
-
exitPropertie = true;
|
|
18
|
+
function hasProperties(targetProperties) {
|
|
19
|
+
var hasProperties = false;
|
|
20
|
+
if (targetProperties !== undefined && targetProperties !== null) {
|
|
21
|
+
// targetProperties 等于""、0、false时均认为是存在的属性
|
|
22
|
+
hasProperties = true;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
return exitPropertie;
|
|
24
|
+
return hasProperties;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -29,21 +31,16 @@ function exitPropertie(targetPropertie) {
|
|
|
29
31
|
* targetJsonDataObj: json数据对象
|
|
30
32
|
* useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
|
|
31
33
|
*/
|
|
32
|
-
|
|
33
34
|
function getJsonDataByKeyRoute(keyRoute, targetJsonDataObj, useObjClone) {
|
|
34
35
|
var curJsonDataObj = targetJsonDataObj;
|
|
35
|
-
|
|
36
36
|
if (useObjClone) {
|
|
37
37
|
curJsonDataObj = objClone(targetJsonDataObj); // 进行深拷贝,避免影响原有数据
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
if (keyRoute) {
|
|
41
40
|
var keyRouteArr = keyRoute.split('-');
|
|
42
|
-
|
|
43
41
|
for (var index = 0, size = keyRouteArr.length; index < size; index++) {
|
|
44
42
|
// 1、获取当前的jsonKey值
|
|
45
43
|
var curKey = keyRouteArr[index];
|
|
46
|
-
|
|
47
44
|
if (curKey) {
|
|
48
45
|
// 只有curKey不为空的时候才进行赋值
|
|
49
46
|
// 2、根据key值获取对应的数据对象
|
|
@@ -51,7 +48,6 @@ function getJsonDataByKeyRoute(keyRoute, targetJsonDataObj, useObjClone) {
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
|
|
55
51
|
return curJsonDataObj;
|
|
56
52
|
}
|
|
57
53
|
|
|
@@ -62,40 +58,33 @@ function getJsonDataByKeyRoute(keyRoute, targetJsonDataObj, useObjClone) {
|
|
|
62
58
|
* targetJsonSchemaObj: schema数据对象
|
|
63
59
|
* useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
|
|
64
60
|
*/
|
|
65
|
-
|
|
66
61
|
function getSchemaByIndexRoute(indexRoute, targetJsonSchemaObj, useObjClone) {
|
|
67
62
|
var curJsonSchemaObj = targetJsonSchemaObj;
|
|
68
|
-
|
|
69
63
|
if (useObjClone) {
|
|
70
64
|
curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
if (indexRoute) {
|
|
74
67
|
var indexRouteArr = indexRoute.split('-');
|
|
75
|
-
|
|
76
68
|
for (var index = 0, size = indexRouteArr.length; index < size; index++) {
|
|
77
69
|
// 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
|
|
78
70
|
var curIndex = indexRouteArr[index];
|
|
79
|
-
|
|
80
71
|
if (curIndex === '0' && (curJsonSchemaObj.format === 'array' || curJsonSchemaObj.format === 'radio' || curJsonSchemaObj.format === 'single-select' || curJsonSchemaObj.format === 'select') && curJsonSchemaObj.items) {
|
|
81
72
|
// 从items中获取数据
|
|
82
73
|
curJsonSchemaObj = curJsonSchemaObj.items;
|
|
83
74
|
} else if (curIndex) {
|
|
84
|
-
var curKeyTemp = '0';
|
|
85
|
-
|
|
75
|
+
var curKeyTemp = '0';
|
|
76
|
+
// 1、先根据路径值获取key值
|
|
86
77
|
if (curJsonSchemaObj.propertyOrder) {
|
|
87
78
|
curKeyTemp = curJsonSchemaObj.propertyOrder[curIndex];
|
|
88
79
|
} else if (curJsonSchemaObj.properties) {
|
|
89
80
|
var propertyOrder = Object.keys(curJsonSchemaObj.properties);
|
|
90
81
|
curKeyTemp = propertyOrder[curIndex];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
}
|
|
83
|
+
// 2、根据key值获取对应的json数据对象
|
|
94
84
|
curJsonSchemaObj = curJsonSchemaObj.properties[curKeyTemp];
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
87
|
}
|
|
98
|
-
|
|
99
88
|
return curJsonSchemaObj;
|
|
100
89
|
}
|
|
101
90
|
|
|
@@ -106,28 +95,22 @@ function getSchemaByIndexRoute(indexRoute, targetJsonSchemaObj, useObjClone) {
|
|
|
106
95
|
* targetJsonSchemaObj: schema数据对象
|
|
107
96
|
* useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
|
|
108
97
|
*/
|
|
109
|
-
|
|
110
98
|
function getSchemaByKeyRoute(keyRoute, targetJsonSchemaObj, useObjClone) {
|
|
111
99
|
var curJsonSchemaObj = targetJsonSchemaObj;
|
|
112
|
-
|
|
113
100
|
if (useObjClone) {
|
|
114
101
|
curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
|
|
115
102
|
}
|
|
116
|
-
|
|
117
103
|
if (keyRoute && curJsonSchemaObj) {
|
|
118
104
|
var keyRouteArr = keyRoute.split('-');
|
|
119
|
-
|
|
120
105
|
for (var index = 0, size = keyRouteArr.length; index < size; index++) {
|
|
121
106
|
// 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
|
|
122
107
|
var curKey = keyRouteArr[index];
|
|
123
|
-
|
|
124
108
|
if (curKey && curJsonSchemaObj.properties) {
|
|
125
109
|
// 根据key值获取对应的json数据对象
|
|
126
110
|
curJsonSchemaObj = curJsonSchemaObj.properties[curKey];
|
|
127
111
|
}
|
|
128
112
|
}
|
|
129
113
|
}
|
|
130
|
-
|
|
131
114
|
return curJsonSchemaObj;
|
|
132
115
|
}
|
|
133
116
|
|
|
@@ -141,34 +124,28 @@ function indexRoute2keyRoute(indexRoute, targetJsonSchemaObj) {
|
|
|
141
124
|
var curJsonSchemaObj = targetJsonSchemaObj;
|
|
142
125
|
var curKeyRoute = '';
|
|
143
126
|
var indexRouteArr = indexRoute.split('-');
|
|
144
|
-
|
|
145
127
|
for (var index = 0, size = indexRouteArr.length; index < size; index++) {
|
|
146
128
|
// 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
|
|
147
129
|
var curIndex = indexRouteArr[index];
|
|
148
|
-
|
|
149
130
|
if (curIndex === '0' && curJsonSchemaObj.items) {
|
|
150
131
|
// 从items中获取数据
|
|
151
132
|
curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
|
|
152
|
-
|
|
153
133
|
curKeyRoute = curKeyRoute ? curKeyRoute + "-items" : 'items';
|
|
154
134
|
} else if (curIndex) {
|
|
155
135
|
// 1、先根据路径值获取key值
|
|
156
|
-
var curKey = '0';
|
|
157
|
-
|
|
136
|
+
var curKey = '0';
|
|
137
|
+
// 1、先根据路径值获取key值
|
|
158
138
|
if (curJsonSchemaObj.propertyOrder) {
|
|
159
139
|
curKey = curJsonSchemaObj.propertyOrder[curIndex];
|
|
160
140
|
} else if (curJsonSchemaObj.properties) {
|
|
161
141
|
var propertyOrder = Object.keys(curJsonSchemaObj.properties);
|
|
162
142
|
curKey = propertyOrder[curIndex];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
143
|
+
}
|
|
144
|
+
// 2、根据key值获取对应的json数据对象
|
|
166
145
|
curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
|
|
167
|
-
|
|
168
146
|
curKeyRoute = curKeyRoute ? curKeyRoute + "-" + curKey : curKey;
|
|
169
147
|
}
|
|
170
148
|
}
|
|
171
|
-
|
|
172
149
|
return curKeyRoute;
|
|
173
150
|
}
|
|
174
151
|
|
|
@@ -182,34 +159,29 @@ function keyRoute2indexRoute(keyRoute, targetJsonSchemaObj) {
|
|
|
182
159
|
var curJsonSchemaObj = targetJsonSchemaObj;
|
|
183
160
|
var curIndexRoute = '';
|
|
184
161
|
var keyRouteArr = keyRoute.split('-');
|
|
185
|
-
|
|
186
162
|
for (var index = 0, size = keyRouteArr.length; index < size; index++) {
|
|
187
163
|
var curKey = keyRouteArr[index];
|
|
188
|
-
|
|
189
164
|
if (curKey) {
|
|
190
165
|
// 1、先根据路径值获取key值
|
|
191
|
-
var curIndex = -1;
|
|
192
|
-
|
|
166
|
+
var curIndex = -1;
|
|
167
|
+
// 1、先根据路径值获取key值
|
|
193
168
|
if (curJsonSchemaObj.propertyOrder) {
|
|
194
|
-
curIndex = curJsonSchemaObj.propertyOrder.indexOf(curKey);
|
|
195
|
-
|
|
169
|
+
curIndex = curJsonSchemaObj.propertyOrder.indexOf(curKey);
|
|
170
|
+
// 2、根据key值获取对应的json数据对象
|
|
196
171
|
curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
|
|
197
172
|
} else if (curJsonSchemaObj.properties) {
|
|
198
173
|
var propertyOrder = Object.keys(curJsonSchemaObj.properties);
|
|
199
|
-
curIndex = propertyOrder.indexOf(curKey);
|
|
200
|
-
|
|
174
|
+
curIndex = propertyOrder.indexOf(curKey);
|
|
175
|
+
// 2、根据key值获取对应的json数据对象
|
|
201
176
|
curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
|
|
202
177
|
} else if (curJsonSchemaObj.items) {
|
|
203
178
|
// 兼容数组类型
|
|
204
179
|
curIndex = 0; // curKey;
|
|
205
|
-
|
|
206
180
|
curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
|
|
207
181
|
}
|
|
208
|
-
|
|
209
182
|
curIndexRoute = curIndexRoute ? curIndexRoute + "-" + curIndex : curIndex.toString();
|
|
210
183
|
}
|
|
211
184
|
}
|
|
212
|
-
|
|
213
185
|
return curIndexRoute;
|
|
214
186
|
}
|
|
215
187
|
|
|
@@ -440,14 +412,17 @@ var initRadioData = {
|
|
|
440
412
|
type: 'string',
|
|
441
413
|
title: '单选',
|
|
442
414
|
format: 'radio',
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
415
|
+
options: [{
|
|
416
|
+
label: '选项a',
|
|
417
|
+
value: 'a'
|
|
418
|
+
}, {
|
|
419
|
+
label: '选项b',
|
|
420
|
+
value: 'b'
|
|
421
|
+
}, {
|
|
422
|
+
label: '选项c',
|
|
423
|
+
value: 'c'
|
|
424
|
+
}],
|
|
449
425
|
description: '',
|
|
450
|
-
// 字段项的说明和描述
|
|
451
426
|
isRequired: false,
|
|
452
427
|
readOnly: false
|
|
453
428
|
};
|
|
@@ -466,14 +441,17 @@ var initSingleSelectData = {
|
|
|
466
441
|
type: 'string',
|
|
467
442
|
title: '下拉单选',
|
|
468
443
|
format: 'single-select',
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
444
|
+
options: [{
|
|
445
|
+
label: '选项a',
|
|
446
|
+
value: 'a'
|
|
447
|
+
}, {
|
|
448
|
+
label: '选项b',
|
|
449
|
+
value: 'b'
|
|
450
|
+
}, {
|
|
451
|
+
label: '选项c',
|
|
452
|
+
value: 'c'
|
|
453
|
+
}],
|
|
475
454
|
description: '',
|
|
476
|
-
// 字段项的说明和描述
|
|
477
455
|
isRequired: false,
|
|
478
456
|
readOnly: false
|
|
479
457
|
};
|
|
@@ -492,14 +470,17 @@ var initSelectData = {
|
|
|
492
470
|
type: 'array',
|
|
493
471
|
title: '多选',
|
|
494
472
|
format: 'select',
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
473
|
+
options: [{
|
|
474
|
+
label: '选项a',
|
|
475
|
+
value: 'a'
|
|
476
|
+
}, {
|
|
477
|
+
label: '选项b',
|
|
478
|
+
value: 'b'
|
|
479
|
+
}, {
|
|
480
|
+
label: '选项c',
|
|
481
|
+
value: 'c'
|
|
482
|
+
}],
|
|
501
483
|
description: '',
|
|
502
|
-
// 字段项的说明和描述
|
|
503
484
|
isRequired: false,
|
|
504
485
|
readOnly: false
|
|
505
486
|
};
|
|
@@ -930,9 +911,9 @@ var initHtmlAreaData = {
|
|
|
930
911
|
* required:存放所有子字段的key值,用于验证子字段项是否存在,同时required可充当排序功能
|
|
931
912
|
* propertyOrder:按序存放所有子字段的key值(排序功能)
|
|
932
913
|
* */
|
|
914
|
+
|
|
933
915
|
/** 新版EventData
|
|
934
916
|
* type: emit 的默认数据 */
|
|
935
|
-
|
|
936
917
|
var initEventData = {
|
|
937
918
|
type: 'object',
|
|
938
919
|
format: 'event',
|
|
@@ -975,9 +956,9 @@ var initEventData = {
|
|
|
975
956
|
required: ['type', 'trigger', 'eventData'],
|
|
976
957
|
propertyOrder: ['type', 'trigger', 'eventData']
|
|
977
958
|
};
|
|
959
|
+
|
|
978
960
|
/** 新版EventData
|
|
979
961
|
* type: on 的默认数据 */
|
|
980
|
-
|
|
981
962
|
var initEventDataTypeON = {
|
|
982
963
|
type: 'object',
|
|
983
964
|
format: 'event',
|
|
@@ -1067,8 +1048,9 @@ var initDataSourceData = {
|
|
|
1067
1048
|
},
|
|
1068
1049
|
required: ['type', 'data', 'filter'],
|
|
1069
1050
|
propertyOrder: ['type', 'data', 'filter']
|
|
1070
|
-
};
|
|
1051
|
+
};
|
|
1071
1052
|
|
|
1053
|
+
// 默认是用于展示local本地数据源的,如果展示远程数据源使用initDataSourceDataV2
|
|
1072
1054
|
var initDataSourceDataV2 = {
|
|
1073
1055
|
type: 'object',
|
|
1074
1056
|
format: 'datasource',
|
|
@@ -1185,8 +1167,9 @@ var initDynamicData = {
|
|
|
1185
1167
|
},
|
|
1186
1168
|
required: ['type', 'config', 'data', 'localFilter'],
|
|
1187
1169
|
propertyOrder: ['type', 'config', 'data', 'localFilter']
|
|
1188
|
-
};
|
|
1170
|
+
};
|
|
1189
1171
|
|
|
1172
|
+
// 动态数据对应的空json数据内容
|
|
1190
1173
|
var EmptyDynamicDataCont = {
|
|
1191
1174
|
type: 'local',
|
|
1192
1175
|
config: {
|
|
@@ -1199,7 +1182,7 @@ var EmptyDynamicDataCont = {
|
|
|
1199
1182
|
data: '{}',
|
|
1200
1183
|
// 用于存储结果数据
|
|
1201
1184
|
localFilter: 'return data;'
|
|
1202
|
-
};
|
|
1185
|
+
};
|
|
1203
1186
|
|
|
1204
1187
|
/* widget类型字段
|
|
1205
1188
|
* 【字段属性说明】
|
|
@@ -1222,9 +1205,9 @@ var initWidgetData = {
|
|
|
1222
1205
|
// 字段项的说明和描述
|
|
1223
1206
|
isRequired: false,
|
|
1224
1207
|
readOnly: true // 默认只读
|
|
1225
|
-
|
|
1226
1208
|
};
|
|
1227
1209
|
|
|
1210
|
+
// 类型数据清单
|
|
1228
1211
|
var TypeDataList = {
|
|
1229
1212
|
jsonschema: initJSONSchemaData,
|
|
1230
1213
|
input: initInputData,
|
|
@@ -1254,125 +1237,120 @@ var TypeDataList = {
|
|
|
1254
1237
|
datasource: initDataSourceData,
|
|
1255
1238
|
event: initEventData,
|
|
1256
1239
|
widget: initWidgetData
|
|
1257
|
-
};
|
|
1240
|
+
};
|
|
1258
1241
|
|
|
1242
|
+
// 事件类型数据
|
|
1259
1243
|
var EventTypeDataList = {
|
|
1260
1244
|
on: initEventDataTypeON,
|
|
1261
1245
|
emit: initEventData
|
|
1262
|
-
};
|
|
1246
|
+
};
|
|
1263
1247
|
|
|
1248
|
+
// 数据源类型
|
|
1264
1249
|
var DataSourceTypeList = {
|
|
1265
1250
|
local: initDataSourceData,
|
|
1266
1251
|
remote: initDataSourceDataV2
|
|
1267
1252
|
};
|
|
1268
1253
|
|
|
1254
|
+
// 判断是否是URL地址类型
|
|
1269
1255
|
function isURL(s) {
|
|
1270
1256
|
return /^http[s]?:\/\/.*/.test(s);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1257
|
+
}
|
|
1258
|
+
// 判断是否是字符串类型
|
|
1273
1259
|
function isString(o) {
|
|
1274
1260
|
return Object.prototype.toString.call(o).slice(8, -1) === 'String';
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1261
|
+
}
|
|
1262
|
+
// 判断是否是数字类型
|
|
1277
1263
|
function isNumber(value) {
|
|
1278
1264
|
return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]';
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1265
|
+
}
|
|
1266
|
+
// 判断是否是Boolean类型
|
|
1281
1267
|
function isBoolean(o) {
|
|
1282
1268
|
return Object.prototype.toString.call(o).slice(8, -1) === 'Boolean';
|
|
1283
|
-
}
|
|
1269
|
+
}
|
|
1284
1270
|
|
|
1271
|
+
// 判断是否是年月日的时间类型
|
|
1285
1272
|
function isDateStr(dateStr) {
|
|
1286
1273
|
return /^\d{4}-\d{2}-\d{2}$/.test(dateStr);
|
|
1287
|
-
}
|
|
1274
|
+
}
|
|
1288
1275
|
|
|
1276
|
+
// 判断是否是年月日时分的时间类型
|
|
1289
1277
|
function isDateTimeStr(dateStr) {
|
|
1290
1278
|
return /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.test(dateStr) || /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(dateStr);
|
|
1291
|
-
}
|
|
1279
|
+
}
|
|
1292
1280
|
|
|
1281
|
+
// 判断是否是时分的时间类型
|
|
1293
1282
|
function isTimeStr(dateStr) {
|
|
1294
1283
|
return /^\d{2}:\d{2}:\d{2}$/.test(dateStr) || /^\d{2}:\d{2}$/.test(dateStr);
|
|
1295
1284
|
}
|
|
1285
|
+
|
|
1296
1286
|
/**
|
|
1297
1287
|
* 判断是否是数组类型
|
|
1298
1288
|
* */
|
|
1299
|
-
|
|
1300
1289
|
function isArray(curObj) {
|
|
1301
1290
|
var isArray = false;
|
|
1302
|
-
|
|
1303
1291
|
if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Array') {
|
|
1304
1292
|
isArray = true;
|
|
1305
1293
|
}
|
|
1306
|
-
|
|
1307
1294
|
return isArray;
|
|
1308
1295
|
}
|
|
1296
|
+
|
|
1309
1297
|
/**
|
|
1310
1298
|
* 判断是否是select多选类型(基础类型的array)
|
|
1311
1299
|
* select类型一定是一个array类型
|
|
1312
1300
|
* */
|
|
1313
|
-
|
|
1314
1301
|
function isSelect(curObj) {
|
|
1315
1302
|
if (!isArray(curObj)) {
|
|
1316
1303
|
return false;
|
|
1317
1304
|
}
|
|
1318
|
-
|
|
1319
1305
|
for (var ind = 0, size = curObj.length; ind < size; ind++) {
|
|
1320
1306
|
var arrItem = curObj[ind];
|
|
1321
|
-
|
|
1322
1307
|
if (!isString(arrItem)) {
|
|
1323
1308
|
// 只要有一个不是string类型就认为不是select
|
|
1324
1309
|
return false;
|
|
1325
1310
|
}
|
|
1326
1311
|
}
|
|
1327
|
-
|
|
1328
1312
|
return true;
|
|
1329
1313
|
}
|
|
1314
|
+
|
|
1330
1315
|
/**
|
|
1331
1316
|
* 判断是否是对象类型
|
|
1332
1317
|
* */
|
|
1333
|
-
|
|
1334
1318
|
function isObject(curObj) {
|
|
1335
1319
|
var isObject = false;
|
|
1336
|
-
|
|
1337
1320
|
if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Object') {
|
|
1338
1321
|
isObject = true;
|
|
1339
1322
|
}
|
|
1340
|
-
|
|
1341
1323
|
return isObject;
|
|
1342
1324
|
}
|
|
1325
|
+
|
|
1343
1326
|
/**
|
|
1344
1327
|
* 判断是否是单位类型
|
|
1345
1328
|
* */
|
|
1346
|
-
|
|
1347
1329
|
function isQuantity(val) {
|
|
1348
|
-
var isObject = false;
|
|
1349
|
-
|
|
1330
|
+
var isObject = false;
|
|
1331
|
+
// 获取当前计量单位元素可选的单位类型
|
|
1350
1332
|
var quantityList = TypeDataList.quantity.properties.quantity.enum;
|
|
1351
|
-
|
|
1352
1333
|
if (quantityList.indexOf(val) >= 0) {
|
|
1353
1334
|
isObject = true;
|
|
1354
1335
|
}
|
|
1355
|
-
|
|
1356
1336
|
return isObject;
|
|
1357
1337
|
}
|
|
1338
|
+
|
|
1358
1339
|
/**
|
|
1359
1340
|
* 判断是否是颜色值
|
|
1360
1341
|
* */
|
|
1361
|
-
|
|
1362
1342
|
function isColor(colorVal) {
|
|
1363
1343
|
return /^#[0-9a-f]{6}$/.test(colorVal) || /^#[0-9a-f]{3}$/.test(colorVal);
|
|
1364
1344
|
}
|
|
1345
|
+
|
|
1365
1346
|
/**
|
|
1366
1347
|
* 判断是否是函数类型
|
|
1367
1348
|
* */
|
|
1368
|
-
|
|
1369
1349
|
function isFunction(curObj) {
|
|
1370
1350
|
var isFunction = false;
|
|
1371
|
-
|
|
1372
1351
|
if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Function') {
|
|
1373
1352
|
isFunction = true;
|
|
1374
1353
|
}
|
|
1375
|
-
|
|
1376
1354
|
return isFunction;
|
|
1377
1355
|
}
|
|
1378
1356
|
|
|
@@ -1380,15 +1358,14 @@ function isFunction(curObj) {
|
|
|
1380
1358
|
* json2schema:根据json数据内容获取对应的schema数据
|
|
1381
1359
|
* 当前包含三个转换方法:baseJson2Schema、objectJson2Schema、arrayJson2Schema
|
|
1382
1360
|
* */
|
|
1361
|
+
|
|
1383
1362
|
/**
|
|
1384
1363
|
* 基础类型的jsonData转schema
|
|
1385
1364
|
* 备注:目前可转换Boolean、Number、URL、Date、DateTime、Time、color、json类型
|
|
1386
1365
|
* 其中textarea、radio、codearea和htmlarea的数值不好和input区分,故均转换为input类型
|
|
1387
1366
|
* */
|
|
1388
|
-
|
|
1389
1367
|
function baseJson2Schema(jsonData) {
|
|
1390
1368
|
var curJsonSchema = '';
|
|
1391
|
-
|
|
1392
1369
|
if (isBoolean(jsonData)) {
|
|
1393
1370
|
// 1、Boolean类型
|
|
1394
1371
|
curJsonSchema = objClone(TypeDataList.boolean);
|
|
@@ -1414,7 +1391,6 @@ function baseJson2Schema(jsonData) {
|
|
|
1414
1391
|
try {
|
|
1415
1392
|
// json数据类型:进行格式化(检查是否是合格的json字符串数据)
|
|
1416
1393
|
var jsonDataObj = JSON.parse(jsonData);
|
|
1417
|
-
|
|
1418
1394
|
if (isNumber(jsonDataObj)) {
|
|
1419
1395
|
// 简单数字字符串类型数值统一认为是字符串类型
|
|
1420
1396
|
curJsonSchema = objClone(TypeDataList.input);
|
|
@@ -1433,21 +1409,17 @@ function baseJson2Schema(jsonData) {
|
|
|
1433
1409
|
}
|
|
1434
1410
|
}
|
|
1435
1411
|
}
|
|
1436
|
-
|
|
1437
1412
|
return curJsonSchema;
|
|
1438
1413
|
}
|
|
1414
|
+
|
|
1439
1415
|
/**
|
|
1440
1416
|
* Object类型的jsonData转schema
|
|
1441
1417
|
* 备注:目前可转换datasource、event、quantity、object四种对象类型
|
|
1442
1418
|
* */
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
1419
|
function objectJson2Schema(jsonData) {
|
|
1446
1420
|
var curJsonSchema;
|
|
1447
|
-
|
|
1448
1421
|
if (isObject(jsonData)) {
|
|
1449
1422
|
var properties = Object.keys(jsonData);
|
|
1450
|
-
|
|
1451
1423
|
if (jsonData.data && jsonData.filter && properties.length === 2) {
|
|
1452
1424
|
// DataSource数据源类型
|
|
1453
1425
|
if (isArray(jsonData.data) || isObject(jsonData.data)) {
|
|
@@ -1470,34 +1442,30 @@ function objectJson2Schema(jsonData) {
|
|
|
1470
1442
|
// 其他非固定格式的Object类型
|
|
1471
1443
|
curJsonSchema = objClone(TypeDataList['empty-object']); // 新建空数组对象schema
|
|
1472
1444
|
// 遍历子数据项目
|
|
1473
|
-
|
|
1474
1445
|
Object.keys(jsonData).map(function (jsonKey) {
|
|
1475
1446
|
var curJsonItem = jsonData[jsonKey];
|
|
1476
1447
|
curJsonSchema.properties[jsonKey] = json2schema(curJsonItem);
|
|
1477
1448
|
});
|
|
1478
1449
|
}
|
|
1479
1450
|
}
|
|
1480
|
-
|
|
1481
1451
|
return curJsonSchema;
|
|
1482
1452
|
}
|
|
1453
|
+
|
|
1483
1454
|
/**
|
|
1484
1455
|
* Array类型的jsonData转schema
|
|
1485
1456
|
* 备注:目前可转换select、array两种数组类型
|
|
1486
1457
|
* */
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
1458
|
function arrayJson2Schema(jsonData) {
|
|
1490
|
-
var curJsonSchema;
|
|
1491
|
-
|
|
1459
|
+
var curJsonSchema;
|
|
1460
|
+
// 判断是否是数组类型
|
|
1492
1461
|
if (jsonData && isArray(jsonData)) {
|
|
1493
1462
|
// 判断是否select类型(select类型是字符串类型的array)
|
|
1494
1463
|
if (isSelect(jsonData)) {
|
|
1495
|
-
curJsonSchema = objClone(TypeDataList.select);
|
|
1496
|
-
|
|
1464
|
+
curJsonSchema = objClone(TypeDataList.select);
|
|
1465
|
+
// 将当前jsonData的值设置为select的选项值
|
|
1497
1466
|
curJsonSchema.items.enum = jsonData;
|
|
1498
1467
|
var enumextraLength = curJsonSchema.items.enumextra.length;
|
|
1499
1468
|
var arrLength = jsonData.length;
|
|
1500
|
-
|
|
1501
1469
|
if (arrLength > enumextraLength) {
|
|
1502
1470
|
// 如果当前jsonDats的数值个数大于selectSchemaData的选项个数,则需要进行补充
|
|
1503
1471
|
for (var ind = enumextraLength, size = arrLength; ind < size; ind++) {
|
|
@@ -1507,23 +1475,18 @@ function arrayJson2Schema(jsonData) {
|
|
|
1507
1475
|
} else {
|
|
1508
1476
|
curJsonSchema = objClone(TypeDataList['empty-array']); // 新建空数组对象schema
|
|
1509
1477
|
// 根据第一个数组项获取items的schema对象
|
|
1510
|
-
|
|
1511
1478
|
var arrItemObj = json2schema(jsonData[0]); // 正常情况下,Array的一级子对象是Object类型
|
|
1512
|
-
|
|
1513
1479
|
curJsonSchema.items.properties = arrItemObj.properties;
|
|
1514
1480
|
}
|
|
1515
1481
|
}
|
|
1516
|
-
|
|
1517
1482
|
return curJsonSchema;
|
|
1518
1483
|
}
|
|
1484
|
+
|
|
1519
1485
|
/**
|
|
1520
1486
|
* 根据jsonData生成一份对应的jsonSchema
|
|
1521
1487
|
* */
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
1488
|
function json2schema(jsonData) {
|
|
1525
1489
|
var curJsonSchema = {};
|
|
1526
|
-
|
|
1527
1490
|
if (jsonData && isObject(jsonData)) {
|
|
1528
1491
|
curJsonSchema = objectJson2Schema(jsonData);
|
|
1529
1492
|
} else if (jsonData && isArray(jsonData)) {
|
|
@@ -1531,7 +1494,6 @@ function json2schema(jsonData) {
|
|
|
1531
1494
|
} else {
|
|
1532
1495
|
curJsonSchema = baseJson2Schema(jsonData);
|
|
1533
1496
|
}
|
|
1534
|
-
|
|
1535
1497
|
return curJsonSchema;
|
|
1536
1498
|
}
|
|
1537
1499
|
|
|
@@ -1545,7 +1507,6 @@ function json2schema(jsonData) {
|
|
|
1545
1507
|
*/
|
|
1546
1508
|
function getCurrentFormat(targetJsonData) {
|
|
1547
1509
|
var currentType = targetJsonData && targetJsonData.format;
|
|
1548
|
-
|
|
1549
1510
|
if (!currentType) {
|
|
1550
1511
|
if (targetJsonData && targetJsonData.type) {
|
|
1551
1512
|
currentType = targetJsonData.type;
|
|
@@ -1553,22 +1514,18 @@ function getCurrentFormat(targetJsonData) {
|
|
|
1553
1514
|
currentType = 'input';
|
|
1554
1515
|
}
|
|
1555
1516
|
}
|
|
1556
|
-
|
|
1557
1517
|
return currentType;
|
|
1558
1518
|
}
|
|
1519
|
+
|
|
1559
1520
|
/** 判断是否为空的Schema
|
|
1560
1521
|
* 包括 通用schema和组件配置专用的schema
|
|
1561
1522
|
* */
|
|
1562
|
-
|
|
1563
1523
|
function isEmptySchema(targetJsonSchema) {
|
|
1564
1524
|
var isEmpty = true;
|
|
1565
|
-
|
|
1566
1525
|
if (!targetJsonSchema) {
|
|
1567
1526
|
return isEmpty;
|
|
1568
1527
|
}
|
|
1569
|
-
|
|
1570
1528
|
var curType = getCurrentFormat(targetJsonSchema);
|
|
1571
|
-
|
|
1572
1529
|
if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.propertyOrder.length > 0) {
|
|
1573
1530
|
// Object对象类型
|
|
1574
1531
|
isEmpty = false;
|
|
@@ -1579,104 +1536,89 @@ function isEmptySchema(targetJsonSchema) {
|
|
|
1579
1536
|
// 其他基本类型
|
|
1580
1537
|
isEmpty = false;
|
|
1581
1538
|
}
|
|
1582
|
-
|
|
1583
1539
|
return isEmpty;
|
|
1584
1540
|
}
|
|
1541
|
+
|
|
1585
1542
|
/** 判断是否为空的WidgetSchema
|
|
1586
1543
|
* 备注:WidgetSchema 一级字段必须为object,且有三个子属性:func、style、data
|
|
1587
1544
|
* */
|
|
1588
|
-
|
|
1589
1545
|
function isEmptyWidgetSchema(targetJsonSchema) {
|
|
1590
1546
|
var isEmpty = true;
|
|
1591
|
-
|
|
1592
1547
|
if (targetJsonSchema) {
|
|
1593
1548
|
var curType = getCurrentFormat(targetJsonSchema);
|
|
1594
|
-
|
|
1595
1549
|
if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.propertyOrder.length > 0) {
|
|
1596
1550
|
var funcSchema = targetJsonSchema.properties.func || {};
|
|
1597
1551
|
var styleSchema = targetJsonSchema.properties.style || {};
|
|
1598
1552
|
var dataSchema = targetJsonSchema.properties.data || {};
|
|
1599
|
-
|
|
1600
1553
|
if (funcSchema.propertyOrder && funcSchema.propertyOrder.length > 0 || styleSchema.propertyOrder && styleSchema.propertyOrder.length > 0 || dataSchema.propertyOrder && dataSchema.propertyOrder.length > 0) {
|
|
1601
1554
|
isEmpty = false;
|
|
1602
1555
|
}
|
|
1603
1556
|
}
|
|
1604
1557
|
}
|
|
1605
|
-
|
|
1606
1558
|
return isEmpty;
|
|
1607
1559
|
}
|
|
1560
|
+
|
|
1608
1561
|
/** 判断是否为用于组件配置的jsonSchema数据
|
|
1609
1562
|
* 备注:一级字段必须为object(用于规避非法的jsonSchema数据,以及结构单一的jsonSchema数据)
|
|
1610
1563
|
* 且具备固定的三个子属性(func、style、data)
|
|
1611
1564
|
* */
|
|
1612
|
-
|
|
1613
1565
|
function isUsedToWidgetConfig(targetJsonSchema) {
|
|
1614
1566
|
var isWidgetConfig = false;
|
|
1615
|
-
|
|
1616
1567
|
if (targetJsonSchema) {
|
|
1617
1568
|
var curType = getCurrentFormat(targetJsonSchema);
|
|
1618
|
-
|
|
1619
1569
|
if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.properties.func && targetJsonSchema.properties.style && targetJsonSchema.properties.data) {
|
|
1620
1570
|
isWidgetConfig = true;
|
|
1621
1571
|
}
|
|
1622
1572
|
}
|
|
1623
|
-
|
|
1624
1573
|
return isWidgetConfig;
|
|
1625
1574
|
}
|
|
1575
|
+
|
|
1626
1576
|
/**
|
|
1627
1577
|
* 判断是否是最新版的schema数据
|
|
1628
1578
|
* 备注:确保当前schema数据是通过@wibetter/json-schema-editor生成的
|
|
1629
1579
|
* */
|
|
1630
|
-
|
|
1631
1580
|
function isNewSchemaData(schemaData) {
|
|
1632
1581
|
var isNewVersion = false;
|
|
1633
|
-
var lastUpdateTime = schemaData.lastUpdateTime;
|
|
1634
|
-
|
|
1582
|
+
var lastUpdateTime = schemaData.lastUpdateTime;
|
|
1583
|
+
// 从那一刻开始就认为是新版JSONSchema
|
|
1635
1584
|
var newVersionTime = new Date('2020-07-29T07:30:00.691Z').getTime();
|
|
1636
|
-
|
|
1637
1585
|
if (lastUpdateTime && new Date(lastUpdateTime).getTime() >= newVersionTime) {
|
|
1638
1586
|
isNewVersion = true;
|
|
1639
1587
|
}
|
|
1640
|
-
|
|
1641
1588
|
return isNewVersion;
|
|
1642
1589
|
}
|
|
1590
|
+
|
|
1643
1591
|
/** 根据format判断是否是容器类型字段
|
|
1644
1592
|
* 容器类型字段:func、style、data、object
|
|
1645
1593
|
* 主要用于判断当前元素点击新增时是添加子元素还是添加兄弟节点,容器类型点击新增时则添加子节点。
|
|
1646
1594
|
* 备注:array类型字段只有固定的一个items属性,不能新增其他子元素。
|
|
1647
1595
|
* */
|
|
1648
|
-
|
|
1649
1596
|
function isBoxSchemaData(format) {
|
|
1650
1597
|
var isBoxSchema = false;
|
|
1651
|
-
|
|
1652
1598
|
if (format === 'object' || format === 'func' || format === 'style' || format === 'data' || format === 'widgets' || format === 'func-schema' || format === 'style-schema' || format === 'data-schema' || format === 'event-schema' || format === 'widgets-schema') {
|
|
1653
1599
|
isBoxSchema = true;
|
|
1654
1600
|
}
|
|
1655
|
-
|
|
1656
1601
|
return isBoxSchema;
|
|
1657
1602
|
}
|
|
1603
|
+
|
|
1658
1604
|
/** 根据format判断是否是一级类型字段
|
|
1659
1605
|
* 一级类型字段:func、style、data、props、event-schema、widgets
|
|
1660
1606
|
* 备注:一级类型字段不允许拖拽和复制
|
|
1661
1607
|
* */
|
|
1662
|
-
|
|
1663
1608
|
function isFirstSchemaData(format) {
|
|
1664
1609
|
var isFirstSchema = false;
|
|
1665
|
-
|
|
1666
1610
|
if (format === 'func' || format === 'style' || format === 'data' || format === 'props' || format === 'event-schema' || format === 'widgets') {
|
|
1667
1611
|
isFirstSchema = true;
|
|
1668
1612
|
}
|
|
1669
|
-
|
|
1670
1613
|
return isFirstSchema;
|
|
1671
1614
|
}
|
|
1615
|
+
|
|
1672
1616
|
/** 判断是否是结构化的schema数据,
|
|
1673
1617
|
* 判定条件:一级schema为object类型,其所有二级schema也为object类型
|
|
1674
1618
|
* */
|
|
1675
|
-
|
|
1676
1619
|
function isStructuredSchema(jsonSchema) {
|
|
1677
1620
|
var isStructured = true;
|
|
1678
1621
|
var currentType = jsonSchema.type || getCurrentFormat(jsonSchema);
|
|
1679
|
-
|
|
1680
1622
|
if (currentType !== 'object' || !jsonSchema.propertyOrder || !jsonSchema.properties) {
|
|
1681
1623
|
isStructured = false;
|
|
1682
1624
|
} else {
|
|
@@ -1684,70 +1626,61 @@ function isStructuredSchema(jsonSchema) {
|
|
|
1684
1626
|
/** 1. 获取当前schema对象 */
|
|
1685
1627
|
var curSchemaData = jsonSchema.properties[key];
|
|
1686
1628
|
/** 2. 判断是否是容器类型元素,如果是则禁止选中 */
|
|
1687
|
-
|
|
1688
1629
|
var curType = jsonSchema.type || getCurrentFormat(curSchemaData);
|
|
1689
|
-
|
|
1690
1630
|
if (curType !== 'object' || !curSchemaData.propertyOrder || !curSchemaData.properties) {
|
|
1691
1631
|
isStructured = false;
|
|
1692
1632
|
}
|
|
1693
1633
|
});
|
|
1694
1634
|
}
|
|
1695
|
-
|
|
1696
1635
|
return isStructured;
|
|
1697
1636
|
}
|
|
1637
|
+
|
|
1698
1638
|
/**
|
|
1699
1639
|
* 判断是否是同一个父元素
|
|
1700
1640
|
* 备注:用于判断两个元素是否在同一个父级容器中
|
|
1701
1641
|
*/
|
|
1702
|
-
|
|
1703
1642
|
function isSameParent(curIndex, targetIndex) {
|
|
1704
1643
|
var curIndexArr = curIndex.split('-');
|
|
1705
1644
|
var targetIndexArr = targetIndex.split('-');
|
|
1706
1645
|
curIndexArr.pop();
|
|
1707
1646
|
targetIndexArr.pop();
|
|
1708
|
-
|
|
1709
1647
|
if (curIndexArr.join('-') === targetIndexArr.join('-')) {
|
|
1710
1648
|
return true;
|
|
1711
1649
|
}
|
|
1712
|
-
|
|
1713
1650
|
return false;
|
|
1714
1651
|
}
|
|
1652
|
+
|
|
1715
1653
|
/**
|
|
1716
1654
|
* 判断当前元素在目标元素的位置 前 or 后(根据当前元素的位置和目标元素的位置)
|
|
1717
1655
|
*/
|
|
1718
|
-
|
|
1719
1656
|
function getCurPosition(curIndex, targetIndex) {
|
|
1720
1657
|
var curIndexArr = curIndex.split('-');
|
|
1721
1658
|
var targetIndexArr = targetIndex.split('-');
|
|
1722
1659
|
var curPosition = 'before'; // 默认在目标元素的前面
|
|
1723
1660
|
// 使用短的路径进行遍历(避免空指针)
|
|
1724
|
-
|
|
1725
1661
|
var forEachArr = curIndexArr.length > targetIndexArr.length ? targetIndexArr : curIndexArr;
|
|
1726
|
-
|
|
1727
1662
|
for (var index = 0, size = forEachArr.length; index < size; index += 1) {
|
|
1728
1663
|
var curIndexItem = Number(curIndexArr[index]);
|
|
1729
1664
|
var targetIndexItem = Number(targetIndexArr[index]);
|
|
1730
|
-
|
|
1731
1665
|
if (curIndexItem > targetIndexItem) {
|
|
1732
1666
|
curPosition = 'after'; // 表示当前元素在目标元素的后面
|
|
1733
1667
|
}
|
|
1734
1668
|
}
|
|
1735
|
-
|
|
1736
1669
|
return curPosition;
|
|
1737
1670
|
}
|
|
1671
|
+
|
|
1738
1672
|
/**
|
|
1739
1673
|
* 获取父元素的路径值
|
|
1740
1674
|
*/
|
|
1741
|
-
|
|
1742
1675
|
function getParentIndexRoute(curIndexRoute) {
|
|
1743
1676
|
var curIndexArr = curIndexRoute.split('-');
|
|
1744
1677
|
curIndexArr.pop();
|
|
1745
1678
|
return curIndexArr.join('-');
|
|
1746
1679
|
}
|
|
1680
|
+
|
|
1747
1681
|
/**
|
|
1748
1682
|
* 获取下一个兄弟元素的路径值
|
|
1749
1683
|
*/
|
|
1750
|
-
|
|
1751
1684
|
function getNextIndexRoute(curIndexRoute) {
|
|
1752
1685
|
var curIndexArr = curIndexRoute.split('-');
|
|
1753
1686
|
var lastIndex = curIndexArr.pop();
|
|
@@ -1755,29 +1688,29 @@ function getNextIndexRoute(curIndexRoute) {
|
|
|
1755
1688
|
curIndexArr.push("" + endIndex);
|
|
1756
1689
|
return curIndexArr.join('-');
|
|
1757
1690
|
}
|
|
1691
|
+
|
|
1758
1692
|
/**
|
|
1759
1693
|
* 获取父元素的路径值和当前index
|
|
1760
1694
|
*/
|
|
1761
|
-
|
|
1762
1695
|
function getParentIndexRoute_CurIndex(curIndexRoute) {
|
|
1763
1696
|
var curIndexArr = curIndexRoute.split('-');
|
|
1764
1697
|
var curIndex = curIndexArr.pop();
|
|
1765
1698
|
return [curIndexArr.join('-'), curIndex];
|
|
1766
1699
|
}
|
|
1700
|
+
|
|
1767
1701
|
/**
|
|
1768
1702
|
* 将当前路径值向前移动一位
|
|
1769
1703
|
*/
|
|
1770
|
-
|
|
1771
1704
|
function moveForward(curIndexRoute) {
|
|
1772
1705
|
var curIndexArr = curIndexRoute.split('-');
|
|
1773
1706
|
var curIndex = curIndexArr.pop();
|
|
1774
1707
|
curIndexArr.push(Number(curIndex) - 1);
|
|
1775
1708
|
return curIndexArr.join('-');
|
|
1776
1709
|
}
|
|
1710
|
+
|
|
1777
1711
|
/**
|
|
1778
1712
|
* 将当前路径值向后移动一位
|
|
1779
1713
|
*/
|
|
1780
|
-
|
|
1781
1714
|
function moveBackward(curIndexRoute) {
|
|
1782
1715
|
var curIndexArr = curIndexRoute.split('-');
|
|
1783
1716
|
var curIndex = curIndexArr.pop();
|
|
@@ -1804,41 +1737,35 @@ function moveBackward(curIndexRoute) {
|
|
|
1804
1737
|
* }
|
|
1805
1738
|
* }
|
|
1806
1739
|
*/
|
|
1740
|
+
|
|
1807
1741
|
/**
|
|
1808
1742
|
* Object类型的schema元数据分析
|
|
1809
1743
|
* */
|
|
1810
|
-
|
|
1811
1744
|
function objectSchema2JsonData$1(jsonSchema, analyzerResult) {
|
|
1812
1745
|
var curAnalyzerResult = analyzerResult || {};
|
|
1813
|
-
|
|
1814
1746
|
if (isObject(jsonSchema) && jsonSchema.type === 'object' && jsonSchema.properties) {
|
|
1815
1747
|
var curPropertyOrder = [];
|
|
1816
|
-
|
|
1817
1748
|
if (jsonSchema.propertyOrder) {
|
|
1818
1749
|
curPropertyOrder = jsonSchema.propertyOrder;
|
|
1819
1750
|
} else {
|
|
1820
1751
|
curPropertyOrder = Object.keys(jsonSchema.properties);
|
|
1821
1752
|
}
|
|
1822
|
-
|
|
1823
1753
|
curPropertyOrder.map(function (jsonKey) {
|
|
1824
1754
|
var curSchema = jsonSchema.properties[jsonKey];
|
|
1825
1755
|
curAnalyzerResult = metaElemAnalyzer(curSchema, curAnalyzerResult);
|
|
1826
1756
|
});
|
|
1827
1757
|
}
|
|
1828
|
-
|
|
1829
1758
|
return curAnalyzerResult;
|
|
1830
1759
|
}
|
|
1831
|
-
/** 主方法 */
|
|
1832
|
-
|
|
1833
1760
|
|
|
1761
|
+
/** 主方法 */
|
|
1834
1762
|
function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
|
|
1835
1763
|
// 根据analyzerResult是否为空,判断是否是最外层的调用
|
|
1836
1764
|
var isFirstAnalyzer = !analyzerResult ? true : false;
|
|
1837
|
-
var curAnalyzerResult = analyzerResult || {};
|
|
1838
|
-
|
|
1765
|
+
var curAnalyzerResult = analyzerResult || {};
|
|
1766
|
+
// 根据当前schem数据分析使用到的元数据情况
|
|
1839
1767
|
if (curJsonSchemaObj && JSON.stringify(curJsonSchemaObj) !== '{}') {
|
|
1840
1768
|
var curFormat = getCurrentFormat(curJsonSchemaObj);
|
|
1841
|
-
|
|
1842
1769
|
if (curFormat === 'object' || curFormat === 'func' || curFormat === 'style' || curFormat === 'data') {
|
|
1843
1770
|
// 最外层的schema类型不进行统计
|
|
1844
1771
|
if (!isFirstAnalyzer && curAnalyzerResult['object']) {
|
|
@@ -1846,7 +1773,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
|
|
|
1846
1773
|
} else if (!isFirstAnalyzer) {
|
|
1847
1774
|
curAnalyzerResult['object'] = 1;
|
|
1848
1775
|
}
|
|
1849
|
-
|
|
1850
1776
|
curAnalyzerResult = objectSchema2JsonData$1(curJsonSchemaObj, curAnalyzerResult);
|
|
1851
1777
|
} else if (curFormat === 'array') {
|
|
1852
1778
|
// 最外层的schema类型不进行统计
|
|
@@ -1855,7 +1781,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
|
|
|
1855
1781
|
} else if (!isFirstAnalyzer) {
|
|
1856
1782
|
curAnalyzerResult['array'] = 1;
|
|
1857
1783
|
}
|
|
1858
|
-
|
|
1859
1784
|
curJsonSchemaObj = curJsonSchemaObj.items;
|
|
1860
1785
|
curAnalyzerResult = objectSchema2JsonData$1(curJsonSchemaObj, curAnalyzerResult);
|
|
1861
1786
|
} else {
|
|
@@ -1866,7 +1791,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
|
|
|
1866
1791
|
}
|
|
1867
1792
|
}
|
|
1868
1793
|
}
|
|
1869
|
-
|
|
1870
1794
|
return curAnalyzerResult;
|
|
1871
1795
|
}
|
|
1872
1796
|
|
|
@@ -1878,61 +1802,51 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
|
|
|
1878
1802
|
function oldSchemaToNewSchema(oldSchema) {
|
|
1879
1803
|
var newJSONSchema = objClone(oldSchema); // 进行深拷贝,避免影响原有数据;
|
|
1880
1804
|
// 1.根据原有的description值生成title值
|
|
1881
|
-
|
|
1882
1805
|
if (!newJSONSchema.title && newJSONSchema.description) {
|
|
1883
1806
|
newJSONSchema.title = newJSONSchema.description;
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1807
|
+
}
|
|
1808
|
+
// 2.当format为空时重新进行赋值
|
|
1887
1809
|
if (!newJSONSchema.format) {
|
|
1888
1810
|
newJSONSchema.format = getCurrentFormat(newJSONSchema);
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
if ((newJSONSchema.format === 'quantity' || newJSONSchema.format === 'array' || newJSONSchema.format === 'datasource' || newJSONSchema.format === 'event' || newJSONSchema.format === 'object' || newJSONSchema.format === 'radio' || newJSONSchema.format === 'select') && exitPropertie(newJSONSchema.default)) {
|
|
1811
|
+
}
|
|
1812
|
+
// 3.不需要default属性的类型自动删除
|
|
1813
|
+
if ((newJSONSchema.format === 'quantity' || newJSONSchema.format === 'array' || newJSONSchema.format === 'datasource' || newJSONSchema.format === 'event' || newJSONSchema.format === 'object' || newJSONSchema.format === 'radio' || newJSONSchema.format === 'select') && hasProperties(newJSONSchema.default)) {
|
|
1893
1814
|
delete newJSONSchema.default; // 单位计量输入类型的默认值改放unit属性中
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1815
|
+
}
|
|
1816
|
+
// 转换旧版的radio类型的数据结构
|
|
1897
1817
|
if (newJSONSchema.format === 'radio') {
|
|
1898
1818
|
newJSONSchema.type = 'string';
|
|
1899
|
-
|
|
1900
1819
|
if (newJSONSchema.enum && newJSONSchema.enumextra) {
|
|
1901
1820
|
// 统一转换至items
|
|
1902
1821
|
newJSONSchema.items = {
|
|
1903
1822
|
type: 'string',
|
|
1904
1823
|
enum: objClone(newJSONSchema.enum),
|
|
1905
1824
|
enumextra: objClone(newJSONSchema.enumextra)
|
|
1906
|
-
};
|
|
1907
|
-
|
|
1825
|
+
};
|
|
1826
|
+
// 删除此前的enum、enumextra
|
|
1908
1827
|
delete newJSONSchema.enum;
|
|
1909
1828
|
delete newJSONSchema.enumextra;
|
|
1910
1829
|
}
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
|
|
1830
|
+
}
|
|
1831
|
+
// 转换旧版的quantity类型的数据结构
|
|
1914
1832
|
if (newJSONSchema.format === 'quantity') {
|
|
1915
1833
|
var curProperties = newJSONSchema.properties;
|
|
1916
1834
|
var newQuantitySchema = objClone(TypeDataList.quantity); // 新版quantity的schema数据对象
|
|
1917
|
-
|
|
1918
1835
|
if (curProperties.quantity && isObject(curProperties.quantity) && curProperties.quantity.default) {
|
|
1919
|
-
var oldDefault = curProperties.quantity.default;
|
|
1920
|
-
|
|
1836
|
+
var oldDefault = curProperties.quantity.default;
|
|
1837
|
+
// percent 自动转换成 %
|
|
1921
1838
|
newQuantitySchema.properties.quantity.default = oldDefault === 'percent' ? '%' : oldDefault;
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
|
|
1839
|
+
}
|
|
1840
|
+
// 融合新版schema数据
|
|
1925
1841
|
newJSONSchema = newQuantitySchema;
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
|
|
1842
|
+
}
|
|
1843
|
+
// 转换旧版的datasource类型的数据结构
|
|
1929
1844
|
if (newJSONSchema.format === 'datasource') {
|
|
1930
|
-
var _curProperties = newJSONSchema.properties;
|
|
1931
|
-
|
|
1845
|
+
var _curProperties = newJSONSchema.properties;
|
|
1846
|
+
// 先获取旧版的关键数据
|
|
1932
1847
|
var typeProp = _curProperties.type && _curProperties.type.default;
|
|
1933
1848
|
var dataProp = _curProperties.data && _curProperties.data.default;
|
|
1934
1849
|
var filterProp = _curProperties.filter && _curProperties.filter.default;
|
|
1935
|
-
|
|
1936
1850
|
if (typeProp === 'local') {
|
|
1937
1851
|
newJSONSchema = objClone(DataSourceTypeList.local);
|
|
1938
1852
|
newJSONSchema.properties.data.default = dataProp ? objClone(dataProp) : '{}';
|
|
@@ -1940,22 +1854,19 @@ function oldSchemaToNewSchema(oldSchema) {
|
|
|
1940
1854
|
newJSONSchema = objClone(DataSourceTypeList.remote);
|
|
1941
1855
|
newJSONSchema.properties.data.default = dataProp ? objClone(dataProp) : 'http://xxx';
|
|
1942
1856
|
}
|
|
1943
|
-
|
|
1944
1857
|
newJSONSchema.properties.filter.default = filterProp ? objClone(filterProp) : '() => {}';
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1858
|
+
}
|
|
1859
|
+
// 转换旧版的event类型的数据结构
|
|
1948
1860
|
if (newJSONSchema.format === 'event') {
|
|
1949
|
-
var _curProperties2 = newJSONSchema.properties;
|
|
1950
|
-
|
|
1951
|
-
var eventType = _curProperties2.type && _curProperties2.type.default;
|
|
1952
|
-
|
|
1861
|
+
var _curProperties2 = newJSONSchema.properties;
|
|
1862
|
+
// 先获取旧版的关键数据
|
|
1863
|
+
var eventType = _curProperties2.type && _curProperties2.type.default;
|
|
1864
|
+
// 重构Event的数据结构
|
|
1953
1865
|
if (eventType === 'in' || eventType === 'on') {
|
|
1954
1866
|
// 兼容旧版的'in'和新版的'on'
|
|
1955
1867
|
// 注册类事件: 新版type改成'on'
|
|
1956
1868
|
var eventFunc = _curProperties2.filter && _curProperties2.filter.default || '() => {}';
|
|
1957
1869
|
newJSONSchema = objClone(EventTypeDataList.on);
|
|
1958
|
-
|
|
1959
1870
|
if (_curProperties2.actionFunc && isObject(_curProperties2.actionFunc)) {
|
|
1960
1871
|
newJSONSchema.properties.actionFunc.default = _curProperties2.actionFunc.default || objClone(eventFunc);
|
|
1961
1872
|
}
|
|
@@ -1963,37 +1874,30 @@ function oldSchemaToNewSchema(oldSchema) {
|
|
|
1963
1874
|
// 其他,则默认为触发事件
|
|
1964
1875
|
// 注册类事件: 新版type改成'emit'
|
|
1965
1876
|
var _eventFunc = _curProperties2.filter && _curProperties2.filter.default || '{}';
|
|
1966
|
-
|
|
1967
1877
|
newJSONSchema = objClone(EventTypeDataList.emit);
|
|
1968
|
-
|
|
1969
1878
|
if (_curProperties2.eventData && isObject(_curProperties2.eventData)) {
|
|
1970
1879
|
newJSONSchema.properties.eventData.default = _curProperties2.eventData.default || objClone(_eventFunc);
|
|
1971
1880
|
}
|
|
1972
1881
|
}
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1882
|
+
}
|
|
1883
|
+
// 判断是否有propertyOrder属性
|
|
1976
1884
|
if (newJSONSchema.properties) {
|
|
1977
1885
|
// 3.重新生成required属性
|
|
1978
1886
|
newJSONSchema.required = Object.keys(newJSONSchema.properties);
|
|
1979
|
-
|
|
1980
1887
|
if (!newJSONSchema.propertyOrder) {
|
|
1981
1888
|
// 4.生成propertyOrder属性
|
|
1982
1889
|
newJSONSchema.propertyOrder = newJSONSchema.required;
|
|
1983
|
-
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1890
|
+
}
|
|
1891
|
+
// 5.继续遍历properties属性进行转换
|
|
1986
1892
|
newJSONSchema.propertyOrder.map(function (jsonKey) {
|
|
1987
1893
|
newJSONSchema.properties[jsonKey] = oldSchemaToNewSchema(newJSONSchema.properties[jsonKey]);
|
|
1988
1894
|
});
|
|
1989
|
-
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1895
|
+
}
|
|
1896
|
+
// 判断是否有items属性
|
|
1992
1897
|
if (newJSONSchema.items) {
|
|
1993
1898
|
// 6. 转换items中的数据
|
|
1994
1899
|
newJSONSchema.items = oldSchemaToNewSchema(newJSONSchema.items);
|
|
1995
1900
|
}
|
|
1996
|
-
|
|
1997
1901
|
return newJSONSchema;
|
|
1998
1902
|
}
|
|
1999
1903
|
|
|
@@ -2009,20 +1913,15 @@ function oldSchemaToNewSchema(oldSchema) {
|
|
|
2009
1913
|
* 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
|
|
2010
1914
|
* 备注:使用旧版数据,以便进行新旧数据融合
|
|
2011
1915
|
* */
|
|
2012
|
-
|
|
2013
1916
|
function baseSchema2JsonData(jsonSchema, jsonData) {
|
|
2014
1917
|
var curJsonData = '';
|
|
2015
1918
|
var oldValue = jsonData;
|
|
2016
|
-
|
|
2017
|
-
if (exitPropertie(oldValue) && exitPropertie(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
|
|
1919
|
+
if (hasProperties(oldValue) && hasProperties(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
|
|
2018
1920
|
// 表示当前数据类型发生变化,则丢弃旧版数据
|
|
2019
1921
|
oldValue = undefined;
|
|
2020
1922
|
}
|
|
2021
1923
|
/** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
var curValue = exitPropertie(oldValue) ? oldValue : jsonSchema.default;
|
|
2025
|
-
|
|
1924
|
+
var curValue = hasProperties(oldValue) ? oldValue : jsonSchema.default;
|
|
2026
1925
|
switch (jsonSchema.type) {
|
|
2027
1926
|
case 'string':
|
|
2028
1927
|
if (jsonSchema.format === 'typeSelect') {
|
|
@@ -2032,14 +1931,12 @@ function baseSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2032
1931
|
if (curValue === '#fff' || curValue === '#FFF') {
|
|
2033
1932
|
curValue = '#ffffff'; // 避免出现#fff类型的值,type=color不能识别
|
|
2034
1933
|
}
|
|
2035
|
-
|
|
2036
1934
|
curJsonData = curValue || '#ffffff';
|
|
2037
1935
|
} else if (jsonSchema.format === 'json' || jsonSchema.format === 'widget') {
|
|
2038
1936
|
/** 转成json类型进行特殊处理
|
|
2039
1937
|
* 需要保证json类型的数值是json对象 */
|
|
2040
1938
|
var curJsonItemData = ''; // 字符串类型的json数据
|
|
2041
1939
|
// 判断当前jsonData是否是对象类型
|
|
2042
|
-
|
|
2043
1940
|
if (isObject(jsonData) || isArray(jsonData)) {
|
|
2044
1941
|
curJsonItemData = jsonData;
|
|
2045
1942
|
} else if (isFunction(jsonData) || jsonData === '') {
|
|
@@ -2057,57 +1954,44 @@ function baseSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2057
1954
|
curJsonItemData = {};
|
|
2058
1955
|
}
|
|
2059
1956
|
}
|
|
2060
|
-
|
|
2061
1957
|
curJsonData = curJsonItemData;
|
|
2062
1958
|
} else {
|
|
2063
1959
|
// 其他类型允许出现空字符串
|
|
2064
|
-
curJsonData =
|
|
1960
|
+
curJsonData = hasProperties(curValue) ? curValue : '';
|
|
2065
1961
|
}
|
|
2066
|
-
|
|
2067
1962
|
break;
|
|
2068
|
-
|
|
2069
1963
|
case 'boolean':
|
|
2070
|
-
curJsonData =
|
|
1964
|
+
curJsonData = hasProperties(curValue) ? curValue : false;
|
|
2071
1965
|
break;
|
|
2072
|
-
|
|
2073
1966
|
case 'number':
|
|
2074
|
-
curJsonData =
|
|
1967
|
+
curJsonData = hasProperties(curValue) ? curValue : 1;
|
|
2075
1968
|
break;
|
|
2076
|
-
|
|
2077
1969
|
default:
|
|
2078
|
-
curJsonData =
|
|
1970
|
+
curJsonData = hasProperties(curValue) ? curValue : '';
|
|
2079
1971
|
}
|
|
2080
|
-
|
|
2081
1972
|
return curJsonData;
|
|
2082
1973
|
}
|
|
1974
|
+
|
|
2083
1975
|
/**
|
|
2084
1976
|
* Object类型的schema转jsonData
|
|
2085
1977
|
* 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
|
|
2086
1978
|
* 备注:使用旧版数据,以便进行新旧数据融合
|
|
2087
1979
|
* */
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
1980
|
function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
2091
1981
|
var curJsonData = {};
|
|
2092
1982
|
var curType = getCurrentFormat(jsonSchema);
|
|
2093
|
-
|
|
2094
1983
|
if (isObject(jsonSchema) && jsonSchema.type === 'object') {
|
|
2095
1984
|
var jsonItem = jsonSchema;
|
|
2096
1985
|
var oldValue = jsonData;
|
|
2097
|
-
|
|
2098
|
-
if (exitPropertie(oldValue) && exitPropertie(jsonItem.default) && typeof oldValue !== typeof jsonItem.default) {
|
|
1986
|
+
if (hasProperties(oldValue) && hasProperties(jsonItem.default) && typeof oldValue !== typeof jsonItem.default) {
|
|
2099
1987
|
// 表示当前数据类型发生变化,则丢弃旧版数据
|
|
2100
1988
|
oldValue = undefined;
|
|
2101
1989
|
}
|
|
2102
1990
|
/** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
var curValue = exitPropertie(oldValue) ? oldValue : jsonItem.default;
|
|
2106
|
-
|
|
1991
|
+
var curValue = hasProperties(oldValue) ? oldValue : jsonItem.default;
|
|
2107
1992
|
if (curType === 'dynamic-data') {
|
|
2108
1993
|
// 动态数据源类型(固定格式的Object类型)
|
|
2109
1994
|
curJsonData = objClone(EmptyDynamicDataCont);
|
|
2110
|
-
|
|
2111
1995
|
if (curValue && isObject(curValue) && JSON.stringify(curValue) !== '{}') {
|
|
2112
1996
|
curJsonData = Object.assign(curJsonData, curValue);
|
|
2113
1997
|
}
|
|
@@ -2118,17 +2002,15 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2118
2002
|
curJsonData = {
|
|
2119
2003
|
data: '{}',
|
|
2120
2004
|
filter: '() => {}'
|
|
2121
|
-
};
|
|
2122
|
-
|
|
2005
|
+
};
|
|
2006
|
+
// 读取旧值
|
|
2123
2007
|
if (curValue && curValue.data) {
|
|
2124
2008
|
curJsonData.data = curValue.data;
|
|
2125
2009
|
}
|
|
2126
|
-
|
|
2127
2010
|
if (curValue && curValue.filter) {
|
|
2128
2011
|
curJsonData.filter = curValue.filter;
|
|
2129
|
-
}
|
|
2130
|
-
|
|
2131
|
-
|
|
2012
|
+
}
|
|
2013
|
+
// 纠正data中的默认数据
|
|
2132
2014
|
if (curJsonData.data === 'http://xxx') {
|
|
2133
2015
|
curJsonData.data = '{}';
|
|
2134
2016
|
}
|
|
@@ -2137,17 +2019,15 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2137
2019
|
curJsonData = {
|
|
2138
2020
|
data: 'http://xxx',
|
|
2139
2021
|
filter: '() => {}'
|
|
2140
|
-
};
|
|
2141
|
-
|
|
2022
|
+
};
|
|
2023
|
+
// 读取旧值
|
|
2142
2024
|
if (curValue && curValue.data) {
|
|
2143
2025
|
curJsonData.data = curValue.data;
|
|
2144
2026
|
}
|
|
2145
|
-
|
|
2146
2027
|
if (curValue && curValue.filter) {
|
|
2147
2028
|
curJsonData.filter = curValue.filter;
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2029
|
+
}
|
|
2030
|
+
// 纠正data中的默认数据
|
|
2151
2031
|
if (curJsonData.data === '{}') {
|
|
2152
2032
|
curJsonData.data = 'http://xxx';
|
|
2153
2033
|
}
|
|
@@ -2167,12 +2047,11 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2167
2047
|
trigger: 'eventName',
|
|
2168
2048
|
// 兼容旧版数据
|
|
2169
2049
|
eventData: '{}'
|
|
2170
|
-
};
|
|
2171
|
-
|
|
2050
|
+
};
|
|
2051
|
+
// 读取旧值
|
|
2172
2052
|
if (curValue && curValue.trigger) {
|
|
2173
2053
|
curJsonData.trigger = curValue.trigger;
|
|
2174
2054
|
}
|
|
2175
|
-
|
|
2176
2055
|
if (curValue && curValue.eventData) {
|
|
2177
2056
|
curJsonData.eventData = curValue.eventData;
|
|
2178
2057
|
}
|
|
@@ -2183,19 +2062,17 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2183
2062
|
curJsonData = {
|
|
2184
2063
|
register: 'eventName',
|
|
2185
2064
|
actionFunc: curValue && curValue.filter || '() => {}' // 兼容旧版数据
|
|
2186
|
-
|
|
2187
2065
|
};
|
|
2188
2066
|
} else {
|
|
2189
2067
|
curJsonData = {
|
|
2190
2068
|
register: 'eventName',
|
|
2191
2069
|
// 兼容旧版数据
|
|
2192
2070
|
actionFunc: '() => {}'
|
|
2193
|
-
};
|
|
2194
|
-
|
|
2071
|
+
};
|
|
2072
|
+
// 读取旧值
|
|
2195
2073
|
if (curValue && curValue.register) {
|
|
2196
2074
|
curJsonData.register = curValue.register;
|
|
2197
2075
|
}
|
|
2198
|
-
|
|
2199
2076
|
if (curValue && curValue.actionFunc) {
|
|
2200
2077
|
curJsonData.actionFunc = curValue.actionFunc;
|
|
2201
2078
|
}
|
|
@@ -2203,28 +2080,23 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2203
2080
|
}
|
|
2204
2081
|
} else if (jsonSchema.properties) {
|
|
2205
2082
|
var curPropertyOrder = [];
|
|
2206
|
-
|
|
2207
2083
|
if (jsonSchema.propertyOrder) {
|
|
2208
2084
|
curPropertyOrder = jsonSchema.propertyOrder;
|
|
2209
2085
|
} else {
|
|
2210
2086
|
curPropertyOrder = Object.keys(jsonSchema.properties);
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2087
|
+
}
|
|
2088
|
+
// 其他非固定格式的Object类型
|
|
2214
2089
|
curPropertyOrder.map(function (jsonKey) {
|
|
2215
2090
|
var curJsonItem = jsonSchema.properties[jsonKey];
|
|
2216
2091
|
var curOldValue = jsonData && jsonData[jsonKey];
|
|
2217
|
-
|
|
2218
2092
|
switch (curJsonItem.type) {
|
|
2219
2093
|
case 'array':
|
|
2220
2094
|
curJsonData[jsonKey] = arraySchema2JsonData(curJsonItem, curOldValue);
|
|
2221
2095
|
break;
|
|
2222
|
-
|
|
2223
2096
|
case 'object':
|
|
2224
2097
|
// 普通对象类型
|
|
2225
2098
|
curJsonData[jsonKey] = objectSchema2JsonData(curJsonItem, curOldValue);
|
|
2226
2099
|
break;
|
|
2227
|
-
|
|
2228
2100
|
default:
|
|
2229
2101
|
// 其他基础类型
|
|
2230
2102
|
curJsonData[jsonKey] = baseSchema2JsonData(curJsonItem, curOldValue);
|
|
@@ -2232,32 +2104,26 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
|
|
|
2232
2104
|
});
|
|
2233
2105
|
}
|
|
2234
2106
|
}
|
|
2235
|
-
|
|
2236
2107
|
return curJsonData;
|
|
2237
2108
|
}
|
|
2109
|
+
|
|
2238
2110
|
/**
|
|
2239
2111
|
* Array类型的schema转jsonData
|
|
2240
2112
|
* 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
|
|
2241
2113
|
* 备注:使用旧版数据,以便进行新旧数据融合
|
|
2242
2114
|
* */
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
2115
|
function arraySchema2JsonData(jsonSchema, jsonData) {
|
|
2246
|
-
var curJsonData = [];
|
|
2247
|
-
|
|
2116
|
+
var curJsonData = [];
|
|
2117
|
+
// 判断是否是数组类型
|
|
2248
2118
|
if (jsonSchema && jsonSchema.type === 'array') {
|
|
2249
2119
|
// Array数据对象类型
|
|
2250
2120
|
var oldValue = jsonData;
|
|
2251
|
-
|
|
2252
|
-
if (exitPropertie(oldValue) && exitPropertie(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
|
|
2121
|
+
if (hasProperties(oldValue) && hasProperties(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
|
|
2253
2122
|
// 表示当前数据类型发生变化,则丢弃旧版数据
|
|
2254
2123
|
oldValue = undefined;
|
|
2255
2124
|
}
|
|
2256
2125
|
/** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
var curValue = exitPropertie(oldValue) ? oldValue : jsonSchema.default;
|
|
2260
|
-
|
|
2126
|
+
var curValue = hasProperties(oldValue) ? oldValue : jsonSchema.default;
|
|
2261
2127
|
if (jsonSchema.format === 'array') {
|
|
2262
2128
|
if (isArray(curValue)) {
|
|
2263
2129
|
curValue.map(function (arrItem) {
|
|
@@ -2269,21 +2135,18 @@ function arraySchema2JsonData(jsonSchema, jsonData) {
|
|
|
2269
2135
|
}
|
|
2270
2136
|
} else {
|
|
2271
2137
|
// 考虑select类型(多选的数值也是以array对象记录)
|
|
2272
|
-
curJsonData =
|
|
2138
|
+
curJsonData = hasProperties(curValue) ? curValue : [];
|
|
2273
2139
|
}
|
|
2274
2140
|
}
|
|
2275
|
-
|
|
2276
2141
|
return curJsonData;
|
|
2277
2142
|
}
|
|
2143
|
+
|
|
2278
2144
|
/**
|
|
2279
2145
|
* 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
|
|
2280
2146
|
* 备注:使用旧版数据,以便进行新旧数据融合
|
|
2281
2147
|
* */
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
2148
|
function schema2json(jsonSchema, jsonData) {
|
|
2285
2149
|
var curJsonData = {};
|
|
2286
|
-
|
|
2287
2150
|
if (jsonSchema.type === 'object') {
|
|
2288
2151
|
curJsonData = objectSchema2JsonData(jsonSchema, jsonData);
|
|
2289
2152
|
} else if (jsonSchema.type === 'array') {
|
|
@@ -2291,7 +2154,6 @@ function schema2json(jsonSchema, jsonData) {
|
|
|
2291
2154
|
} else {
|
|
2292
2155
|
curJsonData = baseSchema2JsonData(jsonSchema, jsonData);
|
|
2293
2156
|
}
|
|
2294
|
-
|
|
2295
2157
|
return curJsonData;
|
|
2296
2158
|
}
|
|
2297
2159
|
|
|
@@ -2301,6 +2163,7 @@ function schema2json(jsonSchema, jsonData) {
|
|
|
2301
2163
|
* 10个特殊类型组件(Object、Array、Json、datasource、DynamicData、Event、CodeArea、htmlArea、quantity、widget)
|
|
2302
2164
|
*/
|
|
2303
2165
|
|
|
2166
|
+
// 类型数据清单
|
|
2304
2167
|
var schemaMetaList = TypeDataList;
|
|
2305
2168
|
|
|
2306
2169
|
/**
|
|
@@ -2377,15 +2240,14 @@ var schemaMetaList = TypeDataList;
|
|
|
2377
2240
|
}
|
|
2378
2241
|
*/
|
|
2379
2242
|
function dynamicDataAnalyzer(curJsonData, analyzerResult) {
|
|
2380
|
-
var curAnalyzerResult = analyzerResult || [];
|
|
2381
|
-
|
|
2243
|
+
var curAnalyzerResult = analyzerResult || [];
|
|
2244
|
+
// 根据当前schema数据分析使用到的元数据情况
|
|
2382
2245
|
if (curJsonData && JSON.stringify(curJsonData) !== '{}') {
|
|
2383
2246
|
if (isObject(curJsonData)) {
|
|
2384
2247
|
// const curJsonMap = Object.keys(curJsonData); // 动态数据类型的jsonData包含四个数值:type、config(dataName/body/filter)、data、localFilter
|
|
2385
2248
|
// 判断是否是动态数据类型
|
|
2386
|
-
if (curJsonData.type && curJsonData.type === 'remote' && curJsonData.config && isObject(curJsonData.config) && curJsonData.config.dataName &&
|
|
2249
|
+
if (curJsonData.type && curJsonData.type === 'remote' && curJsonData.config && isObject(curJsonData.config) && curJsonData.config.dataName && hasProperties(curJsonData.localFilter) && hasProperties(curJsonData.data)) {
|
|
2387
2250
|
var apiParams = curJsonData.config.body;
|
|
2388
|
-
|
|
2389
2251
|
if (apiParams && !isObject(apiParams)) {
|
|
2390
2252
|
try {
|
|
2391
2253
|
apiParams = JSON.parse(apiParams);
|
|
@@ -2393,7 +2255,6 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
|
|
|
2393
2255
|
apiParams = {};
|
|
2394
2256
|
}
|
|
2395
2257
|
}
|
|
2396
|
-
|
|
2397
2258
|
curAnalyzerResult.push({
|
|
2398
2259
|
id: curJsonData.config.id,
|
|
2399
2260
|
dataName: curJsonData.config.dataName,
|
|
@@ -2411,7 +2272,6 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
|
|
|
2411
2272
|
});
|
|
2412
2273
|
}
|
|
2413
2274
|
}
|
|
2414
|
-
|
|
2415
2275
|
return curAnalyzerResult;
|
|
2416
2276
|
}
|
|
2417
2277
|
|
|
@@ -2445,13 +2305,12 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
|
|
|
2445
2305
|
},
|
|
2446
2306
|
];
|
|
2447
2307
|
*/
|
|
2308
|
+
|
|
2448
2309
|
/**
|
|
2449
2310
|
* DataRoute转真实数据路径
|
|
2450
2311
|
* */
|
|
2451
|
-
|
|
2452
2312
|
function dataRoute2dataPath(dataRoute, baseDataPath) {
|
|
2453
2313
|
var dataPath = baseDataPath || 'data'; // 默认数据根路径值为data
|
|
2454
|
-
|
|
2455
2314
|
var dataRouteArr = dataRoute.split('-');
|
|
2456
2315
|
dataRouteArr.map(function (path) {
|
|
2457
2316
|
if (/^\d+$/.test(path)) {
|
|
@@ -2462,19 +2321,17 @@ function dataRoute2dataPath(dataRoute, baseDataPath) {
|
|
|
2462
2321
|
});
|
|
2463
2322
|
return dataPath;
|
|
2464
2323
|
}
|
|
2324
|
+
|
|
2465
2325
|
/**
|
|
2466
2326
|
* mockData转treeData(供antd的TreeSelect使用)
|
|
2467
2327
|
* */
|
|
2468
|
-
|
|
2469
2328
|
function json2treeData(mockData, parentDataRoute) {
|
|
2470
2329
|
var treeData = [];
|
|
2471
|
-
|
|
2472
2330
|
if (isObject(mockData)) {
|
|
2473
2331
|
var mockDataProps = Object.keys(mockData);
|
|
2474
2332
|
mockDataProps.map(function (propKey) {
|
|
2475
2333
|
var mockDataItem = mockData[propKey];
|
|
2476
2334
|
var curDataRoute = parentDataRoute ? parentDataRoute + "-" + propKey : propKey;
|
|
2477
|
-
|
|
2478
2335
|
if (isObject(mockDataItem) || isArray(mockDataItem)) {
|
|
2479
2336
|
treeData.push({
|
|
2480
2337
|
title: propKey,
|
|
@@ -2494,7 +2351,6 @@ function json2treeData(mockData, parentDataRoute) {
|
|
|
2494
2351
|
mockData.map(function (mockDataItem, index) {
|
|
2495
2352
|
var indexStr = index.toString();
|
|
2496
2353
|
var curDataRoute = parentDataRoute ? parentDataRoute + "-" + index : indexStr;
|
|
2497
|
-
|
|
2498
2354
|
if (isObject(mockDataItem) || isArray(mockDataItem)) {
|
|
2499
2355
|
treeData.push({
|
|
2500
2356
|
title: indexStr,
|
|
@@ -2511,7 +2367,6 @@ function json2treeData(mockData, parentDataRoute) {
|
|
|
2511
2367
|
}
|
|
2512
2368
|
});
|
|
2513
2369
|
}
|
|
2514
|
-
|
|
2515
2370
|
return treeData;
|
|
2516
2371
|
}
|
|
2517
2372
|
|
|
@@ -2523,10 +2378,10 @@ function getParentKeyRoute(curKeyRoute) {
|
|
|
2523
2378
|
curKeyArr.pop();
|
|
2524
2379
|
return curKeyArr.join('-');
|
|
2525
2380
|
}
|
|
2381
|
+
|
|
2526
2382
|
/**
|
|
2527
2383
|
* 获取父元素的key路径值和当前key
|
|
2528
2384
|
*/
|
|
2529
|
-
|
|
2530
2385
|
function getParentKeyRoute_CurKey(curKeyRoute) {
|
|
2531
2386
|
var curKeyArr = curKeyRoute.split('-');
|
|
2532
2387
|
var curKey = curKeyArr.pop();
|
|
@@ -2536,4 +2391,4 @@ function getParentKeyRoute_CurKey(curKeyRoute) {
|
|
|
2536
2391
|
// JSONSchema关键字清单
|
|
2537
2392
|
var KeyWordList = ['key', 'enum', 'enumextra', 'items', 'input', 'boolean', 'number', 'color', 'url', 'textarea', 'text-editor', 'radio', 'single-select', 'select', 'date', 'date-time', 'time', 'json', 'codearea', 'htmlarea', 'quantity', 'box-style', 'dynamic-data', 'datasource', 'event', 'array', 'object', 'widget', 'widgets', 'widgetUUID', 'embedWidgetList'];
|
|
2538
2393
|
|
|
2539
|
-
export { DataSourceTypeList, EventTypeDataList, KeyWordList, TypeDataList, dataRoute2dataPath, dynamicDataAnalyzer,
|
|
2394
|
+
export { DataSourceTypeList, EventTypeDataList, KeyWordList, TypeDataList, dataRoute2dataPath, dynamicDataAnalyzer, getCurPosition, getCurrentFormat, getJsonDataByKeyRoute, getNextIndexRoute, getParentIndexRoute, getParentIndexRoute_CurIndex, getParentKeyRoute, getParentKeyRoute_CurKey, getSchemaByIndexRoute, getSchemaByKeyRoute, hasProperties, indexRoute2keyRoute, isArray, isBoolean, isBoxSchemaData, isColor, isDateStr, isDateTimeStr, isEmptySchema, isEmptyWidgetSchema, isEqual, isFirstSchemaData, isFunction, isNewSchemaData, isNumber, isObject, isQuantity, isSameParent, isSelect, isString, isStructuredSchema, isTimeStr, isURL, isUsedToWidgetConfig, json2schema, json2treeData, keyRoute2indexRoute, metaElemAnalyzer, moveBackward, moveForward, objClone, oldSchemaToNewSchema, schema2json, schemaMetaList };
|