@ecoding/components.antd 0.3.7 → 0.3.9
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/lib/core/form.list/index.d.ts +1 -0
- package/lib/core/form.list/index.js +1 -1
- package/lib/core/length-input/index.js +6 -6
- package/lib/core/search.input/index.d.ts +17 -0
- package/lib/core/search.input/index.js +80 -0
- package/lib/helpers/throttle.d.ts +34 -47
- package/lib/helpers/throttle.js +60 -27
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +2 -2
|
@@ -49,7 +49,7 @@ const C = ({ columns, rules, name, hideOperation, hideBottom, operation, i18n })
|
|
|
49
49
|
React.createElement("td", { style: tdStyle }, index + 1),
|
|
50
50
|
columns.map((column, i) => {
|
|
51
51
|
return (React.createElement("td", { style: tdStyle },
|
|
52
|
-
React.createElement(Form.Item, { name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index))));
|
|
52
|
+
React.createElement(Form.Item, { tooltip: column.tooltip || undefined, name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index))));
|
|
53
53
|
}),
|
|
54
54
|
hideOperation ? null : operation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) }, operation.component)) : (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
|
|
55
55
|
React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => remove(field.name) }, i18n ? i18n.$t("global.del", '删除') : '删除')))));
|
|
@@ -54,12 +54,12 @@ const LengthInput = (props) => {
|
|
|
54
54
|
props.onChange(e);
|
|
55
55
|
}, []);
|
|
56
56
|
useEffect(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (props.value) {
|
|
58
|
+
const vs = props.value || "";
|
|
59
|
+
const len = getLen(vs);
|
|
60
|
+
setN(len);
|
|
61
|
+
setV(vs);
|
|
62
|
+
}
|
|
63
63
|
}, [props]);
|
|
64
64
|
const compositionStartHandler = useCallback(() => {
|
|
65
65
|
isCompositionStart.current = true;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { InputProps } from 'antd';
|
|
3
|
+
interface IItem {
|
|
4
|
+
key: any;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
interface IProps extends InputProps {
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
action: string | (() => string);
|
|
11
|
+
actionKey?: string;
|
|
12
|
+
actionParams?: any;
|
|
13
|
+
transformItems?: (res: any) => IItem[];
|
|
14
|
+
[props: string]: any;
|
|
15
|
+
}
|
|
16
|
+
declare const C: React.FC<IProps>;
|
|
17
|
+
export default C;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react';
|
|
13
|
+
import { Input, Dropdown } from 'antd';
|
|
14
|
+
import { LoadingOutlined } from '@ant-design/icons';
|
|
15
|
+
import throttle from '../../helpers/throttle';
|
|
16
|
+
import http from '../../helpers/http';
|
|
17
|
+
const C = (_a) => {
|
|
18
|
+
var { transformItems, actionKey, actionParams, value, placeholder, onChange } = _a, rest = __rest(_a, ["transformItems", "actionKey", "actionParams", "value", "placeholder", "onChange"]);
|
|
19
|
+
const isCompositionStart = useRef(false);
|
|
20
|
+
const [loading, setLoading] = useState(false);
|
|
21
|
+
const [open, setOpen] = useState(false);
|
|
22
|
+
const [v, setV] = useState();
|
|
23
|
+
const [items, setItems] = useState([]);
|
|
24
|
+
const r = http.getRequest();
|
|
25
|
+
const action = useMemo(() => {
|
|
26
|
+
if (typeof rest.action === "string") {
|
|
27
|
+
return rest.action;
|
|
28
|
+
}
|
|
29
|
+
return rest.action();
|
|
30
|
+
}, [rest.action]);
|
|
31
|
+
const handleSearch = useCallback(throttle((vs) => {
|
|
32
|
+
setLoading(true);
|
|
33
|
+
r.get(action, Object.assign({}, actionParams || {}, { [actionKey]: vs })).then((res) => {
|
|
34
|
+
setLoading(false);
|
|
35
|
+
const temp = transformItems ? transformItems(res) : res;
|
|
36
|
+
if (temp && temp.length > 0) {
|
|
37
|
+
setOpen(true);
|
|
38
|
+
setItems(temp);
|
|
39
|
+
}
|
|
40
|
+
}).catch(e => {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
});
|
|
43
|
+
}, 500, { leading: false, trailing: true }), []);
|
|
44
|
+
const keyUpHandler = useCallback((e) => {
|
|
45
|
+
let vs = e.target.value.trim();
|
|
46
|
+
setV(vs);
|
|
47
|
+
// 估计form表单会默认有onChange事件
|
|
48
|
+
onChange && onChange(vs);
|
|
49
|
+
if (action) {
|
|
50
|
+
handleSearch(vs);
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
53
|
+
const onClick = ({ key }) => {
|
|
54
|
+
const temp = items && items.find(item => item.key === key);
|
|
55
|
+
if (temp) {
|
|
56
|
+
setV(temp.label);
|
|
57
|
+
onChange && onChange(temp.label);
|
|
58
|
+
}
|
|
59
|
+
setOpen(false);
|
|
60
|
+
};
|
|
61
|
+
const compositionStartHandler = useCallback(() => {
|
|
62
|
+
isCompositionStart.current = true;
|
|
63
|
+
}, []);
|
|
64
|
+
const compositionEndHandler = useCallback((e) => {
|
|
65
|
+
isCompositionStart.current = false;
|
|
66
|
+
keyUpHandler(e);
|
|
67
|
+
}, []);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (value) {
|
|
70
|
+
setV(value);
|
|
71
|
+
}
|
|
72
|
+
}, [value]);
|
|
73
|
+
return (React.createElement(Dropdown, { destroyPopupOnHide: true, open: open, menu: { items, onClick }, overlayStyle: { maxHeight: rest.maxHeight, overflowY: "auto", boxShadow: "0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)" } },
|
|
74
|
+
React.createElement(Input, Object.assign({}, rest, { value: v, placeholder: placeholder, onChange: keyUpHandler, suffix: loading ? React.createElement(LoadingOutlined, { style: { color: "#ccc" } }) : null, onCompositionStart: compositionStartHandler, onCompositionEnd: compositionEndHandler }))));
|
|
75
|
+
};
|
|
76
|
+
C.defaultProps = {
|
|
77
|
+
actionKey: "searchKey",
|
|
78
|
+
maxHeight: 220
|
|
79
|
+
};
|
|
80
|
+
export default C;
|
|
@@ -4,58 +4,45 @@
|
|
|
4
4
|
* @param {function} func 传入函数
|
|
5
5
|
* @param {number} wait 表示时间窗口的间隔
|
|
6
6
|
* @param {object} [options] 如果想忽略开始边界上的调用,传入{leading: false}。 绑定的函数先执行,而不是delay后后执行。
|
|
7
|
-
* @param {boolean} [options.leading=true]
|
|
8
|
-
* @param {boolean} [options.trailing=true]
|
|
7
|
+
* @param {boolean} [options.leading=true] true: 第一次不管延时都会调用一次, false: 第一次受延迟影响不掉用
|
|
8
|
+
* @param {boolean} [options.trailing=true] true: 最后一次一定会调用一次, false: 最后一次受延迟影响不掉用
|
|
9
9
|
*
|
|
10
10
|
* @return {Function}
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const throttleCallback = throttle(callback, 100);
|
|
14
|
-
|
|
14
|
+
*/
|
|
15
|
+
export default function throttle(func: Function, wait: number, options?: {
|
|
16
|
+
leading: boolean;
|
|
17
|
+
trailing: boolean;
|
|
18
|
+
}): (this: any) => any;
|
|
19
|
+
/**
|
|
20
|
+
const Search = () => {
|
|
21
|
+
const handleOnChange = (e) => {
|
|
22
|
+
console.log(e.target.value)
|
|
23
|
+
}
|
|
24
|
+
const handleSearch = useCallback(throttle((e) => handleOnChange(e), 500), [])
|
|
15
25
|
|
|
16
|
-
|
|
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
|
-
};
|
|
26
|
+
return (<Input onChange={handleSearch} placeholder="Basic usage" />)
|
|
59
27
|
}
|
|
28
|
+
|
|
29
|
+
ReactDOM.render(<Search />, document.getElementById('container'));
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Search extends React.Component {
|
|
33
|
+
constructor(props) {
|
|
34
|
+
super(props)
|
|
35
|
+
this.handleSearch = throttle(this.handleOnChange, 200);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
handleOnChange = (e) => {
|
|
39
|
+
console.log(e.target.value)
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
42
|
+
return (
|
|
43
|
+
<Input onChange={this.handleSearch} />
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
60
48
|
*/
|
|
61
|
-
export default function throttle(fn: Function, delay: number, immediate: boolean, debounce?: boolean): (this: any) => void;
|
package/lib/helpers/throttle.js
CHANGED
|
@@ -4,20 +4,19 @@
|
|
|
4
4
|
* @param {function} func 传入函数
|
|
5
5
|
* @param {number} wait 表示时间窗口的间隔
|
|
6
6
|
* @param {object} [options] 如果想忽略开始边界上的调用,传入{leading: false}。 绑定的函数先执行,而不是delay后后执行。
|
|
7
|
-
* @param {boolean} [options.leading=true]
|
|
8
|
-
* @param {boolean} [options.trailing=true]
|
|
7
|
+
* @param {boolean} [options.leading=true] true: 第一次不管延时都会调用一次, false: 第一次受延迟影响不掉用
|
|
8
|
+
* @param {boolean} [options.trailing=true] true: 最后一次一定会调用一次, false: 最后一次受延迟影响不掉用
|
|
9
9
|
*
|
|
10
10
|
* @return {Function}
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const throttleCallback = throttle(callback, 100);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let timeout: any = null;
|
|
14
|
+
*/
|
|
15
|
+
export default function throttle(func, wait, options = { leading: false, trailing: false }) {
|
|
16
|
+
let context;
|
|
17
|
+
let args;
|
|
18
|
+
let result;
|
|
19
|
+
let timeout = null;
|
|
21
20
|
// 上次执行时间点
|
|
22
21
|
let previous = 0;
|
|
23
22
|
// 延迟执行函数
|
|
@@ -30,7 +29,7 @@ export default function throttle(func: Function, wait: number, options: any = {}
|
|
|
30
29
|
context = args = null;
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
return function f(
|
|
32
|
+
return function f() {
|
|
34
33
|
const now = +new Date();
|
|
35
34
|
// 首次执行时,如果设定了开始边界不执行选项,将上次执行时间设定为当前时间。
|
|
36
35
|
if (!previous && options.leading === false) {
|
|
@@ -51,50 +50,84 @@ export default function throttle(func: Function, wait: number, options: any = {}
|
|
|
51
50
|
context = args = null;
|
|
52
51
|
}
|
|
53
52
|
// 如果延迟执行不存在,且没有设定结尾边界不执行选项
|
|
54
|
-
}
|
|
53
|
+
}
|
|
54
|
+
else if (!timeout && options.trailing !== false) {
|
|
55
55
|
timeout = setTimeout(later, remaining);
|
|
56
56
|
}
|
|
57
57
|
return result;
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
*/
|
|
61
60
|
/*
|
|
62
61
|
* 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次
|
|
63
62
|
* @param fn {function} 需要调用的函数
|
|
64
63
|
* @param delay {number} 延迟时间,单位毫秒
|
|
65
64
|
* @param immediate {bool} 给 immediate参数传递false 绑定的函数先执行,而不是delay后后执行。
|
|
66
65
|
* @return {function} 实际调用函数
|
|
67
|
-
|
|
68
|
-
export default function throttle(fn, delay, immediate, debounce) {
|
|
66
|
+
|
|
67
|
+
export default function throttle(fn: Function, delay: number, immediate: boolean, debounce?: boolean) {
|
|
69
68
|
let curr = +new Date(), //当前时间
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
last_call = 0,
|
|
70
|
+
last_exec = 0,
|
|
71
|
+
timer: any = null,
|
|
72
|
+
diff, //时间差
|
|
73
|
+
context: any, //上下文
|
|
74
|
+
args: any,
|
|
75
|
+
exec = function () {
|
|
76
|
+
last_exec = curr;
|
|
77
|
+
fn.apply(context, args);
|
|
78
|
+
};
|
|
79
|
+
return function (this: any) {
|
|
77
80
|
curr = +new Date();
|
|
78
81
|
context = this;
|
|
79
82
|
args = arguments;
|
|
80
83
|
diff = curr - (debounce ? last_call : last_exec) - delay;
|
|
81
84
|
clearTimeout(timer);
|
|
85
|
+
|
|
82
86
|
if (debounce) {
|
|
83
87
|
if (immediate) {
|
|
84
88
|
timer = setTimeout(exec, delay);
|
|
85
|
-
}
|
|
86
|
-
else if (diff >= 0) {
|
|
89
|
+
} else if (diff >= 0) {
|
|
87
90
|
exec();
|
|
88
91
|
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
92
|
+
} else {
|
|
91
93
|
if (diff >= 0) {
|
|
92
94
|
exec();
|
|
93
|
-
}
|
|
94
|
-
else if (immediate) {
|
|
95
|
+
} else if (immediate) {
|
|
95
96
|
timer = setTimeout(exec, -diff);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
99
|
+
|
|
98
100
|
last_call = curr;
|
|
99
101
|
};
|
|
100
102
|
}
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
const Search = () => {
|
|
106
|
+
const handleOnChange = (e) => {
|
|
107
|
+
console.log(e.target.value)
|
|
108
|
+
}
|
|
109
|
+
const handleSearch = useCallback(throttle((e) => handleOnChange(e), 500), [])
|
|
110
|
+
|
|
111
|
+
return (<Input onChange={handleSearch} placeholder="Basic usage" />)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ReactDOM.render(<Search />, document.getElementById('container'));
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class Search extends React.Component {
|
|
118
|
+
constructor(props) {
|
|
119
|
+
super(props)
|
|
120
|
+
this.handleSearch = throttle(this.handleOnChange, 200);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
handleOnChange = (e) => {
|
|
124
|
+
console.log(e.target.value)
|
|
125
|
+
}
|
|
126
|
+
render() {
|
|
127
|
+
return (
|
|
128
|
+
<Input onChange={this.handleSearch} />
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
*/
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { default as InjectNotification } from "./core/inject-notification";
|
|
|
6
6
|
export { default as Confirm } from "./core/confirm";
|
|
7
7
|
export { default as AsyncCascader } from "./core/async-cascader";
|
|
8
8
|
export { default as LengthInput } from "./core/length-input";
|
|
9
|
+
export { default as SearchInput } from "./core/search.input";
|
|
9
10
|
export { default as PhoneInput } from "./core/phone-input";
|
|
10
11
|
export { default as RangePicker } from "./core/range-picker";
|
|
11
12
|
export { default as DatePicker } from "./core/date.picker";
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { default as InjectNotification } from "./core/inject-notification";
|
|
|
6
6
|
export { default as Confirm } from "./core/confirm";
|
|
7
7
|
export { default as AsyncCascader } from "./core/async-cascader";
|
|
8
8
|
export { default as LengthInput } from "./core/length-input";
|
|
9
|
+
export { default as SearchInput } from "./core/search.input";
|
|
9
10
|
export { default as PhoneInput } from "./core/phone-input";
|
|
10
11
|
export { default as RangePicker } from "./core/range-picker";
|
|
11
12
|
export { default as DatePicker } from "./core/date.picker";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"antd": "^5.8.4",
|
|
44
44
|
"axios": "^1.1.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "0566152c2eb2352226def6ca6c57b0760f603886"
|
|
47
47
|
}
|