@wibetter/json-utils 1.3.2 → 5.0.1

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/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
- var newObj = JSON.stringify(targetObj);
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
- function exitPropertie(targetPropertie) {
15
- var exitPropertie = false;
16
-
17
- if (targetPropertie !== undefined && targetPropertie !== null) {
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'; // 1、先根据路径值获取key值
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
- } // 2、根据key值获取对应的json数据对象
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'; // 1、先根据路径值获取key值
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
- } // 2、根据key值获取对应的json数据对象
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; // 1、先根据路径值获取key值
192
-
166
+ var curIndex = -1;
167
+ // 1、先根据路径值获取key值
193
168
  if (curJsonSchemaObj.propertyOrder) {
194
- curIndex = curJsonSchemaObj.propertyOrder.indexOf(curKey); // 2、根据key值获取对应的json数据对象
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); // 2、根据key值获取对应的json数据对象
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
 
@@ -930,9 +902,9 @@ var initHtmlAreaData = {
930
902
  * required:存放所有子字段的key值,用于验证子字段项是否存在,同时required可充当排序功能
931
903
  * propertyOrder:按序存放所有子字段的key值(排序功能)
932
904
  * */
905
+
933
906
  /** 新版EventData
934
907
  * type: emit 的默认数据 */
935
-
936
908
  var initEventData = {
937
909
  type: 'object',
938
910
  format: 'event',
@@ -975,9 +947,9 @@ var initEventData = {
975
947
  required: ['type', 'trigger', 'eventData'],
976
948
  propertyOrder: ['type', 'trigger', 'eventData']
977
949
  };
950
+
978
951
  /** 新版EventData
979
952
  * type: on 的默认数据 */
980
-
981
953
  var initEventDataTypeON = {
982
954
  type: 'object',
983
955
  format: 'event',
@@ -1067,8 +1039,9 @@ var initDataSourceData = {
1067
1039
  },
1068
1040
  required: ['type', 'data', 'filter'],
1069
1041
  propertyOrder: ['type', 'data', 'filter']
1070
- }; // 默认是用于展示local本地数据源的,如果展示远程数据源使用initDataSourceDataV2
1042
+ };
1071
1043
 
1044
+ // 默认是用于展示local本地数据源的,如果展示远程数据源使用initDataSourceDataV2
1072
1045
  var initDataSourceDataV2 = {
1073
1046
  type: 'object',
1074
1047
  format: 'datasource',
@@ -1185,8 +1158,9 @@ var initDynamicData = {
1185
1158
  },
1186
1159
  required: ['type', 'config', 'data', 'localFilter'],
1187
1160
  propertyOrder: ['type', 'config', 'data', 'localFilter']
1188
- }; // 动态数据对应的空json数据内容
1161
+ };
1189
1162
 
1163
+ // 动态数据对应的空json数据内容
1190
1164
  var EmptyDynamicDataCont = {
1191
1165
  type: 'local',
1192
1166
  config: {
@@ -1199,7 +1173,7 @@ var EmptyDynamicDataCont = {
1199
1173
  data: '{}',
1200
1174
  // 用于存储结果数据
1201
1175
  localFilter: 'return data;'
1202
- }; // 示例对象: 动态数据类型-接口数据 对应的json数据内容
1176
+ };
1203
1177
 
1204
1178
  /* widget类型字段
1205
1179
  * 【字段属性说明】
@@ -1222,9 +1196,9 @@ var initWidgetData = {
1222
1196
  // 字段项的说明和描述
1223
1197
  isRequired: false,
1224
1198
  readOnly: true // 默认只读
1225
-
1226
1199
  };
1227
1200
 
1201
+ // 类型数据清单
1228
1202
  var TypeDataList = {
1229
1203
  jsonschema: initJSONSchemaData,
1230
1204
  input: initInputData,
@@ -1254,125 +1228,120 @@ var TypeDataList = {
1254
1228
  datasource: initDataSourceData,
1255
1229
  event: initEventData,
1256
1230
  widget: initWidgetData
1257
- }; // 事件类型数据
1231
+ };
1258
1232
 
1233
+ // 事件类型数据
1259
1234
  var EventTypeDataList = {
1260
1235
  on: initEventDataTypeON,
1261
1236
  emit: initEventData
1262
- }; // 数据源类型
1237
+ };
1263
1238
 
1239
+ // 数据源类型
1264
1240
  var DataSourceTypeList = {
1265
1241
  local: initDataSourceData,
1266
1242
  remote: initDataSourceDataV2
1267
1243
  };
1268
1244
 
1245
+ // 判断是否是URL地址类型
1269
1246
  function isURL(s) {
1270
1247
  return /^http[s]?:\/\/.*/.test(s);
1271
- } // 判断是否是字符串类型
1272
-
1248
+ }
1249
+ // 判断是否是字符串类型
1273
1250
  function isString(o) {
1274
1251
  return Object.prototype.toString.call(o).slice(8, -1) === 'String';
1275
- } // 判断是否是数字类型
1276
-
1252
+ }
1253
+ // 判断是否是数字类型
1277
1254
  function isNumber(value) {
1278
1255
  return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]';
1279
- } // 判断是否是Boolean类型
1280
-
1256
+ }
1257
+ // 判断是否是Boolean类型
1281
1258
  function isBoolean(o) {
1282
1259
  return Object.prototype.toString.call(o).slice(8, -1) === 'Boolean';
1283
- } // 判断是否是年月日的时间类型
1260
+ }
1284
1261
 
1262
+ // 判断是否是年月日的时间类型
1285
1263
  function isDateStr(dateStr) {
1286
1264
  return /^\d{4}-\d{2}-\d{2}$/.test(dateStr);
1287
- } // 判断是否是年月日时分的时间类型
1265
+ }
1288
1266
 
1267
+ // 判断是否是年月日时分的时间类型
1289
1268
  function isDateTimeStr(dateStr) {
1290
1269
  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
- } // 判断是否是时分的时间类型
1270
+ }
1292
1271
 
1272
+ // 判断是否是时分的时间类型
1293
1273
  function isTimeStr(dateStr) {
1294
1274
  return /^\d{2}:\d{2}:\d{2}$/.test(dateStr) || /^\d{2}:\d{2}$/.test(dateStr);
1295
1275
  }
1276
+
1296
1277
  /**
1297
1278
  * 判断是否是数组类型
1298
1279
  * */
1299
-
1300
1280
  function isArray(curObj) {
1301
1281
  var isArray = false;
1302
-
1303
1282
  if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Array') {
1304
1283
  isArray = true;
1305
1284
  }
1306
-
1307
1285
  return isArray;
1308
1286
  }
1287
+
1309
1288
  /**
1310
1289
  * 判断是否是select多选类型(基础类型的array)
1311
1290
  * select类型一定是一个array类型
1312
1291
  * */
