@kmkf-fe-packages/kmkf-work-order-service-component 2.2.3-rc.1 → 2.2.3
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/esm/FlowTemplateDetailV2/components/FormRender/index.js +36 -84
- package/package.json +5 -5
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/component-dependency-finder.d.ts +0 -75
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/component-dependency-finder.js +0 -328
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/types.d.ts +0 -41
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/types.js +0 -1
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/value-mapping-finder.d.ts +0 -61
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/value-mapping-finder.js +0 -292
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/value-mapping-types.d.ts +0 -65
- package/dist/esm/FlowTemplateDetailV2/components/FormRender/value-mapping-types.js +0 -1
|
@@ -25,7 +25,7 @@ import React, { useState, useRef, useEffect, useMemo, forwardRef, useImperativeH
|
|
|
25
25
|
import { ConfigProvider, Form, Space, Tag } from 'antd';
|
|
26
26
|
import { useWhyDidYouUpdate } from 'ahooks';
|
|
27
27
|
import zhCN from 'antd/es/locale/zh_CN';
|
|
28
|
-
import { get, some, set, every, cloneDeep, isEmpty, intersection, throttle, groupBy, find, isArray
|
|
28
|
+
import { get, some, set, every, cloneDeep, isEmpty, intersection, throttle, groupBy, find, isArray } from 'lodash';
|
|
29
29
|
import 'moment/locale/zh-cn';
|
|
30
30
|
import { calcWorkOrderList, orderBack, getReplaceWarnValues, COMPONENT_MAP_NAME, EXCLUDE_REPLACE_TOP_COMPONENT,
|
|
31
31
|
// 重复检验不需要展示在顶部的
|
|
@@ -44,8 +44,6 @@ import { NEED_CLEAR_FIELDS_WHEN_SHOP_ID_CHANGE } from "../../constant";
|
|
|
44
44
|
import { Context } from "../../context";
|
|
45
45
|
import { orderBackKmAddress } from "./constants";
|
|
46
46
|
import { onBlurExpressLogisticsCode, onBlurErpAfterSaleTradeId, onBlurSkxOutboundNoticeNo } from "./onBlur";
|
|
47
|
-
import { findAllDependencies } from "./component-dependency-finder";
|
|
48
|
-
import { findValueDependencies } from "./value-mapping-finder";
|
|
49
47
|
// 记录显隐触发隐藏的组件。显示后,重新出发一遍映射规则
|
|
50
48
|
// TODO: 用useState会有bug, 不确定是哪里导致的
|
|
51
49
|
var hideByXYComponentsMap = {};
|
|
@@ -223,9 +221,6 @@ var FormRender = function FormRender(props, ref) {
|
|
|
223
221
|
}
|
|
224
222
|
});
|
|
225
223
|
setReplaceValue(function (value) {
|
|
226
|
-
if (isMatch(value, obj)) {
|
|
227
|
-
return value;
|
|
228
|
-
}
|
|
229
224
|
return _objectSpread(_objectSpread({}, value), obj);
|
|
230
225
|
});
|
|
231
226
|
};
|
|
@@ -283,9 +278,6 @@ var FormRender = function FormRender(props, ref) {
|
|
|
283
278
|
return prv;
|
|
284
279
|
}, {});
|
|
285
280
|
setReplaceValue(function (prev) {
|
|
286
|
-
if (isMatch(prev, resultParams)) {
|
|
287
|
-
return prev;
|
|
288
|
-
}
|
|
289
281
|
return _objectSpread(_objectSpread({}, prev), resultParams);
|
|
290
282
|
});
|
|
291
283
|
setReplaceConfig(function (prev) {
|
|
@@ -350,11 +342,6 @@ var FormRender = function FormRender(props, ref) {
|
|
|
350
342
|
// 清空打款组件之前的重复校验
|
|
351
343
|
if (!enterprisePaymentAlipayNo) {
|
|
352
344
|
setReplaceValue(function (value) {
|
|
353
|
-
if (isMatch(value, {
|
|
354
|
-
enterprisePaymentAlipayNo: 0
|
|
355
|
-
})) {
|
|
356
|
-
return value;
|
|
357
|
-
}
|
|
358
345
|
return _objectSpread(_objectSpread({}, value), {}, {
|
|
359
346
|
enterprisePaymentAlipayNo: 0
|
|
360
347
|
});
|
|
@@ -632,7 +619,7 @@ var FormRender = function FormRender(props, ref) {
|
|
|
632
619
|
// 查询标签
|
|
633
620
|
var queryLabels = /*#__PURE__*/function () {
|
|
634
621
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(tid, shopId) {
|
|
635
|
-
var
|
|
622
|
+
var _yield$queryLabelByTr, _yield$queryLabelByTr2, data;
|
|
636
623
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
637
624
|
while (1) switch (_context2.prev = _context2.next) {
|
|
638
625
|
case 0:
|
|
@@ -648,37 +635,26 @@ var FormRender = function FormRender(props, ref) {
|
|
|
648
635
|
}
|
|
649
636
|
return _context2.abrupt("return", console.debug('查询标签缺少必要参数-shopId'));
|
|
650
637
|
case 4:
|
|
651
|
-
oldLabelList = form.getFieldValue("".concat(labelComponent.uniqueKey));
|
|
652
638
|
if (tid) {
|
|
653
|
-
_context2.next =
|
|
639
|
+
_context2.next = 8;
|
|
654
640
|
break;
|
|
655
641
|
}
|
|
656
|
-
setLabelList(
|
|
657
|
-
|
|
658
|
-
return [];
|
|
659
|
-
});
|
|
660
|
-
if (oldLabelList.length !== 0) {
|
|
661
|
-
form.setFieldsValue(_defineProperty({}, "".concat(labelComponent.uniqueKey), []));
|
|
662
|
-
}
|
|
642
|
+
setLabelList([]);
|
|
643
|
+
form.setFieldsValue(_defineProperty({}, "".concat(labelComponent.uniqueKey), []));
|
|
663
644
|
return _context2.abrupt("return", console.debug('查询标签缺少必要参数-tradeId'));
|
|
664
|
-
case
|
|
665
|
-
_context2.next =
|
|
645
|
+
case 8:
|
|
646
|
+
_context2.next = 10;
|
|
666
647
|
return queryLabelByTradeId({
|
|
667
648
|
tid: tid,
|
|
668
649
|
shopId: shopId
|
|
669
650
|
});
|
|
670
|
-
case
|
|
651
|
+
case 10:
|
|
671
652
|
_yield$queryLabelByTr = _context2.sent;
|
|
672
653
|
_yield$queryLabelByTr2 = _yield$queryLabelByTr.data;
|
|
673
654
|
data = _yield$queryLabelByTr2 === void 0 ? [] : _yield$queryLabelByTr2;
|
|
674
|
-
setLabelList(
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
});
|
|
678
|
-
if (!isEqual(oldLabelList, data)) {
|
|
679
|
-
form.setFieldsValue(_defineProperty({}, "".concat(labelComponent.uniqueKey), data));
|
|
680
|
-
}
|
|
681
|
-
case 16:
|
|
655
|
+
setLabelList(data);
|
|
656
|
+
form.setFieldsValue(_defineProperty({}, "".concat(labelComponent.uniqueKey), data));
|
|
657
|
+
case 15:
|
|
682
658
|
case "end":
|
|
683
659
|
return _context2.stop();
|
|
684
660
|
}
|
|
@@ -691,7 +667,7 @@ var FormRender = function FormRender(props, ref) {
|
|
|
691
667
|
// 查询会员等级
|
|
692
668
|
var queryMemberLevels = /*#__PURE__*/function () {
|
|
693
669
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(tid, shopId) {
|
|
694
|
-
var
|
|
670
|
+
var _yield$queryMemberLev, _yield$queryMemberLev2, data;
|
|
695
671
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
696
672
|
while (1) switch (_context3.prev = _context3.next) {
|
|
697
673
|
case 0:
|
|
@@ -707,29 +683,24 @@ var FormRender = function FormRender(props, ref) {
|
|
|
707
683
|
}
|
|
708
684
|
return _context3.abrupt("return", console.debug('查询标签缺少必要参数-shopId'));
|
|
709
685
|
case 4:
|
|
710
|
-
oldMemberLevel = form.getFieldValue("".concat(labelComponent.uniqueKey));
|
|
711
686
|
if (tid) {
|
|
712
|
-
_context3.next =
|
|
687
|
+
_context3.next = 7;
|
|
713
688
|
break;
|
|
714
689
|
}
|
|
715
|
-
|
|
716
|
-
form.setFieldsValue(_defineProperty({}, "".concat(labelComponent.uniqueKey), []));
|
|
717
|
-
}
|
|
690
|
+
form.setFieldsValue(_defineProperty({}, "".concat(memberLevelComponent.uniqueKey), []));
|
|
718
691
|
return _context3.abrupt("return", console.debug('查询标签缺少必要参数-tradeId'));
|
|
719
|
-
case
|
|
720
|
-
_context3.next =
|
|
692
|
+
case 7:
|
|
693
|
+
_context3.next = 9;
|
|
721
694
|
return queryMemberLevel({
|
|
722
695
|
tid: tid,
|
|
723
696
|
shopId: shopId
|
|
724
697
|
});
|
|
725
|
-
case
|
|
698
|
+
case 9:
|
|
726
699
|
_yield$queryMemberLev = _context3.sent;
|
|
727
700
|
_yield$queryMemberLev2 = _yield$queryMemberLev.data;
|
|
728
701
|
data = _yield$queryMemberLev2 === void 0 ? [] : _yield$queryMemberLev2;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
}
|
|
732
|
-
case 14:
|
|
702
|
+
form.setFieldsValue(_defineProperty({}, "".concat(memberLevelComponent.uniqueKey), data));
|
|
703
|
+
case 13:
|
|
733
704
|
case "end":
|
|
734
705
|
return _context3.stop();
|
|
735
706
|
}
|
|
@@ -932,9 +903,6 @@ var FormRender = function FormRender(props, ref) {
|
|
|
932
903
|
break;
|
|
933
904
|
}
|
|
934
905
|
setReplaceValue(function (prev) {
|
|
935
|
-
if (isMatch(prev, _defineProperty({}, type, 0))) {
|
|
936
|
-
return prev;
|
|
937
|
-
}
|
|
938
906
|
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, type, 0));
|
|
939
907
|
});
|
|
940
908
|
replaceValueRef.current = _objectSpread(_objectSpread({}, replaceValue), {}, _defineProperty({}, type, 0));
|
|
@@ -1123,6 +1091,13 @@ var FormRender = function FormRender(props, ref) {
|
|
|
1123
1091
|
if (Reflect.has(currentComponentDisplayStatus.current, prefixId) && !currentComponentDisplayStatus.current[prefixId]) {
|
|
1124
1092
|
return false;
|
|
1125
1093
|
}
|
|
1094
|
+
// console.debug(
|
|
1095
|
+
// '显影计算',
|
|
1096
|
+
// dependenceDetail?.type,
|
|
1097
|
+
// leftValue,
|
|
1098
|
+
// item.compareSymbol?.toUpperCase(),
|
|
1099
|
+
// item.rightValue,
|
|
1100
|
+
// );
|
|
1126
1101
|
return getExpression((_item$compareSymbol = item.compareSymbol) === null || _item$compareSymbol === void 0 ? void 0 : _item$compareSymbol.toUpperCase(), leftValue, item.rightValue);
|
|
1127
1102
|
};
|
|
1128
1103
|
var getDisplayAndDisabledConfig = function getDisplayAndDisabledConfig(config) {
|
|
@@ -1209,23 +1184,12 @@ var FormRender = function FormRender(props, ref) {
|
|
|
1209
1184
|
currentTemplateAllComponentsDisplay.current[instance === null || instance === void 0 ? void 0 : instance.id] = true;
|
|
1210
1185
|
if (Reflect.has(idConditionListMap, instance.id)) {
|
|
1211
1186
|
var currentIdDependenceOtherFields = idConditionListMap[instance.id];
|
|
1212
|
-
// console.group('当前组件', instance.id, instance.name);
|
|
1213
|
-
var dependencies = findAllDependencies(instance.id, idConditionListMap);
|
|
1214
|
-
// console.log('当前组件所依赖项: ', dependencies);
|
|
1215
|
-
var currentDependenciesMappingComponent = _toConsumableArray(new Set(dependencies.concat(instance.id))).reduce(function (cur, nxt) {
|
|
1216
|
-
var _findValueDependencie, _findValueDependencie2;
|
|
1217
|
-
var mappingDependencies = (_findValueDependencie = findValueDependencies(nxt, mappingConfig.config)) === null || _findValueDependencie === void 0 ? void 0 : (_findValueDependencie2 = _findValueDependencie.dependencies) === null || _findValueDependencie2 === void 0 ? void 0 : _findValueDependencie2.map(function (item) {
|
|
1218
|
-
return item.sourceComponent;
|
|
1219
|
-
});
|
|
1220
|
-
cur = cur.concat(mappingDependencies);
|
|
1221
|
-
return cur;
|
|
1222
|
-
}, []);
|
|
1223
|
-
// console.log('当前组件所依赖项+值映射依赖项: ', currentDependenciesMappingComponent);
|
|
1224
|
-
// console.groupEnd();
|
|
1225
1187
|
// 需要增加显隐处理逻辑
|
|
1226
1188
|
return /*#__PURE__*/React.createElement(Form.Item, {
|
|
1227
1189
|
noStyle: true,
|
|
1228
|
-
|
|
1190
|
+
shouldUpdate: function shouldUpdate() {
|
|
1191
|
+
return true; // TODO: 修复重复依赖的问题 https://tb.raycloud.com/task/64e4491e0b8b5c001e1099b9
|
|
1192
|
+
}
|
|
1229
1193
|
}, function (_ref8) {
|
|
1230
1194
|
var getFieldValue = _ref8.getFieldValue;
|
|
1231
1195
|
var show = currentIdDependenceOtherFields === null || currentIdDependenceOtherFields === void 0 ? void 0 : currentIdDependenceOtherFields.reduce(function (cur, nxt) {
|
|
@@ -1328,29 +1292,17 @@ var FormRender = function FormRender(props, ref) {
|
|
|
1328
1292
|
var handleWatchFormValueChange = function handleWatchFormValueChange(changedValues) {
|
|
1329
1293
|
var allValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1330
1294
|
var componentShowMap = currentTemplateAllComponentsDisplay.current;
|
|
1331
|
-
var formValue = {
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
componentShowMap: componentShowMap
|
|
1338
|
-
});
|
|
1339
|
-
if (!isMatch(allValues, formValue)) {
|
|
1340
|
-
form.setFieldsValue(_objectSpread(_objectSpread({}, allValues), formValue));
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1295
|
+
var formValue = getCalculationComponentValue({
|
|
1296
|
+
calculationTypeComponentList: calculationTypeComponentList,
|
|
1297
|
+
allValues: allValues,
|
|
1298
|
+
componentShowMap: componentShowMap
|
|
1299
|
+
});
|
|
1300
|
+
form.setFieldsValue(_objectSpread(_objectSpread({}, allValues), formValue));
|
|
1344
1301
|
//缓存防止bs商品组件联动返填获取不到值
|
|
1345
1302
|
setTimeout(function () {
|
|
1346
1303
|
changeValuesCacheOrderInfo(_objectSpread(_objectSpread({}, form.getFieldsValue()), formValue), templateDetail === null || templateDetail === void 0 ? void 0 : templateDetail.componentDtoList);
|
|
1347
1304
|
});
|
|
1348
1305
|
};
|
|
1349
|
-
var debouncedHandleWatchFormValueChange = useMemo(function () {
|
|
1350
|
-
return debounce(handleWatchFormValueChange, 150);
|
|
1351
|
-
},
|
|
1352
|
-
// 150ms防抖
|
|
1353
|
-
[handleWatchFormValueChange]);
|
|
1354
1306
|
var changeValuesCacheOrderInfo = throttle(function (value, tempLateList) {
|
|
1355
1307
|
//如果店铺id不存在 不缓存
|
|
1356
1308
|
if (!(value !== null && value !== void 0 && value.shopId)) return;
|
|
@@ -1464,7 +1416,7 @@ var FormRender = function FormRender(props, ref) {
|
|
|
1464
1416
|
}, formProps), preNodeFormItems), /*#__PURE__*/React.createElement(Form, _extends({
|
|
1465
1417
|
form: form
|
|
1466
1418
|
}, formProps, {
|
|
1467
|
-
onValuesChange:
|
|
1419
|
+
onValuesChange: handleWatchFormValueChange
|
|
1468
1420
|
}), /*#__PURE__*/React.createElement(ShopName, {
|
|
1469
1421
|
shopList: shopList,
|
|
1470
1422
|
handleChangeShopId: handleChangeShopId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmkf-fe-packages/kmkf-work-order-service-component",
|
|
3
|
-
"version": "2.2.3
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"module": "dist/esm/index.js",
|
|
5
5
|
"typings": "dist/esm/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ant-design/icons": "^4.7.0",
|
|
35
|
-
"@kmkf-fe-packages/basic-components": "2.2.3
|
|
36
|
-
"@kmkf-fe-packages/kmkf-utils": "2.2.3
|
|
37
|
-
"@kmkf-fe-packages/services-components": "2.2.3
|
|
35
|
+
"@kmkf-fe-packages/basic-components": "2.2.3",
|
|
36
|
+
"@kmkf-fe-packages/kmkf-utils": "2.2.3",
|
|
37
|
+
"@kmkf-fe-packages/services-components": "2.2.3",
|
|
38
38
|
"@reduxjs/toolkit": "^1.8.5",
|
|
39
39
|
"ahooks": "^3.7.4",
|
|
40
40
|
"copy-to-clipboard": "^3.3.3",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "48d5bd6efb74f49f619bbf822d3530954bcf4801",
|
|
77
77
|
"gitHooks": {
|
|
78
78
|
"pre-commit": "lint-staged"
|
|
79
79
|
}
|
package/dist/esm/FlowTemplateDetailV2/components/FormRender/component-dependency-finder.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件显隐依赖关系查找器 - TypeScript ES Module版本
|
|
3
|
-
* 根据配置文件递归查找组件的所有依赖关系
|
|
4
|
-
*/
|
|
5
|
-
import type { Config, DependencyGraph, CircularDependency, DependencyLevels, ComponentStat, DependencyOptions, DependencyAnalysis } from './types.js';
|
|
6
|
-
/**
|
|
7
|
-
* 查找组件的所有依赖关系(递归)
|
|
8
|
-
* @param componentKey - 要查找依赖的组件key
|
|
9
|
-
* @param config - 显隐配置对象
|
|
10
|
-
* @param visited - 已访问的组件集合,用于避免循环依赖
|
|
11
|
-
* @param dependencies - 依赖组件集合
|
|
12
|
-
* @param options - 查找选项
|
|
13
|
-
* @returns 所有依赖组件的key数组
|
|
14
|
-
*/
|
|
15
|
-
export declare function findAllDependencies(componentKey: string, config: Config, visited?: Set<string>, dependencies?: Set<string>, options?: DependencyOptions): string[];
|
|
16
|
-
/**
|
|
17
|
-
* 获取组件的直接依赖
|
|
18
|
-
* @param componentKey - 组件key
|
|
19
|
-
* @param config - 显隐配置对象
|
|
20
|
-
* @returns 直接依赖的组件key数组
|
|
21
|
-
*/
|
|
22
|
-
export declare function getDirectDependencies(componentKey: string, config: Config): string[];
|
|
23
|
-
/**
|
|
24
|
-
* 构建整个依赖关系图
|
|
25
|
-
* @param config - 显隐配置对象
|
|
26
|
-
* @returns 依赖关系图,格式:{ componentKey: [依赖的组件数组] }
|
|
27
|
-
*/
|
|
28
|
-
export declare function buildDependencyGraph(config: Config): DependencyGraph;
|
|
29
|
-
/**
|
|
30
|
-
* 检测循环依赖
|
|
31
|
-
* @param config - 显隐配置对象
|
|
32
|
-
* @returns 包含循环依赖的组件组
|
|
33
|
-
*/
|
|
34
|
-
export declare function detectCircularDependencies(config: Config): CircularDependency[];
|
|
35
|
-
/**
|
|
36
|
-
* 打印依赖关系树
|
|
37
|
-
* @param componentKey - 组件key
|
|
38
|
-
* @param config - 显隐配置对象
|
|
39
|
-
* @param level - 缩进级别
|
|
40
|
-
* @param visited - 已访问的组件集合
|
|
41
|
-
*/
|
|
42
|
-
export declare function printDependencyTree(componentKey: string, config: Config, level?: number, visited?: Set<string>): void;
|
|
43
|
-
/**
|
|
44
|
-
* 获取组件的依赖层级
|
|
45
|
-
* @param componentKey - 组件key
|
|
46
|
-
* @param config - 显隐配置对象
|
|
47
|
-
* @returns 依赖层级对象
|
|
48
|
-
*/
|
|
49
|
-
export declare function getDependencyLevels(componentKey: string, config: Config): DependencyLevels;
|
|
50
|
-
/**
|
|
51
|
-
* 分析组件的完整依赖信息
|
|
52
|
-
* @param componentKey - 组件key
|
|
53
|
-
* @param config - 显隐配置对象
|
|
54
|
-
* @returns 完整的依赖分析结果
|
|
55
|
-
*/
|
|
56
|
-
export declare function analyzeDependency(componentKey: string, config: Config): DependencyAnalysis;
|
|
57
|
-
/**
|
|
58
|
-
* 获取依赖统计信息
|
|
59
|
-
* @param config - 显隐配置对象
|
|
60
|
-
* @param topN - 返回前N个结果
|
|
61
|
-
* @returns 组件统计信息数组
|
|
62
|
-
*/
|
|
63
|
-
export declare function getDependencyStats(config: Config, topN?: number): {
|
|
64
|
-
mostDependencies: ComponentStat[];
|
|
65
|
-
mostDependedOn: ComponentStat[];
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* 验证配置文件格式
|
|
69
|
-
* @param config - 要验证的配置对象
|
|
70
|
-
* @returns 验证结果和错误信息
|
|
71
|
-
*/
|
|
72
|
-
export declare function validateConfig(config: unknown): {
|
|
73
|
-
isValid: boolean;
|
|
74
|
-
errors: string[];
|
|
75
|
-
};
|
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
5
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
-
/**
|
|
13
|
-
* 组件显隐依赖关系查找器 - TypeScript ES Module版本
|
|
14
|
-
* 根据配置文件递归查找组件的所有依赖关系
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 查找组件的所有依赖关系(递归)
|
|
19
|
-
* @param componentKey - 要查找依赖的组件key
|
|
20
|
-
* @param config - 显隐配置对象
|
|
21
|
-
* @param visited - 已访问的组件集合,用于避免循环依赖
|
|
22
|
-
* @param dependencies - 依赖组件集合
|
|
23
|
-
* @param options - 查找选项
|
|
24
|
-
* @returns 所有依赖组件的key数组
|
|
25
|
-
*/
|
|
26
|
-
export function findAllDependencies(componentKey, config) {
|
|
27
|
-
var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
|
|
28
|
-
var dependencies = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Set();
|
|
29
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
30
|
-
var _options$maxDepth = options.maxDepth,
|
|
31
|
-
maxDepth = _options$maxDepth === void 0 ? Infinity : _options$maxDepth;
|
|
32
|
-
|
|
33
|
-
// 如果已经访问过这个组件,直接返回(避免循环依赖)
|
|
34
|
-
if (visited.has(componentKey)) {
|
|
35
|
-
return Array.from(dependencies);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 检查递归深度
|
|
39
|
-
if (visited.size >= maxDepth) {
|
|
40
|
-
return Array.from(dependencies);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 标记当前组件为已访问
|
|
44
|
-
visited.add(componentKey);
|
|
45
|
-
|
|
46
|
-
// 获取当前组件的配置
|
|
47
|
-
var componentConfig = config[componentKey];
|
|
48
|
-
|
|
49
|
-
// 如果组件不存在配置,返回当前依赖列表
|
|
50
|
-
if (!componentConfig || !Array.isArray(componentConfig)) {
|
|
51
|
-
return Array.from(dependencies);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 遍历组件的所有规则组
|
|
55
|
-
componentConfig.forEach(function (ruleGroup) {
|
|
56
|
-
if (ruleGroup.rules && Array.isArray(ruleGroup.rules)) {
|
|
57
|
-
// 遍历规则组中的所有规则
|
|
58
|
-
ruleGroup.rules.forEach(function (rule) {
|
|
59
|
-
if (rule.leftValue && typeof rule.leftValue === 'string') {
|
|
60
|
-
var dependencyKey = rule.leftValue;
|
|
61
|
-
|
|
62
|
-
// 添加直接依赖
|
|
63
|
-
dependencies.add(dependencyKey);
|
|
64
|
-
|
|
65
|
-
// 递归查找间接依赖
|
|
66
|
-
findAllDependencies(dependencyKey, config, visited, dependencies, options);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return Array.from(dependencies);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 获取组件的直接依赖
|
|
76
|
-
* @param componentKey - 组件key
|
|
77
|
-
* @param config - 显隐配置对象
|
|
78
|
-
* @returns 直接依赖的组件key数组
|
|
79
|
-
*/
|
|
80
|
-
export function getDirectDependencies(componentKey, config) {
|
|
81
|
-
var componentConfig = config[componentKey];
|
|
82
|
-
var dependencies = new Set();
|
|
83
|
-
if (!componentConfig || !Array.isArray(componentConfig)) {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
componentConfig.forEach(function (ruleGroup) {
|
|
87
|
-
if (ruleGroup.rules && Array.isArray(ruleGroup.rules)) {
|
|
88
|
-
ruleGroup.rules.forEach(function (rule) {
|
|
89
|
-
if (rule.leftValue && typeof rule.leftValue === 'string') {
|
|
90
|
-
dependencies.add(rule.leftValue);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return Array.from(dependencies);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 构建整个依赖关系图
|
|
100
|
-
* @param config - 显隐配置对象
|
|
101
|
-
* @returns 依赖关系图,格式:{ componentKey: [依赖的组件数组] }
|
|
102
|
-
*/
|
|
103
|
-
export function buildDependencyGraph(config) {
|
|
104
|
-
var dependencyGraph = {};
|
|
105
|
-
Object.keys(config).forEach(function (componentKey) {
|
|
106
|
-
dependencyGraph[componentKey] = findAllDependencies(componentKey, config);
|
|
107
|
-
});
|
|
108
|
-
return dependencyGraph;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 检测循环依赖
|
|
113
|
-
* @param config - 显隐配置对象
|
|
114
|
-
* @returns 包含循环依赖的组件组
|
|
115
|
-
*/
|
|
116
|
-
export function detectCircularDependencies(config) {
|
|
117
|
-
var circularDeps = [];
|
|
118
|
-
var visiting = new Set();
|
|
119
|
-
var visited = new Set();
|
|
120
|
-
function dfs(componentKey) {
|
|
121
|
-
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
122
|
-
if (visiting.has(componentKey)) {
|
|
123
|
-
// 发现循环依赖
|
|
124
|
-
var cycleStart = path.indexOf(componentKey);
|
|
125
|
-
circularDeps.push(path.slice(cycleStart).concat(componentKey));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (visited.has(componentKey)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
visiting.add(componentKey);
|
|
132
|
-
path.push(componentKey);
|
|
133
|
-
var directDeps = getDirectDependencies(componentKey, config);
|
|
134
|
-
directDeps.forEach(function (dep) {
|
|
135
|
-
dfs(dep, _toConsumableArray(path));
|
|
136
|
-
});
|
|
137
|
-
visiting.delete(componentKey);
|
|
138
|
-
visited.add(componentKey);
|
|
139
|
-
}
|
|
140
|
-
Object.keys(config).forEach(function (componentKey) {
|
|
141
|
-
if (!visited.has(componentKey)) {
|
|
142
|
-
dfs(componentKey);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
return circularDeps;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* 打印依赖关系树
|
|
150
|
-
* @param componentKey - 组件key
|
|
151
|
-
* @param config - 显隐配置对象
|
|
152
|
-
* @param level - 缩进级别
|
|
153
|
-
* @param visited - 已访问的组件集合
|
|
154
|
-
*/
|
|
155
|
-
export function printDependencyTree(componentKey, config) {
|
|
156
|
-
var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
157
|
-
var visited = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Set();
|
|
158
|
-
var indent = ' '.repeat(level);
|
|
159
|
-
console.log("".concat(indent).concat(componentKey));
|
|
160
|
-
if (visited.has(componentKey)) {
|
|
161
|
-
console.log("".concat(indent, " [\u5FAA\u73AF\u4F9D\u8D56]"));
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
visited.add(componentKey);
|
|
165
|
-
var directDeps = getDirectDependencies(componentKey, config);
|
|
166
|
-
directDeps.forEach(function (dep) {
|
|
167
|
-
printDependencyTree(dep, config, level + 1, new Set(visited));
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 获取组件的依赖层级
|
|
173
|
-
* @param componentKey - 组件key
|
|
174
|
-
* @param config - 显隐配置对象
|
|
175
|
-
* @returns 依赖层级对象
|
|
176
|
-
*/
|
|
177
|
-
export function getDependencyLevels(componentKey, config) {
|
|
178
|
-
var levels = {};
|
|
179
|
-
var queue = [{
|
|
180
|
-
key: componentKey,
|
|
181
|
-
level: 0
|
|
182
|
-
}];
|
|
183
|
-
var visited = new Set();
|
|
184
|
-
var _loop = function _loop() {
|
|
185
|
-
var current = queue.shift();
|
|
186
|
-
if (!current) return "break";
|
|
187
|
-
var key = current.key,
|
|
188
|
-
level = current.level;
|
|
189
|
-
if (visited.has(key)) return "continue";
|
|
190
|
-
visited.add(key);
|
|
191
|
-
if (level > 0) {
|
|
192
|
-
// 不包含自己
|
|
193
|
-
if (!levels[level]) levels[level] = [];
|
|
194
|
-
levels[level].push(key);
|
|
195
|
-
}
|
|
196
|
-
var directDeps = getDirectDependencies(key, config);
|
|
197
|
-
directDeps.forEach(function (dep) {
|
|
198
|
-
if (!visited.has(dep)) {
|
|
199
|
-
queue.push({
|
|
200
|
-
key: dep,
|
|
201
|
-
level: level + 1
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
while (queue.length > 0) {
|
|
207
|
-
var _ret = _loop();
|
|
208
|
-
if (_ret === "break") break;
|
|
209
|
-
if (_ret === "continue") continue;
|
|
210
|
-
}
|
|
211
|
-
return levels;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* 分析组件的完整依赖信息
|
|
216
|
-
* @param componentKey - 组件key
|
|
217
|
-
* @param config - 显隐配置对象
|
|
218
|
-
* @returns 完整的依赖分析结果
|
|
219
|
-
*/
|
|
220
|
-
export function analyzeDependency(componentKey, config) {
|
|
221
|
-
var directDependencies = getDirectDependencies(componentKey, config);
|
|
222
|
-
var allDependencies = findAllDependencies(componentKey, config);
|
|
223
|
-
var dependencyLevels = getDependencyLevels(componentKey, config);
|
|
224
|
-
|
|
225
|
-
// 检查是否有循环依赖
|
|
226
|
-
var circularDeps = detectCircularDependencies(config);
|
|
227
|
-
var hasCircularDependency = circularDeps.some(function (cycle) {
|
|
228
|
-
return cycle.includes(componentKey);
|
|
229
|
-
});
|
|
230
|
-
return {
|
|
231
|
-
componentKey: componentKey,
|
|
232
|
-
directDependencies: directDependencies,
|
|
233
|
-
allDependencies: allDependencies,
|
|
234
|
-
dependencyCount: allDependencies.length,
|
|
235
|
-
dependencyLevels: dependencyLevels,
|
|
236
|
-
hasCircularDependency: hasCircularDependency
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* 获取依赖统计信息
|
|
242
|
-
* @param config - 显隐配置对象
|
|
243
|
-
* @param topN - 返回前N个结果
|
|
244
|
-
* @returns 组件统计信息数组
|
|
245
|
-
*/
|
|
246
|
-
export function getDependencyStats(config) {
|
|
247
|
-
var topN = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
248
|
-
var dependencyGraph = buildDependencyGraph(config);
|
|
249
|
-
|
|
250
|
-
// 统计依赖数量最多的组件
|
|
251
|
-
var mostDependencies = Object.entries(dependencyGraph).map(function (_ref) {
|
|
252
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
253
|
-
key = _ref2[0],
|
|
254
|
-
deps = _ref2[1];
|
|
255
|
-
return {
|
|
256
|
-
key: key,
|
|
257
|
-
count: deps.length
|
|
258
|
-
};
|
|
259
|
-
}).sort(function (a, b) {
|
|
260
|
-
return b.count - a.count;
|
|
261
|
-
}).slice(0, topN);
|
|
262
|
-
|
|
263
|
-
// 统计被依赖最多的组件
|
|
264
|
-
var dependedOnCount = {};
|
|
265
|
-
Object.values(dependencyGraph).forEach(function (deps) {
|
|
266
|
-
deps.forEach(function (dep) {
|
|
267
|
-
dependedOnCount[dep] = (dependedOnCount[dep] || 0) + 1;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
var mostDependedOn = Object.entries(dependedOnCount).map(function (_ref3) {
|
|
271
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
272
|
-
key = _ref4[0],
|
|
273
|
-
count = _ref4[1];
|
|
274
|
-
return {
|
|
275
|
-
key: key,
|
|
276
|
-
count: count
|
|
277
|
-
};
|
|
278
|
-
}).sort(function (a, b) {
|
|
279
|
-
return b.count - a.count;
|
|
280
|
-
}).slice(0, topN);
|
|
281
|
-
return {
|
|
282
|
-
mostDependencies: mostDependencies,
|
|
283
|
-
mostDependedOn: mostDependedOn
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* 验证配置文件格式
|
|
289
|
-
* @param config - 要验证的配置对象
|
|
290
|
-
* @returns 验证结果和错误信息
|
|
291
|
-
*/
|
|
292
|
-
export function validateConfig(config) {
|
|
293
|
-
var errors = [];
|
|
294
|
-
if (!config || _typeof(config) !== 'object') {
|
|
295
|
-
errors.push('配置必须是一个对象');
|
|
296
|
-
return {
|
|
297
|
-
isValid: false,
|
|
298
|
-
errors: errors
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
var configObj = config;
|
|
302
|
-
Object.entries(configObj).forEach(function (_ref5) {
|
|
303
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
304
|
-
key = _ref6[0],
|
|
305
|
-
value = _ref6[1];
|
|
306
|
-
if (!Array.isArray(value)) {
|
|
307
|
-
errors.push("\u7EC4\u4EF6 ".concat(key, " \u7684\u914D\u7F6E\u5FC5\u987B\u662F\u6570\u7EC4"));
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
value.forEach(function (ruleGroup, index) {
|
|
311
|
-
if (!ruleGroup || _typeof(ruleGroup) !== 'object') {
|
|
312
|
-
errors.push("\u7EC4\u4EF6 ".concat(key, " \u7684\u89C4\u5219\u7EC4 ").concat(index, " \u5FC5\u987B\u662F\u5BF9\u8C61"));
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
var group = ruleGroup;
|
|
316
|
-
if (!group.linkCondition || !['some', 'every'].includes(group.linkCondition)) {
|
|
317
|
-
errors.push("\u7EC4\u4EF6 ".concat(key, " \u7684\u89C4\u5219\u7EC4 ").concat(index, " linkCondition \u5FC5\u987B\u662F 'some' \u6216 'every'"));
|
|
318
|
-
}
|
|
319
|
-
if (!Array.isArray(group.rules)) {
|
|
320
|
-
errors.push("\u7EC4\u4EF6 ".concat(key, " \u7684\u89C4\u5219\u7EC4 ").concat(index, " rules \u5FC5\u987B\u662F\u6570\u7EC4"));
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
return {
|
|
325
|
-
isValid: errors.length === 0,
|
|
326
|
-
errors: errors
|
|
327
|
-
};
|
|
328
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件显隐配置相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
export declare type CompareSymbol = 'eq' | 'include' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte';
|
|
5
|
-
export declare type LinkCondition = 'some' | 'every';
|
|
6
|
-
export interface Rule {
|
|
7
|
-
compareSymbol: CompareSymbol;
|
|
8
|
-
leftValue: string;
|
|
9
|
-
rightValue: string | string[] | number | boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface RuleGroup {
|
|
12
|
-
linkCondition: LinkCondition;
|
|
13
|
-
rules: Rule[];
|
|
14
|
-
}
|
|
15
|
-
export declare type ComponentConfig = RuleGroup[];
|
|
16
|
-
export interface Config {
|
|
17
|
-
[componentKey: string]: ComponentConfig;
|
|
18
|
-
}
|
|
19
|
-
export interface DependencyGraph {
|
|
20
|
-
[componentKey: string]: string[];
|
|
21
|
-
}
|
|
22
|
-
export declare type CircularDependency = string[];
|
|
23
|
-
export interface DependencyLevels {
|
|
24
|
-
[level: number]: string[];
|
|
25
|
-
}
|
|
26
|
-
export interface ComponentStat {
|
|
27
|
-
key: string;
|
|
28
|
-
count: number;
|
|
29
|
-
}
|
|
30
|
-
export interface DependencyOptions {
|
|
31
|
-
maxDepth?: number;
|
|
32
|
-
includeCircular?: boolean;
|
|
33
|
-
}
|
|
34
|
-
export interface DependencyAnalysis {
|
|
35
|
-
componentKey: string;
|
|
36
|
-
directDependencies: string[];
|
|
37
|
-
allDependencies: string[];
|
|
38
|
-
dependencyCount: number;
|
|
39
|
-
dependencyLevels: DependencyLevels;
|
|
40
|
-
hasCircularDependency: boolean;
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件值映射依赖关系查找器 - TypeScript ES Module版本
|
|
3
|
-
* 根据值映射配置查找组件之间的依赖关系
|
|
4
|
-
*/
|
|
5
|
-
import type { ValueMappingConfig, ValueDependencyResult } from './value-mapping-types.js';
|
|
6
|
-
/**
|
|
7
|
-
* 查找组件的所有反向依赖(哪些组件会影响当前组件的值)
|
|
8
|
-
* @param targetComponentKey - 目标组件key
|
|
9
|
-
* @param config - 值映射配置对象
|
|
10
|
-
* @returns 反向依赖关系结果
|
|
11
|
-
*/
|
|
12
|
-
export declare function findValueDependencies(targetComponentKey: string, config: ValueMappingConfig): ValueDependencyResult;
|
|
13
|
-
/**
|
|
14
|
-
* 查找所有组件的反向依赖关系
|
|
15
|
-
* @param config - 值映射配置对象
|
|
16
|
-
* @returns 所有组件的反向依赖关系图
|
|
17
|
-
*/
|
|
18
|
-
export declare function buildValueDependencyGraph(config: ValueMappingConfig): Record<string, ValueDependencyResult>;
|
|
19
|
-
/**
|
|
20
|
-
* 查找特定源组件和值对目标组件的影响
|
|
21
|
-
* @param sourceComponentKey - 源组件key
|
|
22
|
-
* @param sourceValue - 源组件的值
|
|
23
|
-
* @param config - 值映射配置对象
|
|
24
|
-
* @returns 受影响的目标组件及其值
|
|
25
|
-
*/
|
|
26
|
-
export declare function findTargetsBySourceValue(sourceComponentKey: string, sourceValue: string, config: ValueMappingConfig): Array<{
|
|
27
|
-
targetComponent: string;
|
|
28
|
-
targetValue: string;
|
|
29
|
-
}>;
|
|
30
|
-
/**
|
|
31
|
-
* 获取所有源组件的统计信息
|
|
32
|
-
* @param config - 值映射配置对象
|
|
33
|
-
* @returns 源组件统计信息
|
|
34
|
-
*/
|
|
35
|
-
export declare function getSourceComponentStats(config: ValueMappingConfig): Array<{
|
|
36
|
-
componentKey: string;
|
|
37
|
-
valueCount: number;
|
|
38
|
-
targetCount: number;
|
|
39
|
-
totalMappings: number;
|
|
40
|
-
}>;
|
|
41
|
-
/**
|
|
42
|
-
* 查找值映射链(A影响B,B影响C的传递关系)
|
|
43
|
-
* @param startComponent - 起始组件
|
|
44
|
-
* @param config - 值映射配置对象
|
|
45
|
-
* @param maxDepth - 最大深度
|
|
46
|
-
* @returns 映射链
|
|
47
|
-
*/
|
|
48
|
-
export declare function findValueMappingChain(startComponent: string, config: ValueMappingConfig, maxDepth?: number): Array<{
|
|
49
|
-
chain: string[];
|
|
50
|
-
depth: number;
|
|
51
|
-
}>;
|
|
52
|
-
/**
|
|
53
|
-
* 验证值映射配置的格式
|
|
54
|
-
* @param config - 要验证的配置对象
|
|
55
|
-
* @returns 验证结果
|
|
56
|
-
*/
|
|
57
|
-
export declare function validateValueMappingConfig(config: unknown): {
|
|
58
|
-
isValid: boolean;
|
|
59
|
-
errors: string[];
|
|
60
|
-
warnings: string[];
|
|
61
|
-
};
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
6
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
/**
|
|
13
|
-
* 组件值映射依赖关系查找器 - TypeScript ES Module版本
|
|
14
|
-
* 根据值映射配置查找组件之间的依赖关系
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 查找组件的所有反向依赖(哪些组件会影响当前组件的值)
|
|
19
|
-
* @param targetComponentKey - 目标组件key
|
|
20
|
-
* @param config - 值映射配置对象
|
|
21
|
-
* @returns 反向依赖关系结果
|
|
22
|
-
*/
|
|
23
|
-
export function findValueDependencies(targetComponentKey, config) {
|
|
24
|
-
var dependencies = [];
|
|
25
|
-
|
|
26
|
-
// 遍历配置中的所有组件
|
|
27
|
-
Object.entries(config).forEach(function (_ref) {
|
|
28
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
29
|
-
sourceComponentKey = _ref2[0],
|
|
30
|
-
componentMapping = _ref2[1];
|
|
31
|
-
// 跳过 SHOP_SELECT_MAPPING 等非组件映射的配置
|
|
32
|
-
if (_typeof(componentMapping) !== 'object' || componentMapping === null) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
var sourceValues = [];
|
|
36
|
-
var mappingDetails = [];
|
|
37
|
-
|
|
38
|
-
// 遍历源组件的所有值映射
|
|
39
|
-
Object.entries(componentMapping).forEach(function (_ref3) {
|
|
40
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
41
|
-
sourceValue = _ref4[0],
|
|
42
|
-
valueMapping = _ref4[1];
|
|
43
|
-
// 检查这个值映射中是否包含目标组件
|
|
44
|
-
if (_typeof(valueMapping) === 'object' && valueMapping !== null) {
|
|
45
|
-
// 检查是否有目标组件的映射
|
|
46
|
-
if (targetComponentKey in valueMapping) {
|
|
47
|
-
var targetMapping = valueMapping[targetComponentKey];
|
|
48
|
-
var targetValue;
|
|
49
|
-
|
|
50
|
-
// 处理不同格式的目标值
|
|
51
|
-
if (typeof targetMapping === 'string') {
|
|
52
|
-
targetValue = targetMapping;
|
|
53
|
-
} else if (Array.isArray(targetMapping)) {
|
|
54
|
-
targetValue = targetMapping.join(', '); // 数组转为字符串
|
|
55
|
-
} else if (_typeof(targetMapping) === 'object' && targetMapping !== null && 'value' in targetMapping) {
|
|
56
|
-
targetValue = targetMapping.value;
|
|
57
|
-
} else {
|
|
58
|
-
return; // 跳过无效的映射
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
sourceValues.push(sourceValue);
|
|
62
|
-
mappingDetails.push({
|
|
63
|
-
sourceValue: sourceValue,
|
|
64
|
-
targetValue: targetValue
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// 如果找到了依赖关系,添加到结果中
|
|
71
|
-
if (sourceValues.length > 0) {
|
|
72
|
-
dependencies.push({
|
|
73
|
-
sourceComponent: sourceComponentKey,
|
|
74
|
-
sourceValues: sourceValues,
|
|
75
|
-
mappingDetails: mappingDetails
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
targetComponent: targetComponentKey,
|
|
81
|
-
dependencies: dependencies,
|
|
82
|
-
dependencyCount: dependencies.length,
|
|
83
|
-
totalMappings: dependencies.reduce(function (sum, dep) {
|
|
84
|
-
return sum + dep.mappingDetails.length;
|
|
85
|
-
}, 0)
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 查找所有组件的反向依赖关系
|
|
91
|
-
* @param config - 值映射配置对象
|
|
92
|
-
* @returns 所有组件的反向依赖关系图
|
|
93
|
-
*/
|
|
94
|
-
export function buildValueDependencyGraph(config) {
|
|
95
|
-
var dependencyGraph = {};
|
|
96
|
-
|
|
97
|
-
// 首先收集所有可能的目标组件
|
|
98
|
-
var allTargetComponents = new Set();
|
|
99
|
-
Object.values(config).forEach(function (componentMapping) {
|
|
100
|
-
if (_typeof(componentMapping) === 'object' && componentMapping !== null) {
|
|
101
|
-
Object.values(componentMapping).forEach(function (valueMapping) {
|
|
102
|
-
if (_typeof(valueMapping) === 'object' && valueMapping !== null) {
|
|
103
|
-
Object.keys(valueMapping).forEach(function (targetKey) {
|
|
104
|
-
allTargetComponents.add(targetKey);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// 为每个目标组件构建依赖关系
|
|
112
|
-
allTargetComponents.forEach(function (targetComponent) {
|
|
113
|
-
dependencyGraph[targetComponent] = findValueDependencies(targetComponent, config);
|
|
114
|
-
});
|
|
115
|
-
return dependencyGraph;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 查找特定源组件和值对目标组件的影响
|
|
120
|
-
* @param sourceComponentKey - 源组件key
|
|
121
|
-
* @param sourceValue - 源组件的值
|
|
122
|
-
* @param config - 值映射配置对象
|
|
123
|
-
* @returns 受影响的目标组件及其值
|
|
124
|
-
*/
|
|
125
|
-
export function findTargetsBySourceValue(sourceComponentKey, sourceValue, config) {
|
|
126
|
-
var results = [];
|
|
127
|
-
var componentMapping = config[sourceComponentKey];
|
|
128
|
-
if (_typeof(componentMapping) !== 'object' || componentMapping === null) {
|
|
129
|
-
return results;
|
|
130
|
-
}
|
|
131
|
-
var valueMapping = componentMapping[sourceValue];
|
|
132
|
-
if (_typeof(valueMapping) !== 'object' || valueMapping === null) {
|
|
133
|
-
return results;
|
|
134
|
-
}
|
|
135
|
-
Object.entries(valueMapping).forEach(function (_ref5) {
|
|
136
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
137
|
-
targetComponent = _ref6[0],
|
|
138
|
-
targetMapping = _ref6[1];
|
|
139
|
-
var targetValue;
|
|
140
|
-
if (typeof targetMapping === 'string') {
|
|
141
|
-
targetValue = targetMapping;
|
|
142
|
-
} else if (Array.isArray(targetMapping)) {
|
|
143
|
-
targetValue = targetMapping.join(', '); // 数组转为字符串
|
|
144
|
-
} else if (_typeof(targetMapping) === 'object' && targetMapping !== null && 'value' in targetMapping) {
|
|
145
|
-
targetValue = targetMapping.value;
|
|
146
|
-
} else {
|
|
147
|
-
return; // 跳过无效的映射
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
results.push({
|
|
151
|
-
targetComponent: targetComponent,
|
|
152
|
-
targetValue: targetValue
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
return results;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* 获取所有源组件的统计信息
|
|
160
|
-
* @param config - 值映射配置对象
|
|
161
|
-
* @returns 源组件统计信息
|
|
162
|
-
*/
|
|
163
|
-
export function getSourceComponentStats(config) {
|
|
164
|
-
var stats = [];
|
|
165
|
-
Object.entries(config).forEach(function (_ref7) {
|
|
166
|
-
var _ref8 = _slicedToArray(_ref7, 2),
|
|
167
|
-
componentKey = _ref8[0],
|
|
168
|
-
componentMapping = _ref8[1];
|
|
169
|
-
if (_typeof(componentMapping) !== 'object' || componentMapping === null) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
var allTargets = new Set();
|
|
173
|
-
var totalMappings = 0;
|
|
174
|
-
var valueCount = Object.keys(componentMapping).length;
|
|
175
|
-
Object.values(componentMapping).forEach(function (valueMapping) {
|
|
176
|
-
if (_typeof(valueMapping) === 'object' && valueMapping !== null) {
|
|
177
|
-
Object.keys(valueMapping).forEach(function (targetKey) {
|
|
178
|
-
allTargets.add(targetKey);
|
|
179
|
-
totalMappings++;
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
stats.push({
|
|
184
|
-
componentKey: componentKey,
|
|
185
|
-
valueCount: valueCount,
|
|
186
|
-
targetCount: allTargets.size,
|
|
187
|
-
totalMappings: totalMappings
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
return stats.sort(function (a, b) {
|
|
191
|
-
return b.totalMappings - a.totalMappings;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* 查找值映射链(A影响B,B影响C的传递关系)
|
|
197
|
-
* @param startComponent - 起始组件
|
|
198
|
-
* @param config - 值映射配置对象
|
|
199
|
-
* @param maxDepth - 最大深度
|
|
200
|
-
* @returns 映射链
|
|
201
|
-
*/
|
|
202
|
-
export function findValueMappingChain(startComponent, config) {
|
|
203
|
-
var maxDepth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
|
|
204
|
-
var chains = [];
|
|
205
|
-
var visited = new Set();
|
|
206
|
-
function dfs(currentComponent, path, depth) {
|
|
207
|
-
if (depth >= maxDepth || visited.has(currentComponent)) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
visited.add(currentComponent);
|
|
211
|
-
|
|
212
|
-
// 查找当前组件影响的目标组件
|
|
213
|
-
var componentMapping = config[currentComponent];
|
|
214
|
-
if (_typeof(componentMapping) === 'object' && componentMapping !== null) {
|
|
215
|
-
var targets = new Set();
|
|
216
|
-
Object.values(componentMapping).forEach(function (valueMapping) {
|
|
217
|
-
if (_typeof(valueMapping) === 'object' && valueMapping !== null) {
|
|
218
|
-
Object.keys(valueMapping).forEach(function (targetKey) {
|
|
219
|
-
targets.add(targetKey);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
targets.forEach(function (target) {
|
|
224
|
-
var newPath = [].concat(_toConsumableArray(path), [target]);
|
|
225
|
-
chains.push({
|
|
226
|
-
chain: newPath,
|
|
227
|
-
depth: depth + 1
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// 递归查找更深层的链
|
|
231
|
-
dfs(target, newPath, depth + 1);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
visited.delete(currentComponent);
|
|
235
|
-
}
|
|
236
|
-
dfs(startComponent, [startComponent], 0);
|
|
237
|
-
return chains.filter(function (chain) {
|
|
238
|
-
return chain.depth > 1;
|
|
239
|
-
}); // 只返回长度大于1的链
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* 验证值映射配置的格式
|
|
244
|
-
* @param config - 要验证的配置对象
|
|
245
|
-
* @returns 验证结果
|
|
246
|
-
*/
|
|
247
|
-
export function validateValueMappingConfig(config) {
|
|
248
|
-
var errors = [];
|
|
249
|
-
var warnings = [];
|
|
250
|
-
if (!config || _typeof(config) !== 'object') {
|
|
251
|
-
errors.push('配置必须是一个对象');
|
|
252
|
-
return {
|
|
253
|
-
isValid: false,
|
|
254
|
-
errors: errors,
|
|
255
|
-
warnings: warnings
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
var configObj = config;
|
|
259
|
-
Object.entries(configObj).forEach(function (_ref9) {
|
|
260
|
-
var _ref10 = _slicedToArray(_ref9, 2),
|
|
261
|
-
componentKey = _ref10[0],
|
|
262
|
-
componentMapping = _ref10[1];
|
|
263
|
-
if (_typeof(componentMapping) !== 'object' || componentMapping === null) {
|
|
264
|
-
warnings.push("\u7EC4\u4EF6 ".concat(componentKey, " \u7684\u6620\u5C04\u4E0D\u662F\u5BF9\u8C61\uFF0C\u53EF\u80FD\u662F\u7279\u6B8A\u914D\u7F6E"));
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
var mapping = componentMapping;
|
|
268
|
-
Object.entries(mapping).forEach(function (_ref11) {
|
|
269
|
-
var _ref12 = _slicedToArray(_ref11, 2),
|
|
270
|
-
value = _ref12[0],
|
|
271
|
-
valueMapping = _ref12[1];
|
|
272
|
-
if (_typeof(valueMapping) !== 'object' || valueMapping === null) {
|
|
273
|
-
warnings.push("\u7EC4\u4EF6 ".concat(componentKey, " \u7684\u503C ").concat(value, " \u7684\u6620\u5C04\u4E0D\u662F\u5BF9\u8C61"));
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
var valueMappingObj = valueMapping;
|
|
277
|
-
Object.entries(valueMappingObj).forEach(function (_ref13) {
|
|
278
|
-
var _ref14 = _slicedToArray(_ref13, 2),
|
|
279
|
-
targetComponent = _ref14[0],
|
|
280
|
-
targetMapping = _ref14[1];
|
|
281
|
-
if (typeof targetMapping !== 'string' && !Array.isArray(targetMapping) && (_typeof(targetMapping) !== 'object' || targetMapping === null || !('value' in targetMapping))) {
|
|
282
|
-
errors.push("\u7EC4\u4EF6 ".concat(componentKey, " \u503C ").concat(value, " \u5230 ").concat(targetComponent, " \u7684\u6620\u5C04\u683C\u5F0F\u65E0\u6548"));
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
return {
|
|
288
|
-
isValid: errors.length === 0,
|
|
289
|
-
errors: errors,
|
|
290
|
-
warnings: warnings
|
|
291
|
-
};
|
|
292
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件值映射相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
export interface TargetValueMapping {
|
|
5
|
-
value: string;
|
|
6
|
-
other?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare type ValueMappingItem = string | TargetValueMapping | string[];
|
|
9
|
-
export interface SingleValueMapping {
|
|
10
|
-
[targetComponentKey: string]: ValueMappingItem;
|
|
11
|
-
}
|
|
12
|
-
export interface ComponentValueMapping {
|
|
13
|
-
[sourceValue: string]: SingleValueMapping;
|
|
14
|
-
}
|
|
15
|
-
export interface ValueMappingConfig {
|
|
16
|
-
[sourceComponentKey: string]: ComponentValueMapping | any;
|
|
17
|
-
}
|
|
18
|
-
export interface ValueDependencyResult {
|
|
19
|
-
targetComponent: string;
|
|
20
|
-
dependencies: Array<{
|
|
21
|
-
sourceComponent: string;
|
|
22
|
-
sourceValues: string[];
|
|
23
|
-
mappingDetails: Array<{
|
|
24
|
-
sourceValue: string;
|
|
25
|
-
targetValue: string;
|
|
26
|
-
}>;
|
|
27
|
-
}>;
|
|
28
|
-
dependencyCount: number;
|
|
29
|
-
totalMappings: number;
|
|
30
|
-
}
|
|
31
|
-
export interface SourceComponentStat {
|
|
32
|
-
componentKey: string;
|
|
33
|
-
valueCount: number;
|
|
34
|
-
targetCount: number;
|
|
35
|
-
totalMappings: number;
|
|
36
|
-
}
|
|
37
|
-
export interface MappingChainNode {
|
|
38
|
-
chain: string[];
|
|
39
|
-
depth: number;
|
|
40
|
-
}
|
|
41
|
-
export interface TargetImpact {
|
|
42
|
-
targetComponent: string;
|
|
43
|
-
targetValue: string;
|
|
44
|
-
}
|
|
45
|
-
export interface ValidationResult {
|
|
46
|
-
isValid: boolean;
|
|
47
|
-
errors: string[];
|
|
48
|
-
warnings: string[];
|
|
49
|
-
}
|
|
50
|
-
export interface ValueMappingAnalysis {
|
|
51
|
-
totalSourceComponents: number;
|
|
52
|
-
totalTargetComponents: number;
|
|
53
|
-
totalValueMappings: number;
|
|
54
|
-
mostComplexSource: SourceComponentStat | null;
|
|
55
|
-
mostDependedTarget: {
|
|
56
|
-
componentKey: string;
|
|
57
|
-
dependencyCount: number;
|
|
58
|
-
} | null;
|
|
59
|
-
longestChains: MappingChainNode[];
|
|
60
|
-
}
|
|
61
|
-
export interface ReverseLookupOptions {
|
|
62
|
-
includeEmptyValues?: boolean;
|
|
63
|
-
caseSensitive?: boolean;
|
|
64
|
-
exactMatch?: boolean;
|
|
65
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|