@etsoo/appscript 1.3.33 → 1.3.34
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 -4
- package/lib/cjs/address/AddressContinent.d.ts +1 -1
- package/lib/cjs/address/AddressRegion.d.ts +7 -1
- package/lib/cjs/address/AddressRegion.js +21 -20
- package/lib/cjs/address/AddressState.d.ts +1 -1
- package/lib/cjs/app/CoreApp.js +45 -45
- package/lib/cjs/app/IApp.d.ts +2 -2
- package/lib/cjs/bridges/FlutterHost.d.ts +2 -1
- package/lib/cjs/bridges/FlutterHost.js +1 -0
- package/lib/cjs/bridges/IBridgeHost.d.ts +5 -0
- package/lib/cjs/business/BusinessTax.js +6 -6
- package/lib/cjs/business/Currency.d.ts +1 -1
- package/lib/cjs/business/ProductUnit.d.ts +1 -1
- package/lib/cjs/def/ListItem.d.ts +1 -1
- package/lib/cjs/erp/AddressApi.d.ts +16 -2
- package/lib/cjs/erp/AddressApi.js +43 -12
- package/lib/cjs/erp/BaseApi.js +6 -6
- package/lib/cjs/erp/dto/AuditLineDto.d.ts +3 -3
- package/lib/cjs/erp/dto/CurrencyDto.d.ts +1 -1
- package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +1 -1
- package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
- package/lib/cjs/erp/dto/IdLabelDto.d.ts +1 -1
- package/lib/cjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
- package/lib/cjs/erp/dto/InitCallDto.d.ts +1 -1
- package/lib/cjs/erp/dto/OrgDto.d.ts +1 -1
- package/lib/cjs/erp/dto/OrgQueryDto.d.ts +1 -1
- package/lib/cjs/erp/dto/PublicProductDto.d.ts +2 -2
- package/lib/cjs/erp/dto/ResultPayload.d.ts +3 -3
- package/lib/cjs/erp/rq/MemberListRQ.d.ts +1 -1
- package/lib/cjs/erp/rq/OrgListRQ.d.ts +1 -1
- package/lib/cjs/erp/rq/OrgQueryRQ.d.ts +1 -1
- package/lib/cjs/erp/rq/QueryRQ.d.ts +1 -1
- package/lib/cjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
- package/lib/cjs/erp/rq/RegionsRQ.d.ts +14 -0
- package/lib/cjs/erp/rq/RegionsRQ.js +2 -0
- package/lib/cjs/erp/rq/TiplistRQ.d.ts +1 -1
- package/lib/cjs/i18n/en-US.json +1 -0
- package/lib/cjs/i18n/zh-CN.json +1 -0
- package/lib/cjs/i18n/zh-HK.json +1 -0
- package/lib/cjs/result/ActionResultError.js +12 -12
- package/lib/cjs/result/IActionResult.d.ts +2 -2
- package/lib/cjs/result/InitCallResult.d.ts +1 -1
- package/lib/cjs/state/User.d.ts +1 -1
- package/lib/mjs/address/AddressContinent.d.ts +1 -1
- package/lib/mjs/address/AddressRegion.d.ts +7 -1
- package/lib/mjs/address/AddressRegion.js +21 -20
- package/lib/mjs/address/AddressState.d.ts +1 -1
- package/lib/mjs/app/CoreApp.js +45 -45
- package/lib/mjs/app/IApp.d.ts +2 -2
- package/lib/mjs/bridges/FlutterHost.d.ts +2 -1
- package/lib/mjs/bridges/FlutterHost.js +1 -0
- package/lib/mjs/bridges/IBridgeHost.d.ts +5 -0
- package/lib/mjs/business/BusinessTax.js +6 -6
- package/lib/mjs/business/Currency.d.ts +1 -1
- package/lib/mjs/business/ProductUnit.d.ts +1 -1
- package/lib/mjs/def/ListItem.d.ts +1 -1
- package/lib/mjs/erp/AddressApi.d.ts +16 -2
- package/lib/mjs/erp/AddressApi.js +43 -12
- package/lib/mjs/erp/BaseApi.js +6 -6
- package/lib/mjs/erp/dto/AuditLineDto.d.ts +3 -3
- package/lib/mjs/erp/dto/CurrencyDto.d.ts +1 -1
- package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +1 -1
- package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
- package/lib/mjs/erp/dto/IdLabelDto.d.ts +1 -1
- package/lib/mjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
- package/lib/mjs/erp/dto/InitCallDto.d.ts +1 -1
- package/lib/mjs/erp/dto/OrgDto.d.ts +1 -1
- package/lib/mjs/erp/dto/OrgQueryDto.d.ts +1 -1
- package/lib/mjs/erp/dto/PublicProductDto.d.ts +2 -2
- package/lib/mjs/erp/dto/ResultPayload.d.ts +3 -3
- package/lib/mjs/erp/rq/MemberListRQ.d.ts +1 -1
- package/lib/mjs/erp/rq/OrgListRQ.d.ts +1 -1
- package/lib/mjs/erp/rq/OrgQueryRQ.d.ts +1 -1
- package/lib/mjs/erp/rq/QueryRQ.d.ts +1 -1
- package/lib/mjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
- package/lib/mjs/erp/rq/RegionsRQ.d.ts +14 -0
- package/lib/mjs/erp/rq/RegionsRQ.js +1 -0
- package/lib/mjs/erp/rq/TiplistRQ.d.ts +1 -1
- package/lib/mjs/i18n/en-US.json +1 -0
- package/lib/mjs/i18n/zh-CN.json +1 -0
- package/lib/mjs/i18n/zh-HK.json +1 -0
- package/lib/mjs/result/ActionResultError.js +12 -12
- package/lib/mjs/result/IActionResult.d.ts +2 -2
- package/lib/mjs/result/InitCallResult.d.ts +1 -1
- package/lib/mjs/state/User.d.ts +1 -1
- package/package.json +8 -8
- package/src/address/AddressRegion.ts +29 -10
- package/src/bridges/FlutterHost.ts +2 -0
- package/src/bridges/IBridgeHost.ts +6 -0
- package/src/erp/AddressApi.ts +72 -25
- package/src/erp/rq/RegionsRQ.ts +16 -0
- package/src/i18n/en-US.json +1 -0
- package/src/i18n/zh-CN.json +1 -0
- package/src/i18n/zh-HK.json +1 -0
package/src/erp/AddressApi.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { AddressState } from '../address/AddressState';
|
|
|
5
5
|
import { IdLabelConditional } from './dto/IdLabelDto';
|
|
6
6
|
import { BaseApi } from './BaseApi';
|
|
7
7
|
import { IApiPayload } from '@etsoo/restclient';
|
|
8
|
+
import { RegionsRQ } from './rq/RegionsRQ';
|
|
9
|
+
|
|
10
|
+
const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Address Api
|
|
@@ -13,19 +16,21 @@ export class AddressApi extends BaseApi {
|
|
|
13
16
|
/**
|
|
14
17
|
* Get all continents
|
|
15
18
|
* @param isNumberKey Is number key or key as id
|
|
19
|
+
* @param includeAntarctica Include Antarctica or not
|
|
16
20
|
* @returns Continents
|
|
17
21
|
*/
|
|
18
|
-
|
|
19
|
-
isNumberKey = <T>false
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
continents<T extends boolean>(
|
|
23
|
+
isNumberKey = <T>false,
|
|
24
|
+
includeAntarctica: boolean = false
|
|
25
|
+
): IdLabelConditional<T> {
|
|
26
|
+
return <IdLabelConditional<T>>DataTypes.getEnumKeys(AddressContinent)
|
|
27
|
+
.filter((item) => includeAntarctica || item !== 'AN')
|
|
28
|
+
.map((key) => ({
|
|
29
|
+
id: isNumberKey
|
|
30
|
+
? <number>DataTypes.getEnumByKey(AddressContinent, key)!
|
|
31
|
+
: key.toString(),
|
|
32
|
+
label: this.getContinentLabel(key)
|
|
33
|
+
}));
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
/**
|
|
@@ -37,27 +42,69 @@ export class AddressApi extends BaseApi {
|
|
|
37
42
|
return this.app.get('continent' + id) ?? (id as string);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
regions(isRemote: true): Promise<AddressRegionDb[] | undefined>;
|
|
41
|
-
regions(): AddressRegion[];
|
|
42
|
-
|
|
43
45
|
/**
|
|
44
|
-
* Get
|
|
45
|
-
* @param
|
|
46
|
-
* @returns Result
|
|
46
|
+
* Get all regions
|
|
47
|
+
* @param rq Rquest data
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
async getRegions(rq?: RegionsRQ): Promise<AddressRegionDb[] | undefined> {
|
|
50
|
+
const culture = this.app.culture;
|
|
51
|
+
let regions = cachedRegions[culture];
|
|
52
|
+
if (regions == null) {
|
|
53
|
+
regions = await this.api.get<AddressRegionDb[]>(
|
|
54
|
+
`Address/RegionList?language=${culture}`,
|
|
52
55
|
undefined,
|
|
53
56
|
{ defaultValue: [], showLoading: false }
|
|
54
57
|
);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (regions == null) return undefined;
|
|
59
|
+
cachedRegions[culture] = regions;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { favoredIds = [], items = 8, keyword } = rq ?? {};
|
|
63
|
+
|
|
64
|
+
// Keyword filter
|
|
65
|
+
if (keyword)
|
|
66
|
+
regions = regions.filter(
|
|
67
|
+
(region) =>
|
|
68
|
+
region.label.includes(keyword) || region.id === keyword
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Order by favoredIds
|
|
72
|
+
if (favoredIds.length > 0) {
|
|
73
|
+
regions = [...regions].sort((r1, r2) => {
|
|
74
|
+
const n1 = favoredIds.indexOf(r1.id);
|
|
75
|
+
const n2 = favoredIds.indexOf(r2.id);
|
|
76
|
+
|
|
77
|
+
if (n1 === n2) return 0;
|
|
78
|
+
if (n1 === -1) return 1;
|
|
79
|
+
if (n2 === -1) return -1;
|
|
80
|
+
return n1 - n2;
|
|
59
81
|
});
|
|
60
82
|
}
|
|
83
|
+
|
|
84
|
+
// Return the top items
|
|
85
|
+
return regions.slice(0, items);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get all local regions
|
|
90
|
+
*/
|
|
91
|
+
regions(): AddressRegion[];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get all local regions limited to favored ids
|
|
95
|
+
* @param favoredIds Favored ids
|
|
96
|
+
*/
|
|
97
|
+
regions(favoredIds: string[]): AddressRegion[];
|
|
98
|
+
|
|
99
|
+
regions(p?: string[]) {
|
|
100
|
+
const items =
|
|
101
|
+
p == null || p.length === 0
|
|
102
|
+
? AddressRegion.all
|
|
103
|
+
: AddressRegion.all.filter((ad) => p.includes(ad.id));
|
|
104
|
+
return items.map((region) => ({
|
|
105
|
+
...region,
|
|
106
|
+
label: this.app.getRegionLabel(region.id)
|
|
107
|
+
}));
|
|
61
108
|
}
|
|
62
109
|
|
|
63
110
|
/**
|
package/src/i18n/en-US.json
CHANGED
package/src/i18n/zh-CN.json
CHANGED