@ecoding/components.antd 0.3.61 → 0.3.62
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.
|
@@ -26,7 +26,7 @@ import { isSomething } from "@ecoding/helper.is";
|
|
|
26
26
|
import { jsonFormatNewKey, jsonFormatNewKey2 } from "@ecoding/helper.json";
|
|
27
27
|
const { Option } = Select;
|
|
28
28
|
let timeout;
|
|
29
|
-
const
|
|
29
|
+
const AsyncSelect = memo((props) => {
|
|
30
30
|
const r = http.getRequest();
|
|
31
31
|
const [loading, setLoading] = useState(true);
|
|
32
32
|
const [options, setOptions] = useState([]);
|
|
@@ -37,57 +37,57 @@ const AsyncSlect = memo((props) => {
|
|
|
37
37
|
const { onChange, searchIface, data, iface } = p, rest = __rest(p, ["onChange", "searchIface", "data", "iface"]);
|
|
38
38
|
return rest;
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
const initEx = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
var _a;
|
|
42
|
+
// 获得第一个接口信息
|
|
43
|
+
if (data) {
|
|
44
|
+
const res = data.format2 ? jsonFormatNewKey2(data.datas, data.format2) : data.format ? jsonFormatNewKey(data.datas, data.format) : data.datas;
|
|
45
|
+
return Promise.resolve(res);
|
|
46
|
+
}
|
|
47
|
+
let params = {};
|
|
48
|
+
if (iface) {
|
|
49
|
+
if (iface.paramKey) {
|
|
50
|
+
// 设置接口调用参数
|
|
51
|
+
params[iface.paramKey] = iface.paramValue;
|
|
52
|
+
}
|
|
53
|
+
if (iface.params) {
|
|
54
|
+
params = Object.assign({}, params, iface.params);
|
|
55
|
+
}
|
|
56
|
+
let resOrigin = [];
|
|
57
|
+
// 这里支持了外部直接传入列表结果
|
|
58
|
+
const cache = isSomething(iface.cache) ? iface.cache : false;
|
|
59
|
+
if (((_a = iface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
|
|
60
|
+
resOrigin = yield r.post(iface.url, params, { cache });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
resOrigin = yield r.get(iface.url, params, { cache });
|
|
64
|
+
}
|
|
65
|
+
// 指定数据key
|
|
66
|
+
if (iface && iface.fromKey) {
|
|
67
|
+
if (Array.isArray(iface.fromKey)) {
|
|
68
|
+
iface.fromKey.forEach((key) => {
|
|
69
|
+
resOrigin = resOrigin[key];
|
|
70
|
+
});
|
|
48
71
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (iface.paramKey) {
|
|
52
|
-
// 设置接口调用参数
|
|
53
|
-
params[iface.paramKey] = iface.paramValue;
|
|
54
|
-
}
|
|
55
|
-
if (iface.params) {
|
|
56
|
-
params = Object.assign({}, params, iface.params);
|
|
57
|
-
}
|
|
58
|
-
let resOrigin = [];
|
|
59
|
-
// 这里支持了外部直接传入列表结果
|
|
60
|
-
const cache = isSomething(iface.cache) ? iface.cache : false;
|
|
61
|
-
if (((_a = iface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
|
|
62
|
-
resOrigin = yield r.post(iface.url, params, { cache });
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
resOrigin = yield r.get(iface.url, params, { cache });
|
|
66
|
-
}
|
|
67
|
-
// 指定数据key
|
|
68
|
-
if (iface && iface.fromKey) {
|
|
69
|
-
if (Array.isArray(iface.fromKey)) {
|
|
70
|
-
iface.fromKey.forEach((key) => {
|
|
71
|
-
resOrigin = resOrigin[key];
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
resOrigin = resOrigin[iface.fromKey];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const res = iface.format2 ? jsonFormatNewKey2(resOrigin, iface.format2) : iface.format ? jsonFormatNewKey(resOrigin, iface.format) : resOrigin;
|
|
79
|
-
return Promise.resolve(res);
|
|
72
|
+
else {
|
|
73
|
+
resOrigin = resOrigin[iface.fromKey];
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
}
|
|
76
|
+
const res = iface.format2 ? jsonFormatNewKey2(resOrigin, iface.format2) : iface.format ? jsonFormatNewKey(resOrigin, iface.format) : resOrigin;
|
|
77
|
+
return Promise.resolve(res);
|
|
78
|
+
}
|
|
79
|
+
return Promise.reject("没有iface或data");
|
|
80
|
+
});
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const ex = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const res = yield initEx();
|
|
84
84
|
setOptions(res);
|
|
85
85
|
setLoading(false);
|
|
86
86
|
});
|
|
87
87
|
ex();
|
|
88
88
|
}, [data, iface]);
|
|
89
89
|
const handleSearch = (newValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
-
if (!
|
|
90
|
+
if (!searchIface) {
|
|
91
91
|
return null;
|
|
92
92
|
}
|
|
93
93
|
if (timeout) {
|
|
@@ -95,8 +95,13 @@ const AsyncSlect = memo((props) => {
|
|
|
95
95
|
timeout = null;
|
|
96
96
|
}
|
|
97
97
|
const innerEx = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
-
var
|
|
98
|
+
var _b;
|
|
99
99
|
let params = {};
|
|
100
|
+
if (!newValue) {
|
|
101
|
+
const res = yield initEx();
|
|
102
|
+
setOptions(res);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
100
105
|
if (searchIface) {
|
|
101
106
|
if (searchIface.paramKey) {
|
|
102
107
|
// 设置接口调用参数
|
|
@@ -108,7 +113,7 @@ const AsyncSlect = memo((props) => {
|
|
|
108
113
|
let resOrigin = [];
|
|
109
114
|
// 这里支持了外部直接传入列表结果
|
|
110
115
|
const cache = isSomething(searchIface.cache) ? searchIface.cache : false;
|
|
111
|
-
if (((
|
|
116
|
+
if (((_b = searchIface.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === "post") {
|
|
112
117
|
resOrigin = yield r.post(searchIface.url, params, { cache });
|
|
113
118
|
}
|
|
114
119
|
else {
|
|
@@ -151,4 +156,4 @@ const AsyncSlect = memo((props) => {
|
|
|
151
156
|
return option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
|
|
152
157
|
}, allowClear: true, showSearch: true, onSearch: handleSearch, optionFilterProp: "children" }, getRest(props), { onChange: changeHandler }), children));
|
|
153
158
|
});
|
|
154
|
-
export default
|
|
159
|
+
export default AsyncSelect;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { PlusOutlined } from '@ant-design/icons';
|
|
3
3
|
import { isEqual } from "@ecoding/helper.is";
|
|
4
|
-
import { Flex, Input, Tag, theme, Tooltip } from 'antd';
|
|
4
|
+
import { Flex, Input, message, Tag, theme, Tooltip } from 'antd';
|
|
5
5
|
const tagInputStyle = {
|
|
6
6
|
width: 64,
|
|
7
7
|
height: 22,
|
|
@@ -39,10 +39,15 @@ const C = (props) => {
|
|
|
39
39
|
setInputValue(e.target.value);
|
|
40
40
|
};
|
|
41
41
|
const handleInputConfirm = () => {
|
|
42
|
-
if (inputValue
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (inputValue) {
|
|
43
|
+
if (!tags.includes(inputValue.trim())) {
|
|
44
|
+
const values = [...tags, inputValue.trim()];
|
|
45
|
+
setTags(values);
|
|
46
|
+
props.onChange && props.onChange(values && values.length > 0 ? values : undefined);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
message.error(props.multipleError || '标签已存在');
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
setInputVisible(false);
|
|
48
53
|
setInputValue('');
|
|
@@ -52,9 +57,14 @@ const C = (props) => {
|
|
|
52
57
|
};
|
|
53
58
|
const handleEditInputConfirm = () => {
|
|
54
59
|
const newTags = [...(tags || [])];
|
|
55
|
-
newTags
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
if (!newTags.includes(editInputValue.trim())) {
|
|
61
|
+
newTags[editInputIndex] = editInputValue.trim();
|
|
62
|
+
setTags(newTags);
|
|
63
|
+
props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
message.error(props.multipleError || '标签已存在');
|
|
67
|
+
}
|
|
58
68
|
setEditInputIndex(-1);
|
|
59
69
|
setEditInputValue('');
|
|
60
70
|
};
|
|
@@ -63,6 +73,12 @@ const C = (props) => {
|
|
|
63
73
|
background: token.colorBgContainer,
|
|
64
74
|
borderStyle: 'dashed'
|
|
65
75
|
};
|
|
76
|
+
const tagDisabledPlusStyle = {
|
|
77
|
+
height: 22,
|
|
78
|
+
background: token.colorBgContainerDisabled,
|
|
79
|
+
borderStyle: 'dashed',
|
|
80
|
+
color: token.colorTextDisabled
|
|
81
|
+
};
|
|
66
82
|
useEffect(() => {
|
|
67
83
|
if (props.value && !isEqual(props.value, tags)) {
|
|
68
84
|
setTags(props.value);
|
|
@@ -74,7 +90,7 @@ const C = (props) => {
|
|
|
74
90
|
return (React.createElement(Input, { ref: editInputRef, key: tag, size: "small", style: tagInputStyle, value: editInputValue, onChange: handleEditInputChange, onBlur: handleEditInputConfirm, onPressEnter: handleEditInputConfirm }));
|
|
75
91
|
}
|
|
76
92
|
const isLongTag = tag.length > 20;
|
|
77
|
-
const tagElem = (React.createElement(Tag, { key: tag, closable: props.fixedFirst ? index !== 0 : true, style: { userSelect: 'none' }, onClose: () => handleClose(tag) },
|
|
93
|
+
const tagElem = (React.createElement(Tag, { key: tag, closable: props.disabled ? false : props.fixedFirst ? index !== 0 : true, style: { userSelect: 'none' }, onClose: () => handleClose(tag) },
|
|
78
94
|
React.createElement("span", { onDoubleClick: (e) => {
|
|
79
95
|
if (props.disabled) {
|
|
80
96
|
return;
|
|
@@ -87,7 +103,7 @@ const C = (props) => {
|
|
|
87
103
|
} }, isLongTag ? `${tag.slice(0, 20)}...` : tag)));
|
|
88
104
|
return isLongTag ? (React.createElement(Tooltip, { title: tag, key: tag }, tagElem)) : (tagElem);
|
|
89
105
|
}),
|
|
90
|
-
props.disabled ? null : inputVisible ? (React.createElement(Input, { ref: inputRef, type: "text", size: "small", style: tagInputStyle, value: inputValue, onChange: handleInputChange, onBlur: handleInputConfirm, onPressEnter: handleInputConfirm })) : (React.createElement(Tag, { style: tagPlusStyle, icon: React.createElement(PlusOutlined, null), onClick: showInput }, props.addTagText))));
|
|
106
|
+
props.disabled ? (React.createElement(Tag, { style: tagDisabledPlusStyle, icon: React.createElement(PlusOutlined, null) }, props.addTagText)) : inputVisible ? (React.createElement(Input, { ref: inputRef, type: "text", size: "small", style: tagInputStyle, value: inputValue, onChange: handleInputChange, onBlur: handleInputConfirm, onPressEnter: handleInputConfirm })) : (React.createElement(Tag, { style: tagPlusStyle, icon: React.createElement(PlusOutlined, null), onClick: showInput }, props.addTagText))));
|
|
91
107
|
};
|
|
92
108
|
C.defaultProps = {
|
|
93
109
|
disabled: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.62",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"antd": "5.27.0",
|
|
48
48
|
"axios": "^1.1.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "08d74aa3e9086a168e7482332a68a209d1dce911"
|
|
51
51
|
}
|