@zat-design/sisyphus-react 3.14.10-beta.5 → 3.14.10-beta.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/es/ProConfigProvider/index.d.ts +1 -0
- package/es/ProForm/components/combination/ProCascader/index.js +22 -19
- package/es/ProTree/components/ProTreeSelect/index.js +24 -12
- package/es/ProTree/components/ProTreeSelect/propsType.d.ts +6 -0
- package/es/ProTree/propsType.d.ts +6 -0
- package/es/ProTree/utils.d.ts +10 -0
- package/es/ProTree/utils.js +23 -0
- package/lib/ProConfigProvider/index.d.ts +1 -0
- package/lib/ProForm/components/combination/ProCascader/index.js +22 -19
- package/lib/ProTree/components/ProTreeSelect/index.js +23 -11
- package/lib/ProTree/components/ProTreeSelect/propsType.d.ts +6 -0
- package/lib/ProTree/propsType.d.ts +6 -0
- package/lib/ProTree/utils.d.ts +10 -0
- package/lib/ProTree/utils.js +24 -0
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ export interface ProConfigState {
|
|
|
11
11
|
ProSelect?: Partial<PropSelectType> & Record<string, any>;
|
|
12
12
|
ProModalSelect?: Partial<ProModalSelectType> & Record<string, any>;
|
|
13
13
|
ProAddressBar?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
|
+
ProCascader?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
15
|
forms: Record<string, FormInstance | undefined>;
|
|
15
16
|
[key: string]: any;
|
|
16
17
|
}
|
|
@@ -53,8 +53,10 @@ var getViewLabel = _ref => {
|
|
|
53
53
|
return viewLabel;
|
|
54
54
|
};
|
|
55
55
|
var ProCascader = props => {
|
|
56
|
-
var _props$otherProps, _useRequest$options3, _value$slice,
|
|
57
|
-
var
|
|
56
|
+
var _ref3, _props$otherProps, _useRequest$options3, _value$slice, _ref8, _defaultLabel$filter, _locale$ProAddressBar, _locale$ProAddressBar2;
|
|
57
|
+
var proCascaderConfig = useProConfig('ProCascader');
|
|
58
|
+
var proAddressBarConfig = useProConfig('ProAddressBar');
|
|
59
|
+
var _ref2 = (_ref3 = proCascaderConfig !== null && proCascaderConfig !== void 0 ? proCascaderConfig : proAddressBarConfig) !== null && _ref3 !== void 0 ? _ref3 : {},
|
|
58
60
|
configDetailMaxLength = _ref2.detailMaxLength,
|
|
59
61
|
configEnumCode = _ref2.enumCode,
|
|
60
62
|
configCode = _ref2.code;
|
|
@@ -88,9 +90,9 @@ var ProCascader = props => {
|
|
|
88
90
|
desensitization = props.desensitization,
|
|
89
91
|
otherProps = props.otherProps,
|
|
90
92
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
91
|
-
var
|
|
92
|
-
isViewCon =
|
|
93
|
-
viewEmpty =
|
|
93
|
+
var _ref4 = ProForm.useFieldProps() || {},
|
|
94
|
+
isViewCon = _ref4.isView,
|
|
95
|
+
viewEmpty = _ref4.viewEmpty;
|
|
94
96
|
var addressCode = code || enumCode;
|
|
95
97
|
var realIsView = typeof isView === 'boolean' ? isView : isViewCon;
|
|
96
98
|
var realLevel = level || 2;
|
|
@@ -103,7 +105,8 @@ var ProCascader = props => {
|
|
|
103
105
|
if (!(props !== null && props !== void 0 && props.mode)) {
|
|
104
106
|
return (dics === null || dics === void 0 ? void 0 : dics[addressCode]) || [];
|
|
105
107
|
}
|
|
106
|
-
|
|
108
|
+
var fromEnum = Array.isArray(enumData) ? enumData[0] : [];
|
|
109
|
+
return fromEnum !== null && fromEnum !== void 0 && fromEnum.length ? fromEnum : (dics === null || dics === void 0 ? void 0 : dics[addressCode]) || [];
|
|
107
110
|
}, [dics === null || dics === void 0 ? void 0 : dics[addressCode], enumData]);
|
|
108
111
|
var realDataSource = useMemo(() => {
|
|
109
112
|
var innerDataSource = dataSource || (addressCode ? enumDataSource : []);
|
|
@@ -127,11 +130,11 @@ var ProCascader = props => {
|
|
|
127
130
|
|
|
128
131
|
// 默认成功处理函数
|
|
129
132
|
var defaultOnSuccessFun = res => {
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
status =
|
|
133
|
-
msg =
|
|
134
|
-
data =
|
|
133
|
+
var _ref5 = res || {},
|
|
134
|
+
_ref5$status = _ref5.status,
|
|
135
|
+
status = _ref5$status === void 0 ? 200 : _ref5$status,
|
|
136
|
+
msg = _ref5.message,
|
|
137
|
+
data = _ref5.data;
|
|
135
138
|
if (status !== 200) {
|
|
136
139
|
_message.error(msg);
|
|
137
140
|
return;
|
|
@@ -154,11 +157,11 @@ var ProCascader = props => {
|
|
|
154
157
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
155
158
|
return transformResponse(res);
|
|
156
159
|
}
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
status =
|
|
160
|
-
msg =
|
|
161
|
-
data =
|
|
160
|
+
var _ref6 = res || {},
|
|
161
|
+
_ref6$status = _ref6.status,
|
|
162
|
+
status = _ref6$status === void 0 ? 200 : _ref6$status,
|
|
163
|
+
msg = _ref6.message,
|
|
164
|
+
data = _ref6.data;
|
|
162
165
|
if (status !== 200) {
|
|
163
166
|
_message.error(msg);
|
|
164
167
|
return;
|
|
@@ -214,8 +217,8 @@ var ProCascader = props => {
|
|
|
214
217
|
if (!(useRequest !== null && useRequest !== void 0 && useRequest.service)) {
|
|
215
218
|
return;
|
|
216
219
|
}
|
|
217
|
-
var
|
|
218
|
-
manual =
|
|
220
|
+
var _ref7 = (useRequest === null || useRequest === void 0 ? void 0 : useRequest.options) || {},
|
|
221
|
+
manual = _ref7.manual;
|
|
219
222
|
if (manual || cacheList !== null && cacheList !== void 0 && cacheList.length) {
|
|
220
223
|
return;
|
|
221
224
|
}
|
|
@@ -265,7 +268,7 @@ var ProCascader = props => {
|
|
|
265
268
|
return label === null || label === void 0 ? void 0 : label.filter(item => !!item).join('/');
|
|
266
269
|
};
|
|
267
270
|
var addressValue = isAddressMode ? value && (_value$slice = value.slice(0, realLevel)) !== null && _value$slice !== void 0 && _value$slice.some(item => !!item) ? value.slice(0, realLevel) : undefined : value;
|
|
268
|
-
var viewValue = isAddressMode ? ((
|
|
271
|
+
var viewValue = isAddressMode ? ((_ref8 = [...defaultLabel, value === null || value === void 0 ? void 0 : value[realLevel]]) === null || _ref8 === void 0 || (_ref8 = _ref8.filter(item => !!item)) === null || _ref8 === void 0 ? void 0 : _ref8.join(separator)) || '-' : (defaultLabel === null || defaultLabel === void 0 || (_defaultLabel$filter = defaultLabel.filter(item => !!item)) === null || _defaultLabel$filter === void 0 ? void 0 : _defaultLabel$filter.join(separator)) || '-';
|
|
269
272
|
var findSelectedOptions = function findSelectedOptions(options, value) {
|
|
270
273
|
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
271
274
|
var _value = value !== null && value !== void 0 ? value : [];
|
|
@@ -11,7 +11,7 @@ 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"];
|
|
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", "checkLeaf"];
|
|
15
15
|
/* eslint-disable react/no-danger */
|
|
16
16
|
/* eslint-disable react/jsx-closing-tag-location */
|
|
17
17
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
@@ -24,7 +24,7 @@ import locale from "../../../locale";
|
|
|
24
24
|
import { useProConfig } from "../../../ProConfigProvider";
|
|
25
25
|
import Container from "../../../ProForm/components/Container";
|
|
26
26
|
import AdaptiveTooltip from "../AdaptiveTooltip";
|
|
27
|
-
import { getFlatTreeData } from "../../utils";
|
|
27
|
+
import { getFlatTreeData, applyCheckLeaf } from "../../utils";
|
|
28
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
30
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -73,6 +73,7 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
73
73
|
className = props.className,
|
|
74
74
|
checkStrictly = props.checkStrictly,
|
|
75
75
|
checkable = props.checkable,
|
|
76
|
+
checkLeaf = props.checkLeaf,
|
|
76
77
|
selectProps = _objectWithoutProperties(props, _excluded);
|
|
77
78
|
var _props$value = props.value,
|
|
78
79
|
value = _props$value === void 0 ? undefined : _props$value;
|
|
@@ -159,6 +160,17 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
159
160
|
loop(copyData);
|
|
160
161
|
return copyData;
|
|
161
162
|
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 统一数据后处理:先处理 code-name 展示,再按 checkLeaf 标记非叶子节点禁用
|
|
166
|
+
* 数据已是标准格式(label, value, children)
|
|
167
|
+
* @param dataArr 标准格式数据
|
|
168
|
+
* @returns 后处理结果
|
|
169
|
+
*/
|
|
170
|
+
var processData = dataArr => {
|
|
171
|
+
var result = transferDataSource(dataArr, showCodeName);
|
|
172
|
+
return checkLeaf ? applyCheckLeaf(result) : result;
|
|
173
|
+
};
|
|
162
174
|
var defaultOnSuccessFun = res => {
|
|
163
175
|
var _res$status = res.status,
|
|
164
176
|
status = _res$status === void 0 ? 200 : _res$status,
|
|
@@ -168,9 +180,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
168
180
|
_message.error(msg);
|
|
169
181
|
return;
|
|
170
182
|
}
|
|
171
|
-
// 先转换字段名,再处理 code-name
|
|
183
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
172
184
|
var transformedData = transformFieldNames(data || []);
|
|
173
|
-
var resultData =
|
|
185
|
+
var resultData = processData(transformedData);
|
|
174
186
|
setState({
|
|
175
187
|
selectList: resultData || [],
|
|
176
188
|
origDataSource: resultData || []
|
|
@@ -199,9 +211,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
199
211
|
onSuccess: data => {
|
|
200
212
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
201
213
|
var responseData = transformResponse(data);
|
|
202
|
-
// 先转换字段名,再处理 code-name
|
|
214
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
203
215
|
var transformedData = transformFieldNames(responseData);
|
|
204
|
-
var resultData =
|
|
216
|
+
var resultData = processData(transformedData);
|
|
205
217
|
setState({
|
|
206
218
|
selectList: countChild(resultData),
|
|
207
219
|
origDataSource: resultData
|
|
@@ -222,9 +234,9 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
222
234
|
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) {
|
|
223
235
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
224
236
|
var responseData = transformResponse(fetchFunction.data);
|
|
225
|
-
// 先转换字段名,再处理 code-name
|
|
237
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
226
238
|
var transformedData = transformFieldNames(responseData);
|
|
227
|
-
var resultData =
|
|
239
|
+
var resultData = processData(transformedData);
|
|
228
240
|
setState({
|
|
229
241
|
selectList: countChild(resultData),
|
|
230
242
|
origDataSource: resultData
|
|
@@ -238,18 +250,18 @@ export var ProTreeSelect = (props, ref) => {
|
|
|
238
250
|
useDeepCompareEffect(() => {
|
|
239
251
|
if (enumCode) {
|
|
240
252
|
var dictEnum = dics[enumCode] || [];
|
|
241
|
-
// 先转换字段名,再处理 code-name
|
|
253
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
242
254
|
var transformedData = transformFieldNames(dictEnum);
|
|
243
|
-
var resultData =
|
|
255
|
+
var resultData = processData(transformedData);
|
|
244
256
|
var processedList = countChild(resultData);
|
|
245
257
|
setState({
|
|
246
258
|
selectList: processedList,
|
|
247
259
|
origDataSource: resultData
|
|
248
260
|
});
|
|
249
261
|
} else if (dataSource) {
|
|
250
|
-
// 先转换字段名,再处理 code-name
|
|
262
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
251
263
|
var _transformedData = transformFieldNames(dataSource);
|
|
252
|
-
var _resultData =
|
|
264
|
+
var _resultData = processData(_transformedData);
|
|
253
265
|
var _processedList = countChild(_resultData);
|
|
254
266
|
setState({
|
|
255
267
|
selectList: _processedList,
|
|
@@ -304,6 +304,12 @@ export interface ProTreeSelectType extends Omit<TreeSelectProps, 'onSearch'> {
|
|
|
304
304
|
* @default false
|
|
305
305
|
*/
|
|
306
306
|
checkable?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* 只选叶子节点
|
|
309
|
+
* @description 开启后只能选择叶子节点,非叶子节点置灰禁用,仅 treeSelect 单选模式生效
|
|
310
|
+
* @default false
|
|
311
|
+
*/
|
|
312
|
+
checkLeaf?: boolean;
|
|
307
313
|
/**
|
|
308
314
|
* 显示省略号
|
|
309
315
|
* @description 是否单行省略
|
|
@@ -298,6 +298,12 @@ export interface ProTreeType extends ProTreeSelectType {
|
|
|
298
298
|
* @default false
|
|
299
299
|
*/
|
|
300
300
|
checkable?: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* 只选叶子节点
|
|
303
|
+
* @description 开启后只能选择叶子节点,非叶子节点置灰禁用,仅 treeSelect 单选模式生效
|
|
304
|
+
* @default false
|
|
305
|
+
*/
|
|
306
|
+
checkLeaf?: boolean;
|
|
301
307
|
/**
|
|
302
308
|
* 可勾选
|
|
303
309
|
* @description 是否显示 checkbox
|
package/es/ProTree/utils.d.ts
CHANGED
|
@@ -41,3 +41,13 @@ export declare function getChildrenKeys(node: ProTreeDataType, childrenKeys: str
|
|
|
41
41
|
* @param allkeys 所有key
|
|
42
42
|
*/
|
|
43
43
|
export declare function getDefaultExpandKeys(isExpand: any, allKeys: any): any;
|
|
44
|
+
/**
|
|
45
|
+
* checkLeaf 模式:只能选择叶子节点,非叶子节点设 disabled=true 整行置灰不可点
|
|
46
|
+
* 数据已是标准格式(label, value, children),仅单选 treeSelect 场景使用
|
|
47
|
+
* 不可变:返回全新数组,不修改入参
|
|
48
|
+
* @param data 标准格式树数据
|
|
49
|
+
* @returns 标记后的新树数据
|
|
50
|
+
*/
|
|
51
|
+
export declare function applyCheckLeaf<T extends {
|
|
52
|
+
children?: T[];
|
|
53
|
+
}>(data: T[]): T[];
|
package/es/ProTree/utils.js
CHANGED
|
@@ -199,4 +199,27 @@ export function getDefaultExpandKeys(isExpand, allKeys) {
|
|
|
199
199
|
return allKeys;
|
|
200
200
|
}
|
|
201
201
|
return [];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* checkLeaf 模式:只能选择叶子节点,非叶子节点设 disabled=true 整行置灰不可点
|
|
206
|
+
* 数据已是标准格式(label, value, children),仅单选 treeSelect 场景使用
|
|
207
|
+
* 不可变:返回全新数组,不修改入参
|
|
208
|
+
* @param data 标准格式树数据
|
|
209
|
+
* @returns 标记后的新树数据
|
|
210
|
+
*/
|
|
211
|
+
export function applyCheckLeaf(data) {
|
|
212
|
+
if (!Array.isArray(data)) {
|
|
213
|
+
return data;
|
|
214
|
+
}
|
|
215
|
+
return data.map(node => {
|
|
216
|
+
var hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
217
|
+
if (!hasChildren) {
|
|
218
|
+
return _objectSpread({}, node);
|
|
219
|
+
}
|
|
220
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
221
|
+
disabled: true,
|
|
222
|
+
children: applyCheckLeaf(node.children)
|
|
223
|
+
});
|
|
224
|
+
});
|
|
202
225
|
}
|
|
@@ -11,6 +11,7 @@ export interface ProConfigState {
|
|
|
11
11
|
ProSelect?: Partial<PropSelectType> & Record<string, any>;
|
|
12
12
|
ProModalSelect?: Partial<ProModalSelectType> & Record<string, any>;
|
|
13
13
|
ProAddressBar?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
|
+
ProCascader?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
15
|
forms: Record<string, FormInstance | undefined>;
|
|
15
16
|
[key: string]: any;
|
|
16
17
|
}
|
|
@@ -59,8 +59,10 @@ var getViewLabel = _ref => {
|
|
|
59
59
|
return viewLabel;
|
|
60
60
|
};
|
|
61
61
|
var ProCascader = props => {
|
|
62
|
-
var _props$otherProps, _useRequest$options3, _value$slice,
|
|
63
|
-
var
|
|
62
|
+
var _ref3, _props$otherProps, _useRequest$options3, _value$slice, _ref8, _defaultLabel$filter, _locale$ProAddressBar, _locale$ProAddressBar2;
|
|
63
|
+
var proCascaderConfig = (0, _ProConfigProvider.useProConfig)('ProCascader');
|
|
64
|
+
var proAddressBarConfig = (0, _ProConfigProvider.useProConfig)('ProAddressBar');
|
|
65
|
+
var _ref2 = (_ref3 = proCascaderConfig !== null && proCascaderConfig !== void 0 ? proCascaderConfig : proAddressBarConfig) !== null && _ref3 !== void 0 ? _ref3 : {},
|
|
64
66
|
configDetailMaxLength = _ref2.detailMaxLength,
|
|
65
67
|
configEnumCode = _ref2.enumCode,
|
|
66
68
|
configCode = _ref2.code;
|
|
@@ -94,9 +96,9 @@ var ProCascader = props => {
|
|
|
94
96
|
desensitization = props.desensitization,
|
|
95
97
|
otherProps = props.otherProps,
|
|
96
98
|
restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
97
|
-
var
|
|
98
|
-
isViewCon =
|
|
99
|
-
viewEmpty =
|
|
99
|
+
var _ref4 = _.default.useFieldProps() || {},
|
|
100
|
+
isViewCon = _ref4.isView,
|
|
101
|
+
viewEmpty = _ref4.viewEmpty;
|
|
100
102
|
var addressCode = code || enumCode;
|
|
101
103
|
var realIsView = typeof isView === 'boolean' ? isView : isViewCon;
|
|
102
104
|
var realLevel = level || 2;
|
|
@@ -109,7 +111,8 @@ var ProCascader = props => {
|
|
|
109
111
|
if (!(props !== null && props !== void 0 && props.mode)) {
|
|
110
112
|
return (dics === null || dics === void 0 ? void 0 : dics[addressCode]) || [];
|
|
111
113
|
}
|
|
112
|
-
|
|
114
|
+
var fromEnum = Array.isArray(enumData) ? enumData[0] : [];
|
|
115
|
+
return fromEnum !== null && fromEnum !== void 0 && fromEnum.length ? fromEnum : (dics === null || dics === void 0 ? void 0 : dics[addressCode]) || [];
|
|
113
116
|
}, [dics === null || dics === void 0 ? void 0 : dics[addressCode], enumData]);
|
|
114
117
|
var realDataSource = (0, _react.useMemo)(() => {
|
|
115
118
|
var innerDataSource = dataSource || (addressCode ? enumDataSource : []);
|
|
@@ -133,11 +136,11 @@ var ProCascader = props => {
|
|
|
133
136
|
|
|
134
137
|
// 默认成功处理函数
|
|
135
138
|
var defaultOnSuccessFun = res => {
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
status =
|
|
139
|
-
msg =
|
|
140
|
-
data =
|
|
139
|
+
var _ref5 = res || {},
|
|
140
|
+
_ref5$status = _ref5.status,
|
|
141
|
+
status = _ref5$status === void 0 ? 200 : _ref5$status,
|
|
142
|
+
msg = _ref5.message,
|
|
143
|
+
data = _ref5.data;
|
|
141
144
|
if (status !== 200) {
|
|
142
145
|
_message2.default.error(msg);
|
|
143
146
|
return;
|
|
@@ -160,11 +163,11 @@ var ProCascader = props => {
|
|
|
160
163
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
161
164
|
return transformResponse(res);
|
|
162
165
|
}
|
|
163
|
-
var
|
|
164
|
-
|
|
165
|
-
status =
|
|
166
|
-
msg =
|
|
167
|
-
data =
|
|
166
|
+
var _ref6 = res || {},
|
|
167
|
+
_ref6$status = _ref6.status,
|
|
168
|
+
status = _ref6$status === void 0 ? 200 : _ref6$status,
|
|
169
|
+
msg = _ref6.message,
|
|
170
|
+
data = _ref6.data;
|
|
168
171
|
if (status !== 200) {
|
|
169
172
|
_message2.default.error(msg);
|
|
170
173
|
return;
|
|
@@ -220,8 +223,8 @@ var ProCascader = props => {
|
|
|
220
223
|
if (!(useRequest !== null && useRequest !== void 0 && useRequest.service)) {
|
|
221
224
|
return;
|
|
222
225
|
}
|
|
223
|
-
var
|
|
224
|
-
manual =
|
|
226
|
+
var _ref7 = (useRequest === null || useRequest === void 0 ? void 0 : useRequest.options) || {},
|
|
227
|
+
manual = _ref7.manual;
|
|
225
228
|
if (manual || cacheList !== null && cacheList !== void 0 && cacheList.length) {
|
|
226
229
|
return;
|
|
227
230
|
}
|
|
@@ -271,7 +274,7 @@ var ProCascader = props => {
|
|
|
271
274
|
return label === null || label === void 0 ? void 0 : label.filter(item => !!item).join('/');
|
|
272
275
|
};
|
|
273
276
|
var addressValue = isAddressMode ? value && (_value$slice = value.slice(0, realLevel)) !== null && _value$slice !== void 0 && _value$slice.some(item => !!item) ? value.slice(0, realLevel) : undefined : value;
|
|
274
|
-
var viewValue = isAddressMode ? ((
|
|
277
|
+
var viewValue = isAddressMode ? ((_ref8 = [...defaultLabel, value === null || value === void 0 ? void 0 : value[realLevel]]) === null || _ref8 === void 0 || (_ref8 = _ref8.filter(item => !!item)) === null || _ref8 === void 0 ? void 0 : _ref8.join(separator)) || '-' : (defaultLabel === null || defaultLabel === void 0 || (_defaultLabel$filter = defaultLabel.filter(item => !!item)) === null || _defaultLabel$filter === void 0 ? void 0 : _defaultLabel$filter.join(separator)) || '-';
|
|
275
278
|
var findSelectedOptions = function findSelectedOptions(options, value) {
|
|
276
279
|
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
277
280
|
var _value = value !== null && value !== void 0 ? value : [];
|
|
@@ -30,7 +30,7 @@ var _Container = _interopRequireDefault(require("../../../ProForm/components/Con
|
|
|
30
30
|
var _AdaptiveTooltip = _interopRequireDefault(require("../AdaptiveTooltip"));
|
|
31
31
|
var _utils2 = require("../../utils");
|
|
32
32
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
|
-
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"];
|
|
33
|
+
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", "checkLeaf"];
|
|
34
34
|
/* eslint-disable react/no-danger */
|
|
35
35
|
/* eslint-disable react/jsx-closing-tag-location */
|
|
36
36
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
@@ -79,6 +79,7 @@ var ProTreeSelect = (props, ref) => {
|
|
|
79
79
|
className = props.className,
|
|
80
80
|
checkStrictly = props.checkStrictly,
|
|
81
81
|
checkable = props.checkable,
|
|
82
|
+
checkLeaf = props.checkLeaf,
|
|
82
83
|
selectProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
83
84
|
var _props$value = props.value,
|
|
84
85
|
value = _props$value === void 0 ? undefined : _props$value;
|
|
@@ -165,6 +166,17 @@ var ProTreeSelect = (props, ref) => {
|
|
|
165
166
|
loop(copyData);
|
|
166
167
|
return copyData;
|
|
167
168
|
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 统一数据后处理:先处理 code-name 展示,再按 checkLeaf 标记非叶子节点禁用
|
|
172
|
+
* 数据已是标准格式(label, value, children)
|
|
173
|
+
* @param dataArr 标准格式数据
|
|
174
|
+
* @returns 后处理结果
|
|
175
|
+
*/
|
|
176
|
+
var processData = dataArr => {
|
|
177
|
+
var result = transferDataSource(dataArr, showCodeName);
|
|
178
|
+
return checkLeaf ? (0, _utils2.applyCheckLeaf)(result) : result;
|
|
179
|
+
};
|
|
168
180
|
var defaultOnSuccessFun = res => {
|
|
169
181
|
var _res$status = res.status,
|
|
170
182
|
status = _res$status === void 0 ? 200 : _res$status,
|
|
@@ -174,9 +186,9 @@ var ProTreeSelect = (props, ref) => {
|
|
|
174
186
|
_message2.default.error(msg);
|
|
175
187
|
return;
|
|
176
188
|
}
|
|
177
|
-
// 先转换字段名,再处理 code-name
|
|
189
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
178
190
|
var transformedData = transformFieldNames(data || []);
|
|
179
|
-
var resultData =
|
|
191
|
+
var resultData = processData(transformedData);
|
|
180
192
|
setState({
|
|
181
193
|
selectList: resultData || [],
|
|
182
194
|
origDataSource: resultData || []
|
|
@@ -205,9 +217,9 @@ var ProTreeSelect = (props, ref) => {
|
|
|
205
217
|
onSuccess: data => {
|
|
206
218
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
207
219
|
var responseData = transformResponse(data);
|
|
208
|
-
// 先转换字段名,再处理 code-name
|
|
220
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
209
221
|
var transformedData = transformFieldNames(responseData);
|
|
210
|
-
var resultData =
|
|
222
|
+
var resultData = processData(transformedData);
|
|
211
223
|
setState({
|
|
212
224
|
selectList: countChild(resultData),
|
|
213
225
|
origDataSource: resultData
|
|
@@ -228,9 +240,9 @@ var ProTreeSelect = (props, ref) => {
|
|
|
228
240
|
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) {
|
|
229
241
|
if (transformResponse && typeof transformResponse === 'function') {
|
|
230
242
|
var responseData = transformResponse(fetchFunction.data);
|
|
231
|
-
// 先转换字段名,再处理 code-name
|
|
243
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
232
244
|
var transformedData = transformFieldNames(responseData);
|
|
233
|
-
var resultData =
|
|
245
|
+
var resultData = processData(transformedData);
|
|
234
246
|
setState({
|
|
235
247
|
selectList: countChild(resultData),
|
|
236
248
|
origDataSource: resultData
|
|
@@ -244,18 +256,18 @@ var ProTreeSelect = (props, ref) => {
|
|
|
244
256
|
(0, _ahooks.useDeepCompareEffect)(() => {
|
|
245
257
|
if (enumCode) {
|
|
246
258
|
var dictEnum = dics[enumCode] || [];
|
|
247
|
-
// 先转换字段名,再处理 code-name
|
|
259
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
248
260
|
var transformedData = transformFieldNames(dictEnum);
|
|
249
|
-
var resultData =
|
|
261
|
+
var resultData = processData(transformedData);
|
|
250
262
|
var processedList = countChild(resultData);
|
|
251
263
|
setState({
|
|
252
264
|
selectList: processedList,
|
|
253
265
|
origDataSource: resultData
|
|
254
266
|
});
|
|
255
267
|
} else if (dataSource) {
|
|
256
|
-
// 先转换字段名,再处理 code-name
|
|
268
|
+
// 先转换字段名,再处理 code-name 展示与 checkLeaf 标记
|
|
257
269
|
var _transformedData = transformFieldNames(dataSource);
|
|
258
|
-
var _resultData =
|
|
270
|
+
var _resultData = processData(_transformedData);
|
|
259
271
|
var _processedList = countChild(_resultData);
|
|
260
272
|
setState({
|
|
261
273
|
selectList: _processedList,
|
|
@@ -304,6 +304,12 @@ export interface ProTreeSelectType extends Omit<TreeSelectProps, 'onSearch'> {
|
|
|
304
304
|
* @default false
|
|
305
305
|
*/
|
|
306
306
|
checkable?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* 只选叶子节点
|
|
309
|
+
* @description 开启后只能选择叶子节点,非叶子节点置灰禁用,仅 treeSelect 单选模式生效
|
|
310
|
+
* @default false
|
|
311
|
+
*/
|
|
312
|
+
checkLeaf?: boolean;
|
|
307
313
|
/**
|
|
308
314
|
* 显示省略号
|
|
309
315
|
* @description 是否单行省略
|
|
@@ -298,6 +298,12 @@ export interface ProTreeType extends ProTreeSelectType {
|
|
|
298
298
|
* @default false
|
|
299
299
|
*/
|
|
300
300
|
checkable?: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* 只选叶子节点
|
|
303
|
+
* @description 开启后只能选择叶子节点,非叶子节点置灰禁用,仅 treeSelect 单选模式生效
|
|
304
|
+
* @default false
|
|
305
|
+
*/
|
|
306
|
+
checkLeaf?: boolean;
|
|
301
307
|
/**
|
|
302
308
|
* 可勾选
|
|
303
309
|
* @description 是否显示 checkbox
|
package/lib/ProTree/utils.d.ts
CHANGED
|
@@ -41,3 +41,13 @@ export declare function getChildrenKeys(node: ProTreeDataType, childrenKeys: str
|
|
|
41
41
|
* @param allkeys 所有key
|
|
42
42
|
*/
|
|
43
43
|
export declare function getDefaultExpandKeys(isExpand: any, allKeys: any): any;
|
|
44
|
+
/**
|
|
45
|
+
* checkLeaf 模式:只能选择叶子节点,非叶子节点设 disabled=true 整行置灰不可点
|
|
46
|
+
* 数据已是标准格式(label, value, children),仅单选 treeSelect 场景使用
|
|
47
|
+
* 不可变:返回全新数组,不修改入参
|
|
48
|
+
* @param data 标准格式树数据
|
|
49
|
+
* @returns 标记后的新树数据
|
|
50
|
+
*/
|
|
51
|
+
export declare function applyCheckLeaf<T extends {
|
|
52
|
+
children?: T[];
|
|
53
|
+
}>(data: T[]): T[];
|
package/lib/ProTree/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.applyCheckLeaf = applyCheckLeaf;
|
|
7
8
|
exports.filterCheckedNodes = filterCheckedNodes;
|
|
8
9
|
exports.findTreeNodeByKey = findTreeNodeByKey;
|
|
9
10
|
exports.getAllKeys = getAllKeys;
|
|
@@ -213,4 +214,27 @@ function getDefaultExpandKeys(isExpand, allKeys) {
|
|
|
213
214
|
return allKeys;
|
|
214
215
|
}
|
|
215
216
|
return [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* checkLeaf 模式:只能选择叶子节点,非叶子节点设 disabled=true 整行置灰不可点
|
|
221
|
+
* 数据已是标准格式(label, value, children),仅单选 treeSelect 场景使用
|
|
222
|
+
* 不可变:返回全新数组,不修改入参
|
|
223
|
+
* @param data 标准格式树数据
|
|
224
|
+
* @returns 标记后的新树数据
|
|
225
|
+
*/
|
|
226
|
+
function applyCheckLeaf(data) {
|
|
227
|
+
if (!Array.isArray(data)) {
|
|
228
|
+
return data;
|
|
229
|
+
}
|
|
230
|
+
return data.map(node => {
|
|
231
|
+
var hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
232
|
+
if (!hasChildren) {
|
|
233
|
+
return (0, _objectSpread2.default)({}, node);
|
|
234
|
+
}
|
|
235
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, node), {}, {
|
|
236
|
+
disabled: true,
|
|
237
|
+
children: applyCheckLeaf(node.children)
|
|
238
|
+
});
|
|
239
|
+
});
|
|
216
240
|
}
|