@wibetter/json-utils 5.2.3 → 5.2.8

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
@@ -5,267 +5,6 @@ import {
5
5
  } from 'lodash';
6
6
  import qs from 'qs';
7
7
 
8
- /**
9
- * 获取 URL 上的所有参数
10
- * 例如:比如当前页面的地址为 xx?a1=123 则 urlParse() => {a1: 123}
11
- */
12
- function urlParse() {
13
- var urlParams = {};
14
- if (location.search) {
15
- urlParams = qs.parse(location.search.substring(1));
16
- }
17
- return urlParams;
18
- }
19
-
20
- /**
21
- * 转换成 URL 上的参数字符串
22
- * @param {*} urlParams
23
- * 例如:{a1: 123} => a1=123
24
- */
25
- function urlStringify(urlParams) {
26
- var urlStr = '';
27
- if (url) {
28
- urlStr = qs.stringify(urlParams);
29
- }
30
- return urlStr;
31
- }
32
-
33
- /** js对象数据深拷贝,避免数据联动 */
34
- function objClone(targetObj) {
35
- // const newObj = JSON.stringify(targetObj);
36
- // return JSON.parse(newObj);
37
- return cloneDeep(targetObj);
38
- }
39
-
40
- /** 对比两个json数据是否相等 */
41
- function isEqual(targetObj, nextTargetObj) {
42
- // return JSON.stringify(targetObj) === JSON.stringify(nextTargetObj);
43
- return isEqual$1(targetObj, nextTargetObj);
44
- }
45
-
46
- /** 判断当前属性是否存在
47
- * 备注:要识别boolean类型的数值 */
48
- function hasProperties(targetProperties) {
49
- var hasProperties = false;
50
- if (targetProperties !== undefined && targetProperties !== null) {
51
- // targetProperties 等于""、0、false时均认为是存在的属性
52
- hasProperties = true;
53
- }
54
- return hasProperties;
55
- }
56
-
57
- // 截断字符串,避免撑开元素
58
- // https://www.lodashjs.com/docs/lodash.truncate
59
- function truncate(str, paramConfig) {
60
- if (str) {
61
- return truncate$1(str, paramConfig);
62
- }
63
- return truncate$1(str, paramConfig);
64
- }
65
-
66
- /**
67
- * 支持属性表达式
68
- */
69
- function evalExpression(expressionStr, data) {
70
- var curData = data || {};
71
- if (!expressionStr) return false;
72
- var expressionFunc = new Function(
73
- 'data',
74
- 'with(data) { return (' + expressionStr + ');}',
75
- );
76
- var expressionResult = '';
77
- try {
78
- expressionResult = expressionFunc(curData);
79
- } catch (error) {
80
- console.warn(
81
- '\u8868\u8FBE\u5F0F\u8FD0\u7B97\u51FA\u9519: ' +
82
- expressionStr +
83
- '\uFF0C\u62A5\u9519\u4FE1\u606F\uFF1A',
84
- error,
85
- );
86
- return expressionResult;
87
- }
88
- return expressionResult;
89
- }
90
-
91
- /**
92
- * getJSONDataByKeyRoute: 根据key值路径获取对应的json数据
93
- * 【方法参数说明】
94
- * keyRoute: key值索引路径
95
- * targetJsonDataObj: json数据对象
96
- * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
97
- */
98
- function getJsonDataByKeyRoute(keyRoute, targetJsonDataObj, useObjClone) {
99
- var curJsonDataObj = targetJsonDataObj;
100
- if (useObjClone) {
101
- curJsonDataObj = objClone(targetJsonDataObj); // 进行深拷贝,避免影响原有数据
102
- }
103
- if (keyRoute) {
104
- var keyRouteArr = keyRoute.split('-');
105
- for (var index = 0, size = keyRouteArr.length; index < size; index++) {
106
- // 1、获取当前的jsonKey值
107
- var curKey = keyRouteArr[index];
108
- if (curKey) {
109
- // 只有curKey不为空的时候才进行赋值
110
- // 2、根据key值获取对应的数据对象
111
- curJsonDataObj = curJsonDataObj && curJsonDataObj[curKey];
112
- }
113
- }
114
- }
115
- return curJsonDataObj;
116
- }
117
-
118
- /**
119
- * getSchemaByIndexRoute: 根据index索引路径获取对应的schema数据
120
- * 【方法参数说明】
121
- * indexRoute: index索引路径
122
- * targetJsonSchemaObj: schema数据对象
123
- * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
124
- */
125
- function getSchemaByIndexRoute(indexRoute, targetJsonSchemaObj, useObjClone) {
126
- var curJsonSchemaObj = targetJsonSchemaObj;
127
- if (useObjClone) {
128
- curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
129
- }
130
- if (indexRoute) {
131
- var indexRouteArr = indexRoute.split('-');
132
- for (var index = 0, size = indexRouteArr.length; index < size; index++) {
133
- // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
134
- var curIndex = indexRouteArr[index];
135
- if (
136
- curIndex === '0' &&
137
- (curJsonSchemaObj.type === 'array' ||
138
- curJsonSchemaObj.type === 'radio' ||
139
- curJsonSchemaObj.type === 'select' ||
140
- curJsonSchemaObj.type === 'checkboxes') &&
141
- (curJsonSchemaObj.options || curJsonSchemaObj.items)
142
- ) {
143
- // 从items中获取数据
144
- curJsonSchemaObj = curJsonSchemaObj.options || curJsonSchemaObj.items;
145
- } else if (curIndex) {
146
- var curKeyTemp = '0';
147
- // 1、先根据路径值获取key值
148
- if (curJsonSchemaObj.propertyOrder) {
149
- curKeyTemp = curJsonSchemaObj.propertyOrder[curIndex];
150
- } else if (curJsonSchemaObj.properties) {
151
- var propertyOrder = Object.keys(curJsonSchemaObj.properties);
152
- curKeyTemp = propertyOrder[curIndex];
153
- }
154
- // 2、根据key值获取对应的json数据对象
155
- curJsonSchemaObj = curJsonSchemaObj.properties[curKeyTemp];
156
- }
157
- }
158
- }
159
- return curJsonSchemaObj;
160
- }
161
-
162
- /**
163
- * getSchemaByKeyRoute: 根据key值路径获取对应的schema数据
164
- * 【方法参数说明】
165
- * keyRoute: key值路径
166
- * targetJsonSchemaObj: schema数据对象
167
- * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
168
- */
169
- function getSchemaByKeyRoute(keyRoute, targetJsonSchemaObj, useObjClone) {
170
- var curJsonSchemaObj = targetJsonSchemaObj;
171
- if (useObjClone) {
172
- curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
173
- }
174
- if (keyRoute && curJsonSchemaObj) {
175
- var keyRouteArr = keyRoute.split('-');
176
- for (var index = 0, size = keyRouteArr.length; index < size; index++) {
177
- // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
178
- var curKey = keyRouteArr[index];
179
- if (curKey && curJsonSchemaObj.properties) {
180
- // 根据key值获取对应的json数据对象
181
- curJsonSchemaObj = curJsonSchemaObj.properties[curKey];
182
- }
183
- }
184
- }
185
- return curJsonSchemaObj;
186
- }
187
-
188
- /**
189
- * indexRoute2keyRoute:根据index索引路径获取对应的key值路径
190
- * 【方法参数说明】
191
- * indexRoute: index索引路径
192
- * targetJsonSchemaObj: schema数据对象
193
- * */
194
- function indexRoute2keyRoute(indexRoute, targetJsonSchemaObj) {
195
- var curJsonSchemaObj = targetJsonSchemaObj;
196
- var curKeyRoute = '';
197
- var indexRouteArr = indexRoute.split('-');
198
- for (var index = 0, size = indexRouteArr.length; index < size; index++) {
199
- // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
200
- var curIndex = indexRouteArr[index];
201
- if (curIndex === '0' && curJsonSchemaObj.items) {
202
- // 从items中获取数据
203
- curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
204
- curKeyRoute = curKeyRoute ? curKeyRoute + '-items' : 'items';
205
- } else if (curIndex === '0' && curJsonSchemaObj.options) {
206
- // 从options中获取数据
207
- curJsonSchemaObj = curJsonSchemaObj.options;
208
- curKeyRoute = curKeyRoute ? curKeyRoute + '-options' : 'options';
209
- } else if (curIndex) {
210
- // 1、先根据路径值获取key值
211
- var curKey = '0';
212
- // 1、先根据路径值获取key值
213
- if (curJsonSchemaObj.propertyOrder) {
214
- curKey = curJsonSchemaObj.propertyOrder[curIndex];
215
- } else if (curJsonSchemaObj.properties) {
216
- var propertyOrder = Object.keys(curJsonSchemaObj.properties);
217
- curKey = propertyOrder[curIndex];
218
- }
219
- // 2、根据key值获取对应的json数据对象
220
- curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
221
- curKeyRoute = curKeyRoute ? curKeyRoute + '-' + curKey : curKey;
222
- }
223
- }
224
- return curKeyRoute;
225
- }
226
-
227
- /**
228
- * keyRoute2indexRoute:根据key值路径获取对应的index索引路径
229
- * 【方法参数说明】
230
- * keyRoute: key值路径
231
- * targetJsonSchemaObj: schema数据对象
232
- * */
233
- function keyRoute2indexRoute(keyRoute, targetJsonSchemaObj) {
234
- var curJsonSchemaObj = targetJsonSchemaObj;
235
- var curIndexRoute = '';
236
- var keyRouteArr = keyRoute.split('-');
237
- for (var index = 0, size = keyRouteArr.length; index < size; index++) {
238
- var curKey = keyRouteArr[index];
239
- if (curKey) {
240
- // 1、先根据路径值获取key值
241
- var curIndex = -1;
242
- // 1、先根据路径值获取key值
243
- if (curJsonSchemaObj.propertyOrder) {
244
- curIndex = curJsonSchemaObj.propertyOrder.indexOf(curKey);
245
- // 2、根据key值获取对应的json数据对象
246
- curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
247
- } else if (curJsonSchemaObj.properties) {
248
- var propertyOrder = Object.keys(curJsonSchemaObj.properties);
249
- curIndex = propertyOrder.indexOf(curKey);
250
- // 2、根据key值获取对应的json数据对象
251
- curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
252
- } else if (curJsonSchemaObj.items) {
253
- // 兼容数组类型
254
- curIndex = 0; // curKey;
255
- curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
256
- } else if (curJsonSchemaObj.options) {
257
- // 兼容数组类型
258
- curIndex = 0;
259
- curJsonSchemaObj = curJsonSchemaObj.options;
260
- }
261
- curIndexRoute = curIndexRoute
262
- ? curIndexRoute + '-' + curIndex
263
- : curIndex.toString();
264
- }
265
- }
266
- return curIndexRoute;
267
- }
268
-
269
8
  /** 新版JSONSchema一级字段项
270
9
  * 【字段属性说明】
271
10
  * title:字段项的label值
@@ -1587,8 +1326,15 @@ var initDynamicArray = {
1587
1326
  description: '',
1588
1327
  placeholder: '',
1589
1328
  },
1329
+ tipText: {
1330
+ title: '提示说明',
1331
+ type: 'textarea',
1332
+ default: '',
1333
+ description: '',
1334
+ placeholder: '',
1335
+ },
1590
1336
  },
1591
- propertyOrder: ['attr', 'description'],
1337
+ propertyOrder: ['attr', 'description', 'tipText'],
1592
1338
  },
1593
1339
  'minimum-child': 1,
1594
1340
  onShow: "type === 'ContentStaticConfig' || type === 'ResourceCenter'",
@@ -2702,88 +2448,410 @@ function isDateStr(dateStr) {
2702
2448
  return /^\d{4}-\d{2}-\d{2}$/.test(dateStr);
2703
2449
  }
2704
2450
 
2705
- // 判断是否是年月日时分的时间类型
2706
- function isDateTimeStr(dateStr) {
2707
- return (
2708
- /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.test(dateStr) ||
2709
- /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(dateStr)
2710
- );
2451
+ // 判断是否是年月日时分的时间类型
2452
+ function isDateTimeStr(dateStr) {
2453
+ return (
2454
+ /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.test(dateStr) ||
2455
+ /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(dateStr)
2456
+ );
2457
+ }
2458
+
2459
+ // 判断是否是时分的时间类型
2460
+ function isTimeStr(dateStr) {
2461
+ return /^\d{2}:\d{2}:\d{2}$/.test(dateStr) || /^\d{2}:\d{2}$/.test(dateStr);
2462
+ }
2463
+
2464
+ /**
2465
+ * 判断是否是数组类型
2466
+ * */
2467
+ function isArray(curObj) {
2468
+ var isArray = false;
2469
+ if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Array') {
2470
+ isArray = true;
2471
+ }
2472
+ return isArray;
2473
+ }
2474
+
2475
+ /**
2476
+ * 判断是否是select多选类型(基础类型的array)
2477
+ * select类型一定是一个array类型
2478
+ * */
2479
+ function isSelect(curObj) {
2480
+ if (!isArray(curObj)) {
2481
+ return false;
2482
+ }
2483
+ for (var ind = 0, size = curObj.length; ind < size; ind++) {
2484
+ var arrItem = curObj[ind];
2485
+ if (!isString(arrItem)) {
2486
+ // 只要有一个不是string类型就认为不是select
2487
+ return false;
2488
+ }
2489
+ }
2490
+ return true;
2491
+ }
2492
+
2493
+ /**
2494
+ * 判断是否是对象类型
2495
+ * */
2496
+ function isObject$1(curObj) {
2497
+ var isObject = false;
2498
+ if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Object') {
2499
+ isObject = true;
2500
+ }
2501
+ return isObject;
2502
+ }
2503
+
2504
+ /**
2505
+ * 判断是否是单位类型
2506
+ * */
2507
+ function isQuantity(val) {
2508
+ var isObject = false;
2509
+ // 获取当前计量单位元素可选的单位类型
2510
+ var quantityList = TypeDataList.quantity.properties.quantity.enum;
2511
+ if (quantityList.indexOf(val) >= 0) {
2512
+ isObject = true;
2513
+ }
2514
+ return isObject;
2515
+ }
2516
+
2517
+ /**
2518
+ * 判断是否是颜色值
2519
+ * */
2520
+ function isColor(colorVal) {
2521
+ return /^#[0-9a-f]{6}$/.test(colorVal) || /^#[0-9a-f]{3}$/.test(colorVal);
2522
+ }
2523
+
2524
+ /**
2525
+ * 判断是否是函数类型
2526
+ * */
2527
+ function isFunction(curObj) {
2528
+ var isFunction = false;
2529
+ if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Function') {
2530
+ isFunction = true;
2531
+ }
2532
+ return isFunction;
2533
+ }
2534
+
2535
+ /**
2536
+ * 获取 URL 上的所有参数
2537
+ * 例如:比如当前页面的地址为 xx?a1=123 则 urlParse() => {a1: 123}
2538
+ */
2539
+ function urlParse() {
2540
+ var urlParams = {};
2541
+ if (location.search) {
2542
+ urlParams = qs.parse(location.search.substring(1));
2543
+ }
2544
+ return urlParams;
2545
+ }
2546
+
2547
+ /**
2548
+ * 转换成 URL 上的参数字符串
2549
+ * @param {*} urlParams
2550
+ * 例如:{a1: 123} => a1=123
2551
+ */
2552
+ function urlStringify(urlParams) {
2553
+ var urlStr = '';
2554
+ if (url) {
2555
+ urlStr = qs.stringify(urlParams);
2556
+ }
2557
+ return urlStr;
2558
+ }
2559
+
2560
+ /** js对象数据深拷贝,避免数据联动 */
2561
+ function objClone(targetObj) {
2562
+ // const newObj = JSON.stringify(targetObj);
2563
+ // return JSON.parse(newObj);
2564
+ return cloneDeep(targetObj);
2565
+ }
2566
+
2567
+ /** 对比两个json数据是否相等 */
2568
+ function isEqual(targetObj, nextTargetObj) {
2569
+ if (
2570
+ (hasProperties(targetObj) && !hasProperties(nextTargetObj)) ||
2571
+ (!hasProperties(targetObj) && hasProperties(nextTargetObj)) ||
2572
+ typeof targetObj !== typeof nextTargetObj
2573
+ ) {
2574
+ return false;
2575
+ }
2576
+ if (
2577
+ isObject$1(targetObj) &&
2578
+ (targetObj.id !== nextTargetObj.id ||
2579
+ targetObj.lastUpdateTime !== nextTargetObj.lastUpdateTime)
2580
+ ) {
2581
+ return false;
2582
+ }
2583
+ var curTime = new Date().getTime();
2584
+ if (
2585
+ isObject$1(targetObj) &&
2586
+ targetObj.lastUpdateTime &&
2587
+ targetObj.lastUpdateTime === nextTargetObj.lastUpdateTime &&
2588
+ curTime - targetObj.lastUpdateTime < 500
2589
+ ) {
2590
+ // 当两个对象的时间戳相同,且和当前时间的时间戳数值相差不到500毫秒,则直接认为两者数据相同
2591
+ return true;
2592
+ }
2593
+ return isEqual$1(targetObj, nextTargetObj);
2594
+ }
2595
+
2596
+ // 根据 id 或 lastUpdateTime 判断 数据是否相等
2597
+ function isEqualByIdT(targetObj, nextTargetObj) {
2598
+ if (
2599
+ (hasProperties(targetObj) && !hasProperties(nextTargetObj)) ||
2600
+ (!hasProperties(targetObj) && hasProperties(nextTargetObj)) ||
2601
+ typeof targetObj !== typeof nextTargetObj
2602
+ ) {
2603
+ return false;
2604
+ }
2605
+ if (
2606
+ isObject$1(targetObj) &&
2607
+ (targetObj.id !== nextTargetObj.id ||
2608
+ targetObj.lastUpdateTime !== nextTargetObj.lastUpdateTime)
2609
+ ) {
2610
+ return false;
2611
+ }
2612
+ var curTime = new Date().getTime();
2613
+ if (
2614
+ isObject$1(targetObj) &&
2615
+ targetObj.lastUpdateTime &&
2616
+ targetObj.lastUpdateTime === nextTargetObj.lastUpdateTime &&
2617
+ curTime - targetObj.lastUpdateTime < 500
2618
+ ) {
2619
+ // 当两个对象的时间戳相同,且和当前时间的时间戳数值相差不到500毫秒,则直接认为两者数据相同
2620
+ return true;
2621
+ }
2622
+ if (
2623
+ isObject$1(targetObj) &&
2624
+ ((hasProperties(targetObj.id) && targetObj.id === nextTargetObj.id) ||
2625
+ (hasProperties(targetObj.lastUpdateTime) &&
2626
+ targetObj.lastUpdateTime === nextTargetObj.lastUpdateTime))
2627
+ ) {
2628
+ return true;
2629
+ } else {
2630
+ return isEqual$1(targetObj, nextTargetObj);
2631
+ }
2632
+ }
2633
+
2634
+ /** 判断当前属性是否存在
2635
+ * 备注:要识别boolean类型的数值 */
2636
+ function hasProperties(targetProperties) {
2637
+ var hasProperties = false;
2638
+ if (targetProperties !== undefined && targetProperties !== null) {
2639
+ // targetProperties 等于""、0、false时均认为是存在的属性
2640
+ hasProperties = true;
2641
+ }
2642
+ return hasProperties;
2711
2643
  }
