Skip to content

Commit e32e489

Browse files
committed
Merge branch 'feat_enhanced_typeSystem' into 'dev'
improvement(type): improve easy select type See merge request dt-insight-front/infrastructure/dt-react-component!43
2 parents 27eb402 + 965aa07 commit e32e489

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@
102102
"enzyme": "^3.11.0",
103103
"enzyme-adapter-react-16": "^1.15.2",
104104
"eslint": "^5.16.0",
105+
"eslint-config-prettier": "^6.11.0",
105106
"eslint-config-standard": "^12.0.0",
107+
"eslint-formatter-pretty": "^4.0.0",
106108
"eslint-loader": "^1.7.1",
107109
"eslint-plugin-import": "^2.14.0",
108110
"eslint-plugin-jest": "^22.14.0",
@@ -112,9 +114,8 @@
112114
"eslint-plugin-react": "^7.11.1",
113115
"eslint-plugin-sort-requires": "^2.1.0",
114116
"eslint-plugin-standard": "^4.0.0",
115-
"eslint-config-prettier": "^6.11.0",
116-
"eslint-formatter-pretty": "^4.0.0",
117117
"eslint-plugin-unicorn": "^21.0.0",
118+
"fetch-jsonp": "^1.1.3",
118119
"file-loader": "^6.0.0",
119120
"gulp": "^4.0.2",
120121
"gulp-babel": "^8.0.0",
@@ -147,7 +148,6 @@
147148
"@handsontable/react": "^2.1.0",
148149
"antd": "3.26.13",
149150
"classnames": "^2.2.6",
150-
"fetch-jsonp": "^1.1.3",
151151
"handsontable": "^6.2.2",
152152
"highlight.js": "^9.14.2",
153153
"lodash": "^4.17.15",
@@ -158,4 +158,4 @@
158158
"react-router": "3.0.4",
159159
"showdown": "^1.9.0"
160160
}
161-
}
161+
}

src/components/easySelect/index.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import * as React from 'react';
22
import { Select } from 'antd';
33
import debounce from 'lodash/debounce';
4-
4+
import { SelectProps } from 'antd/lib/select'
55
const { Option } = Select;
6-
class EasySelect extends React.Component<any, any> {
6+
7+
interface EasySelectProps {
8+
autoValue?: string;
9+
dataSource?: any[];
10+
clearValueRequest?: boolean;
11+
isLazy?: boolean;
12+
filterLocal?: boolean;
13+
servise?: (str: string) => Promise<any>;
14+
}
15+
16+
const initStates = {
17+
dataSource: [],
18+
str: '',
19+
scrollPage: 1,
20+
allData: []
21+
}
22+
type EasySelectStates = typeof initStates
23+
class EasySelect extends React.Component<EasySelectProps & SelectProps, EasySelectStates> {
724

825
state = {
9-
dataSource: [],
10-
str: '',
11-
scrollPage: 1,
12-
allData: []
26+
...initStates
1327
};
1428

1529
static getDerivedStateFromProps({ dataSource }) {
@@ -26,7 +40,7 @@ class EasySelect extends React.Component<any, any> {
2640
}
2741
}
2842

29-
onSearch = (str: any) => {
43+
onSearch = (str: string) => {
3044
const { clearValueRequest = false, autoValue } = this.props;
3145
if (!clearValueRequest && !str) {
3246
// 默认清空展示上次的数据
@@ -40,7 +54,7 @@ class EasySelect extends React.Component<any, any> {
4054
}
4155
};
4256

43-
lazyDataSource = (data: any) => {
57+
lazyDataSource = (data: any[]) => {
4458
const { scrollPage = 1 } = this.state;
4559
const { isLazy = true } = this.props;
4660
if (data.length > (scrollPage * 100) && isLazy) {
@@ -55,7 +69,7 @@ class EasySelect extends React.Component<any, any> {
5569
}
5670
}
5771

58-
getDataSource = async (str: any) => {
72+
getDataSource = async (str: string) => {
5973
const { servise } = this.props;
6074
if (servise) {
6175
await servise(str).then((res: any) => {

0 commit comments

Comments
 (0)