@wibetter/json-utils 5.0.7 → 5.0.9

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
@@ -37,6 +37,17 @@ function truncate(str, paramConfig) {
37
37
  return truncate$1(str, paramConfig);
38
38
  }
39
39
 
40
+ /**
41
+ * 支持属性表达式
42
+ */
43
+ function expressionOn(expressionStr, data) {
44
+ var expressionFunc = new Function(
45
+ 'data',
46
+ 'with(data) { return (' + expressionStr + ');}',
47
+ );
48
+ return expressionFunc(data);
49
+ }
50
+
40
51
  /**
41
52
  * getJSONDataByKeyRoute: 根据key值路径获取对应的json数据
42
53
  * 【方法参数说明】
@@ -591,6 +602,24 @@ var initIMGData = {
591
602
  imgRatioReadOnly: true, // 图片宽高比例是否可调整
592
603
  };
593
604
 
605
+ /* input类型字段
606
+ * 【字段属性说明】
607
+ * title:字段项的label值
608
+ * type:用于标识字段项的展示类型(input、date、data-time、url、textarea 等)
609
+ * isRequired:是否是必填项
610
+ * default:默认值
611
+ * description:字段说明&描述
612
+ * readOnly:字段项可设置是否可编辑
613
+ * */
614
+ var initInputImageData = {
615
+ title: '图片地址',
616
+ type: 'input-image',
617
+ description: '',
618
+ // 字段项的说明和描述
619
+ accept: '.jpeg,.jpg,.png',
620
+ multiple: true,
621
+ };
622
+
594
623
  /* array类型字段
595
624
  * 【字段属性说明】
596
625
  * title:字段项的label值
@@ -605,7 +634,7 @@ var initArrayData = {
605
634
  title: '数组Array',
606
635
  description: '',
607
636
  // 字段项的说明和描述
608
- default: [],
637
+ // default: [],
609
638
  items: {
610
639
  type: 'object',
611
640
  title: '数组项',
@@ -1171,6 +1200,8 @@ var initDynamicConfig = {
1171
1200
  default: '',
1172
1201
  description: '',
1173
1202
  placeholder: '',
1203
+ onShow:
1204
+ 'type === "DevDefaults" || type === "Content" || type === "RuntimeConst"',
1174
1205
  },
1175
1206
  description: {
1176
1207
  title: '属性名称',
@@ -1178,6 +1209,7 @@ var initDynamicConfig = {
1178
1209
  default: '',
1179
1210
  description: '',
1180
1211
  placeholder: '',
1212
+ onShow: 'type === "ContentStaticConfig" || type === "ResourceCenter"',
1181
1213
  },
1182
1214
  valueType: {
1183
1215
  type: 'radio',
@@ -1195,12 +1227,15 @@ var initDynamicConfig = {
1195
1227
  default: 'string',
1196
1228
  isConditionProp: true,
1197
1229
  description: '',
1230
+ onShow: 'type === "ContentStaticConfig" || type === "ResourceCenter"',
1198
1231
  },
1199
1232
  range: {
1200
1233
  type: 'select',
1201
1234
  title: '可选项',
1202
1235
  multiple: true,
1203
1236
  options: [],
1237
+ onShow:
1238
+ '(type === "ContentStaticConfig" || type === "ResourceCenter") && valueType === "select"',
1204
1239
  description: '这里会使用value中的配置选项作为options',
1205
1240
  },
1206
1241
  },
@@ -1252,6 +1287,7 @@ var initSohuSourceData = {
1252
1287
  default: '',
1253
1288
  description: '',
1254
1289
  placeholder: '',
1290
+ onShow: 'type === "ContentStaticConfig"',
1255
1291
  },
1256
1292
  dataType: {
1257
1293
  type: 'radio',
@@ -1278,6 +1314,7 @@ var initSohuSourceData = {
1278
1314
  default: '',
1279
1315
  description: '',
1280
1316
  placeholder: '',
1317
+ onShow: 'type === "RuntimeDataSelfDefine"',
1281
1318
  },
1282
1319
  CONTENTTYPE: {
1283
1320
  type: 'select',
@@ -1297,6 +1334,7 @@ var initSohuSourceData = {
1297
1334
  },
1298
1335
  ],
1299
1336
  description: '',
1337
+ onShow: 'type === "RuntimeDataSelfDefine"',
1300
1338
  },
1301
1339
  },
1302
1340
  propertyOrder: [
@@ -1510,6 +1548,619 @@ var initSohuSourceData = {
1510
1548
  propertyOrder: ['mainConfig', 'otherConfig', 'outConfig'],
1511
1549
  showCodeViewBtn: false,
1512
1550
  };
1551
+ var initAdConfigSchema = {
1552
+ type: 'object',
1553
+ title: '广告配置',
1554
+ description: '',
1555
+ properties: {
1556
+ type: {
1557
+ type: 'select',
1558
+ title: '数据源类型',
1559
+ isConditionProp: true,
1560
+ options: [
1561
+ {
1562
+ label: '模板直接设置',
1563
+ value: 'DevDefaults',
1564
+ },
1565
+ {
1566
+ label: '资源中心配置',
1567
+ value: 'ResourceCenter',
1568
+ },
1569
+ ],
1570
+ description: '',
1571
+ },
1572
+ value: {
1573
+ type: 'object',
1574
+ title: '广告规则',
1575
+ description: '',
1576
+ onShow: 'type === "DevDefaults"',
1577
+ properties: {
1578
+ id: {
1579
+ title: '广告ID',
1580
+ type: 'input',
1581
+ default: '',
1582
+ description: '',
1583
+ placeholder: '',
1584
+ },
1585
+ rule: {
1586
+ type: 'radio',
1587
+ title: '规则类型',
1588
+ options: [
1589
+ {
1590
+ label: '固定位置',
1591
+ value: 1,
1592
+ },
1593
+ {
1594
+ label: '隔几出几',
1595
+ value: 2,
1596
+ },
1597
+ {
1598
+ label: '固定位置隔几出几',
1599
+ value: 3,
1600
+ },
1601
+ ],
1602
+ default: 1,
1603
+ description: '',
1604
+ },
1605
+ fixArray: {
1606
+ type: 'select',
1607
+ title: '固定位置',
1608
+ default: 1,
1609
+ description: '',
1610
+ options: [
1611
+ {
1612
+ label: '1',
1613
+ value: 1,
1614
+ },
1615
+ {
1616
+ label: '2',
1617
+ value: 2,
1618
+ },
1619
+ {
1620
+ label: '3',
1621
+ value: 3,
1622
+ },
1623
+ {
1624
+ label: '4',
1625
+ value: 4,
1626
+ },
1627
+ {
1628
+ label: '5',
1629
+ value: 5,
1630
+ },
1631
+ {
1632
+ label: '6',
1633
+ value: 6,
1634
+ },
1635
+ {
1636
+ label: '7',
1637
+ value: 7,
1638
+ },
1639
+ {
1640
+ label: '8',
1641
+ value: 8,
1642
+ },
1643
+ {
1644
+ label: '9',
1645
+ value: 9,
1646
+ },
1647
+ {
1648
+ label: '10',
1649
+ value: 10,
1650
+ },
1651
+ {
1652
+ label: '11',
1653
+ value: 11,
1654
+ },
1655
+ {
1656
+ label: '12',
1657
+ value: 12,
1658
+ },
1659
+ {
1660
+ label: '13',
1661
+ value: 13,
1662
+ },
1663
+ {
1664
+ label: '14',
1665
+ value: 14,
1666
+ },
1667
+ {
1668
+ label: '15',
1669
+ value: 15,
1670
+ },
1671
+ {
1672
+ label: '16',
1673
+ value: 16,
1674
+ },
1675
+ {
1676
+ label: '17',
1677
+ value: 17,
1678
+ },
1679
+ {
1680
+ label: '18',
1681
+ value: 18,
1682
+ },
1683
+ {
1684
+ label: '19',
1685
+ value: 19,
1686
+ },
1687
+ {
1688
+ label: '20',
1689
+ value: 20,
1690
+ },
1691
+ {
1692
+ label: '21',
1693
+ value: 21,
1694
+ },
1695
+ {
1696
+ label: '22',
1697
+ value: 22,
1698
+ },
1699
+ {
1700
+ label: '23',
1701
+ value: 23,
1702
+ },
1703
+ {
1704
+ label: '24',
1705
+ value: 24,
1706
+ },
1707
+ {
1708
+ label: '25',
1709
+ value: 25,
1710
+ },
1711
+ {
1712
+ label: '26',
1713
+ value: 26,
1714
+ },
1715
+ {
1716
+ label: '27',
1717
+ value: 27,
1718
+ },
1719
+ {
1720
+ label: '28',
1721
+ value: 28,
1722
+ },
1723
+ {
1724
+ label: '29',
1725
+ value: 29,
1726
+ },
1727
+ {
1728
+ label: '30',
1729
+ value: 30,
1730
+ },
1731
+ {
1732
+ label: '31',
1733
+ value: 31,
1734
+ },
1735
+ {
1736
+ label: '32',
1737
+ value: 32,
1738
+ },
1739
+ {
1740
+ label: '33',
1741
+ value: 33,
1742
+ },
1743
+ {
1744
+ label: '34',
1745
+ value: 34,
1746
+ },
1747
+ {
1748
+ label: '35',
1749
+ value: 35,
1750
+ },
1751
+ {
1752
+ label: '36',
1753
+ value: 36,
1754
+ },
1755
+ {
1756
+ label: '37',
1757
+ value: 37,
1758
+ },
1759
+ {
1760
+ label: '38',
1761
+ value: 38,
1762
+ },
1763
+ {
1764
+ label: '39',
1765
+ value: 39,
1766
+ },
1767
+ {
1768
+ label: '40',
1769
+ value: 40,
1770
+ },
1771
+ {
1772
+ label: '41',
1773
+ value: 41,
1774
+ },
1775
+ {
1776
+ label: '42',
1777
+ value: 42,
1778
+ },
1779
+ {
1780
+ label: '43',
1781
+ value: 43,
1782
+ },
1783
+ {
1784
+ label: '44',
1785
+ value: 44,
1786
+ },
1787
+ {
1788
+ label: '45',
1789
+ value: 45,
1790
+ },
1791
+ {
1792
+ label: '46',
1793
+ value: 46,
1794
+ },
1795
+ {
1796
+ label: '47',
1797
+ value: 47,
1798
+ },
1799
+ {
1800
+ label: '48',
1801
+ value: 48,
1802
+ },
1803
+ {
1804
+ label: '49',
1805
+ value: 49,
1806
+ },
1807
+ {
1808
+ label: '50',
1809
+ value: 50,
1810
+ },
1811
+ ],
1812
+ },
1813
+ begin: {
1814
+ type: 'number',
1815
+ title: '开始位置',
1816
+ default: 1,
1817
+ minimum: '1',
1818
+ maximum: '50',
1819
+ description: '',
1820
+ },
1821
+ turn: {
1822
+ type: 'number',
1823
+ title: '间隔/隔',
1824
+ default: 1,
1825
+ minimum: '1',
1826
+ maximum: '50',
1827
+ description: '',
1828
+ },
1829
+ number: {
1830
+ type: 'number',
1831
+ title: '间隔/出',
1832
+ default: 1,
1833
+ minimum: '1',
1834
+ maximum: '50',
1835
+ description: '',
1836
+ },
1837
+ mergeType: {
1838
+ type: 'radio',
1839
+ title: '插入规则',
1840
+ options: [
1841
+ {
1842
+ label: '覆盖',
1843
+ value: 0,
1844
+ },
1845
+ {
1846
+ label: '插入',
1847
+ value: 1,
1848
+ },
1849
+ ],
1850
+ default: 0,
1851
+ description: '',
1852
+ },
1853
+ },
1854
+ propertyOrder: [
1855
+ 'id',
1856
+ 'rule',
1857
+ 'fixArray',
1858
+ 'begin',
1859
+ 'turn',
1860
+ 'number',
1861
+ 'mergeType',
1862
+ ],
1863
+ },
1864
+ range: {
1865
+ type: 'array',
1866
+ title: '广告规则列表',
1867
+ description: '',
1868
+ onShow: 'type === "ResourceCenter"',
1869
+ items: {
1870
+ type: 'object',
1871
+ title: '数组项',
1872
+ description: '',
1873
+ properties: {
1874
+ id: {
1875
+ title: '广告ID',
1876
+ type: 'input',
1877
+ default: '',
1878
+ description: '',
1879
+ placeholder: '',
1880
+ },
1881
+ rule: {
1882
+ type: 'radio',
1883
+ title: '规则类型',
1884
+ options: [
1885
+ {
1886
+ label: '固定位置',
1887
+ value: 1,
1888
+ },
1889
+ {
1890
+ label: '隔几出几',
1891
+ value: 2,
1892
+ },
1893
+ {
1894
+ label: '固定位置隔几出几',
1895
+ value: 3,
1896
+ },
1897
+ ],
1898
+ default: 1,
1899
+ description: '',
1900
+ },
1901
+ fixArray: {
1902
+ type: 'select',
1903
+ title: '固定位置',
1904
+ default: 1,
1905
+ description: '',
1906
+ options: [
1907
+ {
1908
+ label: '1',
1909
+ value: 1,
1910
+ },
1911
+ {
1912
+ label: '2',
1913
+ value: 2,
1914
+ },
1915
+ {
1916
+ label: '3',
1917
+ value: 3,
1918
+ },
1919
+ {
1920
+ label: '4',
1921
+ value: 4,
1922
+ },
1923
+ {
1924
+ label: '5',
1925
+ value: 5,
1926
+ },
1927
+ {
1928
+ label: '6',
1929
+ value: 6,
1930
+ },
1931
+ {
1932
+ label: '7',
1933
+ value: 7,
1934
+ },
1935
+ {
1936
+ label: '8',
1937
+ value: 8,
1938
+ },
1939
+ {
1940
+ label: '9',
1941
+ value: 9,
1942
+ },
1943
+ {
1944
+ label: '10',
1945
+ value: 10,
1946
+ },
1947
+ {
1948
+ label: '11',
1949
+ value: 11,
1950
+ },
1951
+ {
1952
+ label: '12',
1953
+ value: 12,
1954
+ },
1955
+ {
1956
+ label: '13',
1957
+ value: 13,
1958
+ },
1959
+ {
1960
+ label: '14',
1961
+ value: 14,
1962
+ },
1963
+ {
1964
+ label: '15',
1965
+ value: 15,
1966
+ },
1967
+ {
1968
+ label: '16',
1969
+ value: 16,
1970
+ },
1971
+ {
1972
+ label: '17',
1973
+ value: 17,
1974
+ },
1975
+ {
1976
+ label: '18',
1977
+ value: 18,
1978
+ },
1979
+ {
1980
+ label: '19',
1981
+ value: 19,
1982
+ },
1983
+ {
1984
+ label: '20',
1985
+ value: 20,
1986
+ },
1987
+ {
1988
+ label: '21',
1989
+ value: 21,
1990
+ },
1991
+ {
1992
+ label: '22',
1993
+ value: 22,
1994
+ },
1995
+ {
1996
+ label: '23',
1997
+ value: 23,
1998
+ },
1999
+ {
2000
+ label: '24',
2001
+ value: 24,
2002
+ },
2003
+ {
2004
+ label: '25',
2005
+ value: 25,
2006
+ },
2007
+ {
2008
+ label: '26',
2009
+ value: 26,
2010
+ },
2011
+ {
2012
+ label: '27',
2013
+ value: 27,
2014
+ },
2015
+ {
2016
+ label: '28',
2017
+ value: 28,
2018
+ },
2019
+ {
2020
+ label: '29',
2021
+ value: 29,
2022
+ },
2023
+ {
2024
+ label: '30',
2025
+ value: 30,
2026
+ },
2027
+ {
2028
+ label: '31',
2029
+ value: 31,
2030
+ },
2031
+ {
2032
+ label: '32',
2033
+ value: 32,
2034
+ },
2035
+ {
2036
+ label: '33',
2037
+ value: 33,
2038
+ },
2039
+ {
2040
+ label: '34',
2041
+ value: 34,
2042
+ },
2043
+ {
2044
+ label: '35',
2045
+ value: 35,
2046
+ },
2047
+ {
2048
+ label: '36',
2049
+ value: 36,
2050
+ },
2051
+ {
2052
+ label: '37',
2053
+ value: 37,
2054
+ },
2055
+ {
2056
+ label: '38',
2057
+ value: 38,
2058
+ },
2059
+ {
2060
+ label: '39',
2061
+ value: 39,
2062
+ },
2063
+ {
2064
+ label: '40',
2065
+ value: 40,
2066
+ },
2067
+ {
2068
+ label: '41',
2069
+ value: 41,
2070
+ },
2071
+ {
2072
+ label: '42',
2073
+ value: 42,
2074
+ },
2075
+ {
2076
+ label: '43',
2077
+ value: 43,
2078
+ },
2079
+ {
2080
+ label: '44',
2081
+ value: 44,
2082
+ },
2083
+ {
2084
+ label: '45',
2085
+ value: 45,
2086
+ },
2087
+ {
2088
+ label: '46',
2089
+ value: 46,
2090
+ },
2091
+ {
2092
+ label: '47',
2093
+ value: 47,
2094
+ },
2095
+ {
2096
+ label: '48',
2097
+ value: 48,
2098
+ },
2099
+ {
2100
+ label: '49',
2101
+ value: 49,
2102
+ },
2103
+ {
2104
+ label: '50',
2105
+ value: 50,
2106
+ },
2107
+ ],
2108
+ },
2109
+ begin: {
2110
+ type: 'number',
2111
+ title: '开始位置',
2112
+ default: 1,
2113
+ minimum: '1',
2114
+ maximum: '50',
2115
+ description: '',
2116
+ },
2117
+ turn: {
2118
+ type: 'number',
2119
+ title: '间隔/隔',
2120
+ default: 1,
2121
+ minimum: '1',
2122
+ maximum: '50',
2123
+ description: '',
2124
+ },
2125
+ number: {
2126
+ type: 'number',
2127
+ title: '间隔/出',
2128
+ default: 1,
2129
+ minimum: '1',
2130
+ maximum: '50',
2131
+ description: '',
2132
+ },
2133
+ mergeType: {
2134
+ type: 'radio',
2135
+ title: '插入规则',
2136
+ options: [
2137
+ {
2138
+ label: '覆盖',
2139
+ value: 0,
2140
+ },
2141
+ {
2142
+ label: '插入',
2143
+ value: 1,
2144
+ },
2145
+ ],
2146
+ default: 0,
2147
+ description: '',
2148
+ },
2149
+ },
2150
+ propertyOrder: [
2151
+ 'id',
2152
+ 'rule',
2153
+ 'fixArray',
2154
+ 'begin',
2155
+ 'turn',
2156
+ 'number',
2157
+ 'mergeType',
2158
+ ],
2159
+ },
2160
+ },
2161
+ },
2162
+ propertyOrder: ['type', 'value', 'range'],
2163
+ };
1513
2164
 
1514
2165
  /** dynamicConfig: 动态配置
1515
2166
  * 【字段属性说明】
@@ -1603,6 +2254,7 @@ var TypeDataList = {
1603
2254
  color: initColorData,
1604
2255
  image: initIMGData,
1605
2256
  number: initNumberData,
2257
+ 'input-image': initInputImageData,
1606
2258
  json: initJsonData,
1607
2259
  codearea: initCodeAreaData,
1608
2260
  htmlarea: initHtmlAreaData,
@@ -1621,6 +2273,7 @@ var TypeDataList = {
1621
2273
  'dynamic-config': initDynamicConfig,
1622
2274
  'sohu-source': initSohuSourceData,
1623
2275
  'sohu-event': initSohuEventConfig,
2276
+ 'sohu-ad': initAdConfigSchema,
1624
2277
  };
1625
2278
 
1626
2279
  // 事件类型数据
@@ -6682,6 +7335,7 @@ var valExpectType =
6682
7335
  input: 'string',
6683
7336
  json: 'string',
6684
7337
  number: 'number',
7338
+ 'input-image': 'string',
6685
7339
  object: 'object',
6686
7340
  quantity: 'object',
6687
7341
  radio: 'string',
@@ -7014,8 +7668,9 @@ function objectSchema2JsonData(jsonSchema, jsonData) {
7014
7668
  var oldValue = jsonData;
7015
7669
  if (
7016
7670
  hasProperties(oldValue) &&
7017
- hasProperties(jsonItem.default) &&
7018
- typeof oldValue !== typeof jsonItem.default
7671
+ ((hasProperties(jsonItem.default) &&
7672
+ typeof oldValue !== typeof jsonSchema.default) ||
7673
+ !isObject$1(oldValue))
7019
7674
  ) {
7020
7675
  // 表示当前数据类型发生变化,则丢弃旧版数据
7021
7676
  oldValue = undefined;
@@ -7183,8 +7838,9 @@ function arraySchema2JsonData(jsonSchema, jsonData) {
7183
7838
  var oldValue = jsonData;
7184
7839
  if (
7185
7840
  hasProperties(oldValue) &&
7186
- hasProperties(jsonSchema.default) &&
7187
- typeof oldValue !== typeof jsonSchema.default
7841
+ ((hasProperties(jsonSchema.default) &&
7842
+ typeof oldValue !== typeof jsonSchema.default) ||
7843
+ !isArray(oldValue))
7188
7844
  ) {
7189
7845
  // 表示当前数据类型发生变化,则丢弃旧版数据
7190
7846
  oldValue = undefined;
@@ -7451,6 +8107,39 @@ function json2treeData(mockData, parentDataRoute) {
7451
8107
  return treeData;
7452
8108
  }
7453
8109
 
8110
+ /**
8111
+ * 收集当前schema中的所有条件子字段,根据其数值拼接成对应的 conditionValue
8112
+ */
8113
+ function schema2conditionValue(jsonSchema, jsonData) {
8114
+ var conditionValue = '';
8115
+ if (getExpectType$1(jsonSchema.type) === 'object' && jsonSchema.properties) {
8116
+ var curPropertyOrder = [];
8117
+ if (jsonSchema.propertyOrder) {
8118
+ curPropertyOrder = jsonSchema.propertyOrder;
8119
+ } else {
8120
+ curPropertyOrder = Object.keys(jsonSchema.properties);
8121
+ }
8122
+ curPropertyOrder.map(function (jsonKey) {
8123
+ var curJsonItem = jsonSchema.properties[jsonKey];
8124
+ var curConditionValue = jsonData[jsonKey];
8125
+ if (
8126
+ getExpectType$1(curJsonItem.type) !== 'array' ||
8127
+ getExpectType$1(curJsonItem.type) !== 'object'
8128
+ ) {
8129
+ if (curConditionValue && curJsonItem.isConditionProp) {
8130
+ // 仅记录条件字段数值
8131
+ if (conditionValue.indexOf('-') > 0) {
8132
+ conditionValue += '-' + curConditionValue;
8133
+ } else {
8134
+ conditionValue = curConditionValue;
8135
+ }
8136
+ }
8137
+ }
8138
+ });
8139
+ }
8140
+ return conditionValue;
8141
+ }
8142
+
7454
8143
  /**
7455
8144
  * 获取父元素的key路径值
7456
8145
  */
@@ -7507,6 +8196,7 @@ export {
7507
8196
  TypeDataList,
7508
8197
  dataRoute2dataPath,
7509
8198
  dynamicDataAnalyzer,
8199
+ expressionOn,
7510
8200
  getCurPosition,
7511
8201
  getDefaultOptionVal,
7512
8202
  getExpectType$1 as getExpectType,
@@ -7549,6 +8239,7 @@ export {
7549
8239
  oldSchemaToNewSchema,
7550
8240
  oldSchemaToNewSchemaV1,
7551
8241
  registerExpectType,
8242
+ schema2conditionValue,
7552
8243
  schema2json,
7553
8244
  schemaMetaList,
7554
8245
  truncate,