@gm-pc/business 1.25.1-beta.0 → 1.26.0-beta.0

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
-
2
-
3
- DataXXXX 代表有数据的组件,约定 Data 有 onReady(data) 回调
1
+
2
+
3
+ DataXXXX 代表有数据的组件,约定 Data 有 onReady(data) 回调
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/business",
3
- "version": "1.25.1-beta.0",
3
+ "version": "1.26.0-beta.0",
4
4
  "description": "观麦科技业务组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -28,8 +28,8 @@
28
28
  "dependencies": {
29
29
  "@gm-common/hooks": "^2.10.0",
30
30
  "@gm-common/tool": "^2.10.0",
31
- "@gm-pc/react": "^1.25.1-beta.0",
32
- "@gm-pc/table-x": "^1.25.1-beta.0"
31
+ "@gm-pc/react": "^1.26.0-beta.0",
32
+ "@gm-pc/table-x": "^1.26.0-beta.0"
33
33
  },
34
- "gitHead": "ce2c73b31a9d2c721900cac171be628a47983c5e"
34
+ "gitHead": "e0160777f413f99a31a390a340bc3a88857218b7"
35
35
  }
@@ -1,38 +1,38 @@
1
- import React, { ChangeEvent, useEffect, forwardRef, useRef } from 'react'
2
- import { Input, InputProps } from '@gm-pc/react'
3
-
4
- import { getCustomizedCode } from './util'
5
-
6
- interface CodeInputProps extends Omit<InputProps, 'onChange'> {
7
- text?: string
8
- onChange?(value: string): void
9
- /** 是否需要随text变化 */
10
- needTextChange?: boolean
11
- }
12
-
13
- // 一旦本身输入修改,就不再根据外层变动
14
- const CodeInput = forwardRef<HTMLInputElement, CodeInputProps>(
15
- ({ text, onChange, needTextChange = true, ...rest }, ref) => {
16
- // 记录当前自身是否编辑
17
- const changed = useRef<boolean>(false)
18
- const random = useRef<number>(Math.floor(Math.random() * 10000))
19
-
20
- useEffect(() => {
21
- if (!changed.current && needTextChange) {
22
- const new_value: string = getCustomizedCode(text || '').trim()
23
- const code: string = new_value ? `${new_value}${random.current}` : new_value
24
- onChange && onChange(code)
25
- }
26
- }, [text, needTextChange])
27
-
28
- const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
29
- changed.current = true
30
- onChange && onChange(e.target.value)
31
- }
32
-
33
- return <Input {...rest} ref={ref} onChange={handleChange} />
34
- }
35
- )
36
-
37
- export default CodeInput
38
- export type { CodeInputProps }
1
+ import React, { ChangeEvent, useEffect, forwardRef, useRef } from 'react'
2
+ import { Input, InputProps } from '@gm-pc/react'
3
+
4
+ import { getCustomizedCode } from './util'
5
+
6
+ interface CodeInputProps extends Omit<InputProps, 'onChange'> {
7
+ text?: string
8
+ onChange?(value: string): void
9
+ /** 是否需要随text变化 */
10
+ needTextChange?: boolean
11
+ }
12
+
13
+ // 一旦本身输入修改,就不再根据外层变动
14
+ const CodeInput = forwardRef<HTMLInputElement, CodeInputProps>(
15
+ ({ text, onChange, needTextChange = true, ...rest }, ref) => {
16
+ // 记录当前自身是否编辑
17
+ const changed = useRef<boolean>(false)
18
+ const random = useRef<number>(Math.floor(Math.random() * 10000))
19
+
20
+ useEffect(() => {
21
+ if (!changed.current && needTextChange) {
22
+ const new_value: string = getCustomizedCode(text || '').trim()
23
+ const code: string = new_value ? `${new_value}${random.current}` : new_value
24
+ onChange && onChange(code)
25
+ }
26
+ }, [text, needTextChange])
27
+
28
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
29
+ changed.current = true
30
+ onChange && onChange(e.target.value)
31
+ }
32
+
33
+ return <Input {...rest} ref={ref} onChange={handleChange} />
34
+ }
35
+ )
36
+
37
+ export default CodeInput
38
+ export type { CodeInputProps }
@@ -1,2 +1,2 @@
1
- export { default as CodeInput } from './code_input'
2
- export type { CodeInputProps } from './code_input'
1
+ export { default as CodeInput } from './code_input'
2
+ export type { CodeInputProps } from './code_input'
@@ -1,66 +1,66 @@
1
- import React, { ChangeEvent } from 'react'
2
- import { observable } from 'mobx'
3
- import { Input } from '@gm-pc/react'
4
-
5
- import CodeInput from './code_input'
6
-
7
- const store = observable({
8
- value: '',
9
- code: '',
10
- code_value: '111',
11
- setValue(v: string) {
12
- this.value = v
13
- },
14
- setCode(v: string) {
15
- this.code = v
16
- },
17
- setCodeValue(v: string) {
18
- this.code_value = v
19
- },
20
- })
21
-
22
- export const ComCodeInput = () => {
23
- const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
24
- store.setValue(e.target.value)
25
- }
26
-
27
- const handleCodeChange = (value: string) => {
28
- store.setCode(value)
29
- }
30
-
31
- const handleCodeValueChange = (value: string) => {
32
- store.setCodeValue(value)
33
- }
34
-
35
- return (
36
- <>
37
- <div>编码为空</div>
38
- <div>
39
- 名称:
40
- <Input value={store.value} onChange={handleChange} />
41
- </div>
42
- <div>
43
- 编码:
44
- <CodeInput value={store.code} text={store.value} onChange={handleCodeChange} />
45
- </div>
46
- <div className='gm-margin-top-20'>编码不为空</div>
47
- <div>
48
- 名称:
49
- <Input value={store.value} onChange={handleChange} />
50
- </div>
51
- <div>
52
- 编码:
53
- <CodeInput
54
- needTextChange={false}
55
- value={store.code_value}
56
- text={store.value}
57
- onChange={handleCodeValueChange}
58
- />
59
- </div>
60
- </>
61
- )
62
- }
63
-
64
- export default {
65
- title: 'Business/CodeInput',
66
- }
1
+ import React, { ChangeEvent } from 'react'
2
+ import { observable } from 'mobx'
3
+ import { Input } from '@gm-pc/react'
4
+
5
+ import CodeInput from './code_input'
6
+
7
+ const store = observable({
8
+ value: '',
9
+ code: '',
10
+ code_value: '111',
11
+ setValue(v: string) {
12
+ this.value = v
13
+ },
14
+ setCode(v: string) {
15
+ this.code = v
16
+ },
17
+ setCodeValue(v: string) {
18
+ this.code_value = v
19
+ },
20
+ })
21
+
22
+ export const ComCodeInput = () => {
23
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
24
+ store.setValue(e.target.value)
25
+ }
26
+
27
+ const handleCodeChange = (value: string) => {
28
+ store.setCode(value)
29
+ }
30
+
31
+ const handleCodeValueChange = (value: string) => {
32
+ store.setCodeValue(value)
33
+ }
34
+
35
+ return (
36
+ <>
37
+ <div>编码为空</div>
38
+ <div>
39
+ 名称:
40
+ <Input value={store.value} onChange={handleChange} />
41
+ </div>
42
+ <div>
43
+ 编码:
44
+ <CodeInput value={store.code} text={store.value} onChange={handleCodeChange} />
45
+ </div>
46
+ <div className='gm-margin-top-20'>编码不为空</div>
47
+ <div>
48
+ 名称:
49
+ <Input value={store.value} onChange={handleChange} />
50
+ </div>
51
+ <div>
52
+ 编码:
53
+ <CodeInput
54
+ needTextChange={false}
55
+ value={store.code_value}
56
+ text={store.value}
57
+ onChange={handleCodeValueChange}
58
+ />
59
+ </div>
60
+ </>
61
+ )
62
+ }
63
+
64
+ export default {
65
+ title: 'Business/CodeInput',
66
+ }
@@ -1,11 +1,11 @@
1
- import { pinyin } from '@gm-common/tool'
2
- import _ from 'lodash'
3
-
4
- export const getCustomizedCode = (text: string): string => {
5
- if (!text) {
6
- return ''
7
- }
8
-
9
- const code: string = _.map(text, (t) => pinyin(t)[0]).join('')
10
- return code
11
- }
1
+ import { pinyin } from '@gm-common/tool'
2
+ import _ from 'lodash'
3
+
4
+ export const getCustomizedCode = (text: string): string => {
5
+ if (!text) {
6
+ return ''
7
+ }
8
+
9
+ const code: string = _.map(text, (t) => pinyin(t)[0]).join('')
10
+ return code
11
+ }
@@ -1,75 +1,75 @@
1
- import React, { FC, CSSProperties, ReactNode } from 'react'
2
- import { getCategoryTree, CategoryItem, SpuItem, SkuItem } from './util'
3
- import { Tree, LoadingChunk, TreeListItem } from '@gm-pc/react'
4
- import { useAsync } from '@gm-common/hooks'
5
- import classNames from 'classnames'
6
- import { ListSkuRequest } from 'gm_api/src/merchandise'
7
-
8
- interface DataCategoryTreeProps {
9
- className?: string
10
- style?: CSSProperties
11
- border?: boolean
12
- needSku?: boolean
13
- skuParams?: Omit<ListSkuRequest, 'paging'>
14
- onReady?(data?: CategoryItem[]): void
15
- activeValue?: any
16
- findPlaceholder?: string
17
- onActiveValue?(activeValue: any, item: CategoryItem | SpuItem | SkuItem): void
18
- onLeafActiveValue?(activeValue: any, item: SpuItem | SkuItem): void
19
- renderLeafItem?: (data: TreeListItem) => ReactNode
20
- }
21
-
22
- const DataCategoryTree: FC<DataCategoryTreeProps> = ({
23
- style,
24
- border,
25
- needSku,
26
- onReady,
27
- skuParams,
28
- className,
29
- activeValue,
30
- onActiveValue,
31
- findPlaceholder,
32
- onLeafActiveValue,
33
- renderLeafItem,
34
- }) => {
35
- const { data, loading } = useAsync(getCategoryTree, {
36
- manual: false,
37
- cacheKey: 'GMGetCategoryTree',
38
- defaultParams: {
39
- needSku,
40
- skuParams,
41
- },
42
- onSuccess(data) {
43
- onReady && onReady(data)
44
- },
45
- })
46
-
47
- const handleActiveValue = (active: any, item: CategoryItem | SpuItem | SkuItem) => {
48
- onActiveValue && onActiveValue(active, item)
49
- if (!('children' in item && item.children)) {
50
- onLeafActiveValue && onLeafActiveValue(active, item as SpuItem | SkuItem)
51
- }
52
- }
53
-
54
- return (
55
- <LoadingChunk
56
- loading={loading}
57
- className={classNames('gmb-category-tree', className)}
58
- style={style}
59
- >
60
- <Tree
61
- list={data || []}
62
- border={border}
63
- activeValue={activeValue}
64
- onActiveValue={handleActiveValue}
65
- disabledCheckbox
66
- withFilter={false}
67
- findPlaceholder={findPlaceholder}
68
- renderLeafItem={renderLeafItem}
69
- showFind
70
- />
71
- </LoadingChunk>
72
- )
73
- }
74
-
75
- export default React.memo(DataCategoryTree)
1
+ import React, { FC, CSSProperties, ReactNode } from 'react'
2
+ import { getCategoryTree, CategoryItem, SpuItem, SkuItem } from './util'
3
+ import { Tree, LoadingChunk, TreeListItem } from '@gm-pc/react'
4
+ import { useAsync } from '@gm-common/hooks'
5
+ import classNames from 'classnames'
6
+ import { ListSkuRequest } from 'gm_api/src/merchandise'
7
+
8
+ interface DataCategoryTreeProps {
9
+ className?: string
10
+ style?: CSSProperties
11
+ border?: boolean
12
+ needSku?: boolean
13
+ skuParams?: Omit<ListSkuRequest, 'paging'>
14
+ onReady?(data?: CategoryItem[]): void
15
+ activeValue?: any
16
+ findPlaceholder?: string
17
+ onActiveValue?(activeValue: any, item: CategoryItem | SpuItem | SkuItem): void
18
+ onLeafActiveValue?(activeValue: any, item: SpuItem | SkuItem): void
19
+ renderLeafItem?: (data: TreeListItem) => ReactNode
20
+ }
21
+
22
+ const DataCategoryTree: FC<DataCategoryTreeProps> = ({
23
+ style,
24
+ border,
25
+ needSku,
26
+ onReady,
27
+ skuParams,
28
+ className,
29
+ activeValue,
30
+ onActiveValue,
31
+ findPlaceholder,
32
+ onLeafActiveValue,
33
+ renderLeafItem,
34
+ }) => {
35
+ const { data, loading } = useAsync(getCategoryTree, {
36
+ manual: false,
37
+ cacheKey: 'GMGetCategoryTree',
38
+ defaultParams: {
39
+ needSku,
40
+ skuParams,
41
+ },
42
+ onSuccess(data) {
43
+ onReady && onReady(data)
44
+ },
45
+ })
46
+
47
+ const handleActiveValue = (active: any, item: CategoryItem | SpuItem | SkuItem) => {
48
+ onActiveValue && onActiveValue(active, item)
49
+ if (!('children' in item && item.children)) {
50
+ onLeafActiveValue && onLeafActiveValue(active, item as SpuItem | SkuItem)
51
+ }
52
+ }
53
+
54
+ return (
55
+ <LoadingChunk
56
+ loading={loading}
57
+ className={classNames('gmb-category-tree', className)}
58
+ style={style}
59
+ >
60
+ <Tree
61
+ list={data || []}
62
+ border={border}
63
+ activeValue={activeValue}
64
+ onActiveValue={handleActiveValue}
65
+ disabledCheckbox
66
+ withFilter={false}
67
+ findPlaceholder={findPlaceholder}
68
+ renderLeafItem={renderLeafItem}
69
+ showFind
70
+ />
71
+ </LoadingChunk>
72
+ )
73
+ }
74
+
75
+ export default React.memo(DataCategoryTree)
@@ -1 +1 @@
1
- export { default as DataCategoryTree } from './data_category_tree'
1
+ export { default as DataCategoryTree } from './data_category_tree'
@@ -1,46 +1,46 @@
1
- import React from 'react'
2
- import { DataCategoryTree } from './index'
3
-
4
- export const ComDataCategoryTree = () => {
5
- return (
6
- <DataCategoryTree
7
- style={{ width: '250px', height: '500px', padding: '10px' }}
8
- onReady={(data) => {
9
- console.log(data)
10
- }}
11
- onActiveValue={(value, item) => {
12
- console.log(value, item)
13
- }}
14
- onLeafActiveValue={(value, item) => {
15
- console.log(value, item)
16
- }}
17
- />
18
- )
19
- }
20
-
21
- export const ComDataCategoryTreeNeedSku = () => {
22
- return (
23
- <div style={{ width: '250px', padding: '10px' }}>
24
- <DataCategoryTree
25
- border={false}
26
- needSku
27
- style={{ height: '500px' }}
28
- onReady={(data) => {
29
- console.log(data)
30
- }}
31
- onActiveValue={(value, item) => {
32
- console.log(value, item)
33
- }}
34
- onLeafActiveValue={(value, item) => {
35
- console.log('onLeafActiveValue', value, item)
36
- }}
37
- findPlaceholder='输入sku名称'
38
- skuParams={{ process: 1, sku_type: 2 }}
39
- />
40
- </div>
41
- )
42
- }
43
-
44
- export default {
45
- title: 'Business/DataCategoryTree',
46
- }
1
+ import React from 'react'
2
+ import { DataCategoryTree } from './index'
3
+
4
+ export const ComDataCategoryTree = () => {
5
+ return (
6
+ <DataCategoryTree
7
+ style={{ width: '250px', height: '500px', padding: '10px' }}
8
+ onReady={(data) => {
9
+ console.log(data)
10
+ }}
11
+ onActiveValue={(value, item) => {
12
+ console.log(value, item)
13
+ }}
14
+ onLeafActiveValue={(value, item) => {
15
+ console.log(value, item)
16
+ }}
17
+ />
18
+ )
19
+ }
20
+
21
+ export const ComDataCategoryTreeNeedSku = () => {
22
+ return (
23
+ <div style={{ width: '250px', padding: '10px' }}>
24
+ <DataCategoryTree
25
+ border={false}
26
+ needSku
27
+ style={{ height: '500px' }}
28
+ onReady={(data) => {
29
+ console.log(data)
30
+ }}
31
+ onActiveValue={(value, item) => {
32
+ console.log(value, item)
33
+ }}
34
+ onLeafActiveValue={(value, item) => {
35
+ console.log('onLeafActiveValue', value, item)
36
+ }}
37
+ findPlaceholder='输入sku名称'
38
+ skuParams={{ process: 1, sku_type: 2 }}
39
+ />
40
+ </div>
41
+ )
42
+ }
43
+
44
+ export default {
45
+ title: 'Business/DataCategoryTree',
46
+ }