@etsoo/appscript 1.5.64 → 1.5.65
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/.github/workflows/main.yml +6 -5
- package/__tests__/app/CoreApp.ts +141 -143
- package/__tests__/app/Culture.ts +23 -23
- package/__tests__/app/TestApp.ts +107 -105
- package/__tests__/business/BusinessUtils.ts +37 -37
- package/__tests__/result/ActionResult.ts +14 -14
- package/__tests__/tsconfig.json +16 -16
- package/lib/cjs/address/AddressAutocomplete.d.ts +1 -1
- package/lib/cjs/address/AddressPlace.d.ts +3 -3
- package/lib/cjs/address/AddressPlaceBase.d.ts +1 -1
- package/lib/cjs/address/AddressRegion.d.ts +2 -2
- package/lib/cjs/address/AddressRegion.js +12 -12
- package/lib/cjs/address/AddressUtils.d.ts +1 -1
- package/lib/cjs/api/AuthApi.d.ts +14 -14
- package/lib/cjs/api/AuthApi.js +17 -17
- package/lib/cjs/api/BaseApi.d.ts +1 -1
- package/lib/cjs/api/EntityApi.d.ts +8 -8
- package/lib/cjs/api/EntityApi.js +4 -4
- package/lib/cjs/api/dto/IdLabelDto.d.ts +1 -1
- package/lib/cjs/api/dto/IdLabelPrimaryDto.d.ts +1 -1
- package/lib/cjs/api/dto/ResultPayload.d.ts +2 -2
- package/lib/cjs/api/rq/AuthRequest.d.ts +1 -1
- package/lib/cjs/api/rq/LoginRQ.d.ts +2 -2
- package/lib/cjs/api/rq/MergeRQ.d.ts +1 -1
- package/lib/cjs/api/rq/QueryRQ.d.ts +2 -2
- package/lib/cjs/api/rq/StatusQueryRQ.d.ts +3 -3
- package/lib/cjs/api/rq/UpdateModel.d.ts +2 -2
- package/lib/cjs/api/rq/UpdateStatusRQ.d.ts +2 -2
- package/lib/cjs/app/AppSettings.d.ts +3 -3
- package/lib/cjs/bridges/FlutterHost.d.ts +2 -2
- package/lib/cjs/bridges/FlutterHost.js +11 -11
- package/lib/cjs/business/BusinessTax.js +6 -6
- package/lib/cjs/business/BusinessUtils.d.ts +2 -2
- package/lib/cjs/business/BusinessUtils.js +5 -5
- package/lib/cjs/business/Currency.d.ts +1 -1
- package/lib/cjs/business/Currency.js +10 -10
- package/lib/cjs/business/ProductUnit.d.ts +1 -1
- package/lib/cjs/business/ShoppingCart.d.ts +9 -9
- package/lib/cjs/business/ShoppingCart.js +11 -11
- package/lib/cjs/custom/CustomField.d.ts +1 -1
- package/lib/cjs/custom/CustomFieldData.d.ts +2 -2
- package/lib/cjs/i18n/Culture.d.ts +31 -0
- package/lib/cjs/i18n/Culture.js +51 -0
- package/lib/cjs/index.d.ts +1 -4
- package/lib/cjs/index.js +1 -4
- package/lib/cjs/result/ActionResult.d.ts +1 -1
- package/lib/cjs/result/ActionResultError.d.ts +1 -1
- package/lib/cjs/result/ActionResultError.js +3 -3
- package/lib/cjs/result/InitCallResult.d.ts +1 -1
- package/lib/cjs/state/Culture.d.ts +2 -2
- package/lib/cjs/state/User.d.ts +1 -1
- package/lib/mjs/address/AddressAutocomplete.d.ts +1 -1
- package/lib/mjs/address/AddressPlace.d.ts +3 -3
- package/lib/mjs/address/AddressPlaceBase.d.ts +1 -1
- package/lib/mjs/address/AddressRegion.d.ts +2 -2
- package/lib/mjs/address/AddressRegion.js +13 -13
- package/lib/mjs/address/AddressUtils.d.ts +1 -1
- package/lib/mjs/address/AddressUtils.js +1 -1
- package/lib/mjs/api/AuthApi.d.ts +14 -14
- package/lib/mjs/api/AuthApi.js +19 -19
- package/lib/mjs/api/BaseApi.d.ts +1 -1
- package/lib/mjs/api/EntityApi.d.ts +8 -8
- package/lib/mjs/api/EntityApi.js +5 -5
- package/lib/mjs/api/dto/IdLabelDto.d.ts +1 -1
- package/lib/mjs/api/dto/IdLabelPrimaryDto.d.ts +1 -1
- package/lib/mjs/api/dto/ResultPayload.d.ts +2 -2
- package/lib/mjs/api/rq/AuthRequest.d.ts +1 -1
- package/lib/mjs/api/rq/LoginRQ.d.ts +2 -2
- package/lib/mjs/api/rq/MergeRQ.d.ts +1 -1
- package/lib/mjs/api/rq/QueryRQ.d.ts +2 -2
- package/lib/mjs/api/rq/StatusQueryRQ.d.ts +3 -3
- package/lib/mjs/api/rq/UpdateModel.d.ts +2 -2
- package/lib/mjs/api/rq/UpdateStatusRQ.d.ts +2 -2
- package/lib/mjs/app/AppSettings.d.ts +3 -3
- package/lib/mjs/bridges/FlutterHost.d.ts +2 -2
- package/lib/mjs/bridges/FlutterHost.js +13 -13
- package/lib/mjs/business/BusinessTax.js +6 -6
- package/lib/mjs/business/BusinessUtils.d.ts +2 -2
- package/lib/mjs/business/BusinessUtils.js +5 -5
- package/lib/mjs/business/Currency.d.ts +1 -1
- package/lib/mjs/business/Currency.js +10 -10
- package/lib/mjs/business/ProductUnit.d.ts +1 -1
- package/lib/mjs/business/ProductUnit.js +1 -1
- package/lib/mjs/business/ShoppingCart.d.ts +9 -9
- package/lib/mjs/business/ShoppingCart.js +12 -12
- package/lib/mjs/custom/CustomField.d.ts +1 -1
- package/lib/mjs/custom/CustomFieldData.d.ts +2 -2
- package/lib/mjs/i18n/Culture.d.ts +31 -0
- package/lib/mjs/i18n/Culture.js +48 -0
- package/lib/mjs/index.d.ts +1 -4
- package/lib/mjs/index.js +1 -4
- package/lib/mjs/result/ActionResult.d.ts +1 -1
- package/lib/mjs/result/ActionResult.js +1 -1
- package/lib/mjs/result/ActionResultError.d.ts +1 -1
- package/lib/mjs/result/ActionResultError.js +3 -3
- package/lib/mjs/result/InitCallResult.d.ts +1 -1
- package/lib/mjs/state/Culture.d.ts +2 -2
- package/lib/mjs/state/User.d.ts +1 -1
- package/package.json +1 -1
- package/src/address/AddressAutocomplete.ts +16 -16
- package/src/address/AddressCity.ts +12 -12
- package/src/address/AddressContinent.ts +35 -35
- package/src/address/AddressDistrict.ts +12 -12
- package/src/address/AddressLocation.ts +8 -8
- package/src/address/AddressPlace.ts +23 -23
- package/src/address/AddressPlaceBase.ts +31 -31
- package/src/address/AddressRegion.ts +286 -286
- package/src/address/AddressState.ts +12 -12
- package/src/address/AddressUtils.ts +27 -27
- package/src/api/AuthApi.ts +194 -194
- package/src/api/BaseApi.ts +13 -13
- package/src/api/EntityApi.ts +181 -194
- package/src/api/dto/AntiforgeryRequestToken.ts +15 -15
- package/src/api/dto/ApiRefreshTokenDto.ts +16 -16
- package/src/api/dto/IdLabelDto.ts +3 -3
- package/src/api/dto/IdLabelPrimaryDto.ts +7 -7
- package/src/api/dto/InitCallDto.ts +12 -12
- package/src/api/dto/ResultPayload.ts +6 -6
- package/src/api/rq/ApiRefreshTokenRQ.ts +8 -8
- package/src/api/rq/AuthRequest.ts +40 -40
- package/src/api/rq/GetLogInUrlRQ.ts +8 -8
- package/src/api/rq/LoginIdRQ.ts +12 -12
- package/src/api/rq/LoginRQ.ts +18 -18
- package/src/api/rq/MergeRQ.ts +13 -13
- package/src/api/rq/QueryPagingData.ts +16 -16
- package/src/api/rq/QueryRQ.ts +22 -22
- package/src/api/rq/RefreshTokenRQ.ts +4 -4
- package/src/api/rq/ResetPasswordRQ.ts +20 -20
- package/src/api/rq/SignoutRQ.ts +8 -8
- package/src/api/rq/StatusQueryRQ.ts +11 -11
- package/src/api/rq/SwitchOrgRQ.ts +8 -8
- package/src/api/rq/TokenRQ.ts +4 -4
- package/src/api/rq/UpdateModel.ts +12 -12
- package/src/api/rq/UpdateStatusRQ.ts +10 -10
- package/src/app/AppSettings.ts +27 -27
- package/src/app/UserRole.ts +44 -44
- package/src/bridges/FlutterHost.ts +92 -97
- package/src/bridges/IBridgeHost.ts +49 -51
- package/src/business/ApiService.ts +25 -25
- package/src/business/BusinessTax.ts +63 -63
- package/src/business/BusinessUtils.ts +75 -75
- package/src/business/CultureItem.ts +43 -43
- package/src/business/Currency.ts +11 -11
- package/src/business/DataPrivacy.ts +35 -35
- package/src/business/EntityStatus.ts +44 -44
- package/src/business/ProductUnit.ts +58 -58
- package/src/business/RepeatOption.ts +50 -50
- package/src/business/ShoppingCart.ts +696 -706
- package/src/custom/CustomField.ts +20 -20
- package/src/custom/CustomFieldData.ts +43 -43
- package/src/def/ListItem.ts +12 -12
- package/src/i18n/Culture.ts +60 -0
- package/src/i18n/en.json +244 -244
- package/src/i18n/zh-Hans.json +244 -244
- package/src/i18n/zh-Hant.json +244 -244
- package/src/index.ts +1 -4
- package/src/result/ActionResult.ts +19 -19
- package/src/result/ActionResultError.ts +30 -30
- package/src/result/InitCallResult.ts +21 -21
- package/src/state/Culture.ts +3 -3
- package/src/state/State.ts +5 -5
- package/src/state/User.ts +92 -92
- package/lib/cjs/i18n/CultureUtils.d.ts +0 -13
- package/lib/cjs/i18n/CultureUtils.js +0 -32
- package/lib/cjs/i18n/en.d.ts +0 -6
- package/lib/cjs/i18n/en.js +0 -12
- package/lib/cjs/i18n/zhHans.d.ts +0 -6
- package/lib/cjs/i18n/zhHans.js +0 -12
- package/lib/cjs/i18n/zhHant.d.ts +0 -6
- package/lib/cjs/i18n/zhHant.js +0 -12
- package/lib/mjs/i18n/CultureUtils.d.ts +0 -13
- package/lib/mjs/i18n/CultureUtils.js +0 -29
- package/lib/mjs/i18n/en.d.ts +0 -6
- package/lib/mjs/i18n/en.js +0 -8
- package/lib/mjs/i18n/zhHans.d.ts +0 -6
- package/lib/mjs/i18n/zhHans.js +0 -8
- package/lib/mjs/i18n/zhHant.d.ts +0 -6
- package/lib/mjs/i18n/zhHant.js +0 -8
- package/src/i18n/CultureUtils.ts +0 -36
- package/src/i18n/en.ts +0 -10
- package/src/i18n/zhHans.ts +0 -10
- package/src/i18n/zhHant.ts +0 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTypes } from
|
|
2
|
-
import { AddressRegion } from
|
|
3
|
-
import { IExternalSettings } from
|
|
1
|
+
import { DataTypes } from "@etsoo/shared";
|
|
2
|
+
import { AddressRegion } from "../address/AddressRegion";
|
|
3
|
+
import { IExternalSettings } from "./ExternalSettings";
|
|
4
4
|
/**
|
|
5
5
|
* App settings interface
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataTypes } from
|
|
2
|
-
import { BridgeHostName, IBridgeHost } from
|
|
1
|
+
import { DataTypes } from "@etsoo/shared";
|
|
2
|
+
import { BridgeHostName, IBridgeHost } from "./IBridgeHost";
|
|
3
3
|
type CallHandlerType = (name: string, ...args: unknown[]) => PromiseLike<DataTypes.StringRecord | void>;
|
|
4
4
|
/**
|
|
5
5
|
* Flutter JavaScript Host
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExtendUtils } from
|
|
2
|
-
import { BridgeHostName } from
|
|
1
|
+
import { ExtendUtils } from "@etsoo/shared";
|
|
2
|
+
import { BridgeHostName } from "./IBridgeHost";
|
|
3
3
|
/**
|
|
4
4
|
* Flutter JavaScript Host
|
|
5
5
|
* https://inappwebview.dev/docs/javascript/communication/
|
|
@@ -19,7 +19,7 @@ export class FlutterHost {
|
|
|
19
19
|
* Cached commands
|
|
20
20
|
*/
|
|
21
21
|
this.cachedCommands = {};
|
|
22
|
-
window.addEventListener(
|
|
22
|
+
window.addEventListener("flutterInAppWebViewPlatformReady", (_event) => {
|
|
23
23
|
if (this.host.callHandler == null)
|
|
24
24
|
return;
|
|
25
25
|
for (const key in this.cachedCommands) {
|
|
@@ -37,18 +37,18 @@ export class FlutterHost {
|
|
|
37
37
|
}
|
|
38
38
|
changeCulture(locale) {
|
|
39
39
|
if (this.host.callHandler)
|
|
40
|
-
this.host.callHandler(
|
|
40
|
+
this.host.callHandler("changeCulture", locale);
|
|
41
41
|
else
|
|
42
|
-
this.cacheCommand(
|
|
42
|
+
this.cacheCommand("changeCulture", locale);
|
|
43
43
|
}
|
|
44
44
|
closable() {
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
exit() {
|
|
48
48
|
if (this.host.callHandler)
|
|
49
|
-
this.host.callHandler(
|
|
49
|
+
this.host.callHandler("exit");
|
|
50
50
|
else
|
|
51
|
-
this.cacheCommand(
|
|
51
|
+
this.cacheCommand("exit");
|
|
52
52
|
}
|
|
53
53
|
async getLabels(...keys) {
|
|
54
54
|
// Try 500 miliseconds
|
|
@@ -62,10 +62,10 @@ export class FlutterHost {
|
|
|
62
62
|
const init = {};
|
|
63
63
|
if (this.host.callHandler == null)
|
|
64
64
|
return init;
|
|
65
|
-
const result = (await this.host.callHandler(
|
|
65
|
+
const result = (await this.host.callHandler("getLabels")) ?? {};
|
|
66
66
|
return keys.reduce((a, v) => ({
|
|
67
67
|
...a,
|
|
68
|
-
[v]: result[v] ??
|
|
68
|
+
[v]: result[v] ?? ""
|
|
69
69
|
}), init);
|
|
70
70
|
}
|
|
71
71
|
getStartUrl() {
|
|
@@ -74,15 +74,15 @@ export class FlutterHost {
|
|
|
74
74
|
loadApp(name, startUrl) {
|
|
75
75
|
this.startUrl = startUrl;
|
|
76
76
|
if (this.host.callHandler)
|
|
77
|
-
this.host.callHandler(
|
|
77
|
+
this.host.callHandler("loadApp", name, startUrl);
|
|
78
78
|
else
|
|
79
|
-
this.cacheCommand(
|
|
79
|
+
this.cacheCommand("loadApp", name, startUrl);
|
|
80
80
|
}
|
|
81
81
|
userAuthorization(authorized) {
|
|
82
82
|
if (this.host.callHandler)
|
|
83
|
-
this.host.callHandler(
|
|
83
|
+
this.host.callHandler("userAuthorization", authorized);
|
|
84
84
|
else
|
|
85
|
-
this.cacheCommand(
|
|
85
|
+
this.cacheCommand("userAuthorization", authorized);
|
|
86
86
|
}
|
|
87
87
|
onUpdate(func) { }
|
|
88
88
|
setTitle(title) { }
|
|
@@ -20,7 +20,7 @@ export class BusinessTax {
|
|
|
20
20
|
* Get label key
|
|
21
21
|
*/
|
|
22
22
|
get labelKey() {
|
|
23
|
-
return
|
|
23
|
+
return "tax" + this.id + this.name;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -28,23 +28,23 @@ export class BusinessTax {
|
|
|
28
28
|
* Unified Social Credit Code (USCC) / 统一信用代码
|
|
29
29
|
* https://zh.wikisource.org/wiki/GB_32100-2015_%E6%B3%95%E4%BA%BA%E5%92%8C%E5%85%B6%E4%BB%96%E7%BB%84%E7%BB%87%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A0%81%E8%A7%84%E5%88%99
|
|
30
30
|
*/
|
|
31
|
-
BusinessTax.CN = new BusinessTax(
|
|
31
|
+
BusinessTax.CN = new BusinessTax("CN", "USCC", "*0-000000-**********");
|
|
32
32
|
/**
|
|
33
33
|
* NZ, Inland Revenue (IRD)
|
|
34
34
|
*/
|
|
35
|
-
BusinessTax.NZ = new BusinessTax(
|
|
35
|
+
BusinessTax.NZ = new BusinessTax("NZ", "IRD", "00[0]-000-000");
|
|
36
36
|
/**
|
|
37
37
|
* US, Employer Identification Number (EIN)
|
|
38
38
|
*/
|
|
39
|
-
BusinessTax.US = new BusinessTax(
|
|
39
|
+
BusinessTax.US = new BusinessTax("US", "EIN", "00-0000000");
|
|
40
40
|
/**
|
|
41
41
|
* CA, tax ID number (Business Number, BN)
|
|
42
42
|
*/
|
|
43
|
-
BusinessTax.CA = new BusinessTax(
|
|
43
|
+
BusinessTax.CA = new BusinessTax("CA", "BN", "000000000");
|
|
44
44
|
/**
|
|
45
45
|
* HK, Business Registration Number (BRN)
|
|
46
46
|
*/
|
|
47
|
-
BusinessTax.HK = new BusinessTax(
|
|
47
|
+
BusinessTax.HK = new BusinessTax("HK", "BRN", "00000000");
|
|
48
48
|
/**
|
|
49
49
|
* All countries and regions
|
|
50
50
|
*/
|
|
@@ -10,9 +10,9 @@ export var BusinessUtils;
|
|
|
10
10
|
* @param defaultTitle Default title
|
|
11
11
|
* @returns Result
|
|
12
12
|
*/
|
|
13
|
-
function formatAvatarTitle(title, maxChars = 3, defaultTitle =
|
|
13
|
+
function formatAvatarTitle(title, maxChars = 3, defaultTitle = "ME") {
|
|
14
14
|
// Just return for empty cases
|
|
15
|
-
if (title == null || title ===
|
|
15
|
+
if (title == null || title === "")
|
|
16
16
|
return defaultTitle;
|
|
17
17
|
// split with words
|
|
18
18
|
const items = title.trim().split(/\s+/g);
|
|
@@ -27,7 +27,7 @@ export var BusinessUtils;
|
|
|
27
27
|
// First letter of each item
|
|
28
28
|
var firstLetters = items
|
|
29
29
|
.map((item) => item[0])
|
|
30
|
-
.join(
|
|
30
|
+
.join("")
|
|
31
31
|
.toUpperCase();
|
|
32
32
|
const flen = firstLetters.length;
|
|
33
33
|
if (flen <= maxChars)
|
|
@@ -45,13 +45,13 @@ export var BusinessUtils;
|
|
|
45
45
|
const allCultures = data.cultures ?? [];
|
|
46
46
|
cultures.forEach((culture) => {
|
|
47
47
|
if (!allCultures.some((a) => a.id === culture.id)) {
|
|
48
|
-
allCultures.push({ id: culture.id, title:
|
|
48
|
+
allCultures.push({ id: culture.id, title: "" });
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
// Remove the default culture
|
|
52
52
|
allCultures.remove((a) => a.id === cultures[0].id);
|
|
53
53
|
// Sort
|
|
54
|
-
allCultures.sortByProperty(
|
|
54
|
+
allCultures.sortByProperty("id", cultures.map((c) => c.id));
|
|
55
55
|
// Set back
|
|
56
56
|
data.cultures = allCultures;
|
|
57
57
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Currency array
|
|
3
3
|
*/
|
|
4
4
|
export const Currencies = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
"AUD",
|
|
6
|
+
"CAD",
|
|
7
|
+
"CNY",
|
|
8
|
+
"EUR",
|
|
9
|
+
"GBP",
|
|
10
|
+
"HKD",
|
|
11
|
+
"JPY",
|
|
12
|
+
"NZD",
|
|
13
|
+
"SGD",
|
|
14
|
+
"USD"
|
|
15
15
|
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataTypes, IStorage, IdType } from
|
|
2
|
-
import { Currency } from
|
|
1
|
+
import { DataTypes, IStorage, IdType } from "@etsoo/shared";
|
|
2
|
+
import { Currency } from "./Currency";
|
|
3
3
|
/**
|
|
4
4
|
* Shopping cart owner
|
|
5
5
|
* 购物篮所有人
|
|
@@ -107,7 +107,7 @@ export type ShoppingCartItem = ShoppingCartItemBase & {
|
|
|
107
107
|
* Shopping cart change reason
|
|
108
108
|
* 购物篮改变原因
|
|
109
109
|
*/
|
|
110
|
-
export type ShoppingCartChangeReason =
|
|
110
|
+
export type ShoppingCartChangeReason = "add" | "clear" | "remove" | "title" | "update";
|
|
111
111
|
/**
|
|
112
112
|
* Shopping cart
|
|
113
113
|
* 购物篮
|
|
@@ -269,7 +269,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
269
269
|
* @param price Price
|
|
270
270
|
* @param overrideExisting Override existing price
|
|
271
271
|
*/
|
|
272
|
-
cachePrice(id: T[
|
|
272
|
+
cachePrice(id: T["id"], price: number, overrideExisting?: boolean): void;
|
|
273
273
|
/**
|
|
274
274
|
* Change currency
|
|
275
275
|
* @param currency Currency
|
|
@@ -296,7 +296,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
296
296
|
* @param id Item id
|
|
297
297
|
* @returns Result
|
|
298
298
|
*/
|
|
299
|
-
getItem(id: T[
|
|
299
|
+
getItem(id: T["id"]): T | undefined;
|
|
300
300
|
/**
|
|
301
301
|
* Push item
|
|
302
302
|
* 推送项目
|
|
@@ -343,7 +343,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
343
343
|
* @param itemCreator New item creator
|
|
344
344
|
* @returns Updated or not
|
|
345
345
|
*/
|
|
346
|
-
updateAssetItem(id: T[
|
|
346
|
+
updateAssetItem(id: T["id"], assetQty: number | undefined, itemCreator?: () => Omit<T, "id" | "price" | "assetQty" | "subtotal" | "discount" | "promotions">): boolean;
|
|
347
347
|
/**
|
|
348
348
|
* Update item
|
|
349
349
|
* 更新项目
|
|
@@ -352,17 +352,17 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
352
352
|
* @param itemCreator New item creator
|
|
353
353
|
* @returns Updated or not
|
|
354
354
|
*/
|
|
355
|
-
updateItem(id: T[
|
|
355
|
+
updateItem(id: T["id"], qty: number | undefined, itemCreator?: () => Omit<T, "id" | "price" | "qty" | "subtotal" | "discount" | "promotions">): boolean;
|
|
356
356
|
/**
|
|
357
357
|
* Update price
|
|
358
358
|
* @param id Item id
|
|
359
359
|
* @param price New price
|
|
360
360
|
*/
|
|
361
|
-
updatePrice(id: T[
|
|
361
|
+
updatePrice(id: T["id"], price: number): void;
|
|
362
362
|
/**
|
|
363
363
|
* Update title
|
|
364
364
|
* @param id Item id
|
|
365
365
|
* @param title New title
|
|
366
366
|
*/
|
|
367
|
-
updateTitle(id: T[
|
|
367
|
+
updateTitle(id: T["id"], title: string): void;
|
|
368
368
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NumberUtils, WindowStorage } from
|
|
2
|
-
const ShoppingCartKeyField =
|
|
1
|
+
import { NumberUtils, WindowStorage } from "@etsoo/shared";
|
|
2
|
+
const ShoppingCartKeyField = "ETSOO-CART-KEYS";
|
|
3
3
|
/**
|
|
4
4
|
* Shopping cart
|
|
5
5
|
* 购物篮
|
|
@@ -137,7 +137,7 @@ export class ShoppingCart {
|
|
|
137
137
|
const subtotal = this.items
|
|
138
138
|
.map((item) => item.subtotal - item.discount)
|
|
139
139
|
.sum();
|
|
140
|
-
const discount = this.promotions.sum(
|
|
140
|
+
const discount = this.promotions.sum("amount");
|
|
141
141
|
return subtotal - discount;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
@@ -203,7 +203,7 @@ export class ShoppingCart {
|
|
|
203
203
|
*/
|
|
204
204
|
addItems(items) {
|
|
205
205
|
this.items.push(...items);
|
|
206
|
-
this.doChange(
|
|
206
|
+
this.doChange("add", items);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Cache price
|
|
@@ -246,7 +246,7 @@ export class ShoppingCart {
|
|
|
246
246
|
ShoppingCart.clear(this.identifier, this.storage);
|
|
247
247
|
this.keys.remove(this.identifier);
|
|
248
248
|
}
|
|
249
|
-
this.doChange(
|
|
249
|
+
this.doChange("clear", []);
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
252
|
* Format amount
|
|
@@ -295,7 +295,7 @@ export class ShoppingCart {
|
|
|
295
295
|
*/
|
|
296
296
|
removeItem(index) {
|
|
297
297
|
const removedItems = this.items.splice(index, 1);
|
|
298
|
-
this.doChange(
|
|
298
|
+
this.doChange("remove", removedItems);
|
|
299
299
|
}
|
|
300
300
|
/**
|
|
301
301
|
* Reset item
|
|
@@ -346,14 +346,14 @@ export class ShoppingCart {
|
|
|
346
346
|
* 触发更新
|
|
347
347
|
*/
|
|
348
348
|
update() {
|
|
349
|
-
this.doChange(
|
|
349
|
+
this.doChange("update", []);
|
|
350
350
|
}
|
|
351
351
|
/**
|
|
352
352
|
* Update discount
|
|
353
353
|
* @param item Shopping cart item
|
|
354
354
|
*/
|
|
355
355
|
updateDiscount(item) {
|
|
356
|
-
item.discount = item.promotions.sum(
|
|
356
|
+
item.discount = item.promotions.sum("amount");
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
359
|
* Update asset item
|
|
@@ -400,7 +400,7 @@ export class ShoppingCart {
|
|
|
400
400
|
discount: 0
|
|
401
401
|
};
|
|
402
402
|
this.items.splice(index, 1, newItem);
|
|
403
|
-
this.doChange(
|
|
403
|
+
this.doChange("update", [item, newItem]);
|
|
404
404
|
}
|
|
405
405
|
return true;
|
|
406
406
|
}
|
|
@@ -451,7 +451,7 @@ export class ShoppingCart {
|
|
|
451
451
|
discount: 0
|
|
452
452
|
};
|
|
453
453
|
this.items.splice(index, 1, newItem);
|
|
454
|
-
this.doChange(
|
|
454
|
+
this.doChange("update", [item, newItem]);
|
|
455
455
|
}
|
|
456
456
|
return true;
|
|
457
457
|
}
|
|
@@ -473,7 +473,7 @@ export class ShoppingCart {
|
|
|
473
473
|
subtotal: price * qty * assetQty
|
|
474
474
|
};
|
|
475
475
|
this.items.splice(index, 1, newItem);
|
|
476
|
-
this.doChange(
|
|
476
|
+
this.doChange("update", [item, newItem]);
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
/**
|
|
@@ -489,7 +489,7 @@ export class ShoppingCart {
|
|
|
489
489
|
if (newItem.name === newItem.title)
|
|
490
490
|
newItem.title = undefined;
|
|
491
491
|
this.items.splice(index, 1, newItem);
|
|
492
|
-
this.doChange(
|
|
492
|
+
this.doChange("title", [item, newItem]);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IdType, ListType2 } from
|
|
1
|
+
import { IdType, ListType2 } from "@etsoo/shared";
|
|
2
2
|
/**
|
|
3
3
|
* Custom field space (12 columns)
|
|
4
4
|
* 自定义字段空间(12列)
|
|
5
5
|
*/
|
|
6
|
-
export type CustomFieldSpace =
|
|
6
|
+
export type CustomFieldSpace = "quater" | "half" | "half1" | "full" | "five" | "seven";
|
|
7
7
|
/**
|
|
8
8
|
* Custom field data
|
|
9
9
|
* 自定义字段数据
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DataTypes, DomUtils } from "@etsoo/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Culture namespace
|
|
4
|
+
*/
|
|
5
|
+
export declare namespace Culture {
|
|
6
|
+
/**
|
|
7
|
+
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
9
|
+
* @param resources Resources
|
|
10
|
+
* @returns Culture
|
|
11
|
+
*/
|
|
12
|
+
function make(cultureMaker: typeof DomUtils.zhHans, ...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
13
|
+
/**
|
|
14
|
+
* Get en neutral culture
|
|
15
|
+
* @param localResources Local resources
|
|
16
|
+
* @returns Full culture
|
|
17
|
+
*/
|
|
18
|
+
const en: (...resources: (object | (() => Promise<object>))[]) => DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
19
|
+
/**
|
|
20
|
+
* Get zh-Hans neutral cultrue
|
|
21
|
+
* @param localResources Local resources
|
|
22
|
+
* @returns Full culture
|
|
23
|
+
*/
|
|
24
|
+
const zhHans: (...resources: (object | (() => Promise<object>))[]) => DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
25
|
+
/**
|
|
26
|
+
* Get zh-Hant neutral cultrue
|
|
27
|
+
* @param localResources Local resources
|
|
28
|
+
* @returns Full culture
|
|
29
|
+
*/
|
|
30
|
+
const zhHant: (...resources: (object | (() => Promise<object>))[]) => DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DomUtils } from "@etsoo/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Culture namespace
|
|
4
|
+
*/
|
|
5
|
+
export var Culture;
|
|
6
|
+
(function (Culture) {
|
|
7
|
+
/**
|
|
8
|
+
* Make culture
|
|
9
|
+
* @param cultureMaker Culture maker
|
|
10
|
+
* @param resources Resources
|
|
11
|
+
* @returns Culture
|
|
12
|
+
*/
|
|
13
|
+
function make(cultureMaker, ...resources) {
|
|
14
|
+
return cultureMaker(async () => {
|
|
15
|
+
const rs = await Promise.all(resources.map((resource) => new Promise((resolve) => {
|
|
16
|
+
if (typeof resource === "object") {
|
|
17
|
+
resolve(resource);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
resource().then((result) => resolve(result));
|
|
21
|
+
}
|
|
22
|
+
})));
|
|
23
|
+
return rs.reduce((prev, curr) => ({
|
|
24
|
+
...prev,
|
|
25
|
+
...curr
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
Culture.make = make;
|
|
30
|
+
/**
|
|
31
|
+
* Get en neutral culture
|
|
32
|
+
* @param localResources Local resources
|
|
33
|
+
* @returns Full culture
|
|
34
|
+
*/
|
|
35
|
+
Culture.en = (...resources) => make(DomUtils.en, import("./en.json"), ...resources);
|
|
36
|
+
/**
|
|
37
|
+
* Get zh-Hans neutral cultrue
|
|
38
|
+
* @param localResources Local resources
|
|
39
|
+
* @returns Full culture
|
|
40
|
+
*/
|
|
41
|
+
Culture.zhHans = (...resources) => make(DomUtils.zhHans, import("./zh-Hans.json"), ...resources);
|
|
42
|
+
/**
|
|
43
|
+
* Get zh-Hant neutral cultrue
|
|
44
|
+
* @param localResources Local resources
|
|
45
|
+
* @returns Full culture
|
|
46
|
+
*/
|
|
47
|
+
Culture.zhHant = (...resources) => make(DomUtils.zhHant, import("./zh-Hant.json"), ...resources);
|
|
48
|
+
})(Culture || (Culture = {}));
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -55,10 +55,7 @@ export * from "./business/ShoppingCart";
|
|
|
55
55
|
export * from "./custom/CustomField";
|
|
56
56
|
export * from "./custom/CustomFieldData";
|
|
57
57
|
export * from "./def/ListItem";
|
|
58
|
-
export * from "./i18n/
|
|
59
|
-
export * from "./i18n/en";
|
|
60
|
-
export * from "./i18n/zhHans";
|
|
61
|
-
export * from "./i18n/zhHant";
|
|
58
|
+
export * from "./i18n/Culture";
|
|
62
59
|
export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from "@etsoo/restclient";
|
|
63
60
|
export type { IApi, IApiPayload } from "@etsoo/restclient";
|
|
64
61
|
export * from "./result/ActionResult";
|
package/lib/mjs/index.js
CHANGED
|
@@ -63,10 +63,7 @@ export * from "./custom/CustomFieldData";
|
|
|
63
63
|
// def
|
|
64
64
|
export * from "./def/ListItem";
|
|
65
65
|
// i18n
|
|
66
|
-
export * from "./i18n/
|
|
67
|
-
export * from "./i18n/en";
|
|
68
|
-
export * from "./i18n/zhHans";
|
|
69
|
-
export * from "./i18n/zhHant";
|
|
66
|
+
export * from "./i18n/Culture";
|
|
70
67
|
// @etsoo/restclient
|
|
71
68
|
export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from "@etsoo/restclient";
|
|
72
69
|
// result
|
|
@@ -15,8 +15,8 @@ export class ActionResultError extends Error {
|
|
|
15
15
|
addtions.push(result.type);
|
|
16
16
|
if (result.field)
|
|
17
17
|
addtions.push(result.field);
|
|
18
|
-
const add = addtions.length > 0 ? ` (${addtions.join(
|
|
19
|
-
return `${result.title ||
|
|
18
|
+
const add = addtions.length > 0 ? ` (${addtions.join(", ")})` : "";
|
|
19
|
+
return `${result.title || "Error"}${add}`;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Constructor
|
|
@@ -26,7 +26,7 @@ export class ActionResultError extends Error {
|
|
|
26
26
|
// Super
|
|
27
27
|
super(ActionResultError.format(result));
|
|
28
28
|
// Name
|
|
29
|
-
this.name =
|
|
29
|
+
this.name = "ActionResultError";
|
|
30
30
|
// Hold the result
|
|
31
31
|
this.result = result;
|
|
32
32
|
}
|
package/lib/mjs/state/User.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { AddressPlaceBase } from
|
|
1
|
+
import { AddressPlaceBase } from "./AddressPlaceBase";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Address autocomplete
|
|
5
5
|
* 地点自动填充
|
|
6
6
|
*/
|
|
7
7
|
export type AddressAutocomplete = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Place id
|
|
10
|
+
* 地点编号
|
|
11
|
+
*/
|
|
12
|
+
placeId: string;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Name
|
|
16
|
+
* 名称
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Place data
|
|
22
|
+
* 地点数据
|
|
23
|
+
*/
|
|
24
|
+
place?: AddressPlaceBase;
|
|
25
25
|
};
|