@gm-pc/business 1.24.9-beta.13 → 1.24.9-beta.15
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 +3 -3
- package/package.json +4 -4
- package/src/code_input/code_input.tsx +38 -38
- package/src/code_input/index.ts +2 -2
- package/src/code_input/stories.tsx +66 -66
- package/src/code_input/util.ts +11 -11
- package/src/data_category_tree/data_category_tree.tsx +75 -75
- package/src/data_category_tree/index.ts +1 -1
- package/src/data_category_tree/stories.tsx +46 -46
- package/src/data_category_tree/util.ts +109 -109
- package/src/data_gegraphic_label/data_address.tsx +46 -46
- package/src/data_gegraphic_label/data_address_name.tsx +30 -30
- package/src/data_gegraphic_label/index.ts +2 -2
- package/src/data_gegraphic_label/stories.tsx +36 -36
- package/src/data_gegraphic_label/types.ts +44 -44
- package/src/data_gegraphic_label/util.ts +73 -73
- package/src/index.ts +4 -4
- package/src/stories.tsx +27 -27
- package/src/table_list/index.ts +2 -2
- package/src/table_list/table_list.tsx +110 -110
- package/src/table_list/table_total_text.tsx +36 -36
- package/src/table_list/types.ts +51 -51
- package/src/table_list/util.ts +16 -16
|
@@ -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
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import { ListCity, ListDistrict, ListStreet, District } from 'gm_api/src/enterprise'
|
|
3
|
-
import { CityItem, DistrictItem } from './types'
|
|
4
|
-
|
|
5
|
-
async function fetchCityDistrictStreetTree(params: {
|
|
6
|
-
city_ids: string[]
|
|
7
|
-
}): Promise<CityItem[]> {
|
|
8
|
-
const { city_ids } = params
|
|
9
|
-
|
|
10
|
-
const [cityRes, districtRes] = await Promise.all([
|
|
11
|
-
ListCity({
|
|
12
|
-
city_ids,
|
|
13
|
-
}),
|
|
14
|
-
ListDistrict({
|
|
15
|
-
city_ids,
|
|
16
|
-
}),
|
|
17
|
-
])
|
|
18
|
-
|
|
19
|
-
const cityDistrictTree: CityItem[] = []
|
|
20
|
-
const cityMap: { [key: string]: CityItem } = {}
|
|
21
|
-
const districtMap: { [key: string]: DistrictItem } = {}
|
|
22
|
-
|
|
23
|
-
_.each(cityRes.response.cities, (city) => {
|
|
24
|
-
const cityItem = {
|
|
25
|
-
value: city.city_id,
|
|
26
|
-
text: city.local_name,
|
|
27
|
-
children: [],
|
|
28
|
-
original: city,
|
|
29
|
-
}
|
|
30
|
-
cityDistrictTree.push(cityItem)
|
|
31
|
-
cityMap[city.city_id] = cityItem
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
_.each(districtRes.response.districts, (district) => {
|
|
35
|
-
const districtItem = {
|
|
36
|
-
original: district,
|
|
37
|
-
value: district.district_id,
|
|
38
|
-
text: district.local_name,
|
|
39
|
-
children: [],
|
|
40
|
-
}
|
|
41
|
-
districtMap[district.district_id] = districtItem
|
|
42
|
-
|
|
43
|
-
const p = cityMap[district.city_id]
|
|
44
|
-
if (p) {
|
|
45
|
-
p.children.push(districtItem)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const district_ids = _.map(
|
|
50
|
-
districtRes.response.districts,
|
|
51
|
-
(district: District) => district.district_id
|
|
52
|
-
)
|
|
53
|
-
const streetRes = await ListStreet({
|
|
54
|
-
district_ids,
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
_.each(streetRes.response.streets, (street) => {
|
|
58
|
-
const streetItem = {
|
|
59
|
-
original: street,
|
|
60
|
-
value: street.street_id,
|
|
61
|
-
text: street.local_name,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const p = districtMap[street.district_id]
|
|
65
|
-
if (p) {
|
|
66
|
-
p.children.push(streetItem)
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
return cityDistrictTree
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { fetchCityDistrictStreetTree }
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { ListCity, ListDistrict, ListStreet, District } from 'gm_api/src/enterprise'
|
|
3
|
+
import { CityItem, DistrictItem } from './types'
|
|
4
|
+
|
|
5
|
+
async function fetchCityDistrictStreetTree(params: {
|
|
6
|
+
city_ids: string[]
|
|
7
|
+
}): Promise<CityItem[]> {
|
|
8
|
+
const { city_ids } = params
|
|
9
|
+
|
|
10
|
+
const [cityRes, districtRes] = await Promise.all([
|
|
11
|
+
ListCity({
|
|
12
|
+
city_ids,
|
|
13
|
+
}),
|
|
14
|
+
ListDistrict({
|
|
15
|
+
city_ids,
|
|
16
|
+
}),
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
const cityDistrictTree: CityItem[] = []
|
|
20
|
+
const cityMap: { [key: string]: CityItem } = {}
|
|
21
|
+
const districtMap: { [key: string]: DistrictItem } = {}
|
|
22
|
+
|
|
23
|
+
_.each(cityRes.response.cities, (city) => {
|
|
24
|
+
const cityItem = {
|
|
25
|
+
value: city.city_id,
|
|
26
|
+
text: city.local_name,
|
|
27
|
+
children: [],
|
|
28
|
+
original: city,
|
|
29
|
+
}
|
|
30
|
+
cityDistrictTree.push(cityItem)
|
|
31
|
+
cityMap[city.city_id] = cityItem
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
_.each(districtRes.response.districts, (district) => {
|
|
35
|
+
const districtItem = {
|
|
36
|
+
original: district,
|
|
37
|
+
value: district.district_id,
|
|
38
|
+
text: district.local_name,
|
|
39
|
+
children: [],
|
|
40
|
+
}
|
|
41
|
+
districtMap[district.district_id] = districtItem
|
|
42
|
+
|
|
43
|
+
const p = cityMap[district.city_id]
|
|
44
|
+
if (p) {
|
|
45
|
+
p.children.push(districtItem)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const district_ids = _.map(
|
|
50
|
+
districtRes.response.districts,
|
|
51
|
+
(district: District) => district.district_id
|
|
52
|
+
)
|
|
53
|
+
const streetRes = await ListStreet({
|
|
54
|
+
district_ids,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
_.each(streetRes.response.streets, (street) => {
|
|
58
|
+
const streetItem = {
|
|
59
|
+
original: street,
|
|
60
|
+
value: street.street_id,
|
|
61
|
+
text: street.local_name,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const p = districtMap[street.district_id]
|
|
65
|
+
if (p) {
|
|
66
|
+
p.children.push(streetItem)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return cityDistrictTree
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { fetchCityDistrictStreetTree }
|