@etsoo/appscript 1.3.70 → 1.3.72
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/__tests__/app/CoreApp.ts +27 -0
- package/lib/cjs/address/AddressAutocomplete.d.ts +22 -0
- package/lib/cjs/address/AddressAutocomplete.js +2 -0
- package/lib/cjs/address/AddressLocation.d.ts +14 -0
- package/lib/cjs/address/AddressLocation.js +2 -0
- package/lib/cjs/address/AddressPlace.d.ts +28 -0
- package/lib/cjs/address/AddressPlace.js +2 -0
- package/lib/cjs/address/AddressPlaceBase.d.ts +37 -0
- package/lib/cjs/address/AddressPlaceBase.js +2 -0
- package/lib/cjs/erp/AddressApi.d.ts +32 -3
- package/lib/cjs/erp/AddressApi.js +66 -17
- package/lib/cjs/erp/rq/PlaceQueryRQ.d.ts +45 -0
- package/lib/cjs/erp/rq/PlaceQueryRQ.js +12 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +5 -0
- package/lib/mjs/address/AddressAutocomplete.d.ts +22 -0
- package/lib/mjs/address/AddressAutocomplete.js +1 -0
- package/lib/mjs/address/AddressLocation.d.ts +14 -0
- package/lib/mjs/address/AddressLocation.js +1 -0
- package/lib/mjs/address/AddressPlace.d.ts +28 -0
- package/lib/mjs/address/AddressPlace.js +1 -0
- package/lib/mjs/address/AddressPlaceBase.d.ts +37 -0
- package/lib/mjs/address/AddressPlaceBase.js +1 -0
- package/lib/mjs/erp/AddressApi.d.ts +32 -3
- package/lib/mjs/erp/AddressApi.js +67 -18
- package/lib/mjs/erp/rq/PlaceQueryRQ.d.ts +45 -0
- package/lib/mjs/erp/rq/PlaceQueryRQ.js +9 -0
- package/lib/mjs/index.d.ts +5 -0
- package/lib/mjs/index.js +5 -0
- package/package.json +4 -4
- package/src/address/AddressAutocomplete.ts +25 -0
- package/src/address/AddressLocation.ts +15 -0
- package/src/address/AddressPlace.ts +32 -0
- package/src/address/AddressPlaceBase.ts +43 -0
- package/src/erp/AddressApi.ts +78 -16
- package/src/erp/rq/PlaceQueryRQ.ts +52 -0
- package/src/index.ts +5 -0
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -228,6 +228,33 @@ test('Tests for addressApi', async () => {
|
|
|
228
228
|
expect(regionFailed).toBeUndefined();
|
|
229
229
|
|
|
230
230
|
/*
|
|
231
|
+
const results1 = await app.addressApi.autocomplete({
|
|
232
|
+
query: '青岛市玫瑰庭院',
|
|
233
|
+
region: 'CN',
|
|
234
|
+
language: 'zh-CN'
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const results2 = await app.addressApi.autocomplete({
|
|
238
|
+
query: '青岛市玫瑰庭院',
|
|
239
|
+
language: 'zh-CN'
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const results1 = await app.addressApi.searchPlace({
|
|
243
|
+
query: '青岛市玫瑰庭院',
|
|
244
|
+
region: 'CN',
|
|
245
|
+
language: 'zh-CN'
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const result = await app.addressApi.GetPlaceDetails(
|
|
249
|
+
'ChIJczySyo1qljUR1Jnq4Uqak2I',
|
|
250
|
+
'zh-CN'
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const results2 = await app.addressApi.searchPlace({
|
|
254
|
+
query: '青岛市玫瑰庭院',
|
|
255
|
+
language: 'zh-CN'
|
|
256
|
+
});
|
|
257
|
+
|
|
231
258
|
const cities = await app.addressApi.cities('CNHN');
|
|
232
259
|
console.log(cities);
|
|
233
260
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
2
|
+
/**
|
|
3
|
+
* Address autocomplete
|
|
4
|
+
* 地点自动填充
|
|
5
|
+
*/
|
|
6
|
+
export type AddressAutocomplete = {
|
|
7
|
+
/**
|
|
8
|
+
* Place id
|
|
9
|
+
* 地点编号
|
|
10
|
+
*/
|
|
11
|
+
placeId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name
|
|
14
|
+
* 名称
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Place data
|
|
19
|
+
* 地点数据
|
|
20
|
+
*/
|
|
21
|
+
place?: AddressPlaceBase;
|
|
22
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
3
|
+
/**
|
|
4
|
+
* Address place
|
|
5
|
+
* 地点
|
|
6
|
+
*/
|
|
7
|
+
export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Place id
|
|
10
|
+
* 地点编号
|
|
11
|
+
*/
|
|
12
|
+
placeId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Name
|
|
15
|
+
* 名称
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Location
|
|
20
|
+
* 位置
|
|
21
|
+
*/
|
|
22
|
+
location: AddressLocation;
|
|
23
|
+
/**
|
|
24
|
+
* Formatted address
|
|
25
|
+
* 格式化地址
|
|
26
|
+
*/
|
|
27
|
+
formattedAddress: string;
|
|
28
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
/**
|
|
3
|
+
* Address place base
|
|
4
|
+
* 基础地点
|
|
5
|
+
*/
|
|
6
|
+
export type AddressPlaceBase = {
|
|
7
|
+
/**
|
|
8
|
+
* Location
|
|
9
|
+
* 位置
|
|
10
|
+
*/
|
|
11
|
+
location?: AddressLocation;
|
|
12
|
+
/**
|
|
13
|
+
* Region or country, like CN = China
|
|
14
|
+
* 地区或国家,比如 CN 表示中国
|
|
15
|
+
*/
|
|
16
|
+
region?: string;
|
|
17
|
+
/**
|
|
18
|
+
* State or province
|
|
19
|
+
* 州 / 省
|
|
20
|
+
*/
|
|
21
|
+
state?: string;
|
|
22
|
+
/**
|
|
23
|
+
* City
|
|
24
|
+
* 城市
|
|
25
|
+
*/
|
|
26
|
+
city?: string;
|
|
27
|
+
/**
|
|
28
|
+
* District
|
|
29
|
+
* 区县
|
|
30
|
+
*/
|
|
31
|
+
district?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Postcode
|
|
34
|
+
* 邮编
|
|
35
|
+
*/
|
|
36
|
+
postcode?: string;
|
|
37
|
+
};
|
|
@@ -7,10 +7,20 @@ import { IApiPayload } from '@etsoo/restclient';
|
|
|
7
7
|
import { RegionsRQ } from './rq/RegionsRQ';
|
|
8
8
|
import { AddressCity } from '../address/AddressCity';
|
|
9
9
|
import { AddressDistrict } from '../address/AddressDistrict';
|
|
10
|
+
import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
|
|
11
|
+
import { AddressAutocomplete } from '../address/AddressAutocomplete';
|
|
12
|
+
import { AddressPlace } from '../address/AddressPlace';
|
|
10
13
|
/**
|
|
11
14
|
* Address Api
|
|
12
15
|
*/
|
|
13
16
|
export declare class AddressApi extends BaseApi {
|
|
17
|
+
/**
|
|
18
|
+
* Place autocomplete
|
|
19
|
+
* @param rq Request data
|
|
20
|
+
* @param payload Payload
|
|
21
|
+
* @returns Result
|
|
22
|
+
*/
|
|
23
|
+
autocomplete(rq: PlaceQueryRQ, payload?: IApiPayload<AddressAutocomplete[]>): Promise<AddressAutocomplete[] | undefined>;
|
|
14
24
|
/**
|
|
15
25
|
* Get all continents
|
|
16
26
|
* @param isNumberKey Is number key or key as id
|
|
@@ -65,25 +75,44 @@ export declare class AddressApi extends BaseApi {
|
|
|
65
75
|
/**
|
|
66
76
|
* Get state list
|
|
67
77
|
* @param regionId Region id
|
|
78
|
+
* @param favoredIds Favored ids
|
|
68
79
|
* @param payload Payload
|
|
69
80
|
* @param culture Culture
|
|
70
81
|
* @returns Result
|
|
71
82
|
*/
|
|
72
|
-
states(regionId: string, payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
|
|
83
|
+
states(regionId: string, favoredIds?: string[], payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
|
|
73
84
|
/**
|
|
74
85
|
* Get city list
|
|
75
86
|
* @param stateId State id
|
|
87
|
+
* @param favoredIds Favored ids
|
|
76
88
|
* @param payload Payload
|
|
77
89
|
* @param culture Culture
|
|
90
|
+
*
|
|
78
91
|
* @returns Result
|
|
79
92
|
*/
|
|
80
|
-
cities(stateId: string, payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
|
|
93
|
+
cities(stateId: string, favoredIds?: number[], payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
|
|
81
94
|
/**
|
|
82
95
|
* Get district list
|
|
83
96
|
* @param cityId City id
|
|
97
|
+
* @param favoredIds Favored ids
|
|
84
98
|
* @param payload Payload
|
|
85
99
|
* @param culture Culture
|
|
86
100
|
* @returns Result
|
|
87
101
|
*/
|
|
88
|
-
districts(cityId: number, payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
|
|
102
|
+
districts(cityId: number, favoredIds?: number[], payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Get place details
|
|
105
|
+
* @param placeId Place id
|
|
106
|
+
* @param language Language
|
|
107
|
+
* @param payload Payload
|
|
108
|
+
* @returns Result
|
|
109
|
+
*/
|
|
110
|
+
GetPlaceDetails(placeId: string, language?: string, payload?: IApiPayload<AddressPlace>): Promise<AddressPlace | undefined>;
|
|
111
|
+
/**
|
|
112
|
+
* Place autocomplete
|
|
113
|
+
* @param rq Request data
|
|
114
|
+
* @param payload Payload
|
|
115
|
+
* @returns Result
|
|
116
|
+
*/
|
|
117
|
+
searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>): Promise<AddressPlace[] | undefined>;
|
|
89
118
|
}
|
|
@@ -10,6 +10,19 @@ const cachedRegions = {};
|
|
|
10
10
|
* Address Api
|
|
11
11
|
*/
|
|
12
12
|
class AddressApi extends BaseApi_1.BaseApi {
|
|
13
|
+
/**
|
|
14
|
+
* Place autocomplete
|
|
15
|
+
* @param rq Request data
|
|
16
|
+
* @param payload Payload
|
|
17
|
+
* @returns Result
|
|
18
|
+
*/
|
|
19
|
+
autocomplete(rq, payload) {
|
|
20
|
+
var _a;
|
|
21
|
+
if (rq.query === '')
|
|
22
|
+
return Promise.resolve(undefined);
|
|
23
|
+
(_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
|
|
24
|
+
return this.api.post('Address/Autocomplete', rq, payload);
|
|
25
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* Get all continents
|
|
15
28
|
* @param isNumberKey Is number key or key as id
|
|
@@ -94,17 +107,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
94
107
|
});
|
|
95
108
|
// Order by favoredIds
|
|
96
109
|
if (favoredIds.length > 0) {
|
|
97
|
-
regions = [...regions]
|
|
98
|
-
const n1 = favoredIds.indexOf(r1.id);
|
|
99
|
-
const n2 = favoredIds.indexOf(r2.id);
|
|
100
|
-
if (n1 === n2)
|
|
101
|
-
return 0;
|
|
102
|
-
if (n1 === -1)
|
|
103
|
-
return 1;
|
|
104
|
-
if (n2 === -1)
|
|
105
|
-
return -1;
|
|
106
|
-
return n1 - n2;
|
|
107
|
-
});
|
|
110
|
+
regions = shared_1.Utils.sortByFieldFavor([...regions], 'id', favoredIds);
|
|
108
111
|
}
|
|
109
112
|
// Return the top items
|
|
110
113
|
return regions.slice(0, items);
|
|
@@ -143,38 +146,84 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
143
146
|
/**
|
|
144
147
|
* Get state list
|
|
145
148
|
* @param regionId Region id
|
|
149
|
+
* @param favoredIds Favored ids
|
|
146
150
|
* @param payload Payload
|
|
147
151
|
* @param culture Culture
|
|
148
152
|
* @returns Result
|
|
149
153
|
*/
|
|
150
|
-
states(regionId, payload, culture) {
|
|
154
|
+
async states(regionId, favoredIds = [], payload, culture) {
|
|
155
|
+
if (regionId === '')
|
|
156
|
+
return Promise.resolve(undefined);
|
|
151
157
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
152
158
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
153
|
-
|
|
159
|
+
var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
|
|
160
|
+
if (items == null || favoredIds.length === 0)
|
|
161
|
+
return items;
|
|
162
|
+
return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
154
163
|
}
|
|
155
164
|
/**
|
|
156
165
|
* Get city list
|
|
157
166
|
* @param stateId State id
|
|
167
|
+
* @param favoredIds Favored ids
|
|
158
168
|
* @param payload Payload
|
|
159
169
|
* @param culture Culture
|
|
170
|
+
*
|
|
160
171
|
* @returns Result
|
|
161
172
|
*/
|
|
162
|
-
cities(stateId, payload, culture) {
|
|
173
|
+
async cities(stateId, favoredIds = [], payload, culture) {
|
|
174
|
+
if (stateId === '')
|
|
175
|
+
return Promise.resolve(undefined);
|
|
163
176
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
164
177
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
165
|
-
|
|
178
|
+
const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
|
|
179
|
+
if (items == null || favoredIds.length === 0)
|
|
180
|
+
return items;
|
|
181
|
+
return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
166
182
|
}
|
|
167
183
|
/**
|
|
168
184
|
* Get district list
|
|
169
185
|
* @param cityId City id
|
|
186
|
+
* @param favoredIds Favored ids
|
|
170
187
|
* @param payload Payload
|
|
171
188
|
* @param culture Culture
|
|
172
189
|
* @returns Result
|
|
173
190
|
*/
|
|
174
|
-
districts(cityId, payload, culture) {
|
|
191
|
+
async districts(cityId, favoredIds = [], payload, culture) {
|
|
192
|
+
if (cityId < 1)
|
|
193
|
+
return Promise.resolve(undefined);
|
|
175
194
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
176
195
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
177
|
-
|
|
196
|
+
const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
|
|
197
|
+
if (items == null || favoredIds.length === 0)
|
|
198
|
+
return items;
|
|
199
|
+
return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get place details
|
|
203
|
+
* @param placeId Place id
|
|
204
|
+
* @param language Language
|
|
205
|
+
* @param payload Payload
|
|
206
|
+
* @returns Result
|
|
207
|
+
*/
|
|
208
|
+
GetPlaceDetails(placeId, language, payload) {
|
|
209
|
+
if (placeId === '')
|
|
210
|
+
return Promise.resolve(undefined);
|
|
211
|
+
language !== null && language !== void 0 ? language : (language = this.app.culture);
|
|
212
|
+
const url = `Address/GetPlaceDetails/${placeId}/${language}`;
|
|
213
|
+
return this.api.get(url, undefined, payload);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Place autocomplete
|
|
217
|
+
* @param rq Request data
|
|
218
|
+
* @param payload Payload
|
|
219
|
+
* @returns Result
|
|
220
|
+
*/
|
|
221
|
+
searchPlace(rq, payload) {
|
|
222
|
+
var _a;
|
|
223
|
+
if (rq.query === '')
|
|
224
|
+
return Promise.resolve(undefined);
|
|
225
|
+
(_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
|
|
226
|
+
return this.api.post('Address/SearchPlace', rq, payload);
|
|
178
227
|
}
|
|
179
228
|
}
|
|
180
229
|
exports.AddressApi = AddressApi;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AddressLocation } from '../../address/AddressLocation';
|
|
2
|
+
/**
|
|
3
|
+
* Place query output type
|
|
4
|
+
* 地址查询输出类型
|
|
5
|
+
*/
|
|
6
|
+
export declare enum PlaceQueryOutput {
|
|
7
|
+
JSON = 0,
|
|
8
|
+
XML = 1
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Place query request data
|
|
12
|
+
* 地址查询请求数据
|
|
13
|
+
*/
|
|
14
|
+
export type PlaceQueryRQ = {
|
|
15
|
+
/**
|
|
16
|
+
* Query address
|
|
17
|
+
* 查询地址
|
|
18
|
+
*/
|
|
19
|
+
query: string;
|
|
20
|
+
/**
|
|
21
|
+
* Output type
|
|
22
|
+
* 输出类型
|
|
23
|
+
*/
|
|
24
|
+
output?: PlaceQueryOutput;
|
|
25
|
+
/**
|
|
26
|
+
* Language
|
|
27
|
+
* 语言
|
|
28
|
+
*/
|
|
29
|
+
language?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Limited region / country id, like CN
|
|
32
|
+
* 限定的地区获国家编号
|
|
33
|
+
*/
|
|
34
|
+
region?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Center location
|
|
37
|
+
* 中心位置
|
|
38
|
+
*/
|
|
39
|
+
location?: AddressLocation;
|
|
40
|
+
/**
|
|
41
|
+
* Circle radius
|
|
42
|
+
* 方圆半径
|
|
43
|
+
*/
|
|
44
|
+
radius?: number;
|
|
45
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaceQueryOutput = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Place query output type
|
|
6
|
+
* 地址查询输出类型
|
|
7
|
+
*/
|
|
8
|
+
var PlaceQueryOutput;
|
|
9
|
+
(function (PlaceQueryOutput) {
|
|
10
|
+
PlaceQueryOutput[PlaceQueryOutput["JSON"] = 0] = "JSON";
|
|
11
|
+
PlaceQueryOutput[PlaceQueryOutput["XML"] = 1] = "XML";
|
|
12
|
+
})(PlaceQueryOutput = exports.PlaceQueryOutput || (exports.PlaceQueryOutput = {}));
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export * from './address/AddressAutocomplete';
|
|
1
2
|
export * from './address/AddressCity';
|
|
2
3
|
export * from './address/AddressContinent';
|
|
3
4
|
export * from './address/AddressDistrict';
|
|
5
|
+
export * from './address/AddressLocation';
|
|
6
|
+
export * from './address/AddressPlace';
|
|
7
|
+
export * from './address/AddressPlaceBase';
|
|
4
8
|
export * from './address/AddressRegion';
|
|
5
9
|
export * from './address/AddressState';
|
|
6
10
|
export * from './address/AddressUtils';
|
|
@@ -36,6 +40,7 @@ export * from './erp/rq/LoginRQ';
|
|
|
36
40
|
export * from './erp/rq/MemberListRQ';
|
|
37
41
|
export * from './erp/rq/OrgListRQ';
|
|
38
42
|
export * from './erp/rq/OrgQueryRQ';
|
|
43
|
+
export * from './erp/rq/PlaceQueryRQ';
|
|
39
44
|
export * from './erp/rq/QueryRQ';
|
|
40
45
|
export * from './erp/rq/RefreshTokenRQ';
|
|
41
46
|
export * from './erp/rq/RegionsRQ';
|
package/lib/cjs/index.js
CHANGED
|
@@ -16,9 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiAuthorizationScheme = void 0;
|
|
18
18
|
// address
|
|
19
|
+
__exportStar(require("./address/AddressAutocomplete"), exports);
|
|
19
20
|
__exportStar(require("./address/AddressCity"), exports);
|
|
20
21
|
__exportStar(require("./address/AddressContinent"), exports);
|
|
21
22
|
__exportStar(require("./address/AddressDistrict"), exports);
|
|
23
|
+
__exportStar(require("./address/AddressLocation"), exports);
|
|
24
|
+
__exportStar(require("./address/AddressPlace"), exports);
|
|
25
|
+
__exportStar(require("./address/AddressPlaceBase"), exports);
|
|
22
26
|
__exportStar(require("./address/AddressRegion"), exports);
|
|
23
27
|
__exportStar(require("./address/AddressState"), exports);
|
|
24
28
|
__exportStar(require("./address/AddressUtils"), exports);
|
|
@@ -60,6 +64,7 @@ __exportStar(require("./erp/rq/LoginRQ"), exports);
|
|
|
60
64
|
__exportStar(require("./erp/rq/MemberListRQ"), exports);
|
|
61
65
|
__exportStar(require("./erp/rq/OrgListRQ"), exports);
|
|
62
66
|
__exportStar(require("./erp/rq/OrgQueryRQ"), exports);
|
|
67
|
+
__exportStar(require("./erp/rq/PlaceQueryRQ"), exports);
|
|
63
68
|
__exportStar(require("./erp/rq/QueryRQ"), exports);
|
|
64
69
|
__exportStar(require("./erp/rq/RefreshTokenRQ"), exports);
|
|
65
70
|
__exportStar(require("./erp/rq/RegionsRQ"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
2
|
+
/**
|
|
3
|
+
* Address autocomplete
|
|
4
|
+
* 地点自动填充
|
|
5
|
+
*/
|
|
6
|
+
export type AddressAutocomplete = {
|
|
7
|
+
/**
|
|
8
|
+
* Place id
|
|
9
|
+
* 地点编号
|
|
10
|
+
*/
|
|
11
|
+
placeId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name
|
|
14
|
+
* 名称
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Place data
|
|
19
|
+
* 地点数据
|
|
20
|
+
*/
|
|
21
|
+
place?: AddressPlaceBase;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
3
|
+
/**
|
|
4
|
+
* Address place
|
|
5
|
+
* 地点
|
|
6
|
+
*/
|
|
7
|
+
export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Place id
|
|
10
|
+
* 地点编号
|
|
11
|
+
*/
|
|
12
|
+
placeId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Name
|
|
15
|
+
* 名称
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Location
|
|
20
|
+
* 位置
|
|
21
|
+
*/
|
|
22
|
+
location: AddressLocation;
|
|
23
|
+
/**
|
|
24
|
+
* Formatted address
|
|
25
|
+
* 格式化地址
|
|
26
|
+
*/
|
|
27
|
+
formattedAddress: string;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
/**
|
|
3
|
+
* Address place base
|
|
4
|
+
* 基础地点
|
|
5
|
+
*/
|
|
6
|
+
export type AddressPlaceBase = {
|
|
7
|
+
/**
|
|
8
|
+
* Location
|
|
9
|
+
* 位置
|
|
10
|
+
*/
|
|
11
|
+
location?: AddressLocation;
|
|
12
|
+
/**
|
|
13
|
+
* Region or country, like CN = China
|
|
14
|
+
* 地区或国家,比如 CN 表示中国
|
|
15
|
+
*/
|
|
16
|
+
region?: string;
|
|
17
|
+
/**
|
|
18
|
+
* State or province
|
|
19
|
+
* 州 / 省
|
|
20
|
+
*/
|
|
21
|
+
state?: string;
|
|
22
|
+
/**
|
|
23
|
+
* City
|
|
24
|
+
* 城市
|
|
25
|
+
*/
|
|
26
|
+
city?: string;
|
|
27
|
+
/**
|
|
28
|
+
* District
|
|
29
|
+
* 区县
|
|
30
|
+
*/
|
|
31
|
+
district?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Postcode
|
|
34
|
+
* 邮编
|
|
35
|
+
*/
|
|
36
|
+
postcode?: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,10 +7,20 @@ import { IApiPayload } from '@etsoo/restclient';
|
|
|
7
7
|
import { RegionsRQ } from './rq/RegionsRQ';
|
|
8
8
|
import { AddressCity } from '../address/AddressCity';
|
|
9
9
|
import { AddressDistrict } from '../address/AddressDistrict';
|
|
10
|
+
import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
|
|
11
|
+
import { AddressAutocomplete } from '../address/AddressAutocomplete';
|
|
12
|
+
import { AddressPlace } from '../address/AddressPlace';
|
|
10
13
|
/**
|
|
11
14
|
* Address Api
|
|
12
15
|
*/
|
|
13
16
|
export declare class AddressApi extends BaseApi {
|
|
17
|
+
/**
|
|
18
|
+
* Place autocomplete
|
|
19
|
+
* @param rq Request data
|
|
20
|
+
* @param payload Payload
|
|
21
|
+
* @returns Result
|
|
22
|
+
*/
|
|
23
|
+
autocomplete(rq: PlaceQueryRQ, payload?: IApiPayload<AddressAutocomplete[]>): Promise<AddressAutocomplete[] | undefined>;
|
|
14
24
|
/**
|
|
15
25
|
* Get all continents
|
|
16
26
|
* @param isNumberKey Is number key or key as id
|
|
@@ -65,25 +75,44 @@ export declare class AddressApi extends BaseApi {
|
|
|
65
75
|
/**
|
|
66
76
|
* Get state list
|
|
67
77
|
* @param regionId Region id
|
|
78
|
+
* @param favoredIds Favored ids
|
|
68
79
|
* @param payload Payload
|
|
69
80
|
* @param culture Culture
|
|
70
81
|
* @returns Result
|
|
71
82
|
*/
|
|
72
|
-
states(regionId: string, payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
|
|
83
|
+
states(regionId: string, favoredIds?: string[], payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
|
|
73
84
|
/**
|
|
74
85
|
* Get city list
|
|
75
86
|
* @param stateId State id
|
|
87
|
+
* @param favoredIds Favored ids
|
|
76
88
|
* @param payload Payload
|
|
77
89
|
* @param culture Culture
|
|
90
|
+
*
|
|
78
91
|
* @returns Result
|
|
79
92
|
*/
|
|
80
|
-
cities(stateId: string, payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
|
|
93
|
+
cities(stateId: string, favoredIds?: number[], payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
|
|
81
94
|
/**
|
|
82
95
|
* Get district list
|
|
83
96
|
* @param cityId City id
|
|
97
|
+
* @param favoredIds Favored ids
|
|
84
98
|
* @param payload Payload
|
|
85
99
|
* @param culture Culture
|
|
86
100
|
* @returns Result
|
|
87
101
|
*/
|
|
88
|
-
districts(cityId: number, payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
|
|
102
|
+
districts(cityId: number, favoredIds?: number[], payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Get place details
|
|
105
|
+
* @param placeId Place id
|
|
106
|
+
* @param language Language
|
|
107
|
+
* @param payload Payload
|
|
108
|
+
* @returns Result
|
|
109
|
+
*/
|
|
110
|
+
GetPlaceDetails(placeId: string, language?: string, payload?: IApiPayload<AddressPlace>): Promise<AddressPlace | undefined>;
|
|
111
|
+
/**
|
|
112
|
+
* Place autocomplete
|
|
113
|
+
* @param rq Request data
|
|
114
|
+
* @param payload Payload
|
|
115
|
+
* @returns Result
|
|
116
|
+
*/
|
|
117
|
+
searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>): Promise<AddressPlace[] | undefined>;
|
|
89
118
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, Utils } from '@etsoo/shared';
|
|
2
2
|
import { AddressContinent } from '../address/AddressContinent';
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
4
|
import { BaseApi } from './BaseApi';
|
|
@@ -7,6 +7,19 @@ const cachedRegions = {};
|
|
|
7
7
|
* Address Api
|
|
8
8
|
*/
|
|
9
9
|
export class AddressApi extends BaseApi {
|
|
10
|
+
/**
|
|
11
|
+
* Place autocomplete
|
|
12
|
+
* @param rq Request data
|
|
13
|
+
* @param payload Payload
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
autocomplete(rq, payload) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (rq.query === '')
|
|
19
|
+
return Promise.resolve(undefined);
|
|
20
|
+
(_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
|
|
21
|
+
return this.api.post('Address/Autocomplete', rq, payload);
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* Get all continents
|
|
12
25
|
* @param isNumberKey Is number key or key as id
|
|
@@ -91,17 +104,7 @@ export class AddressApi extends BaseApi {
|
|
|
91
104
|
});
|
|
92
105
|
// Order by favoredIds
|
|
93
106
|
if (favoredIds.length > 0) {
|
|
94
|
-
regions = [...regions]
|
|
95
|
-
const n1 = favoredIds.indexOf(r1.id);
|
|
96
|
-
const n2 = favoredIds.indexOf(r2.id);
|
|
97
|
-
if (n1 === n2)
|
|
98
|
-
return 0;
|
|
99
|
-
if (n1 === -1)
|
|
100
|
-
return 1;
|
|
101
|
-
if (n2 === -1)
|
|
102
|
-
return -1;
|
|
103
|
-
return n1 - n2;
|
|
104
|
-
});
|
|
107
|
+
regions = Utils.sortByFieldFavor([...regions], 'id', favoredIds);
|
|
105
108
|
}
|
|
106
109
|
// Return the top items
|
|
107
110
|
return regions.slice(0, items);
|
|
@@ -140,37 +143,83 @@ export class AddressApi extends BaseApi {
|
|
|
140
143
|
/**
|
|
141
144
|
* Get state list
|
|
142
145
|
* @param regionId Region id
|
|
146
|
+
* @param favoredIds Favored ids
|
|
143
147
|
* @param payload Payload
|
|
144
148
|
* @param culture Culture
|
|
145
149
|
* @returns Result
|
|
146
150
|
*/
|
|
147
|
-
states(regionId, payload, culture) {
|
|
151
|
+
async states(regionId, favoredIds = [], payload, culture) {
|
|
152
|
+
if (regionId === '')
|
|
153
|
+
return Promise.resolve(undefined);
|
|
148
154
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
149
155
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
150
|
-
|
|
156
|
+
var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
|
|
157
|
+
if (items == null || favoredIds.length === 0)
|
|
158
|
+
return items;
|
|
159
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
151
160
|
}
|
|
152
161
|
/**
|
|
153
162
|
* Get city list
|
|
154
163
|
* @param stateId State id
|
|
164
|
+
* @param favoredIds Favored ids
|
|
155
165
|
* @param payload Payload
|
|
156
166
|
* @param culture Culture
|
|
167
|
+
*
|
|
157
168
|
* @returns Result
|
|
158
169
|
*/
|
|
159
|
-
cities(stateId, payload, culture) {
|
|
170
|
+
async cities(stateId, favoredIds = [], payload, culture) {
|
|
171
|
+
if (stateId === '')
|
|
172
|
+
return Promise.resolve(undefined);
|
|
160
173
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
161
174
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
162
|
-
|
|
175
|
+
const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
|
|
176
|
+
if (items == null || favoredIds.length === 0)
|
|
177
|
+
return items;
|
|
178
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
163
179
|
}
|
|
164
180
|
/**
|
|
165
181
|
* Get district list
|
|
166
182
|
* @param cityId City id
|
|
183
|
+
* @param favoredIds Favored ids
|
|
167
184
|
* @param payload Payload
|
|
168
185
|
* @param culture Culture
|
|
169
186
|
* @returns Result
|
|
170
187
|
*/
|
|
171
|
-
districts(cityId, payload, culture) {
|
|
188
|
+
async districts(cityId, favoredIds = [], payload, culture) {
|
|
189
|
+
if (cityId < 1)
|
|
190
|
+
return Promise.resolve(undefined);
|
|
172
191
|
payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
|
|
173
192
|
culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
|
|
174
|
-
|
|
193
|
+
const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
|
|
194
|
+
if (items == null || favoredIds.length === 0)
|
|
195
|
+
return items;
|
|
196
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get place details
|
|
200
|
+
* @param placeId Place id
|
|
201
|
+
* @param language Language
|
|
202
|
+
* @param payload Payload
|
|
203
|
+
* @returns Result
|
|
204
|
+
*/
|
|
205
|
+
GetPlaceDetails(placeId, language, payload) {
|
|
206
|
+
if (placeId === '')
|
|
207
|
+
return Promise.resolve(undefined);
|
|
208
|
+
language !== null && language !== void 0 ? language : (language = this.app.culture);
|
|
209
|
+
const url = `Address/GetPlaceDetails/${placeId}/${language}`;
|
|
210
|
+
return this.api.get(url, undefined, payload);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Place autocomplete
|
|
214
|
+
* @param rq Request data
|
|
215
|
+
* @param payload Payload
|
|
216
|
+
* @returns Result
|
|
217
|
+
*/
|
|
218
|
+
searchPlace(rq, payload) {
|
|
219
|
+
var _a;
|
|
220
|
+
if (rq.query === '')
|
|
221
|
+
return Promise.resolve(undefined);
|
|
222
|
+
(_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
|
|
223
|
+
return this.api.post('Address/SearchPlace', rq, payload);
|
|
175
224
|
}
|
|
176
225
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AddressLocation } from '../../address/AddressLocation';
|
|
2
|
+
/**
|
|
3
|
+
* Place query output type
|
|
4
|
+
* 地址查询输出类型
|
|
5
|
+
*/
|
|
6
|
+
export declare enum PlaceQueryOutput {
|
|
7
|
+
JSON = 0,
|
|
8
|
+
XML = 1
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Place query request data
|
|
12
|
+
* 地址查询请求数据
|
|
13
|
+
*/
|
|
14
|
+
export type PlaceQueryRQ = {
|
|
15
|
+
/**
|
|
16
|
+
* Query address
|
|
17
|
+
* 查询地址
|
|
18
|
+
*/
|
|
19
|
+
query: string;
|
|
20
|
+
/**
|
|
21
|
+
* Output type
|
|
22
|
+
* 输出类型
|
|
23
|
+
*/
|
|
24
|
+
output?: PlaceQueryOutput;
|
|
25
|
+
/**
|
|
26
|
+
* Language
|
|
27
|
+
* 语言
|
|
28
|
+
*/
|
|
29
|
+
language?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Limited region / country id, like CN
|
|
32
|
+
* 限定的地区获国家编号
|
|
33
|
+
*/
|
|
34
|
+
region?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Center location
|
|
37
|
+
* 中心位置
|
|
38
|
+
*/
|
|
39
|
+
location?: AddressLocation;
|
|
40
|
+
/**
|
|
41
|
+
* Circle radius
|
|
42
|
+
* 方圆半径
|
|
43
|
+
*/
|
|
44
|
+
radius?: number;
|
|
45
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Place query output type
|
|
3
|
+
* 地址查询输出类型
|
|
4
|
+
*/
|
|
5
|
+
export var PlaceQueryOutput;
|
|
6
|
+
(function (PlaceQueryOutput) {
|
|
7
|
+
PlaceQueryOutput[PlaceQueryOutput["JSON"] = 0] = "JSON";
|
|
8
|
+
PlaceQueryOutput[PlaceQueryOutput["XML"] = 1] = "XML";
|
|
9
|
+
})(PlaceQueryOutput || (PlaceQueryOutput = {}));
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export * from './address/AddressAutocomplete';
|
|
1
2
|
export * from './address/AddressCity';
|
|
2
3
|
export * from './address/AddressContinent';
|
|
3
4
|
export * from './address/AddressDistrict';
|
|
5
|
+
export * from './address/AddressLocation';
|
|
6
|
+
export * from './address/AddressPlace';
|
|
7
|
+
export * from './address/AddressPlaceBase';
|
|
4
8
|
export * from './address/AddressRegion';
|
|
5
9
|
export * from './address/AddressState';
|
|
6
10
|
export * from './address/AddressUtils';
|
|
@@ -36,6 +40,7 @@ export * from './erp/rq/LoginRQ';
|
|
|
36
40
|
export * from './erp/rq/MemberListRQ';
|
|
37
41
|
export * from './erp/rq/OrgListRQ';
|
|
38
42
|
export * from './erp/rq/OrgQueryRQ';
|
|
43
|
+
export * from './erp/rq/PlaceQueryRQ';
|
|
39
44
|
export * from './erp/rq/QueryRQ';
|
|
40
45
|
export * from './erp/rq/RefreshTokenRQ';
|
|
41
46
|
export * from './erp/rq/RegionsRQ';
|
package/lib/mjs/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// address
|
|
2
|
+
export * from './address/AddressAutocomplete';
|
|
2
3
|
export * from './address/AddressCity';
|
|
3
4
|
export * from './address/AddressContinent';
|
|
4
5
|
export * from './address/AddressDistrict';
|
|
6
|
+
export * from './address/AddressLocation';
|
|
7
|
+
export * from './address/AddressPlace';
|
|
8
|
+
export * from './address/AddressPlaceBase';
|
|
5
9
|
export * from './address/AddressRegion';
|
|
6
10
|
export * from './address/AddressState';
|
|
7
11
|
export * from './address/AddressUtils';
|
|
@@ -43,6 +47,7 @@ export * from './erp/rq/LoginRQ';
|
|
|
43
47
|
export * from './erp/rq/MemberListRQ';
|
|
44
48
|
export * from './erp/rq/OrgListRQ';
|
|
45
49
|
export * from './erp/rq/OrgQueryRQ';
|
|
50
|
+
export * from './erp/rq/PlaceQueryRQ';
|
|
46
51
|
export * from './erp/rq/QueryRQ';
|
|
47
52
|
export * from './erp/rq/RefreshTokenRQ';
|
|
48
53
|
export * from './erp/rq/RegionsRQ';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.72",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@etsoo/notificationbase": "^1.1.24",
|
|
56
56
|
"@etsoo/restclient": "^1.0.87",
|
|
57
|
-
"@etsoo/shared": "^1.1.
|
|
57
|
+
"@etsoo/shared": "^1.1.90",
|
|
58
58
|
"@types/crypto-js": "^4.1.1",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"@babel/preset-env": "^7.20.2",
|
|
66
66
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
67
67
|
"@types/jest": "^29.4.0",
|
|
68
|
-
"jest": "^29.
|
|
69
|
-
"jest-environment-jsdom": "^29.
|
|
68
|
+
"jest": "^29.5.0",
|
|
69
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
70
70
|
"ts-jest": "^29.0.5",
|
|
71
71
|
"typescript": "^4.9.5"
|
|
72
72
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Address autocomplete
|
|
5
|
+
* 地点自动填充
|
|
6
|
+
*/
|
|
7
|
+
export type AddressAutocomplete = {
|
|
8
|
+
/**
|
|
9
|
+
* Place id
|
|
10
|
+
* 地点编号
|
|
11
|
+
*/
|
|
12
|
+
placeId: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Name
|
|
16
|
+
* 名称
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Place data
|
|
22
|
+
* 地点数据
|
|
23
|
+
*/
|
|
24
|
+
place?: AddressPlaceBase;
|
|
25
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
import { AddressPlaceBase } from './AddressPlaceBase';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Address place
|
|
6
|
+
* 地点
|
|
7
|
+
*/
|
|
8
|
+
export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
|
|
9
|
+
/**
|
|
10
|
+
* Place id
|
|
11
|
+
* 地点编号
|
|
12
|
+
*/
|
|
13
|
+
placeId: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Name
|
|
17
|
+
* 名称
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Location
|
|
23
|
+
* 位置
|
|
24
|
+
*/
|
|
25
|
+
location: AddressLocation;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Formatted address
|
|
29
|
+
* 格式化地址
|
|
30
|
+
*/
|
|
31
|
+
formattedAddress: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AddressLocation } from './AddressLocation';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Address place base
|
|
5
|
+
* 基础地点
|
|
6
|
+
*/
|
|
7
|
+
export type AddressPlaceBase = {
|
|
8
|
+
/**
|
|
9
|
+
* Location
|
|
10
|
+
* 位置
|
|
11
|
+
*/
|
|
12
|
+
location?: AddressLocation;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Region or country, like CN = China
|
|
16
|
+
* 地区或国家,比如 CN 表示中国
|
|
17
|
+
*/
|
|
18
|
+
region?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* State or province
|
|
22
|
+
* 州 / 省
|
|
23
|
+
*/
|
|
24
|
+
state?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* City
|
|
28
|
+
* 城市
|
|
29
|
+
*/
|
|
30
|
+
city?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* District
|
|
34
|
+
* 区县
|
|
35
|
+
*/
|
|
36
|
+
district?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Postcode
|
|
40
|
+
* 邮编
|
|
41
|
+
*/
|
|
42
|
+
postcode?: string;
|
|
43
|
+
};
|
package/src/erp/AddressApi.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, Utils } from '@etsoo/shared';
|
|
2
2
|
import { AddressContinent } from '../address/AddressContinent';
|
|
3
3
|
import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
|
|
4
4
|
import { AddressState } from '../address/AddressState';
|
|
@@ -8,6 +8,9 @@ import { IApiPayload } from '@etsoo/restclient';
|
|
|
8
8
|
import { RegionsRQ } from './rq/RegionsRQ';
|
|
9
9
|
import { AddressCity } from '../address/AddressCity';
|
|
10
10
|
import { AddressDistrict } from '../address/AddressDistrict';
|
|
11
|
+
import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
|
|
12
|
+
import { AddressAutocomplete } from '../address/AddressAutocomplete';
|
|
13
|
+
import { AddressPlace } from '../address/AddressPlace';
|
|
11
14
|
|
|
12
15
|
const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
|
|
13
16
|
|
|
@@ -15,6 +18,21 @@ const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
|
|
|
15
18
|
* Address Api
|
|
16
19
|
*/
|
|
17
20
|
export class AddressApi extends BaseApi {
|
|
21
|
+
/**
|
|
22
|
+
* Place autocomplete
|
|
23
|
+
* @param rq Request data
|
|
24
|
+
* @param payload Payload
|
|
25
|
+
* @returns Result
|
|
26
|
+
*/
|
|
27
|
+
autocomplete(
|
|
28
|
+
rq: PlaceQueryRQ,
|
|
29
|
+
payload?: IApiPayload<AddressAutocomplete[]>
|
|
30
|
+
) {
|
|
31
|
+
if (rq.query === '') return Promise.resolve(undefined);
|
|
32
|
+
rq.language ??= this.app.culture;
|
|
33
|
+
return this.api.post('Address/Autocomplete', rq, payload);
|
|
34
|
+
}
|
|
35
|
+
|
|
18
36
|
/**
|
|
19
37
|
* Get all continents
|
|
20
38
|
* @param isNumberKey Is number key or key as id
|
|
@@ -108,15 +126,7 @@ export class AddressApi extends BaseApi {
|
|
|
108
126
|
|
|
109
127
|
// Order by favoredIds
|
|
110
128
|
if (favoredIds.length > 0) {
|
|
111
|
-
regions = [...regions]
|
|
112
|
-
const n1 = favoredIds.indexOf(r1.id);
|
|
113
|
-
const n2 = favoredIds.indexOf(r2.id);
|
|
114
|
-
|
|
115
|
-
if (n1 === n2) return 0;
|
|
116
|
-
if (n1 === -1) return 1;
|
|
117
|
-
if (n2 === -1) return -1;
|
|
118
|
-
return n1 - n2;
|
|
119
|
-
});
|
|
129
|
+
regions = Utils.sortByFieldFavor([...regions], 'id', favoredIds);
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
// Return the top items
|
|
@@ -171,66 +181,118 @@ export class AddressApi extends BaseApi {
|
|
|
171
181
|
/**
|
|
172
182
|
* Get state list
|
|
173
183
|
* @param regionId Region id
|
|
184
|
+
* @param favoredIds Favored ids
|
|
174
185
|
* @param payload Payload
|
|
175
186
|
* @param culture Culture
|
|
176
187
|
* @returns Result
|
|
177
188
|
*/
|
|
178
|
-
states(
|
|
189
|
+
async states(
|
|
179
190
|
regionId: string,
|
|
191
|
+
favoredIds: string[] = [],
|
|
180
192
|
payload?: IApiPayload<AddressState[]>,
|
|
181
193
|
culture?: string
|
|
182
194
|
) {
|
|
195
|
+
if (regionId === '') return Promise.resolve(undefined);
|
|
196
|
+
|
|
183
197
|
payload ??= { defaultValue: [], showLoading: false };
|
|
184
198
|
culture ??= this.app.culture;
|
|
185
199
|
|
|
186
|
-
|
|
200
|
+
var items = await this.api.get(
|
|
187
201
|
`Address/StateList?regionId=${regionId}&language=${culture}`,
|
|
188
202
|
undefined,
|
|
189
203
|
payload
|
|
190
204
|
);
|
|
205
|
+
|
|
206
|
+
if (items == null || favoredIds.length === 0) return items;
|
|
207
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
191
208
|
}
|
|
192
209
|
|
|
193
210
|
/**
|
|
194
211
|
* Get city list
|
|
195
212
|
* @param stateId State id
|
|
213
|
+
* @param favoredIds Favored ids
|
|
196
214
|
* @param payload Payload
|
|
197
215
|
* @param culture Culture
|
|
216
|
+
*
|
|
198
217
|
* @returns Result
|
|
199
218
|
*/
|
|
200
|
-
cities(
|
|
219
|
+
async cities(
|
|
201
220
|
stateId: string,
|
|
221
|
+
favoredIds: number[] = [],
|
|
202
222
|
payload?: IApiPayload<AddressCity[]>,
|
|
203
223
|
culture?: string
|
|
204
224
|
) {
|
|
225
|
+
if (stateId === '') return Promise.resolve(undefined);
|
|
226
|
+
|
|
205
227
|
payload ??= { defaultValue: [], showLoading: false };
|
|
206
228
|
culture ??= this.app.culture;
|
|
207
229
|
|
|
208
|
-
|
|
230
|
+
const items = await this.api.get(
|
|
209
231
|
`Address/CityList?stateId=${stateId}&language=${culture}`,
|
|
210
232
|
undefined,
|
|
211
233
|
payload
|
|
212
234
|
);
|
|
235
|
+
|
|
236
|
+
if (items == null || favoredIds.length === 0) return items;
|
|
237
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
213
238
|
}
|
|
214
239
|
|
|
215
240
|
/**
|
|
216
241
|
* Get district list
|
|
217
242
|
* @param cityId City id
|
|
243
|
+
* @param favoredIds Favored ids
|
|
218
244
|
* @param payload Payload
|
|
219
245
|
* @param culture Culture
|
|
220
246
|
* @returns Result
|
|
221
247
|
*/
|
|
222
|
-
districts(
|
|
248
|
+
async districts(
|
|
223
249
|
cityId: number,
|
|
250
|
+
favoredIds: number[] = [],
|
|
224
251
|
payload?: IApiPayload<AddressDistrict[]>,
|
|
225
252
|
culture?: string
|
|
226
253
|
) {
|
|
254
|
+
if (cityId < 1) return Promise.resolve(undefined);
|
|
255
|
+
|
|
227
256
|
payload ??= { defaultValue: [], showLoading: false };
|
|
228
257
|
culture ??= this.app.culture;
|
|
229
258
|
|
|
230
|
-
|
|
259
|
+
const items = await this.api.get(
|
|
231
260
|
`Address/DistrictList?cityId=${cityId}&language=${culture}`,
|
|
232
261
|
undefined,
|
|
233
262
|
payload
|
|
234
263
|
);
|
|
264
|
+
|
|
265
|
+
if (items == null || favoredIds.length === 0) return items;
|
|
266
|
+
return Utils.sortByFieldFavor(items, 'id', favoredIds);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get place details
|
|
271
|
+
* @param placeId Place id
|
|
272
|
+
* @param language Language
|
|
273
|
+
* @param payload Payload
|
|
274
|
+
* @returns Result
|
|
275
|
+
*/
|
|
276
|
+
GetPlaceDetails(
|
|
277
|
+
placeId: string,
|
|
278
|
+
language?: string,
|
|
279
|
+
payload?: IApiPayload<AddressPlace>
|
|
280
|
+
) {
|
|
281
|
+
if (placeId === '') return Promise.resolve(undefined);
|
|
282
|
+
language ??= this.app.culture;
|
|
283
|
+
const url = `Address/GetPlaceDetails/${placeId}/${language}`;
|
|
284
|
+
return this.api.get(url, undefined, payload);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Place autocomplete
|
|
289
|
+
* @param rq Request data
|
|
290
|
+
* @param payload Payload
|
|
291
|
+
* @returns Result
|
|
292
|
+
*/
|
|
293
|
+
searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>) {
|
|
294
|
+
if (rq.query === '') return Promise.resolve(undefined);
|
|
295
|
+
rq.language ??= this.app.culture;
|
|
296
|
+
return this.api.post('Address/SearchPlace', rq, payload);
|
|
235
297
|
}
|
|
236
298
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AddressLocation } from '../../address/AddressLocation';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Place query output type
|
|
5
|
+
* 地址查询输出类型
|
|
6
|
+
*/
|
|
7
|
+
export enum PlaceQueryOutput {
|
|
8
|
+
JSON,
|
|
9
|
+
XML
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Place query request data
|
|
14
|
+
* 地址查询请求数据
|
|
15
|
+
*/
|
|
16
|
+
export type PlaceQueryRQ = {
|
|
17
|
+
/**
|
|
18
|
+
* Query address
|
|
19
|
+
* 查询地址
|
|
20
|
+
*/
|
|
21
|
+
query: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Output type
|
|
25
|
+
* 输出类型
|
|
26
|
+
*/
|
|
27
|
+
output?: PlaceQueryOutput;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Language
|
|
31
|
+
* 语言
|
|
32
|
+
*/
|
|
33
|
+
language?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Limited region / country id, like CN
|
|
37
|
+
* 限定的地区获国家编号
|
|
38
|
+
*/
|
|
39
|
+
region?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Center location
|
|
43
|
+
* 中心位置
|
|
44
|
+
*/
|
|
45
|
+
location?: AddressLocation;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Circle radius
|
|
49
|
+
* 方圆半径
|
|
50
|
+
*/
|
|
51
|
+
radius?: number;
|
|
52
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// address
|
|
2
|
+
export * from './address/AddressAutocomplete';
|
|
2
3
|
export * from './address/AddressCity';
|
|
3
4
|
export * from './address/AddressContinent';
|
|
4
5
|
export * from './address/AddressDistrict';
|
|
6
|
+
export * from './address/AddressLocation';
|
|
7
|
+
export * from './address/AddressPlace';
|
|
8
|
+
export * from './address/AddressPlaceBase';
|
|
5
9
|
export * from './address/AddressRegion';
|
|
6
10
|
export * from './address/AddressState';
|
|
7
11
|
export * from './address/AddressUtils';
|
|
@@ -49,6 +53,7 @@ export * from './erp/rq/LoginRQ';
|
|
|
49
53
|
export * from './erp/rq/MemberListRQ';
|
|
50
54
|
export * from './erp/rq/OrgListRQ';
|
|
51
55
|
export * from './erp/rq/OrgQueryRQ';
|
|
56
|
+
export * from './erp/rq/PlaceQueryRQ';
|
|
52
57
|
export * from './erp/rq/QueryRQ';
|
|
53
58
|
export * from './erp/rq/RefreshTokenRQ';
|
|
54
59
|
export * from './erp/rq/RegionsRQ';
|