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