@gm-pc/react 1.28.0-beta.1 → 1.28.0-beta.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/react",
|
|
3
|
-
"version": "1.28.0-beta.
|
|
3
|
+
"version": "1.28.0-beta.4",
|
|
4
4
|
"description": "观麦前端基础组件库",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-pc#readme",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@gm-common/hooks": "^2.10.0",
|
|
26
26
|
"@gm-common/tool": "^2.10.0",
|
|
27
|
-
"@gm-pc/locales": "^1.28.0-beta.
|
|
27
|
+
"@gm-pc/locales": "^1.28.0-beta.4",
|
|
28
28
|
"big.js": "^6.0.1",
|
|
29
29
|
"classnames": "^2.2.5",
|
|
30
30
|
"lodash": "^4.17.19",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-router-dom": "^5.2.0",
|
|
49
49
|
"react-window": "^1.8.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6e519841a2d50177de1073e36e98c7bc3241ff48"
|
|
52
52
|
}
|
|
@@ -20,8 +20,8 @@ import { getLocale } from '@gm-pc/locales'
|
|
|
20
20
|
import { ListBase } from '../list'
|
|
21
21
|
import { findDOMNode } from 'react-dom'
|
|
22
22
|
import { ConfigConsumer, ConfigProvider, ConfigProviderProps } from '../config_provider'
|
|
23
|
-
import { Checkbox
|
|
24
|
-
|
|
23
|
+
import { Checkbox } from '../checkbox'
|
|
24
|
+
import { Switch } from '../switch'
|
|
25
25
|
interface MoreSelectBaseState {
|
|
26
26
|
searchValue: string
|
|
27
27
|
loading: boolean
|
|
@@ -172,8 +172,14 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
172
172
|
event: ChangeEvent<HTMLInputElement>,
|
|
173
173
|
isInitSearch?: boolean
|
|
174
174
|
): void => {
|
|
175
|
+
const { onSearch } = this.props
|
|
175
176
|
const searchValue = event.target.value
|
|
176
177
|
this.setState({ searchValue })
|
|
178
|
+
if (onSearch && !this._isUnmounted) {
|
|
179
|
+
this.setState({
|
|
180
|
+
loading: true,
|
|
181
|
+
})
|
|
182
|
+
}
|
|
177
183
|
this._debounceDoSearch(searchValue)
|
|
178
184
|
setTimeout(() => {
|
|
179
185
|
// eslint-disable-next-line no-unused-expressions
|
|
@@ -187,14 +193,12 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
187
193
|
private _doSearch = (query: string): void => {
|
|
188
194
|
const { onSearch, data = [] } = this.props
|
|
189
195
|
if (!this._isUnmounted && onSearch) {
|
|
190
|
-
const result = onSearch(query, data)
|
|
191
|
-
if (!result) {
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
196
|
this.setState({ loading: true })
|
|
195
|
-
|
|
197
|
+
const result = onSearch(query, data)
|
|
196
198
|
Promise.resolve(result).finally(() => {
|
|
197
|
-
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
this.setState({ loading: false })
|
|
201
|
+
}, 50)
|
|
198
202
|
})
|
|
199
203
|
}
|
|
200
204
|
}
|
|
@@ -243,9 +247,9 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
243
247
|
}
|
|
244
248
|
|
|
245
249
|
private _getFilterData = () => {
|
|
246
|
-
const { data = [], renderListFilter, renderListFilterType } = this.props
|
|
250
|
+
const { data = [], renderListFilter, renderListFilterType, onSearch } = this.props
|
|
247
251
|
const { searchValue } = this.state
|
|
248
|
-
let filterData: MoreSelectGroupDataItem<V>[]
|
|
252
|
+
let filterData: MoreSelectGroupDataItem<V>[] = []
|
|
249
253
|
if (renderListFilter) {
|
|
250
254
|
filterData = renderListFilter(data, searchValue)
|
|
251
255
|
} else if (renderListFilterType === 'pinyin') {
|
|
@@ -327,7 +331,8 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
327
331
|
<Flex alignCenter>
|
|
328
332
|
<Flex row>
|
|
329
333
|
<Switch
|
|
330
|
-
|
|
334
|
+
size='small'
|
|
335
|
+
style={{ width: 32 }}
|
|
331
336
|
checked={isFilterDelete}
|
|
332
337
|
onChange={(open) => {
|
|
333
338
|
this.setState({
|
|
@@ -344,19 +349,67 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
344
349
|
}}
|
|
345
350
|
/>
|
|
346
351
|
</Flex>
|
|
347
|
-
<span className='gm-margin-left-5'
|
|
352
|
+
<span className='gm-margin-left-5'>过滤已删除数据</span>
|
|
348
353
|
</Flex>
|
|
349
354
|
)}
|
|
350
355
|
</Flex>
|
|
351
356
|
)
|
|
352
357
|
}
|
|
353
358
|
|
|
359
|
+
renderContent = () => {
|
|
360
|
+
const { loading, willActiveIndex, isFilterDelete } = this.state
|
|
361
|
+
|
|
362
|
+
if (loading) {
|
|
363
|
+
return (
|
|
364
|
+
<Flex alignCenter justifyCenter className='gm-bg gm-padding-5'>
|
|
365
|
+
<Loading size='20px' />
|
|
366
|
+
</Flex>
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
let filterData = this._getFilterData()
|
|
371
|
+
|
|
372
|
+
// 如果开启了过滤已删除商品功能,需要过滤掉已删除的商品
|
|
373
|
+
if (isFilterDelete) {
|
|
374
|
+
filterData = filterData
|
|
375
|
+
.map((group) => ({
|
|
376
|
+
...group,
|
|
377
|
+
children: group.children.filter((item) => !item.deleted),
|
|
378
|
+
}))
|
|
379
|
+
.filter((group) => group.children.length > 0)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (!loading && filterData.length === 0) {
|
|
383
|
+
return this._renderEmpty()
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (!loading && filterData.length > 0) {
|
|
387
|
+
const {
|
|
388
|
+
selected = [],
|
|
389
|
+
multiple,
|
|
390
|
+
isGroupList,
|
|
391
|
+
renderListItem,
|
|
392
|
+
listHeight,
|
|
393
|
+
} = this.props
|
|
394
|
+
return (
|
|
395
|
+
<ListBase
|
|
396
|
+
selected={selected.map((v) => v.value)}
|
|
397
|
+
data={filterData}
|
|
398
|
+
multiple={multiple}
|
|
399
|
+
isGroupList={isGroupList}
|
|
400
|
+
className='gm-border-0'
|
|
401
|
+
renderItem={renderListItem}
|
|
402
|
+
onSelect={this._handleSelect}
|
|
403
|
+
isScrollTo
|
|
404
|
+
willActiveIndex={willActiveIndex!}
|
|
405
|
+
style={{ height: listHeight }}
|
|
406
|
+
/>
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
354
411
|
private _renderList = (config: ConfigProviderProps): ReactNode => {
|
|
355
412
|
const {
|
|
356
|
-
selected = [],
|
|
357
|
-
multiple,
|
|
358
|
-
isGroupList,
|
|
359
|
-
renderListItem,
|
|
360
413
|
searchPlaceholder,
|
|
361
414
|
listHeight,
|
|
362
415
|
popupClassName,
|
|
@@ -391,28 +444,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
391
444
|
placeholder={searchPlaceholder}
|
|
392
445
|
/>
|
|
393
446
|
</div>
|
|
394
|
-
<div style={{ height: listHeight }}>
|
|
395
|
-
{loading && (
|
|
396
|
-
<Flex alignCenter justifyCenter className='gm-bg gm-padding-5'>
|
|
397
|
-
<Loading size='20px' />
|
|
398
|
-
</Flex>
|
|
399
|
-
)}
|
|
400
|
-
{!loading && !filterData.length && this._renderEmpty()}
|
|
401
|
-
{!loading && !!filterData.length && (
|
|
402
|
-
<ListBase
|
|
403
|
-
selected={selected.map((v) => v.value)}
|
|
404
|
-
data={filterData}
|
|
405
|
-
multiple={multiple}
|
|
406
|
-
isGroupList={isGroupList}
|
|
407
|
-
className='gm-border-0'
|
|
408
|
-
renderItem={renderListItem}
|
|
409
|
-
onSelect={this._handleSelect}
|
|
410
|
-
isScrollTo
|
|
411
|
-
willActiveIndex={willActiveIndex!}
|
|
412
|
-
style={{ height: listHeight }}
|
|
413
|
-
/>
|
|
414
|
-
)}
|
|
415
|
-
</div>
|
|
447
|
+
<div style={{ height: listHeight }}>{this.renderContent()}</div>
|
|
416
448
|
{!loading &&
|
|
417
449
|
!!filterData.length &&
|
|
418
450
|
(renderCustomizedBottom
|
|
@@ -93,7 +93,7 @@ interface MoreSelectBaseProps<V extends string | number = string>
|
|
|
93
93
|
onSelect(selected: MoreSelectDataItem<V>[]): void
|
|
94
94
|
|
|
95
95
|
/** 搜索回调 */
|
|
96
|
-
onSearch?(searchWord: string, data: MoreSelectGroupDataItem<V>[]): Promise<
|
|
96
|
+
onSearch?(searchWord: string, data: MoreSelectGroupDataItem<V>[]): Promise<any> | any
|
|
97
97
|
/** 点击回调 */
|
|
98
98
|
onClick?(selected: MoreSelectSelected<V>[]): void
|
|
99
99
|
|
|
@@ -128,7 +128,7 @@ interface MoreSelectProps<V extends string | number = string>
|
|
|
128
128
|
onSelect?(selected?: MoreSelectSelected<V>): void
|
|
129
129
|
onChange?(value: V | V[]): void
|
|
130
130
|
/** 搜索回调 */
|
|
131
|
-
onSearch?(searchWord: string, data: MoreSelectData<V>): Promise<void> |
|
|
131
|
+
onSearch?(searchWord: string, data: MoreSelectData<V>): Promise<void | any> | any
|
|
132
132
|
/** 点击回调 */
|
|
133
133
|
onClick?(selected: MoreSelectSelected<V>[]): void
|
|
134
134
|
|
|
@@ -11,6 +11,7 @@ interface SwitchProps {
|
|
|
11
11
|
onChange?(checked: boolean): void
|
|
12
12
|
className?: string
|
|
13
13
|
style?: CSSProperties
|
|
14
|
+
size?: 'small' | 'middle'
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
interface SwitchState {
|
|
@@ -26,10 +27,11 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
26
27
|
on: '',
|
|
27
28
|
off: '',
|
|
28
29
|
onChange: _.noop,
|
|
30
|
+
size: 'middle',
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
readonly state: SwitchState = {
|
|
32
|
-
checked: this.props.checked,
|
|
34
|
+
checked: !!this.props.checked,
|
|
33
35
|
labelWidth: null,
|
|
34
36
|
isReady: false,
|
|
35
37
|
}
|
|
@@ -53,7 +55,7 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
53
55
|
UNSAFE_componentWillReceiveProps(nextProps: Readonly<SwitchProps>) {
|
|
54
56
|
if ('checked' in nextProps) {
|
|
55
57
|
this.setState({
|
|
56
|
-
checked: nextProps.checked,
|
|
58
|
+
checked: !!nextProps.checked,
|
|
57
59
|
})
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -82,6 +84,7 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
82
84
|
disabled,
|
|
83
85
|
on,
|
|
84
86
|
off,
|
|
87
|
+
size,
|
|
85
88
|
...rest
|
|
86
89
|
} = this.props
|
|
87
90
|
|
|
@@ -101,8 +104,9 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
101
104
|
ref={this._inputOffRef}
|
|
102
105
|
className={classNames('gm-switch gm-switch-' + type, className, {
|
|
103
106
|
disabled,
|
|
107
|
+
[`gm-switch-${size}`]: size,
|
|
104
108
|
})}
|
|
105
|
-
style={style}
|
|
109
|
+
style={style as any}
|
|
106
110
|
data-attr={this.state.labelWidth}
|
|
107
111
|
disabled={disabled}
|
|
108
112
|
type='checkbox'
|