@gm-pc/business 1.25.0-beta.0 → 1.25.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.
@@ -1,109 +1,109 @@
1
- import {
2
- GetCategoryTree,
3
- ListSku,
4
- Category,
5
- Spu,
6
- Sku,
7
- ListSkuRequest,
8
- } from 'gm_api/src/merchandise'
9
- import { PagingMaxLimit } from 'gm_api'
10
- import _ from 'lodash'
11
- import { ListSkuResponse_SkuInfo } from 'gm_api/src/merchandise/types'
12
- import { filterGroupListLeaf } from '@gm-common/tool'
13
-
14
- interface CategoryItem {
15
- value: string
16
- text: string
17
- children: CategoryItem[] | SpuItem[]
18
- original: Category
19
- }
20
-
21
- interface SpuItem {
22
- value: string
23
- text: string
24
- // needSku 才有 children
25
- children?: SkuItem[]
26
- original: Spu
27
- }
28
-
29
- interface SkuItem {
30
- value: string
31
- text: string
32
- original: Sku
33
- }
34
-
35
- async function getCategoryTree(params?: {
36
- needSku?: boolean
37
- skuParams?: ListSkuRequest
38
- }) {
39
- const { needSku, skuParams } = params || {}
40
- const res = await GetCategoryTree({})
41
-
42
- const { categories, spus } = res.response
43
-
44
- const map: { [key: string]: any } = {}
45
-
46
- const tree: CategoryItem[] = []
47
-
48
- _.each(categories, (category: Category) => {
49
- const newCategory: CategoryItem = {
50
- value: category.category_id,
51
- text: category.name,
52
- children: [],
53
- original: category,
54
- }
55
-
56
- map[newCategory.value] = newCategory
57
-
58
- // 一级
59
- if (category.parent_id === '0') {
60
- tree.push(newCategory)
61
- } else {
62
- if (map[category.parent_id]) {
63
- map[category.parent_id].children.push(newCategory)
64
- }
65
- }
66
- })
67
-
68
- _.each(spus, (spu: Spu) => {
69
- const newSpu: SpuItem = {
70
- value: spu.spu_id,
71
- text: spu.name,
72
- children: needSku ? [] : undefined,
73
- original: spu,
74
- }
75
-
76
- map[spu.spu_id] = newSpu
77
-
78
- if (map[spu.parent_id]) {
79
- map[spu.parent_id].children.push(newSpu)
80
- }
81
- })
82
-
83
- if (needSku) {
84
- const skuRes = await ListSku({
85
- paging: { limit: PagingMaxLimit },
86
- ...(skuParams || {}),
87
- })
88
-
89
- _.each(skuRes.response.sku_infos, (skuInfo: ListSkuResponse_SkuInfo) => {
90
- const sku: Sku = skuInfo.sku!
91
-
92
- const newSku: SkuItem = {
93
- value: sku.sku_id,
94
- text: sku.name,
95
- original: sku,
96
- }
97
-
98
- if (map[sku.spu_id]) {
99
- map[sku.spu_id].children.push(newSku)
100
- }
101
- })
102
- }
103
-
104
- // 过滤掉没有子的数据
105
- return filterGroupListLeaf(tree as any, () => true) as CategoryItem[]
106
- }
107
-
108
- export { getCategoryTree }
109
- export type { CategoryItem, SpuItem, SkuItem }
1
+ import {
2
+ GetCategoryTree,
3
+ ListSku,
4
+ Category,
5
+ Spu,
6
+ Sku,
7
+ ListSkuRequest,
8
+ } from 'gm_api/src/merchandise'
9
+ import { PagingMaxLimit } from 'gm_api'
10
+ import _ from 'lodash'
11
+ import { ListSkuResponse_SkuInfo } from 'gm_api/src/merchandise/types'
12
+ import { filterGroupListLeaf } from '@gm-common/tool'
13
+
14
+ interface CategoryItem {
15
+ value: string
16
+ text: string
17
+ children: CategoryItem[] | SpuItem[]
18
+ original: Category
19
+ }
20
+
21
+ interface SpuItem {
22
+ value: string
23
+ text: string
24
+ // needSku 才有 children
25
+ children?: SkuItem[]
26
+ original: Spu
27
+ }
28
+
29
+ interface SkuItem {
30
+ value: string
31
+ text: string
32
+ original: Sku
33
+ }
34
+
35
+ async function getCategoryTree(params?: {
36
+ needSku?: boolean
37
+ skuParams?: ListSkuRequest
38
+ }) {
39
+ const { needSku, skuParams } = params || {}
40
+ const res = await GetCategoryTree({})
41
+
42
+ const { categories, spus } = res.response
43
+
44
+ const map: { [key: string]: any } = {}
45
+
46
+ const tree: CategoryItem[] = []
47
+
48
+ _.each(categories, (category: Category) => {
49
+ const newCategory: CategoryItem = {
50
+ value: category.category_id,
51
+ text: category.name,
52
+ children: [],
53
+ original: category,
54
+ }
55
+
56
+ map[newCategory.value] = newCategory
57
+
58
+ // 一级
59
+ if (category.parent_id === '0') {
60
+ tree.push(newCategory)
61
+ } else {
62
+ if (map[category.parent_id]) {
63
+ map[category.parent_id].children.push(newCategory)
64
+ }
65
+ }
66
+ })
67
+
68
+ _.each(spus, (spu: Spu) => {
69
+ const newSpu: SpuItem = {
70
+ value: spu.spu_id,
71
+ text: spu.name,
72
+ children: needSku ? [] : undefined,
73
+ original: spu,
74
+ }
75
+
76
+ map[spu.spu_id] = newSpu
77
+
78
+ if (map[spu.parent_id]) {
79
+ map[spu.parent_id].children.push(newSpu)
80
+ }
81
+ })
82
+
83
+ if (needSku) {
84
+ const skuRes = await ListSku({
85
+ paging: { limit: PagingMaxLimit },
86
+ ...(skuParams || {}),
87
+ })
88
+
89
+ _.each(skuRes.response.sku_infos, (skuInfo: ListSkuResponse_SkuInfo) => {
90
+ const sku: Sku = skuInfo.sku!
91
+
92
+ const newSku: SkuItem = {
93
+ value: sku.sku_id,
94
+ text: sku.name,
95
+ original: sku,
96
+ }
97
+
98
+ if (map[sku.spu_id]) {
99
+ map[sku.spu_id].children.push(newSku)
100
+ }
101
+ })
102
+ }
103
+
104
+ // 过滤掉没有子的数据
105
+ return filterGroupListLeaf(tree as any, () => true) as CategoryItem[]
106
+ }
107
+
108
+ export { getCategoryTree }
109
+ export type { CategoryItem, SpuItem, SkuItem }
@@ -1,46 +1,46 @@
1
- import React, { FC } from 'react'
2
- import { useAsync } from '@gm-common/hooks'
3
- import { fetchCityDistrictStreetTree } from './util'
4
- import { LevelSelect } from '@gm-pc/react'
5
- import { DataAddressProps } from './types'
6
- import _ from 'lodash'
7
-
8
- const DataAddress: FC<DataAddressProps> = ({
9
- selected,
10
- onSelect,
11
- city_ids,
12
- onlySelectLeaf,
13
- placeholder,
14
- }) => {
15
- const { data } = useAsync(fetchCityDistrictStreetTree, {
16
- manual: false,
17
- defaultParams: {
18
- city_ids,
19
- },
20
- })
21
-
22
- const oSelected = _.remove(
23
- [selected.city_id, selected.district_id, selected.street_id],
24
- (v?: string) => !!v
25
- )
26
-
27
- const handleSelect = (selected: string[]) => {
28
- onSelect({
29
- city_id: selected[0],
30
- district_id: selected[1],
31
- street_id: selected[2],
32
- })
33
- }
34
-
35
- return (
36
- <LevelSelect
37
- placeholder={placeholder}
38
- data={data || []}
39
- selected={data ? oSelected : []}
40
- onSelect={handleSelect}
41
- onlySelectLeaf={onlySelectLeaf}
42
- />
43
- )
44
- }
45
-
46
- export default DataAddress
1
+ import React, { FC } from 'react'
2
+ import { useAsync } from '@gm-common/hooks'
3
+ import { fetchCityDistrictStreetTree } from './util'
4
+ import { LevelSelect } from '@gm-pc/react'
5
+ import { DataAddressProps } from './types'
6
+ import _ from 'lodash'
7
+
8
+ const DataAddress: FC<DataAddressProps> = ({
9
+ selected,
10
+ onSelect,
11
+ city_ids,
12
+ onlySelectLeaf,
13
+ placeholder,
14
+ }) => {
15
+ const { data } = useAsync(fetchCityDistrictStreetTree, {
16
+ manual: false,
17
+ defaultParams: {
18
+ city_ids,
19
+ },
20
+ })
21
+
22
+ const oSelected = _.remove(
23
+ [selected.city_id, selected.district_id, selected.street_id],
24
+ (v?: string) => !!v
25
+ )
26
+
27
+ const handleSelect = (selected: string[]) => {
28
+ onSelect({
29
+ city_id: selected[0],
30
+ district_id: selected[1],
31
+ street_id: selected[2],
32
+ })
33
+ }
34
+
35
+ return (
36
+ <LevelSelect
37
+ placeholder={placeholder}
38
+ data={data || []}
39
+ selected={data ? oSelected : []}
40
+ onSelect={handleSelect}
41
+ onlySelectLeaf={onlySelectLeaf}
42
+ />
43
+ )
44
+ }
45
+
46
+ export default DataAddress
@@ -1,30 +1,30 @@
1
- import React, { FC } from 'react'
2
- import { DataAddressNameProps } from './types'
3
- import { MapId_City, MapId_District, MapId_Street } from 'gm_api/src/enterprise/pc'
4
-
5
- const DataAddressName: FC<DataAddressNameProps> = ({
6
- address: { city_id, district_id, street_id },
7
- }) => {
8
- return (
9
- <>
10
- {city_id && (
11
- <>
12
- <MapId_City
13
- id={city_id}
14
- getName={(item) => item.local_name}
15
- getResponseData={(response) => response.cities}
16
- />
17
- /
18
- </>
19
- )}
20
- {district_id && (
21
- <>
22
- <MapId_District id={district_id} getName={(item) => item.local_name} />/
23
- </>
24
- )}
25
- {street_id && <MapId_Street id={street_id} getName={(item) => item.local_name} />}
26
- </>
27
- )
28
- }
29
-
30
- export default DataAddressName
1
+ import React, { FC } from 'react'
2
+ import { DataAddressNameProps } from './types'
3
+ import { MapId_City, MapId_District, MapId_Street } from 'gm_api/src/enterprise/pc'
4
+
5
+ const DataAddressName: FC<DataAddressNameProps> = ({
6
+ address: { city_id, district_id, street_id },
7
+ }) => {
8
+ return (
9
+ <>
10
+ {city_id && (
11
+ <>
12
+ <MapId_City
13
+ id={city_id}
14
+ getName={(item) => item.local_name}
15
+ getResponseData={(response) => response.cities}
16
+ />
17
+ /
18
+ </>
19
+ )}
20
+ {district_id && (
21
+ <>
22
+ <MapId_District id={district_id} getName={(item) => item.local_name} />/
23
+ </>
24
+ )}
25
+ {street_id && <MapId_Street id={street_id} getName={(item) => item.local_name} />}
26
+ </>
27
+ )
28
+ }
29
+
30
+ export default DataAddressName
@@ -1,2 +1,2 @@
1
- export { default as DataAddress } from './data_address'
2
- export { default as DataAddressName } from './data_address_name'
1
+ export { default as DataAddress } from './data_address'
2
+ export { default as DataAddressName } from './data_address_name'
@@ -1,36 +1,36 @@
1
- import React from 'react'
2
- import { DataAddress, DataAddressName } from './index'
3
- import { observable } from 'mobx'
4
-
5
- const store = observable({
6
- selected: {},
7
- setSelected(selected: any) {
8
- this.selected = selected
9
- },
10
- })
11
-
12
- export const ComDataCityDistrict = () => {
13
- return (
14
- <div style={{ width: '300px' }}>
15
- <DataAddress
16
- city_ids={['4401', '4403']}
17
- selected={store.selected}
18
- onSelect={(selected) => {
19
- store.setSelected(selected)
20
- }}
21
- />
22
- </div>
23
- )
24
- }
25
-
26
- export const ComDataAddressCityDistrict = () => {
27
- return (
28
- <DataAddressName
29
- address={{ city_id: '4403', district_id: '440307', street_id: '440103001' }}
30
- />
31
- )
32
- }
33
-
34
- export default {
35
- title: 'Business/DataGegraphicLabel',
36
- }
1
+ import React from 'react'
2
+ import { DataAddress, DataAddressName } from './index'
3
+ import { observable } from 'mobx'
4
+
5
+ const store = observable({
6
+ selected: {},
7
+ setSelected(selected: any) {
8
+ this.selected = selected
9
+ },
10
+ })
11
+
12
+ export const ComDataCityDistrict = () => {
13
+ return (
14
+ <div style={{ width: '300px' }}>
15
+ <DataAddress
16
+ city_ids={['4401', '4403']}
17
+ selected={store.selected}
18
+ onSelect={(selected) => {
19
+ store.setSelected(selected)
20
+ }}
21
+ />
22
+ </div>
23
+ )
24
+ }
25
+
26
+ export const ComDataAddressCityDistrict = () => {
27
+ return (
28
+ <DataAddressName
29
+ address={{ city_id: '4403', district_id: '440307', street_id: '440103001' }}
30
+ />
31
+ )
32
+ }
33
+
34
+ export default {
35
+ title: 'Business/DataGegraphicLabel',
36
+ }
@@ -1,44 +1,44 @@
1
- import { City, District, Street, Address } from 'gm_api/src/enterprise'
2
-
3
- interface CityItem {
4
- value: string
5
- text: string
6
- original: City
7
- children: DistrictItem[]
8
- }
9
-
10
- interface DistrictItem {
11
- value: string
12
- text: string
13
- original: District
14
- children: StreetItem[]
15
- }
16
-
17
- interface StreetItem {
18
- value: string
19
- text: string
20
- original: Street
21
- }
22
-
23
- type DataAddress = Pick<Address, 'city_id' | 'district_id' | 'street_id'>
24
-
25
- interface DataAddressProps {
26
- city_ids: string[]
27
- selected: DataAddress
28
- onSelect(selected: DataAddress): void
29
- onlySelectLeaf?: boolean
30
- placeholder?: string
31
- }
32
-
33
- interface DataAddressNameProps {
34
- address: DataAddress
35
- }
36
-
37
- export type {
38
- CityItem,
39
- DistrictItem,
40
- StreetItem,
41
- DataAddress,
42
- DataAddressProps,
43
- DataAddressNameProps,
44
- }
1
+ import { City, District, Street, Address } from 'gm_api/src/enterprise'
2
+
3
+ interface CityItem {
4
+ value: string
5
+ text: string
6
+ original: City
7
+ children: DistrictItem[]
8
+ }
9
+
10
+ interface DistrictItem {
11
+ value: string
12
+ text: string
13
+ original: District
14
+ children: StreetItem[]
15
+ }
16
+
17
+ interface StreetItem {
18
+ value: string
19
+ text: string
20
+ original: Street
21
+ }
22
+
23
+ type DataAddress = Pick<Address, 'city_id' | 'district_id' | 'street_id'>
24
+
25
+ interface DataAddressProps {
26
+ city_ids: string[]
27
+ selected: DataAddress
28
+ onSelect(selected: DataAddress): void
29
+ onlySelectLeaf?: boolean
30
+ placeholder?: string
31
+ }
32
+
33
+ interface DataAddressNameProps {
34
+ address: DataAddress
35
+ }
36
+
37
+ export type {
38
+ CityItem,
39
+ DistrictItem,
40
+ StreetItem,
41
+ DataAddress,
42
+ DataAddressProps,
43
+ DataAddressNameProps,
44
+ }