@ecoding/components.antd 0.1.16 → 0.1.18
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.
|
@@ -14,12 +14,14 @@ import http from "../../helpers/http";
|
|
|
14
14
|
import { isSomething } from "@ecoding/helper.is";
|
|
15
15
|
import { jsonFormatNewKey } from "@ecoding/helper.json";
|
|
16
16
|
const { Option } = Select;
|
|
17
|
+
let timeout;
|
|
17
18
|
const AsyncSlect = memo((props) => {
|
|
18
19
|
const r = http.getRequest();
|
|
19
20
|
const [loading, setLoading] = useState(true);
|
|
20
21
|
const [options, setOptions] = useState([]);
|
|
21
22
|
const iface = useMemo(() => props.iface, []);
|
|
22
23
|
const data = useMemo(() => props.data, []);
|
|
24
|
+
const searchIface = useMemo(() => props.searchIface, []);
|
|
23
25
|
useEffect(() => {
|
|
24
26
|
const ex = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
27
|
const innerEx = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -69,6 +71,52 @@ const AsyncSlect = memo((props) => {
|
|
|
69
71
|
});
|
|
70
72
|
ex();
|
|
71
73
|
}, []);
|
|
74
|
+
const handleSearch = (newValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
if (!newValue) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (timeout) {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
timeout = null;
|
|
81
|
+
}
|
|
82
|
+
const innerEx = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
var _a;
|
|
84
|
+
let params = {};
|
|
85
|
+
if (searchIface) {
|
|
86
|
+
if (searchIface.paramKey) {
|
|
87
|
+
// 设置接口调用参数
|
|
88
|
+
params[searchIface.paramKey] = newValue;
|
|
89
|
+
}
|
|
90
|
+
if (searchIface.params) {
|
|
91
|
+
params = Object.assign({}, params, searchIface.params);
|
|
92
|
+
}
|
|
93
|
+
let resOrigin = [];
|
|
94
|
+
// 这里支持了外部直接传入列表结果
|
|
95
|
+
const cache = isSomething(searchIface.cache) ? searchIface.cache : false;
|
|
96
|
+
if (((_a = searchIface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
|
|
97
|
+
resOrigin = yield r.post(searchIface.url, params, { cache });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
resOrigin = yield r.get(searchIface.url, params, { cache });
|
|
101
|
+
}
|
|
102
|
+
// 指定数据key
|
|
103
|
+
if (searchIface && searchIface.fromKey) {
|
|
104
|
+
if (Array.isArray(searchIface.fromKey)) {
|
|
105
|
+
searchIface.fromKey.forEach((key) => {
|
|
106
|
+
resOrigin = resOrigin[key];
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
resOrigin = resOrigin[searchIface.fromKey];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const res = jsonFormatNewKey(resOrigin, searchIface.format);
|
|
114
|
+
setOptions(res);
|
|
115
|
+
}
|
|
116
|
+
return Promise.reject("没有searchIface");
|
|
117
|
+
});
|
|
118
|
+
timeout = setTimeout(innerEx, 300);
|
|
119
|
+
});
|
|
72
120
|
const children = useMemo(() => {
|
|
73
121
|
return (options &&
|
|
74
122
|
options.map((item) => {
|
|
@@ -83,6 +131,6 @@ const AsyncSlect = memo((props) => {
|
|
|
83
131
|
return option.children.join("").toLowerCase().indexOf(input.toLowerCase()) >= 0;
|
|
84
132
|
}
|
|
85
133
|
return option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
|
|
86
|
-
}, allowClear: true, showSearch: true, optionFilterProp: "children" }, props), children));
|
|
134
|
+
}, allowClear: true, showSearch: true, onSearch: handleSearch, optionFilterProp: "children" }, props), children));
|
|
87
135
|
});
|
|
88
136
|
export default AsyncSlect;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 频率控制 返回函数连续调用时,func 执行频率限定为 次 / wait
|
|
3
|
+
*
|
|
4
|
+
* @param {function} func 传入函数
|
|
5
|
+
* @param {number} wait 表示时间窗口的间隔
|
|
6
|
+
* @param {object} [options] 如果想忽略开始边界上的调用,传入{leading: false}。 绑定的函数先执行,而不是delay后后执行。
|
|
7
|
+
* @param {boolean} [options.leading=true] 如果想忽略开始边界上的调用,传入{leading: false}。
|
|
8
|
+
* @param {boolean} [options.trailing=true] 如果想忽略结尾边界上的调用,传入{trailing: false}
|
|
9
|
+
*
|
|
10
|
+
* @return {Function}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const throttleCallback = throttle(callback, 100);
|
|
14
|
+
*
|
|
15
|
+
|
|
16
|
+
export default function throttle(func: Function, wait: number, options: any = {}): any {
|
|
17
|
+
let context: any;
|
|
18
|
+
let args: any;
|
|
19
|
+
let result: any;
|
|
20
|
+
let timeout: any = null;
|
|
21
|
+
// 上次执行时间点
|
|
22
|
+
let previous = 0;
|
|
23
|
+
// 延迟执行函数
|
|
24
|
+
const later = () => {
|
|
25
|
+
// 若设定了开始边界不执行选项,上次执行时间始终为0
|
|
26
|
+
previous = options.leading === false ? 0 : +new Date();
|
|
27
|
+
timeout = null;
|
|
28
|
+
result = func.apply(context, args);
|
|
29
|
+
if (!timeout) {
|
|
30
|
+
context = args = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return function f(this: any) {
|
|
34
|
+
const now = +new Date();
|
|
35
|
+
// 首次执行时,如果设定了开始边界不执行选项,将上次执行时间设定为当前时间。
|
|
36
|
+
if (!previous && options.leading === false) {
|
|
37
|
+
previous = now;
|
|
38
|
+
}
|
|
39
|
+
// 延迟执行时间间隔
|
|
40
|
+
const remaining = wait - (now - previous);
|
|
41
|
+
context = this;
|
|
42
|
+
args = arguments; // eslint-disable-line
|
|
43
|
+
// 延迟时间间隔remaining小于等于0,表示上次执行至此所间隔时间已经超过一个时间窗口
|
|
44
|
+
// remaining大于时间窗口wait,表示客户端系统时间被调整过
|
|
45
|
+
if (remaining <= 0 || remaining > wait) {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
timeout = null;
|
|
48
|
+
previous = now;
|
|
49
|
+
result = func.apply(context, args);
|
|
50
|
+
if (!timeout) {
|
|
51
|
+
context = args = null;
|
|
52
|
+
}
|
|
53
|
+
// 如果延迟执行不存在,且没有设定结尾边界不执行选项
|
|
54
|
+
} else if (!timeout && options.trailing !== false) {
|
|
55
|
+
timeout = setTimeout(later, remaining);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
export default function throttle(fn: Function, delay: number, immediate: boolean, debounce?: boolean): (this: any) => void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 频率控制 返回函数连续调用时,func 执行频率限定为 次 / wait
|
|
3
|
+
*
|
|
4
|
+
* @param {function} func 传入函数
|
|
5
|
+
* @param {number} wait 表示时间窗口的间隔
|
|
6
|
+
* @param {object} [options] 如果想忽略开始边界上的调用,传入{leading: false}。 绑定的函数先执行,而不是delay后后执行。
|
|
7
|
+
* @param {boolean} [options.leading=true] 如果想忽略开始边界上的调用,传入{leading: false}。
|
|
8
|
+
* @param {boolean} [options.trailing=true] 如果想忽略结尾边界上的调用,传入{trailing: false}
|
|
9
|
+
*
|
|
10
|
+
* @return {Function}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const throttleCallback = throttle(callback, 100);
|
|
14
|
+
*
|
|
15
|
+
|
|
16
|
+
export default function throttle(func: Function, wait: number, options: any = {}): any {
|
|
17
|
+
let context: any;
|
|
18
|
+
let args: any;
|
|
19
|
+
let result: any;
|
|
20
|
+
let timeout: any = null;
|
|
21
|
+
// 上次执行时间点
|
|
22
|
+
let previous = 0;
|
|
23
|
+
// 延迟执行函数
|
|
24
|
+
const later = () => {
|
|
25
|
+
// 若设定了开始边界不执行选项,上次执行时间始终为0
|
|
26
|
+
previous = options.leading === false ? 0 : +new Date();
|
|
27
|
+
timeout = null;
|
|
28
|
+
result = func.apply(context, args);
|
|
29
|
+
if (!timeout) {
|
|
30
|
+
context = args = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return function f(this: any) {
|
|
34
|
+
const now = +new Date();
|
|
35
|
+
// 首次执行时,如果设定了开始边界不执行选项,将上次执行时间设定为当前时间。
|
|
36
|
+
if (!previous && options.leading === false) {
|
|
37
|
+
previous = now;
|
|
38
|
+
}
|
|
39
|
+
// 延迟执行时间间隔
|
|
40
|
+
const remaining = wait - (now - previous);
|
|
41
|
+
context = this;
|
|
42
|
+
args = arguments; // eslint-disable-line
|
|
43
|
+
// 延迟时间间隔remaining小于等于0,表示上次执行至此所间隔时间已经超过一个时间窗口
|
|
44
|
+
// remaining大于时间窗口wait,表示客户端系统时间被调整过
|
|
45
|
+
if (remaining <= 0 || remaining > wait) {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
timeout = null;
|
|
48
|
+
previous = now;
|
|
49
|
+
result = func.apply(context, args);
|
|
50
|
+
if (!timeout) {
|
|
51
|
+
context = args = null;
|
|
52
|
+
}
|
|
53
|
+
// 如果延迟执行不存在,且没有设定结尾边界不执行选项
|
|
54
|
+
} else if (!timeout && options.trailing !== false) {
|
|
55
|
+
timeout = setTimeout(later, remaining);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
/*
|
|
62
|
+
* 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次
|
|
63
|
+
* @param fn {function} 需要调用的函数
|
|
64
|
+
* @param delay {number} 延迟时间,单位毫秒
|
|
65
|
+
* @param immediate {bool} 给 immediate参数传递false 绑定的函数先执行,而不是delay后后执行。
|
|
66
|
+
* @return {function} 实际调用函数
|
|
67
|
+
*/
|
|
68
|
+
export default function throttle(fn, delay, immediate, debounce) {
|
|
69
|
+
let curr = +new Date(), //当前时间
|
|
70
|
+
last_call = 0, last_exec = 0, timer = null, diff, //时间差
|
|
71
|
+
context, //上下文
|
|
72
|
+
args, exec = function () {
|
|
73
|
+
last_exec = curr;
|
|
74
|
+
fn.apply(context, args);
|
|
75
|
+
};
|
|
76
|
+
return function () {
|
|
77
|
+
curr = +new Date();
|
|
78
|
+
context = this;
|
|
79
|
+
args = arguments;
|
|
80
|
+
diff = curr - (debounce ? last_call : last_exec) - delay;
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
if (debounce) {
|
|
83
|
+
if (immediate) {
|
|
84
|
+
timer = setTimeout(exec, delay);
|
|
85
|
+
}
|
|
86
|
+
else if (diff >= 0) {
|
|
87
|
+
exec();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (diff >= 0) {
|
|
92
|
+
exec();
|
|
93
|
+
}
|
|
94
|
+
else if (immediate) {
|
|
95
|
+
timer = setTimeout(exec, -diff);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
last_call = curr;
|
|
99
|
+
};
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"react-quill": "^2.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e8859f56f486b54a0ea0f4608bb410e497009da4"
|
|
46
46
|
}
|