2712
2644
 
2713
- // 判断是否是时分的时间类型
2714
- function isTimeStr(dateStr) {
2715
- return /^\d{2}:\d{2}:\d{2}$/.test(dateStr) || /^\d{2}:\d{2}$/.test(dateStr);
2645
+ // 截断字符串,避免撑开元素
2646
+ // https://www.lodashjs.com/docs/lodash.truncate
2647
+ function truncate(str, paramConfig) {
2648
+ if (str) {
2649
+ return truncate$1(str, paramConfig);
2650
+ }
2651
+ return truncate$1(str, paramConfig);
2716
2652
  }
2717
2653
 
2718
2654
  /**
2719
- * 判断是否是数组类型
2720
- * */
2721
- function isArray(curObj) {
2722
- var isArray = false;
2723
- if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Array') {
2724
- isArray = true;
2655
+ * 支持属性表达式
2656
+ */
2657
+ function evalExpression(expressionStr, data) {
2658
+ var curData = data || {};
2659
+ if (!expressionStr) return false;
2660
+ var expressionFunc = new Function(
2661
+ 'data',
2662
+ 'with(data) { return (' + expressionStr + ');}',
2663
+ );
2664
+ var expressionResult = '';
2665
+ try {
2666
+ expressionResult = expressionFunc(curData);
2667
+ } catch (error) {
2668
+ console.warn(
2669
+ '\u8868\u8FBE\u5F0F\u8FD0\u7B97\u51FA\u9519: ' +
2670
+ expressionStr +
2671
+ '\uFF0C\u62A5\u9519\u4FE1\u606F\uFF1A',
2672
+ error,
2673
+ );
2674
+ return expressionResult;
2725
2675
  }
2726
- return isArray;
2676
+ return expressionResult;
2727
2677
  }
2728
2678
 
2729
2679
  /**
2730
- * 判断是否是select多选类型(基础类型的array)
2731
- * select类型一定是一个array类型
2732
- * */
2733
- function isSelect(curObj) {
2734
- if (!isArray(curObj)) {
2735
- return false;
2680
+ * getJSONDataByKeyRoute: 根据key值路径获取对应的json数据
2681
+ * 【方法参数说明】
2682
+ * keyRoute: key值索引路径
2683
+ * targetJsonDataObj: json数据对象
2684
+ * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
2685
+ */
2686
+ function getJsonDataByKeyRoute(keyRoute, targetJsonDataObj, useObjClone) {
2687
+ var curJsonDataObj = targetJsonDataObj;
2688
+ if (useObjClone) {
2689
+ curJsonDataObj = objClone(targetJsonDataObj); // 进行深拷贝,避免影响原有数据
2736
2690
  }
2737
- for (var ind = 0, size = curObj.length; ind < size; ind++) {
2738
- var arrItem = curObj[ind];
2739
- if (!isString(arrItem)) {
2740
- // 只要有一个不是string类型就认为不是select
2741
- return false;
2691
+ if (keyRoute) {
2692
+ var keyRouteArr = keyRoute.split('-');
2693
+ for (var index = 0, size = keyRouteArr.length; index < size; index++) {
2694
+ // 1、获取当前的jsonKey值
2695
+ var curKey = keyRouteArr[index];
2696
+ if (curKey) {
2697
+ // 只有curKey不为空的时候才进行赋值
2698
+ // 2、根据key值获取对应的数据对象
2699
+ curJsonDataObj = curJsonDataObj && curJsonDataObj[curKey];
2700
+ }
2742
2701
  }
2743
2702
  }
2744
- return true;
2703
+ return curJsonDataObj;
2745
2704
  }
2746
2705
 
2747
2706
  /**
2748
- * 判断是否是对象类型
2749
- * */
2750
- function isObject$1(curObj) {
2751
- var isObject = false;
2752
- if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Object') {
2753
- isObject = true;
2707
+ * getSchemaByIndexRoute: 根据index索引路径获取对应的schema数据
2708
+ * 【方法参数说明】
2709
+ * indexRoute: index索引路径
2710
+ * targetJsonSchemaObj: schema数据对象
2711
+ * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
2712
+ */
2713
+ function getSchemaByIndexRoute(indexRoute, targetJsonSchemaObj, useObjClone) {
2714
+ var curJsonSchemaObj = targetJsonSchemaObj;
2715
+ if (useObjClone) {
2716
+ curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
2754
2717
  }
2755
- return isObject;
2718
+ if (indexRoute) {
2719
+ var indexRouteArr = indexRoute.split('-');
2720
+ for (var index = 0, size = indexRouteArr.length; index < size; index++) {
2721
+ // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
2722
+ var curIndex = indexRouteArr[index];
2723
+ if (
2724
+ curIndex === '0' &&
2725
+ (curJsonSchemaObj.type === 'array' ||
2726
+ curJsonSchemaObj.type === 'radio' ||
2727
+ curJsonSchemaObj.type === 'select' ||
2728
+ curJsonSchemaObj.type === 'checkboxes') &&
2729
+ (curJsonSchemaObj.options || curJsonSchemaObj.items)
2730
+ ) {
2731
+ // 从items中获取数据
2732
+ curJsonSchemaObj = curJsonSchemaObj.options || curJsonSchemaObj.items;
2733
+ } else if (curIndex) {
2734
+ var curKeyTemp = '0';
2735
+ // 1、先根据路径值获取key值
2736
+ if (curJsonSchemaObj.propertyOrder) {
2737
+ curKeyTemp = curJsonSchemaObj.propertyOrder[curIndex];
2738
+ } else if (curJsonSchemaObj.properties) {
2739
+ var propertyOrder = Object.keys(curJsonSchemaObj.properties);
2740
+ curKeyTemp = propertyOrder[curIndex];
2741
+ }
2742
+ // 2、根据key值获取对应的json数据对象
2743
+ curJsonSchemaObj = curJsonSchemaObj.properties[curKeyTemp];
2744
+ }
2745
+ }
2746
+ }
2747
+ return curJsonSchemaObj;
2756
2748
  }
2757
2749
 
2758
2750
  /**
2759
- * 判断是否是单位类型
2760
- * */
2761
- function isQuantity(val) {
2762
- var isObject = false;
2763
- // 获取当前计量单位元素可选的单位类型
2764
- var quantityList = TypeDataList.quantity.properties.quantity.enum;
2765
- if (quantityList.indexOf(val) >= 0) {
2766
- isObject = true;
2751
+ * getSchemaByKeyRoute: 根据key值路径获取对应的schema数据
2752
+ * 【方法参数说明】
2753
+ * keyRoute: key值路径
2754
+ * targetJsonSchemaObj: schema数据对象
2755
+ * useObjClone: 是否进行深拷贝,避免影响原有数据。(默认不进行深拷贝)
2756
+ */
2757
+ function getSchemaByKeyRoute(keyRoute, targetJsonSchemaObj, useObjClone) {
2758
+ var curJsonSchemaObj = targetJsonSchemaObj;
2759
+ if (useObjClone) {
2760
+ curJsonSchemaObj = objClone(targetJsonSchemaObj); // 进行深拷贝,避免影响原有数据
2767
2761
  }
2768
- return isObject;
2762
+ if (keyRoute && curJsonSchemaObj) {
2763
+ var keyRouteArr = keyRoute.split('-');
2764
+ for (var index = 0, size = keyRouteArr.length; index < size; index++) {
2765
+ // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
2766
+ var curKey = keyRouteArr[index];
2767
+ if (curKey && curJsonSchemaObj.properties) {
2768
+ // 根据key值获取对应的json数据对象
2769
+ curJsonSchemaObj = curJsonSchemaObj.properties[curKey];
2770
+ }
2771
+ }
2772
+ }
2773
+ return curJsonSchemaObj;
2769
2774
  }
2770
2775
 
2771
2776
  /**
2772
- * 判断是否是颜色值
2777
+ * indexRoute2keyRoute:根据index索引路径获取对应的key值路径
2778
+ * 【方法参数说明】
2779
+ * indexRoute: index索引路径
2780
+ * targetJsonSchemaObj: schema数据对象
2773
2781
  * */
2774
- function isColor(colorVal) {
2775
- return /^#[0-9a-f]{6}$/.test(colorVal) || /^#[0-9a-f]{3}$/.test(colorVal);
2782
+ function indexRoute2keyRoute(indexRoute, targetJsonSchemaObj) {
2783
+ var curJsonSchemaObj = targetJsonSchemaObj;
2784
+ var curKeyRoute = '';
2785
+ var indexRouteArr = indexRoute.split('-');
2786
+ for (var index = 0, size = indexRouteArr.length; index < size; index++) {
2787
+ // 获取指定路径的json数据对象,需要按以下步骤(备注:确保是符合规则的json格式数据)
2788
+ var curIndex = indexRouteArr[index];
2789
+ if (curIndex === '0' && curJsonSchemaObj.items) {
2790
+ // 从items中获取数据
2791
+ curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
2792
+ curKeyRoute = curKeyRoute ? curKeyRoute + '-items' : 'items';
2793
+ } else if (curIndex === '0' && curJsonSchemaObj.options) {
2794
+ // 从options中获取数据
2795
+ curJsonSchemaObj = curJsonSchemaObj.options;
2796
+ curKeyRoute = curKeyRoute ? curKeyRoute + '-options' : 'options';
2797
+ } else if (curIndex) {
2798
+ // 1、先根据路径值获取key值
2799
+ var curKey = '0';
2800
+ // 1、先根据路径值获取key值
2801
+ if (curJsonSchemaObj.propertyOrder) {
2802
+ curKey = curJsonSchemaObj.propertyOrder[curIndex];
2803
+ } else if (curJsonSchemaObj.properties) {
2804
+ var propertyOrder = Object.keys(curJsonSchemaObj.properties);
2805
+ curKey = propertyOrder[curIndex];
2806
+ }
2807
+ // 2、根据key值获取对应的json数据对象
2808
+ curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
2809
+ curKeyRoute = curKeyRoute ? curKeyRoute + '-' + curKey : curKey;
2810
+ }
2811
+ }
2812
+ return curKeyRoute;
2776
2813
  }
2777
2814
 
2778
2815
  /**
2779
- * 判断是否是函数类型
2816
+ * keyRoute2indexRoute:根据key值路径获取对应的index索引路径
2817
+ * 【方法参数说明】
2818
+ * keyRoute: key值路径
2819
+ * targetJsonSchemaObj: schema数据对象
2780
2820
  * */
2781
- function isFunction(curObj) {
2782
- var isFunction = false;
2783
- if (Object.prototype.toString.call(curObj).slice(8, -1) === 'Function') {
2784
- isFunction = true;
2821
+ function keyRoute2indexRoute(keyRoute, targetJsonSchemaObj) {
2822
+ var curJsonSchemaObj = targetJsonSchemaObj;
2823
+ var curIndexRoute = '';
2824
+ var keyRouteArr = keyRoute.split('-');
2825
+ for (var index = 0, size = keyRouteArr.length; index < size; index++) {
2826
+ var curKey = keyRouteArr[index];
2827
+ if (curKey) {
2828
+ // 1、先根据路径值获取key值
2829
+ var curIndex = -1;
2830
+ // 1、先根据路径值获取key值
2831
+ if (curJsonSchemaObj.propertyOrder) {
2832
+ curIndex = curJsonSchemaObj.propertyOrder.indexOf(curKey);
2833
+ // 2、根据key值获取对应的json数据对象
2834
+ curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
2835
+ } else if (curJsonSchemaObj.properties) {
2836
+ var propertyOrder = Object.keys(curJsonSchemaObj.properties);
2837
+ curIndex = propertyOrder.indexOf(curKey);
2838
+ // 2、根据key值获取对应的json数据对象
2839
+ curJsonSchemaObj = curJsonSchemaObj.properties[curKey]; // 对象类型数据引用
2840
+ } else if (curJsonSchemaObj.items) {
2841
+ // 兼容数组类型
2842
+ curIndex = 0; // curKey;
2843
+ curJsonSchemaObj = curJsonSchemaObj.items; // 对象类型数据引用
2844
+ } else if (curJsonSchemaObj.options) {
2845
+ // 兼容数组类型
2846
+ curIndex = 0;
2847
+ curJsonSchemaObj = curJsonSchemaObj.options;
2848
+ }
2849
+ curIndexRoute = curIndexRoute
2850
+ ? curIndexRoute + '-' + curIndex
2851
+ : curIndex.toString();
2852
+ }
2785
2853
  }
2786
- return isFunction;
2854
+ return curIndexRoute;
2787
2855
  }
2788
2856
 
2789
2857
  /**
@@ -8634,6 +8702,7 @@ export {
8634
8702
  isDateTimeStr,
8635
8703
  isEmptySchema,
8636
8704
  isEqual,
8705
+ isEqualByIdT,
8637
8706
  isFunction,
8638
8707
  isNewSchemaData,
8639
8708
  isNumber,