@zat-design/sisyphus-react 3.14.2 → 3.14.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProTree/components/ProTreeSelect/index.js +104 -71
- package/es/ProTreeModal/style/index.less +6 -0
- package/lib/ProTree/components/ProTreeSelect/index.js +104 -71
- package/lib/ProTreeModal/style/index.less +6 -0
- package/package.json +2 -1
|
@@ -6,19 +6,19 @@ import "antd/es/input/style";
|
|
|
6
6
|
import _Input from "antd/es/input";
|
|
7
7
|
import "antd/es/message/style";
|
|
8
8
|
import _message from "antd/es/message";
|
|
9
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
10
9
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
10
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
11
11
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
12
12
|
import "antd/es/tree-select/style";
|
|
13
13
|
import _TreeSelect from "antd/es/tree-select";
|
|
14
|
-
var _excluded = ["disabled", "code", "dataSource", "defaultDisableValue", "onChange", "useRequest", "transformResponse", "fieldNames", "placeholder", "tooltip", "showSearch", "filterTreeNode", "treeNodeFilterProp", "defaultExpandAll", "expandedKeys", "treeCheckable", "onSearch", "otherProps", "width", "dropdownStyle", "popupClassName", "style", "allowClear", "listHeight", "showCodeName", "className", "checkStrictly", "checkable"]
|
|
15
|
-
_excluded2 = ["children"];
|
|
14
|
+
var _excluded = ["disabled", "code", "dataSource", "defaultDisableValue", "onChange", "useRequest", "transformResponse", "fieldNames", "placeholder", "tooltip", "showSearch", "filterTreeNode", "treeNodeFilterProp", "defaultExpandAll", "expandedKeys", "treeCheckable", "onSearch", "otherProps", "width", "dropdownStyle", "popupClassName", "style", "allowClear", "listHeight", "showCodeName", "className", "checkStrictly", "checkable"];
|
|
16
15
|
/* eslint-disable react/no-danger */
|
|
17
16
|
/* eslint-disable react/jsx-closing-tag-location */
|
|
18
17
|
import { useDeepCompareEffect, useRequest as useRequestFunc, useSetState } from 'ahooks';
|
|
19
18
|
import classnames from 'classnames';
|
|
20
19
|
import React, { useImperativeHandle, forwardRef, useCallback } from 'react';
|
|
21
20
|
import { cloneDeep, debounce } from 'lodash';
|
|
21
|
+
import { tools } from '@zat-design/utils';
|
|
22
22
|
import locale from "../../../locale";
|
|
23
23
|
import { useProConfig } from "../../../ProConfigProvider";
|
|
24
24
|
import Container from "../../../ProForm/components/Container";
|
|
@@ -35,14 +35,7 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
35
35
|
var _useProConfig = useProConfig('ProEnum'),
|
|
36
36
|
_useProConfig$dics = _useProConfig.dics,
|
|
37
37
|
dics = _useProConfig$dics === void 0 ? {} : _useProConfig$dics;
|
|
38
|
-
|
|
39
|
-
var code = 'value';
|
|
40
|
-
var uuidKey = 'value';
|
|
41
|
-
if (proSelectFieldNames && Object.keys(proSelectFieldNames).length) {
|
|
42
|
-
code = proSelectFieldNames.value;
|
|
43
|
-
label = proSelectFieldNames.label;
|
|
44
|
-
uuidKey = proSelectFieldNames.key || proSelectFieldNames.value;
|
|
45
|
-
}
|
|
38
|
+
|
|
46
39
|
// 配置属性
|
|
47
40
|
var disabled = props.disabled,
|
|
48
41
|
enumCode = props.code,
|
|
@@ -88,11 +81,32 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
88
81
|
var _ref3 = otherProps || {},
|
|
89
82
|
isView = _ref3.isView,
|
|
90
83
|
viewEmpty = _ref3.viewEmpty;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
|
|
85
|
+
// 合并全局和组件级别的 fieldNames,优先级:组件级 > 全局
|
|
86
|
+
var finalFieldNames = _objectSpread(_objectSpread({
|
|
87
|
+
label: 'label',
|
|
88
|
+
value: 'value',
|
|
89
|
+
children: 'children'
|
|
90
|
+
}, proSelectFieldNames), fieldNames);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 使用 tools.transformDataName 统一转换字段名
|
|
94
|
+
* 将原始数据转换为标准格式(label, value, children)
|
|
95
|
+
* tools.transformDataName 会自动检查数据是否已经是标准格式,如果是则直接返回
|
|
96
|
+
*/
|
|
97
|
+
var transformFieldNames = useCallback(data => {
|
|
98
|
+
if (!data || !Array.isArray(data) || !data.length) {
|
|
99
|
+
return data || [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 使用 tools.transformDataName 转换字段名
|
|
103
|
+
// 它会自动检查数据是否已经是标准格式(label, value, children),如果是则直接返回
|
|
104
|
+
return tools.transformDataName(data, {
|
|
105
|
+
label: finalFieldNames.label,
|
|
106
|
+
value: finalFieldNames.value,
|
|
107
|
+
children: finalFieldNames.children
|
|
108
|
+
});
|
|
109
|
+
}, [finalFieldNames]);
|
|
96
110
|
// 经过处理后的枚举数据,可能来自用户配置的处理函数后返回的结果
|
|
97
111
|
var _useSetState = useSetState({}),
|
|
98
112
|
_useSetState2 = _slicedToArray(_useSetState, 2),
|
|
@@ -105,6 +119,7 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
105
119
|
|
|
106
120
|
/**
|
|
107
121
|
* 如果数据少于10条那么将数据平铺返回
|
|
122
|
+
* 注意:当 treeCheckable 为 false 时(单选模式),应保持树形结构,不进行平铺
|
|
108
123
|
* @param dictsEnum 原始数据
|
|
109
124
|
* @returns 平铺或者原始数据
|
|
110
125
|
*/
|
|
@@ -112,50 +127,33 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
112
127
|
if (treeCheckable) {
|
|
113
128
|
return dictsEnum;
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var loopCount = data => {
|
|
118
|
-
data.map(item => {
|
|
119
|
-
count += 1;
|
|
120
|
-
var children = item.children,
|
|
121
|
-
other = _objectWithoutProperties(item, _excluded2);
|
|
122
|
-
result.push(_objectSpread({}, other));
|
|
123
|
-
if (item.children) {
|
|
124
|
-
loopCount(item.children);
|
|
125
|
-
}
|
|
126
|
-
return item;
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
if ((dictsEnum === null || dictsEnum === void 0 ? void 0 : dictsEnum.length) > 10) {
|
|
130
|
-
return dictsEnum;
|
|
131
|
-
}
|
|
132
|
-
loopCount(dictsEnum);
|
|
133
|
-
if (count <= 10) {
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
130
|
+
// 单选模式(treeCheckable=false)时,保持树形结构,不进行平铺
|
|
131
|
+
// 因为 TreeSelect 在单选模式下也需要树形结构来正确展示层级关系
|
|
136
132
|
return dictsEnum;
|
|
137
133
|
};
|
|
138
134
|
|
|
139
135
|
/**
|
|
140
136
|
* 如果要展示code-name,那么将源数据的label转为code-name
|
|
141
|
-
*
|
|
137
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
138
|
+
* @param dataArr 源数据(标准格式)
|
|
142
139
|
* @param showCodeAndName 是否展示code-name
|
|
143
140
|
* @returns 转换结果
|
|
144
141
|
*/
|
|
145
142
|
var transferDataSource = (dataArr, showCodeAndName) => {
|
|
143
|
+
if (!showCodeAndName) {
|
|
144
|
+
return dataArr;
|
|
145
|
+
}
|
|
146
146
|
var copyData = cloneDeep(dataArr);
|
|
147
147
|
var loop = arr => {
|
|
148
148
|
arr.map(item => {
|
|
149
|
-
item
|
|
149
|
+
item.label = `${item.value}-${item.label}`;
|
|
150
150
|
if (item.children) {
|
|
151
151
|
loop(item.children);
|
|
152
152
|
}
|
|
153
153
|
return item;
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
|
-
|
|
157
|
-
loop(copyData);
|
|
158
|
-
}
|
|
156
|
+
loop(copyData);
|
|
159
157
|
return copyData;
|
|
160
158
|
};
|
|
161
159
|
var defaultOnSuccessFun = res => {
|
|
@@ -167,7 +165,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
167
165
|
_message.error(msg);
|
|
168
166
|
return;
|
|
169
167
|
}
|
|
170
|
-
|
|
168
|
+
// 先转换字段名,再处理 code-name 展示
|
|
169
|
+
var transformedData = transformFieldNames(data || []);
|
|
170
|
+
var resultData = transferDataSource(transformedData, showCodeName);
|
|
171
171
|
setState({
|
|
172
172
|
selectList: resultData || [],
|
|
173
173
|
origDataSource: resultData || []
|
|
@@ -196,7 +196,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
196
196
|
onSuccess: data => {
|
|
197
197
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
198
198
|
var responseData = transformResponse(data);
|
|
199
|
-
|
|
199
|
+
// 先转换字段名,再处理 code-name 展示
|
|
200
|
+
var transformedData = transformFieldNames(responseData);
|
|
201
|
+
var resultData = transferDataSource(transformedData, showCodeName);
|
|
200
202
|
setState({
|
|
201
203
|
selectList: countChild(resultData),
|
|
202
204
|
origDataSource: resultData
|
|
@@ -217,7 +219,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
217
219
|
if (fetchFunction !== null && fetchFunction !== void 0 && fetchFunction.data, useRequest !== null && useRequest !== void 0 && (_useRequest$options2 = useRequest.options) !== null && _useRequest$options2 !== void 0 && _useRequest$options2.cacheKey) {
|
|
218
220
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
219
221
|
var responseData = transformResponse(fetchFunction.data);
|
|
220
|
-
|
|
222
|
+
// 先转换字段名,再处理 code-name 展示
|
|
223
|
+
var transformedData = transformFieldNames(responseData);
|
|
224
|
+
var resultData = transferDataSource(transformedData, showCodeName);
|
|
221
225
|
setState({
|
|
222
226
|
selectList: countChild(resultData),
|
|
223
227
|
origDataSource: resultData
|
|
@@ -226,23 +230,29 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
226
230
|
defaultOnSuccessFun(fetchFunction.data);
|
|
227
231
|
}
|
|
228
232
|
}
|
|
229
|
-
}, [fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data]);
|
|
233
|
+
}, [fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data, transformFieldNames]);
|
|
230
234
|
useDeepCompareEffect(() => {
|
|
231
235
|
if (enumCode) {
|
|
232
236
|
var dictEnum = dics[enumCode] || [];
|
|
233
|
-
|
|
237
|
+
// 先转换字段名,再处理 code-name 展示
|
|
238
|
+
var transformedData = transformFieldNames(dictEnum);
|
|
239
|
+
var resultData = transferDataSource(transformedData, showCodeName);
|
|
240
|
+
var processedList = countChild(resultData);
|
|
234
241
|
setState({
|
|
235
|
-
selectList:
|
|
242
|
+
selectList: processedList,
|
|
236
243
|
origDataSource: resultData
|
|
237
244
|
});
|
|
238
245
|
} else if (dataSource) {
|
|
239
|
-
|
|
246
|
+
// 先转换字段名,再处理 code-name 展示
|
|
247
|
+
var _transformedData = transformFieldNames(dataSource);
|
|
248
|
+
var _resultData = transferDataSource(_transformedData, showCodeName);
|
|
249
|
+
var _processedList = countChild(_resultData);
|
|
240
250
|
setState({
|
|
241
|
-
selectList:
|
|
251
|
+
selectList: _processedList,
|
|
242
252
|
origDataSource: _resultData
|
|
243
253
|
});
|
|
244
254
|
}
|
|
245
|
-
}, [enumCode, dataSource]);
|
|
255
|
+
}, [enumCode, dataSource, transformFieldNames]);
|
|
246
256
|
useDeepCompareEffect(() => {
|
|
247
257
|
// code存在huo dataSource存在,不执行接口请求
|
|
248
258
|
if (enumCode || dataSource) {
|
|
@@ -278,6 +288,7 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
278
288
|
|
|
279
289
|
/**
|
|
280
290
|
* 根据值进行回显
|
|
291
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
281
292
|
* @param value 输入值
|
|
282
293
|
* @returns 对应枚举label
|
|
283
294
|
*/
|
|
@@ -287,8 +298,8 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
287
298
|
}
|
|
288
299
|
var labelResult = [];
|
|
289
300
|
var queryLabel = dicts => dicts.map(item => {
|
|
290
|
-
if (value.includes(item
|
|
291
|
-
var labelText = item
|
|
301
|
+
if (value.includes(item.value)) {
|
|
302
|
+
var labelText = item.label;
|
|
292
303
|
labelResult.push(labelText);
|
|
293
304
|
}
|
|
294
305
|
if (item.children) {
|
|
@@ -333,15 +344,22 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
333
344
|
|
|
334
345
|
/**
|
|
335
346
|
* 自定义渲染子树
|
|
336
|
-
*
|
|
347
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
348
|
+
* @param node 每个节点数据对象(标准格式)
|
|
337
349
|
* @returns 整个react节点树
|
|
338
350
|
*/
|
|
339
351
|
var renderTreeNode = (node, grade) => {
|
|
340
352
|
var children = node.children,
|
|
341
|
-
icon = node.icon
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
icon = node.icon,
|
|
354
|
+
label = node.label,
|
|
355
|
+
nodeValue = node.value,
|
|
356
|
+
nodeKey = node.key;
|
|
357
|
+
var labelText = label;
|
|
358
|
+
var value = nodeValue;
|
|
359
|
+
var key = nodeValue; // 使用 value 作为 key,如果有 key 字段则使用 key
|
|
360
|
+
if (nodeKey !== undefined) {
|
|
361
|
+
key = nodeKey;
|
|
362
|
+
}
|
|
345
363
|
// 三无走默认
|
|
346
364
|
if (['undefined-undefined', 'undefined'].includes(labelText) && !value && !key) {
|
|
347
365
|
if (showCodeName) {
|
|
@@ -409,7 +427,8 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
409
427
|
|
|
410
428
|
/**
|
|
411
429
|
* 从树形数据中找出用户搜索得数据,并且将搜索字符串高亮标识
|
|
412
|
-
*
|
|
430
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
431
|
+
* @param data 全量树(标准格式)
|
|
413
432
|
* @param searchStr 搜索字符串
|
|
414
433
|
* @returns 处理后得树
|
|
415
434
|
*/
|
|
@@ -426,11 +445,11 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
426
445
|
}
|
|
427
446
|
// 迭代完子节点向上回溯,如果有匹配到得子节点,那么加入当前节点得孩子对象上,否则加入得是空数组
|
|
428
447
|
item.children = currentNodeChild;
|
|
429
|
-
// 判断节点
|
|
448
|
+
// 判断节点label是否包含关键字 如果有,那么直接进行下一循环
|
|
430
449
|
// @ts-ignore
|
|
431
|
-
if (item
|
|
450
|
+
if (item.label && item.label.indexOf(keyWord) > -1 && (selectProps === null || selectProps === void 0 ? void 0 : selectProps.mode) !== 'treeSelect') {
|
|
432
451
|
var regExp = new RegExp(keyWord);
|
|
433
|
-
item
|
|
452
|
+
item.label = item.label.replace(regExp, `<span class="highlight-search-text">${keyWord}</span>`);
|
|
434
453
|
}
|
|
435
454
|
currentAllNodeChild.push(item);
|
|
436
455
|
}
|
|
@@ -468,16 +487,23 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
468
487
|
return _ref6.apply(this, arguments);
|
|
469
488
|
};
|
|
470
489
|
}(), 500);
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* 从树形数据中查找节点
|
|
493
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
494
|
+
* @param treeList 树形数据(标准格式)
|
|
495
|
+
* @param nodeValue 节点值
|
|
496
|
+
* @returns 找到的节点
|
|
497
|
+
*/
|
|
471
498
|
function findTreeNode(treeList, nodeValue) {
|
|
472
499
|
var result = {};
|
|
473
500
|
var filterData = function filterData(data) {
|
|
474
501
|
for (var i = 0; i < data.length; i++) {
|
|
475
502
|
var item = data[i];
|
|
476
|
-
if (item
|
|
503
|
+
if (item.value === nodeValue || Array.isArray(nodeValue) && nodeValue.includes(item.value)) {
|
|
477
504
|
result = _objectSpread({}, item);
|
|
478
|
-
|
|
479
|
-
result.
|
|
480
|
-
delete result[(fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || 'children'];
|
|
505
|
+
// 删除 children 字段,避免循环引用
|
|
506
|
+
delete result.children;
|
|
481
507
|
return null;
|
|
482
508
|
}
|
|
483
509
|
// 一直递归到最后一层子节点
|
|
@@ -489,6 +515,13 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
489
515
|
filterData(treeList);
|
|
490
516
|
return result;
|
|
491
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* 根据值获取标签
|
|
520
|
+
* 注意:此时数据已经是标准格式(label, value, children)
|
|
521
|
+
* @param treeList 树形数据(标准格式)
|
|
522
|
+
* @param nodeValue 节点值
|
|
523
|
+
* @returns 标签对象或数组
|
|
524
|
+
*/
|
|
492
525
|
function getLabelByValue(treeList, nodeValue) {
|
|
493
526
|
var result = nodeValue;
|
|
494
527
|
if (nodeValue) {
|
|
@@ -500,19 +533,19 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
500
533
|
return item;
|
|
501
534
|
});
|
|
502
535
|
} else {
|
|
503
|
-
result = findTreeNode(treeList, nodeValue
|
|
536
|
+
result = findTreeNode(treeList, nodeValue.value);
|
|
504
537
|
}
|
|
505
538
|
}
|
|
506
539
|
return result;
|
|
507
540
|
}
|
|
508
541
|
var handleChange = (newVal, label, extra) => {
|
|
509
542
|
// newVal回来得一定是label、value
|
|
543
|
+
// 注意:此时数据已经是标准格式(label, value, children)
|
|
510
544
|
var _selectList = selectList.map(item => {
|
|
511
|
-
var
|
|
512
|
-
|
|
513
|
-
if (label) {
|
|
545
|
+
var _label = item.label;
|
|
546
|
+
if (_label) {
|
|
514
547
|
var regex = /<span class="highlight-search-text">(.*?)<\/span>/g;
|
|
515
|
-
_label = item
|
|
548
|
+
_label = item.label = _label.replace(regex, '$1');
|
|
516
549
|
}
|
|
517
550
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
518
551
|
label: _label
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
@root-entry-name: 'default';
|
|
2
2
|
@import (reference) '~antd/es/style/themes/index.less';
|
|
3
3
|
|
|
4
|
+
.pro-tree-select-drop-down-container{
|
|
5
|
+
.@{ant-prefix}-select-tree-checkbox{
|
|
6
|
+
margin-top: 0;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
.pro-tree-modal-container .@{ant-prefix}-modal-content .@{ant-prefix}-modal-body {
|
|
5
11
|
max-height: 498px;
|
|
6
12
|
}
|