1313
-
1314
1292
  function isSelect(curObj) {
1315
1293
  if (!isArray(curObj)) {
1316
1294
  return false;
1317
1295
  }
1318
-
1319
1296
  for (var ind = 0, size = curObj.length; ind < size; ind++) {
1320
1297
  var arrItem = curObj[ind];
1321
-
1322
1298
  if (!isString(arrItem)) {
1323
1299
  // 只要有一个不是string类型就认为不是select
1324
1300
  return false;
1325
1301
  }
1326
1302
  }
1327
-
1328
1303
  return true;
1329
1304
  }
1305
+
1330
1306
  /**
1331
1307
  * 判断是否是对象类型
1332
1308
  * */
1333
-
1334
1309
  function isObject(curObj) {
1335
1310
  var isObject = false;
1336
-
1337
1311
  if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Object') {
1338
1312
  isObject = true;
1339
1313
  }
1340
-
1341
1314
  return isObject;
1342
1315
  }
1316
+
1343
1317
  /**
1344
1318
  * 判断是否是单位类型
1345
1319
  * */
1346
-
1347
1320
  function isQuantity(val) {
1348
- var isObject = false; // 获取当前计量单位元素可选的单位类型
1349
-
1321
+ var isObject = false;
1322
+ // 获取当前计量单位元素可选的单位类型
1350
1323
  var quantityList = TypeDataList.quantity.properties.quantity.enum;
1351
-
1352
1324
  if (quantityList.indexOf(val) >= 0) {
1353
1325
  isObject = true;
1354
1326
  }
1355
-
1356
1327
  return isObject;
1357
1328
  }
1329
+
1358
1330
  /**
1359
1331
  * 判断是否是颜色值
1360
1332
  * */
1361
-
1362
1333
  function isColor(colorVal) {
1363
1334
  return /^#[0-9a-f]{6}$/.test(colorVal) || /^#[0-9a-f]{3}$/.test(colorVal);
1364
1335
  }
1336
+
1365
1337
  /**
1366
1338
  * 判断是否是函数类型
1367
1339
  * */
1368
-
1369
1340
  function isFunction(curObj) {
1370
1341
  var isFunction = false;
1371
-
1372
1342
  if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Function') {
1373
1343
  isFunction = true;
1374
1344
  }
1375
-
1376
1345
  return isFunction;
1377
1346
  }
1378
1347
 
@@ -1380,15 +1349,14 @@ function isFunction(curObj) {
1380
1349
  * json2schema:根据json数据内容获取对应的schema数据
1381
1350
  * 当前包含三个转换方法:baseJson2Schema、objectJson2Schema、arrayJson2Schema
1382
1351
  * */
1352
+
1383
1353
  /**
1384
1354
  * 基础类型的jsonData转schema
1385
1355
  * 备注:目前可转换Boolean、Number、URL、Date、DateTime、Time、color、json类型
1386
1356
  * 其中textarea、radio、codearea和htmlarea的数值不好和input区分,故均转换为input类型
1387
1357
  * */
1388
-
1389
1358
  function baseJson2Schema(jsonData) {
1390
1359
  var curJsonSchema = '';
1391
-
1392
1360
  if (isBoolean(jsonData)) {
1393
1361
  // 1、Boolean类型
1394
1362
  curJsonSchema = objClone(TypeDataList.boolean);
@@ -1414,7 +1382,6 @@ function baseJson2Schema(jsonData) {
1414
1382
  try {
1415
1383
  // json数据类型:进行格式化(检查是否是合格的json字符串数据)
1416
1384
  var jsonDataObj = JSON.parse(jsonData);
1417
-
1418
1385
  if (isNumber(jsonDataObj)) {
1419
1386
  // 简单数字字符串类型数值统一认为是字符串类型
1420
1387
  curJsonSchema = objClone(TypeDataList.input);
@@ -1433,21 +1400,17 @@ function baseJson2Schema(jsonData) {
1433
1400
  }
1434
1401
  }
1435
1402
  }
1436
-
1437
1403
  return curJsonSchema;
1438
1404
  }
1405
+
1439
1406
  /**
1440
1407
  * Object类型的jsonData转schema
1441
1408
  * 备注:目前可转换datasource、event、quantity、object四种对象类型
1442
1409
  * */
1443
-
1444
-
1445
1410
  function objectJson2Schema(jsonData) {
1446
1411
  var curJsonSchema;
1447
-
1448
1412
  if (isObject(jsonData)) {
1449
1413
  var properties = Object.keys(jsonData);
1450
-
1451
1414
  if (jsonData.data && jsonData.filter && properties.length === 2) {
1452
1415
  // DataSource数据源类型
1453
1416
  if (isArray(jsonData.data) || isObject(jsonData.data)) {
@@ -1470,34 +1433,30 @@ function objectJson2Schema(jsonData) {
1470
1433
  // 其他非固定格式的Object类型
1471
1434
  curJsonSchema = objClone(TypeDataList['empty-object']); // 新建空数组对象schema
1472
1435
  // 遍历子数据项目
1473
-
1474
1436
  Object.keys(jsonData).map(function (jsonKey) {
1475
1437
  var curJsonItem = jsonData[jsonKey];
1476
1438
  curJsonSchema.properties[jsonKey] = json2schema(curJsonItem);
1477
1439
  });
1478
1440
  }
1479
1441
  }
1480
-
1481
1442
  return curJsonSchema;
1482
1443
  }
1444
+
1483
1445
  /**
1484
1446
  * Array类型的jsonData转schema
1485
1447
  * 备注:目前可转换select、array两种数组类型
1486
1448
  * */
1487
-
1488
-
1489
1449
  function arrayJson2Schema(jsonData) {
1490
- var curJsonSchema; // 判断是否是数组类型
1491
-
1450
+ var curJsonSchema;
1451
+ // 判断是否是数组类型
1492
1452
  if (jsonData && isArray(jsonData)) {
1493
1453
  // 判断是否select类型(select类型是字符串类型的array)
1494
1454
  if (isSelect(jsonData)) {
1495
- curJsonSchema = objClone(TypeDataList.select); // 将当前jsonData的值设置为select的选项值
1496
-
1455
+ curJsonSchema = objClone(TypeDataList.select);
1456
+ // 将当前jsonData的值设置为select的选项值
1497
1457
  curJsonSchema.items.enum = jsonData;
1498
1458
  var enumextraLength = curJsonSchema.items.enumextra.length;
1499
1459
  var arrLength = jsonData.length;
1500
-
1501
1460
  if (arrLength > enumextraLength) {
1502
1461
  // 如果当前jsonDats的数值个数大于selectSchemaData的选项个数,则需要进行补充
1503
1462
  for (var ind = enumextraLength, size = arrLength; ind < size; ind++) {
@@ -1507,23 +1466,18 @@ function arrayJson2Schema(jsonData) {
1507
1466
  } else {
1508
1467
  curJsonSchema = objClone(TypeDataList['empty-array']); // 新建空数组对象schema
1509
1468
  // 根据第一个数组项获取items的schema对象
1510
-
1511
1469
  var arrItemObj = json2schema(jsonData[0]); // 正常情况下,Array的一级子对象是Object类型
1512
-
1513
1470
  curJsonSchema.items.properties = arrItemObj.properties;
1514
1471
  }
1515
1472
  }
1516
-
1517
1473
  return curJsonSchema;
1518
1474
  }
1475
+
1519
1476
  /**
1520
1477
  * 根据jsonData生成一份对应的jsonSchema
1521
1478
  * */
1522
-
1523
-
1524
1479
  function json2schema(jsonData) {
1525
1480
  var curJsonSchema = {};
1526
-
1527
1481
  if (jsonData && isObject(jsonData)) {
1528
1482
  curJsonSchema = objectJson2Schema(jsonData);
1529
1483
  } else if (jsonData && isArray(jsonData)) {
@@ -1531,7 +1485,6 @@ function json2schema(jsonData) {
1531
1485
  } else {
1532
1486
  curJsonSchema = baseJson2Schema(jsonData);
1533
1487
  }
1534
-
1535
1488
  return curJsonSchema;
1536
1489
  }
1537
1490
 
@@ -1545,7 +1498,6 @@ function json2schema(jsonData) {
1545
1498
  */
1546
1499
  function getCurrentFormat(targetJsonData) {
1547
1500
  var currentType = targetJsonData && targetJsonData.format;
1548
-
1549
1501
  if (!currentType) {
1550
1502
  if (targetJsonData && targetJsonData.type) {
1551
1503
  currentType = targetJsonData.type;
@@ -1553,22 +1505,18 @@ function getCurrentFormat(targetJsonData) {
1553
1505
  currentType = 'input';
1554
1506
  }
1555
1507
  }
1556
-
1557
1508
  return currentType;
1558
1509
  }
1510
+
1559
1511
  /** 判断是否为空的Schema
1560
1512
  * 包括 通用schema和组件配置专用的schema
1561
1513
  * */
1562
-
1563
1514
  function isEmptySchema(targetJsonSchema) {
1564
1515
  var isEmpty = true;
1565
-
1566
1516
  if (!targetJsonSchema) {
1567
1517
  return isEmpty;
1568
1518
  }
1569
-
1570
1519
  var curType = getCurrentFormat(targetJsonSchema);
1571
-
1572
1520
  if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.propertyOrder.length > 0) {
1573
1521
  // Object对象类型
1574
1522
  isEmpty = false;
@@ -1579,104 +1527,89 @@ function isEmptySchema(targetJsonSchema) {
1579
1527
  // 其他基本类型
1580
1528
  isEmpty = false;
1581
1529
  }
1582
-
1583
1530
  return isEmpty;
1584
1531
  }
1532
+
1585
1533
  /** 判断是否为空的WidgetSchema
1586
1534
  * 备注:WidgetSchema 一级字段必须为object,且有三个子属性:func、style、data
1587
1535
  * */
1588
-
1589
1536
  function isEmptyWidgetSchema(targetJsonSchema) {
1590
1537
  var isEmpty = true;
1591
-
1592
1538
  if (targetJsonSchema) {
1593
1539
  var curType = getCurrentFormat(targetJsonSchema);
1594
-
1595
1540
  if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.propertyOrder.length > 0) {
1596
1541
  var funcSchema = targetJsonSchema.properties.func || {};
1597
1542
  var styleSchema = targetJsonSchema.properties.style || {};
1598
1543
  var dataSchema = targetJsonSchema.properties.data || {};
1599
-
1600
1544
  if (funcSchema.propertyOrder && funcSchema.propertyOrder.length > 0 || styleSchema.propertyOrder && styleSchema.propertyOrder.length > 0 || dataSchema.propertyOrder && dataSchema.propertyOrder.length > 0) {
1601
1545
  isEmpty = false;
1602
1546
  }
1603
1547
  }
1604
1548
  }
1605
-
1606
1549
  return isEmpty;
1607
1550
  }
1551
+
1608
1552
  /** 判断是否为用于组件配置的jsonSchema数据
1609
1553
  * 备注:一级字段必须为object(用于规避非法的jsonSchema数据,以及结构单一的jsonSchema数据)
1610
1554
  * 且具备固定的三个子属性(func、style、data)
1611
1555
  * */
1612
-
1613
1556
  function isUsedToWidgetConfig(targetJsonSchema) {
1614
1557
  var isWidgetConfig = false;
1615
-
1616
1558
  if (targetJsonSchema) {
1617
1559
  var curType = getCurrentFormat(targetJsonSchema);
1618
-
1619
1560
  if (curType === 'object' && targetJsonSchema.properties && targetJsonSchema.propertyOrder && targetJsonSchema.properties.func && targetJsonSchema.properties.style && targetJsonSchema.properties.data) {
1620
1561
  isWidgetConfig = true;
1621
1562
  }
1622
1563
  }
1623
-
1624
1564
  return isWidgetConfig;
1625
1565
  }
1566
+
1626
1567
  /**
1627
1568
  * 判断是否是最新版的schema数据
1628
1569
  * 备注:确保当前schema数据是通过@wibetter/json-schema-editor生成的
1629
1570
  * */
1630
-
1631
1571
  function isNewSchemaData(schemaData) {
1632
1572
  var isNewVersion = false;
1633
- var lastUpdateTime = schemaData.lastUpdateTime; // 从那一刻开始就认为是新版JSONSchema
1634
-
1573
+ var lastUpdateTime = schemaData.lastUpdateTime;
1574
+ // 从那一刻开始就认为是新版JSONSchema
1635
1575
  var newVersionTime = new Date('2020-07-29T07:30:00.691Z').getTime();
1636
-
1637
1576
  if (lastUpdateTime && new Date(lastUpdateTime).getTime() >= newVersionTime) {
1638
1577
  isNewVersion = true;
1639
1578
  }
1640
-
1641
1579
  return isNewVersion;
1642
1580
  }
1581
+
1643
1582
  /** 根据format判断是否是容器类型字段
1644
1583
  * 容器类型字段:func、style、data、object
1645
1584
  * 主要用于判断当前元素点击新增时是添加子元素还是添加兄弟节点,容器类型点击新增时则添加子节点。
1646
1585
  * 备注:array类型字段只有固定的一个items属性,不能新增其他子元素。
1647
1586
  * */
1648
-
1649
1587
  function isBoxSchemaData(format) {
1650
1588
  var isBoxSchema = false;
1651
-
1652
1589
  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
1590
  isBoxSchema = true;
1654
1591
  }
1655
-
1656
1592
  return isBoxSchema;
1657
1593
  }
1594
+
1658
1595
  /** 根据format判断是否是一级类型字段
1659
1596
  * 一级类型字段:func、style、data、props、event-schema、widgets
1660
1597
  * 备注:一级类型字段不允许拖拽和复制
1661
1598
  * */
1662
-
1663
1599
  function isFirstSchemaData(format) {
1664
1600
  var isFirstSchema = false;
1665
-
1666
1601
  if (format === 'func' || format === 'style' || format === 'data' || format === 'props' || format === 'event-schema' || format === 'widgets') {
1667
1602
  isFirstSchema = true;
1668
1603
  }
1669
-
1670
1604
  return isFirstSchema;
1671
1605
  }
1606
+
1672
1607
  /** 判断是否是结构化的schema数据,
1673
1608
  * 判定条件:一级schema为object类型,其所有二级schema也为object类型
1674
1609
  * */
1675
-
1676
1610
  function isStructuredSchema(jsonSchema) {
1677
1611
  var isStructured = true;
1678
1612
  var currentType = jsonSchema.type || getCurrentFormat(jsonSchema);
1679
-
1680
1613
  if (currentType !== 'object' || !jsonSchema.propertyOrder || !jsonSchema.properties) {
1681
1614
  isStructured = false;
1682
1615
  } else {
@@ -1684,70 +1617,61 @@ function isStructuredSchema(jsonSchema) {
1684
1617
  /** 1. 获取当前schema对象 */
1685
1618
  var curSchemaData = jsonSchema.properties[key];
1686
1619
  /** 2. 判断是否是容器类型元素,如果是则禁止选中 */
1687
-
1688
1620
  var curType = jsonSchema.type || getCurrentFormat(curSchemaData);
1689
-
1690
1621
  if (curType !== 'object' || !curSchemaData.propertyOrder || !curSchemaData.properties) {
1691
1622
  isStructured = false;
1692
1623
  }
1693
1624
  });
1694
1625
  }
1695
-
1696
1626
  return isStructured;
1697
1627
  }
1628
+
1698
1629
  /**
1699
1630
  * 判断是否是同一个父元素
1700
1631
  * 备注:用于判断两个元素是否在同一个父级容器中
1701
1632
  */
1702
-
1703
1633
  function isSameParent(curIndex, targetIndex) {
1704
1634
  var curIndexArr = curIndex.split('-');
1705
1635
  var targetIndexArr = targetIndex.split('-');
1706
1636
  curIndexArr.pop();
1707
1637
  targetIndexArr.pop();
1708
-
1709
1638
  if (curIndexArr.join('-') === targetIndexArr.join('-')) {
1710
1639
  return true;
1711
1640
  }
1712
-
1713
1641
  return false;
1714
1642
  }
1643
+
1715
1644
  /**
1716
1645
  * 判断当前元素在目标元素的位置 前 or 后(根据当前元素的位置和目标元素的位置)
1717
1646
  */
1718
-
1719
1647
  function getCurPosition(curIndex, targetIndex) {
1720
1648
  var curIndexArr = curIndex.split('-');
1721
1649
  var targetIndexArr = targetIndex.split('-');
1722
1650
  var curPosition = 'before'; // 默认在目标元素的前面
1723
1651
  // 使用短的路径进行遍历(避免空指针)
1724
-
1725
1652
  var forEachArr = curIndexArr.length > targetIndexArr.length ? targetIndexArr : curIndexArr;
1726
-
1727
1653
  for (var index = 0, size = forEachArr.length; index < size; index += 1) {
1728
1654
  var curIndexItem = Number(curIndexArr[index]);
1729
1655
  var targetIndexItem = Number(targetIndexArr[index]);
1730
-
1731
1656
  if (curIndexItem > targetIndexItem) {
1732
1657
  curPosition = 'after'; // 表示当前元素在目标元素的后面
1733
1658
  }
1734
1659
  }
1735
-
1736
1660
  return curPosition;
1737
1661
  }
1662
+
1738
1663
  /**
1739
1664
  * 获取父元素的路径值
1740
1665
  */
1741
-
1742
1666
  function getParentIndexRoute(curIndexRoute) {
1743
1667
  var curIndexArr = curIndexRoute.split('-');
1744
1668
  curIndexArr.pop();
1745
1669
  return curIndexArr.join('-');
1746
1670
  }
1671
+
1747
1672
  /**
1748
1673
  * 获取下一个兄弟元素的路径值
1749
1674
  */
1750
-
1751
1675
  function getNextIndexRoute(curIndexRoute) {
1752
1676
  var curIndexArr = curIndexRoute.split('-');
1753
1677
  var lastIndex = curIndexArr.pop();
@@ -1755,29 +1679,29 @@ function getNextIndexRoute(curIndexRoute) {
1755
1679
  curIndexArr.push("" + endIndex);
1756
1680
  return curIndexArr.join('-');
1757
1681
  }
1682
+
1758
1683
  /**
1759
1684
  * 获取父元素的路径值和当前index
1760
1685
  */
1761
-
1762
1686
  function getParentIndexRoute_CurIndex(curIndexRoute) {
1763
1687
  var curIndexArr = curIndexRoute.split('-');
1764
1688
  var curIndex = curIndexArr.pop();
1765
1689
  return [curIndexArr.join('-'), curIndex];
1766
1690
  }
1691
+
1767
1692
  /**
1768
1693
  * 将当前路径值向前移动一位
1769
1694
  */
1770
-
1771
1695
  function moveForward(curIndexRoute) {
1772
1696
  var curIndexArr = curIndexRoute.split('-');
1773
1697
  var curIndex = curIndexArr.pop();
1774
1698
  curIndexArr.push(Number(curIndex) - 1);
1775
1699
  return curIndexArr.join('-');
1776
1700
  }
1701
+
1777
1702
  /**
1778
1703
  * 将当前路径值向后移动一位
1779
1704
  */
1780
-
1781
1705
  function moveBackward(curIndexRoute) {
1782
1706
  var curIndexArr = curIndexRoute.split('-');
1783
1707
  var curIndex = curIndexArr.pop();
@@ -1804,41 +1728,35 @@ function moveBackward(curIndexRoute) {
1804
1728
  * }
1805
1729
  * }
1806
1730
  */
1731
+
1807
1732
  /**
1808
1733
  * Object类型的schema元数据分析
1809
1734
  * */
1810
-
1811
1735
  function objectSchema2JsonData$1(jsonSchema, analyzerResult) {
1812
1736
  var curAnalyzerResult = analyzerResult || {};
1813
-
1814
1737
  if (isObject(jsonSchema) && jsonSchema.type === 'object' && jsonSchema.properties) {
1815
1738
  var curPropertyOrder = [];
1816
-
1817
1739
  if (jsonSchema.propertyOrder) {
1818
1740
  curPropertyOrder = jsonSchema.propertyOrder;
1819
1741
  } else {
1820
1742
  curPropertyOrder = Object.keys(jsonSchema.properties);
1821
1743
  }
1822
-
1823
1744
  curPropertyOrder.map(function (jsonKey) {
1824
1745
  var curSchema = jsonSchema.properties[jsonKey];
1825
1746
  curAnalyzerResult = metaElemAnalyzer(curSchema, curAnalyzerResult);
1826
1747
  });
1827
1748
  }
1828
-
1829
1749
  return curAnalyzerResult;
1830
1750
  }
1831
- /** 主方法 */
1832
-
1833
1751
 
1752
+ /** 主方法 */
1834
1753
  function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
1835
1754
  // 根据analyzerResult是否为空,判断是否是最外层的调用
1836
1755
  var isFirstAnalyzer = !analyzerResult ? true : false;
1837
- var curAnalyzerResult = analyzerResult || {}; // 根据当前schem数据分析使用到的元数据情况
1838
-
1756
+ var curAnalyzerResult = analyzerResult || {};
1757
+ // 根据当前schem数据分析使用到的元数据情况
1839
1758
  if (curJsonSchemaObj && JSON.stringify(curJsonSchemaObj) !== '{}') {
1840
1759
  var curFormat = getCurrentFormat(curJsonSchemaObj);
1841
-
1842
1760
  if (curFormat === 'object' || curFormat === 'func' || curFormat === 'style' || curFormat === 'data') {
1843
1761
  // 最外层的schema类型不进行统计
1844
1762
  if (!isFirstAnalyzer && curAnalyzerResult['object']) {
@@ -1846,7 +1764,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
1846
1764
  } else if (!isFirstAnalyzer) {
1847
1765
  curAnalyzerResult['object'] = 1;
1848
1766
  }
1849
-
1850
1767
  curAnalyzerResult = objectSchema2JsonData$1(curJsonSchemaObj, curAnalyzerResult);
1851
1768
  } else if (curFormat === 'array') {
1852
1769
  // 最外层的schema类型不进行统计
@@ -1855,7 +1772,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
1855
1772
  } else if (!isFirstAnalyzer) {
1856
1773
  curAnalyzerResult['array'] = 1;
1857
1774
  }
1858
-
1859
1775
  curJsonSchemaObj = curJsonSchemaObj.items;
1860
1776
  curAnalyzerResult = objectSchema2JsonData$1(curJsonSchemaObj, curAnalyzerResult);
1861
1777
  } else {
@@ -1866,7 +1782,6 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
1866
1782
  }
1867
1783
  }
1868
1784
  }
1869
-
1870
1785
  return curAnalyzerResult;
1871
1786
  }
1872
1787
 
@@ -1878,61 +1793,51 @@ function metaElemAnalyzer(curJsonSchemaObj, analyzerResult) {
1878
1793
  function oldSchemaToNewSchema(oldSchema) {
1879
1794
  var newJSONSchema = objClone(oldSchema); // 进行深拷贝,避免影响原有数据;
1880
1795
  // 1.根据原有的description值生成title值
1881
-
1882
1796
  if (!newJSONSchema.title && newJSONSchema.description) {
1883
1797
  newJSONSchema.title = newJSONSchema.description;
1884
- } // 2.当format为空时重新进行赋值
1885
-
1886
-
1798
+ }
1799
+ // 2.当format为空时重新进行赋值
1887
1800
  if (!newJSONSchema.format) {
1888
1801
  newJSONSchema.format = getCurrentFormat(newJSONSchema);
1889
- } // 3.不需要default属性的类型自动删除
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)) {
1802
+ }
1803
+ // 3.不需要default属性的类型自动删除
1804
+ 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
1805
  delete newJSONSchema.default; // 单位计量输入类型的默认值改放unit属性中
1894
- } // 转换旧版的radio类型的数据结构
1895
-
1896
-
1806
+ }
1807
+ // 转换旧版的radio类型的数据结构
1897
1808
  if (newJSONSchema.format === 'radio') {
1898
1809
  newJSONSchema.type = 'string';
1899
-
1900
1810
  if (newJSONSchema.enum && newJSONSchema.enumextra) {
1901
1811
  // 统一转换至items
1902
1812
  newJSONSchema.items = {
1903
1813
  type: 'string',
1904
1814
  enum: objClone(newJSONSchema.enum),
1905
1815
  enumextra: objClone(newJSONSchema.enumextra)
1906
- }; // 删除此前的enum、enumextra
1907
-
1816
+ };
1817
+ // 删除此前的enum、enumextra
1908
1818
  delete newJSONSchema.enum;
1909
1819
  delete newJSONSchema.enumextra;
1910
1820
  }
1911
- } // 转换旧版的quantity类型的数据结构
1912
-
1913
-
1821
+ }
1822
+ // 转换旧版的quantity类型的数据结构
1914
1823
  if (newJSONSchema.format === 'quantity') {
1915
1824
  var curProperties = newJSONSchema.properties;
1916
1825
  var newQuantitySchema = objClone(TypeDataList.quantity); // 新版quantity的schema数据对象
1917
-
1918
1826
  if (curProperties.quantity && isObject(curProperties.quantity) && curProperties.quantity.default) {
1919
- var oldDefault = curProperties.quantity.default; // percent 自动转换成 %
1920
-
1827
+ var oldDefault = curProperties.quantity.default;
1828
+ // percent 自动转换成 %
1921
1829
  newQuantitySchema.properties.quantity.default = oldDefault === 'percent' ? '%' : oldDefault;
1922
- } // 融合新版schema数据
1923
-
1924
-
1830
+ }
1831
+ // 融合新版schema数据
1925
1832
  newJSONSchema = newQuantitySchema;
1926
- } // 转换旧版的datasource类型的数据结构
1927
-
1928
-
1833
+ }
1834
+ // 转换旧版的datasource类型的数据结构
1929
1835
  if (newJSONSchema.format === 'datasource') {
1930
- var _curProperties = newJSONSchema.properties; // 先获取旧版的关键数据
1931
-
1836
+ var _curProperties = newJSONSchema.properties;
1837
+ // 先获取旧版的关键数据
1932
1838
  var typeProp = _curProperties.type && _curProperties.type.default;
1933
1839
  var dataProp = _curProperties.data && _curProperties.data.default;
1934
1840
  var filterProp = _curProperties.filter && _curProperties.filter.default;
1935
-
1936
1841
  if (typeProp === 'local') {
1937
1842
  newJSONSchema = objClone(DataSourceTypeList.local);
1938
1843
  newJSONSchema.properties.data.default = dataProp ? objClone(dataProp) : '{}';
@@ -1940,22 +1845,19 @@ function oldSchemaToNewSchema(oldSchema) {
1940
1845
  newJSONSchema = objClone(DataSourceTypeList.remote);
1941
1846
  newJSONSchema.properties.data.default = dataProp ? objClone(dataProp) : 'http://xxx';
1942
1847
  }
1943
-
1944
1848
  newJSONSchema.properties.filter.default = filterProp ? objClone(filterProp) : '() => {}';
1945
- } // 转换旧版的event类型的数据结构
1946
-
1947
-
1849
+ }
1850
+ // 转换旧版的event类型的数据结构
1948
1851
  if (newJSONSchema.format === 'event') {
1949
- var _curProperties2 = newJSONSchema.properties; // 先获取旧版的关键数据
1950
-
1951
- var eventType = _curProperties2.type && _curProperties2.type.default; // 重构Event的数据结构
1952
-
1852
+ var _curProperties2 = newJSONSchema.properties;
1853
+ // 先获取旧版的关键数据
1854
+ var eventType = _curProperties2.type && _curProperties2.type.default;
1855
+ // 重构Event的数据结构
1953
1856
  if (eventType === 'in' || eventType === 'on') {
1954
1857
  // 兼容旧版的'in'和新版的'on'
1955
1858
  // 注册类事件: 新版type改成'on'
1956
1859
  var eventFunc = _curProperties2.filter && _curProperties2.filter.default || '() => {}';
1957
1860
  newJSONSchema = objClone(EventTypeDataList.on);
1958
-
1959
1861
  if (_curProperties2.actionFunc && isObject(_curProperties2.actionFunc)) {
1960
1862
  newJSONSchema.properties.actionFunc.default = _curProperties2.actionFunc.default || objClone(eventFunc);
1961
1863
  }
@@ -1963,37 +1865,30 @@ function oldSchemaToNewSchema(oldSchema) {
1963
1865
  // 其他,则默认为触发事件
1964
1866
  // 注册类事件: 新版type改成'emit'
1965
1867
  var _eventFunc = _curProperties2.filter && _curProperties2.filter.default || '{}';
1966
-
1967
1868
  newJSONSchema = objClone(EventTypeDataList.emit);
1968
-
1969
1869
  if (_curProperties2.eventData && isObject(_curProperties2.eventData)) {
1970
1870
  newJSONSchema.properties.eventData.default = _curProperties2.eventData.default || objClone(_eventFunc);
1971
1871
  }
1972
1872
  }
1973
- } // 判断是否有propertyOrder属性
1974
-
1975
-
1873
+ }
1874
+ // 判断是否有propertyOrder属性
1976
1875
  if (newJSONSchema.properties) {
1977
1876
  // 3.重新生成required属性
1978
1877
  newJSONSchema.required = Object.keys(newJSONSchema.properties);
1979
-
1980
1878
  if (!newJSONSchema.propertyOrder) {
1981
1879
  // 4.生成propertyOrder属性
1982
1880
  newJSONSchema.propertyOrder = newJSONSchema.required;
1983
- } // 5.继续遍历properties属性进行转换
1984
-
1985
-
1881
+ }
1882
+ // 5.继续遍历properties属性进行转换
1986
1883
  newJSONSchema.propertyOrder.map(function (jsonKey) {
1987
1884
  newJSONSchema.properties[jsonKey] = oldSchemaToNewSchema(newJSONSchema.properties[jsonKey]);
1988
1885
  });
1989
- } // 判断是否有items属性
1990
-
1991
-
1886
+ }
1887
+ // 判断是否有items属性
1992
1888
  if (newJSONSchema.items) {
1993
1889
  // 6. 转换items中的数据
1994
1890
  newJSONSchema.items = oldSchemaToNewSchema(newJSONSchema.items);
1995
1891
  }
1996
-
1997
1892
  return newJSONSchema;
1998
1893
  }
1999
1894
 
@@ -2009,20 +1904,15 @@ function oldSchemaToNewSchema(oldSchema) {
2009
1904
  * 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
2010
1905
  * 备注:使用旧版数据,以便进行新旧数据融合
2011
1906
  * */
2012
-
2013
1907
  function baseSchema2JsonData(jsonSchema, jsonData) {
2014
1908
  var curJsonData = '';
2015
1909
  var oldValue = jsonData;
2016
-
2017
- if (exitPropertie(oldValue) && exitPropertie(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
1910
+ if (hasProperties(oldValue) && hasProperties(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
2018
1911
  // 表示当前数据类型发生变化,则丢弃旧版数据
2019
1912
  oldValue = undefined;
2020
1913
  }
2021
1914
  /** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
2022
-
2023
-
2024
- var curValue = exitPropertie(oldValue) ? oldValue : jsonSchema.default;
2025
-
1915
+ var curValue = hasProperties(oldValue) ? oldValue : jsonSchema.default;
2026
1916
  switch (jsonSchema.type) {
2027
1917
  case 'string':
2028
1918
  if (jsonSchema.format === 'typeSelect') {
@@ -2032,14 +1922,12 @@ function baseSchema2JsonData(jsonSchema, jsonData) {
2032
1922
  if (curValue === '#fff' || curValue === '#FFF') {
2033
1923
  curValue = '#ffffff'; // 避免出现#fff类型的值,type=color不能识别
2034
1924
  }
2035
-
2036
1925
  curJsonData = curValue || '#ffffff';
2037
1926
  } else if (jsonSchema.format === 'json' || jsonSchema.format === 'widget') {
2038
1927
  /** 转成json类型进行特殊处理
2039
1928
  * 需要保证json类型的数值是json对象 */
2040
1929
  var curJsonItemData = ''; // 字符串类型的json数据
2041
1930
  // 判断当前jsonData是否是对象类型
2042
-
2043
1931
  if (isObject(jsonData) || isArray(jsonData)) {
2044
1932
  curJsonItemData = jsonData;
2045
1933
  } else if (isFunction(jsonData) || jsonData === '') {
@@ -2057,57 +1945,44 @@ function baseSchema2JsonData(jsonSchema, jsonData) {
2057
1945
  curJsonItemData = {};
2058
1946
  }
2059
1947
  }
2060
-
2061
1948
  curJsonData = curJsonItemData;
2062
1949
  } else {
2063
1950
  // 其他类型允许出现空字符串
2064
- curJsonData = exitPropertie(curValue) ? curValue : '';
1951
+ curJsonData = hasProperties(curValue) ? curValue : '';
2065
1952
  }
2066
-
2067
1953
  break;
2068
-
2069
1954
  case 'boolean':
2070
- curJsonData = exitPropertie(curValue) ? curValue : false;
1955
+ curJsonData = hasProperties(curValue) ? curValue : false;
2071
1956
  break;
2072
-
2073
1957
  case 'number':
2074
- curJsonData = exitPropertie(curValue) ? curValue : 1;
1958
+ curJsonData = hasProperties(curValue) ? curValue : 1;
2075
1959
  break;
2076
-
2077
1960
  default:
2078
- curJsonData = exitPropertie(curValue) ? curValue : '';
1961
+ curJsonData = hasProperties(curValue) ? curValue : '';
2079
1962
  }
2080
-
2081
1963
  return curJsonData;
2082
1964
  }
1965
+
2083
1966
  /**
2084
1967
  * Object类型的schema转jsonData
2085
1968
  * 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
2086
1969
  * 备注:使用旧版数据,以便进行新旧数据融合
2087
1970
  * */
2088
-
2089
-
2090
1971
  function objectSchema2JsonData(jsonSchema, jsonData) {
2091
1972
  var curJsonData = {};
2092
1973
  var curType = getCurrentFormat(jsonSchema);
2093
-
2094
1974
  if (isObject(jsonSchema) && jsonSchema.type === 'object') {
2095
1975
  var jsonItem = jsonSchema;
2096
1976
  var oldValue = jsonData;
2097
-
2098
- if (exitPropertie(oldValue) && exitPropertie(jsonItem.default) && typeof oldValue !== typeof jsonItem.default) {
1977
+ if (hasProperties(oldValue) && hasProperties(jsonItem.default) && typeof oldValue !== typeof jsonItem.default) {
2099
1978
  // 表示当前数据类型发生变化,则丢弃旧版数据
2100
1979
  oldValue = undefined;
2101
1980
  }
2102
1981
  /** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
2103
-
2104
-
2105
- var curValue = exitPropertie(oldValue) ? oldValue : jsonItem.default;
2106
-
1982
+ var curValue = hasProperties(oldValue) ? oldValue : jsonItem.default;
2107
1983
  if (curType === 'dynamic-data') {
2108
1984
  // 动态数据源类型(固定格式的Object类型)
2109
1985
  curJsonData = objClone(EmptyDynamicDataCont);
2110
-
2111
1986
  if (curValue && isObject(curValue) && JSON.stringify(curValue) !== '{}') {
2112
1987
  curJsonData = Object.assign(curJsonData, curValue);
2113
1988
  }
@@ -2118,17 +1993,15 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2118
1993
  curJsonData = {
2119
1994
  data: '{}',
2120
1995
  filter: '() => {}'
2121
- }; // 读取旧值
2122
-
1996
+ };
1997
+ // 读取旧值
2123
1998
  if (curValue && curValue.data) {
2124
1999
  curJsonData.data = curValue.data;
2125
2000
  }
2126
-
2127
2001
  if (curValue && curValue.filter) {
2128
2002
  curJsonData.filter = curValue.filter;
2129
- } // 纠正data中的默认数据
2130
-
2131
-
2003
+ }
2004
+ // 纠正data中的默认数据
2132
2005
  if (curJsonData.data === 'http://xxx') {
2133
2006
  curJsonData.data = '{}';
2134
2007
  }
@@ -2137,17 +2010,15 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2137
2010
  curJsonData = {
2138
2011
  data: 'http://xxx',
2139
2012
  filter: '() => {}'
2140
- }; // 读取旧值
2141
-
2013
+ };
2014
+ // 读取旧值
2142
2015
  if (curValue && curValue.data) {
2143
2016
  curJsonData.data = curValue.data;
2144
2017
  }
2145
-
2146
2018
  if (curValue && curValue.filter) {
2147
2019
  curJsonData.filter = curValue.filter;
2148
- } // 纠正data中的默认数据
2149
-
2150
-
2020
+ }
2021
+ // 纠正data中的默认数据
2151
2022
  if (curJsonData.data === '{}') {
2152
2023
  curJsonData.data = 'http://xxx';
2153
2024
  }
@@ -2167,12 +2038,11 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2167
2038
  trigger: 'eventName',
2168
2039
  // 兼容旧版数据
2169
2040
  eventData: '{}'
2170
- }; // 读取旧值
2171
-
2041
+ };
2042
+ // 读取旧值
2172
2043
  if (curValue && curValue.trigger) {
2173
2044
  curJsonData.trigger = curValue.trigger;
2174
2045
  }
2175
-
2176
2046
  if (curValue && curValue.eventData) {
2177
2047
  curJsonData.eventData = curValue.eventData;
2178
2048
  }
@@ -2183,19 +2053,17 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2183
2053
  curJsonData = {
2184
2054
  register: 'eventName',
2185
2055
  actionFunc: curValue && curValue.filter || '() => {}' // 兼容旧版数据
2186
-
2187
2056
  };
2188
2057
  } else {
2189
2058
  curJsonData = {
2190
2059
  register: 'eventName',
2191
2060
  // 兼容旧版数据
2192
2061
  actionFunc: '() => {}'
2193
- }; // 读取旧值
2194
-
2062
+ };
2063
+ // 读取旧值
2195
2064
  if (curValue && curValue.register) {
2196
2065
  curJsonData.register = curValue.register;
2197
2066
  }
2198
-
2199
2067
  if (curValue && curValue.actionFunc) {
2200
2068
  curJsonData.actionFunc = curValue.actionFunc;
2201
2069
  }
@@ -2203,28 +2071,23 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2203
2071
  }
2204
2072
  } else if (jsonSchema.properties) {
2205
2073
  var curPropertyOrder = [];
2206
-
2207
2074
  if (jsonSchema.propertyOrder) {
2208
2075
  curPropertyOrder = jsonSchema.propertyOrder;
2209
2076
  } else {
2210
2077
  curPropertyOrder = Object.keys(jsonSchema.properties);
2211
- } // 其他非固定格式的Object类型
2212
-
2213
-
2078
+ }
2079
+ // 其他非固定格式的Object类型
2214
2080
  curPropertyOrder.map(function (jsonKey) {
2215
2081
  var curJsonItem = jsonSchema.properties[jsonKey];
2216
2082
  var curOldValue = jsonData && jsonData[jsonKey];
2217
-
2218
2083
  switch (curJsonItem.type) {
2219
2084
  case 'array':
2220
2085
  curJsonData[jsonKey] = arraySchema2JsonData(curJsonItem, curOldValue);
2221
2086
  break;
2222
-
2223
2087
  case 'object':
2224
2088
  // 普通对象类型
2225
2089
  curJsonData[jsonKey] = objectSchema2JsonData(curJsonItem, curOldValue);
2226
2090
  break;
2227
-
2228
2091
  default:
2229
2092
  // 其他基础类型
2230
2093
  curJsonData[jsonKey] = baseSchema2JsonData(curJsonItem, curOldValue);
@@ -2232,32 +2095,26 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
2232
2095
  });
2233
2096
  }
2234
2097
  }
2235
-
2236
2098
  return curJsonData;
2237
2099
  }
2100
+
2238
2101
  /**
2239
2102
  * Array类型的schema转jsonData
2240
2103
  * 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
2241
2104
  * 备注:使用旧版数据,以便进行新旧数据融合
2242
2105
  * */
2243
-
2244
-
2245
2106
  function arraySchema2JsonData(jsonSchema, jsonData) {
2246
- var curJsonData = []; // 判断是否是数组类型
2247
-
2107
+ var curJsonData = [];
2108
+ // 判断是否是数组类型
2248
2109
  if (jsonSchema && jsonSchema.type === 'array') {
2249
2110
  // Array数据对象类型
2250
2111
  var oldValue = jsonData;
2251
-
2252
- if (exitPropertie(oldValue) && exitPropertie(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
2112
+ if (hasProperties(oldValue) && hasProperties(jsonSchema.default) && typeof oldValue !== typeof jsonSchema.default) {
2253
2113
  // 表示当前数据类型发生变化,则丢弃旧版数据
2254
2114
  oldValue = undefined;
2255
2115
  }
2256
2116
  /** 旧版原有数值优先使用,其次在使用schema中定义的默认值 */
2257
-
2258
-
2259
- var curValue = exitPropertie(oldValue) ? oldValue : jsonSchema.default;
2260
-
2117
+ var curValue = hasProperties(oldValue) ? oldValue : jsonSchema.default;
2261
2118
  if (jsonSchema.format === 'array') {
2262
2119
  if (isArray(curValue)) {
2263
2120
  curValue.map(function (arrItem) {
@@ -2269,21 +2126,18 @@ function arraySchema2JsonData(jsonSchema, jsonData) {
2269
2126
  }
2270
2127
  } else {
2271
2128
  // 考虑select类型(多选的数值也是以array对象记录)
2272
- curJsonData = exitPropertie(curValue) ? curValue : [];
2129
+ curJsonData = hasProperties(curValue) ? curValue : [];
2273
2130
  }
2274
2131
  }
2275
-
2276
2132
  return curJsonData;
2277
2133
  }
2134
+
2278
2135
  /**
2279
2136
  * 根据jsonSchema和旧版的jsonData生成一份对应的jsonData
2280
2137
  * 备注:使用旧版数据,以便进行新旧数据融合
2281
2138
  * */
2282
-
2283
-
2284
2139
  function schema2json(jsonSchema, jsonData) {
2285
2140
  var curJsonData = {};
2286
-
2287
2141
  if (jsonSchema.type === 'object') {
2288
2142
  curJsonData = objectSchema2JsonData(jsonSchema, jsonData);
2289
2143
  } else if (jsonSchema.type === 'array') {
@@ -2291,7 +2145,6 @@ function schema2json(jsonSchema, jsonData) {
2291
2145
  } else {
2292
2146
  curJsonData = baseSchema2JsonData(jsonSchema, jsonData);
2293
2147
  }
2294
-
2295
2148
  return curJsonData;
2296
2149
  }
2297
2150
 
@@ -2301,6 +2154,7 @@ function schema2json(jsonSchema, jsonData) {
2301
2154
  * 10个特殊类型组件(Object、Array、Json、datasource、DynamicData、Event、CodeArea、htmlArea、quantity、widget)
2302
2155
  */
2303
2156
 
2157
+ // 类型数据清单
2304
2158
  var schemaMetaList = TypeDataList;
2305
2159
 
2306
2160
  /**
@@ -2377,15 +2231,14 @@ var schemaMetaList = TypeDataList;
2377
2231
  }
2378
2232
  */
2379
2233
  function dynamicDataAnalyzer(curJsonData, analyzerResult) {
2380
- var curAnalyzerResult = analyzerResult || []; // 根据当前schem数据分析使用到的元数据情况
2381
-
2234
+ var curAnalyzerResult = analyzerResult || [];
2235
+ // 根据当前schema数据分析使用到的元数据情况
2382
2236
  if (curJsonData && JSON.stringify(curJsonData) !== '{}') {
2383
2237
  if (isObject(curJsonData)) {
2384
2238
  // const curJsonMap = Object.keys(curJsonData); // 动态数据类型的jsonData包含四个数值:type、config(dataName/body/filter)、data、localFilter
2385
2239
  // 判断是否是动态数据类型
2386
- if (curJsonData.type && curJsonData.type === 'remote' && curJsonData.config && isObject(curJsonData.config) && curJsonData.config.dataName && exitPropertie(curJsonData.localFilter) && exitPropertie(curJsonData.data)) {
2240
+ if (curJsonData.type && curJsonData.type === 'remote' && curJsonData.config && isObject(curJsonData.config) && curJsonData.config.dataName && hasProperties(curJsonData.localFilter) && hasProperties(curJsonData.data)) {
2387
2241
  var apiParams = curJsonData.config.body;
2388
-
2389
2242
  if (apiParams && !isObject(apiParams)) {
2390
2243
  try {
2391
2244
  apiParams = JSON.parse(apiParams);
@@ -2393,7 +2246,6 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
2393
2246
  apiParams = {};
2394
2247
  }
2395
2248
  }
2396
-
2397
2249
  curAnalyzerResult.push({
2398
2250
  id: curJsonData.config.id,
2399
2251
  dataName: curJsonData.config.dataName,
@@ -2411,7 +2263,6 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
2411
2263
  });
2412
2264
  }
2413
2265
  }
2414
-
2415
2266
  return curAnalyzerResult;
2416
2267
  }
2417
2268
 
@@ -2445,13 +2296,12 @@ function dynamicDataAnalyzer(curJsonData, analyzerResult) {
2445
2296
  },
2446
2297
  ];
2447
2298
  */
2299
+
2448
2300
  /**
2449
2301
  * DataRoute转真实数据路径
2450
2302
  * */
2451
-
2452
2303
  function dataRoute2dataPath(dataRoute, baseDataPath) {
2453
2304
  var dataPath = baseDataPath || 'data'; // 默认数据根路径值为data
2454
-
2455
2305
  var dataRouteArr = dataRoute.split('-');
2456
2306
  dataRouteArr.map(function (path) {
2457
2307
  if (/^\d+$/.test(path)) {
@@ -2462,19 +2312,17 @@ function dataRoute2dataPath(dataRoute, baseDataPath) {
2462
2312
  });
2463
2313
  return dataPath;
2464
2314
  }
2315
+
2465
2316
  /**
2466
2317
  * mockData转treeData(供antd的TreeSelect使用)
2467
2318
  * */
2468
-
2469
2319
  function json2treeData(mockData, parentDataRoute) {
2470
2320
  var treeData = [];
2471
-
2472
2321
  if (isObject(mockData)) {
2473
2322
  var mockDataProps = Object.keys(mockData);
2474
2323
  mockDataProps.map(function (propKey) {
2475
2324
  var mockDataItem = mockData[propKey];
2476
2325
  var curDataRoute = parentDataRoute ? parentDataRoute + "-" + propKey : propKey;
2477
-
2478
2326
  if (isObject(mockDataItem) || isArray(mockDataItem)) {
2479
2327
  treeData.push({
2480
2328
  title: propKey,
@@ -2494,7 +2342,6 @@ function json2treeData(mockData, parentDataRoute) {
2494
2342
  mockData.map(function (mockDataItem, index) {
2495
2343
  var indexStr = index.toString();
2496
2344
  var curDataRoute = parentDataRoute ? parentDataRoute + "-" + index : indexStr;
2497
-
2498
2345
  if (isObject(mockDataItem) || isArray(mockDataItem)) {
2499
2346
  treeData.push({
2500
2347
  title: indexStr,
@@ -2511,7 +2358,6 @@ function json2treeData(mockData, parentDataRoute) {
2511
2358
  }
2512
2359
  });
2513
2360
  }
2514
-
2515
2361
  return treeData;
2516
2362
  }
2517
2363
 
@@ -2523,10 +2369,10 @@ function getParentKeyRoute(curKeyRoute) {
2523
2369
  curKeyArr.pop();
2524
2370
  return curKeyArr.join('-');
2525
2371
  }
2372
+
2526
2373
  /**
2527
2374
  * 获取父元素的key路径值和当前key
2528
2375
  */
2529
-
2530
2376
  function getParentKeyRoute_CurKey(curKeyRoute) {
2531
2377
  var curKeyArr = curKeyRoute.split('-');
2532
2378
  var curKey = curKeyArr.pop();
@@ -2536,4 +2382,4 @@ function getParentKeyRoute_CurKey(curKeyRoute) {
2536
2382
  // JSONSchema关键字清单
2537
2383
  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
2384
 
2539
- export { DataSourceTypeList, EventTypeDataList, KeyWordList, TypeDataList, dataRoute2dataPath, dynamicDataAnalyzer, exitPropertie, getCurPosition, getCurrentFormat, getJsonDataByKeyRoute, getNextIndexRoute, getParentIndexRoute, getParentIndexRoute_CurIndex, getParentKeyRoute, getParentKeyRoute_CurKey, getSchemaByIndexRoute, getSchemaByKeyRoute, 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 };
2385
+ 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 };