@pisell/pisellos 0.0.10 → 0.0.13
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/dist/modules/Account/index.d.ts +4 -2
- package/dist/modules/Account/index.js +23 -36
- package/dist/modules/Account/types.d.ts +1 -0
- package/dist/modules/AccountList/index.d.ts +2 -0
- package/dist/modules/AccountList/index.js +34 -11
- package/dist/modules/Cart/index.d.ts +17 -11
- package/dist/modules/Cart/index.js +179 -121
- package/dist/modules/Cart/types.d.ts +98 -9
- package/dist/modules/Cart/types.js +8 -0
- package/dist/modules/Cart/utils.d.ts +114 -0
- package/dist/modules/Cart/utils.js +345 -0
- package/dist/modules/Date/index.d.ts +11 -12
- package/dist/modules/Date/index.js +104 -60
- package/dist/modules/Date/types.d.ts +51 -20
- package/dist/modules/Date/types.js +2 -5
- package/dist/modules/Date/utils.d.ts +35 -0
- package/dist/modules/Date/utils.js +211 -0
- package/dist/modules/Discount/index.d.ts +26 -0
- package/dist/modules/Discount/index.js +234 -0
- package/dist/modules/Discount/types.d.ts +66 -0
- package/dist/modules/Discount/types.js +5 -0
- package/dist/modules/Order/index.d.ts +16 -12
- package/dist/modules/Order/index.js +38 -166
- package/dist/modules/Order/types.d.ts +18 -41
- package/dist/modules/Order/types.js +0 -14
- package/dist/modules/Payment/index.d.ts +0 -2
- package/dist/modules/Payment/index.js +45 -76
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Product/types.d.ts +48 -1
- package/dist/modules/ProductList/index.d.ts +1 -0
- package/dist/modules/ProductList/index.js +21 -1
- package/dist/modules/ProductList/types.d.ts +1 -0
- package/dist/modules/Resource/types.d.ts +6 -2
- package/dist/modules/Rules/index.d.ts +32 -0
- package/dist/modules/Rules/index.js +423 -0
- package/dist/modules/Rules/types.d.ts +46 -0
- package/dist/modules/Rules/types.js +5 -0
- package/dist/modules/Summary/index.d.ts +13 -0
- package/dist/modules/Summary/index.js +80 -0
- package/dist/modules/Summary/types.d.ts +13 -0
- package/dist/modules/Summary/types.js +1 -0
- package/dist/modules/Summary/utils.d.ts +19 -0
- package/dist/modules/Summary/utils.js +56 -0
- package/dist/plugins/index.d.ts +3 -2
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/request.d.ts +4 -3
- package/dist/plugins/request.js +30 -30
- package/dist/plugins/shopStore.d.ts +4 -0
- package/dist/plugins/shopStore.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +73 -12
- package/dist/solution/BookingByStep/index.js +635 -99
- package/dist/solution/BookingByStep/types.d.ts +2 -0
- package/dist/solution/BookingByStep/types.js +11 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/products.js +47 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/dist/solution/BookingByStep/utils/resources.js +144 -79
- package/dist/solution/ShopDiscount/index.d.ts +50 -0
- package/dist/solution/ShopDiscount/index.js +546 -0
- package/dist/solution/ShopDiscount/types.d.ts +24 -0
- package/dist/solution/ShopDiscount/types.js +10 -0
- package/dist/solution/ShopDiscount/utils.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +7 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Account/index.d.ts +4 -2
- package/lib/modules/Account/index.js +14 -3
- package/lib/modules/Account/types.d.ts +1 -0
- package/lib/modules/AccountList/index.d.ts +2 -0
- package/lib/modules/AccountList/index.js +17 -0
- package/lib/modules/Cart/index.d.ts +17 -11
- package/lib/modules/Cart/index.js +72 -21
- package/lib/modules/Cart/types.d.ts +98 -9
- package/lib/modules/Cart/utils.d.ts +114 -0
- package/lib/modules/Cart/utils.js +320 -0
- package/lib/modules/Date/index.d.ts +11 -12
- package/lib/modules/Date/index.js +50 -31
- package/lib/modules/Date/types.d.ts +51 -20
- package/lib/modules/Date/types.js +0 -4
- package/lib/modules/Date/utils.d.ts +35 -0
- package/lib/modules/Date/utils.js +167 -0
- package/lib/modules/Discount/index.d.ts +26 -0
- package/lib/modules/Discount/index.js +118 -0
- package/lib/modules/Discount/types.d.ts +66 -0
- package/lib/modules/Discount/types.js +33 -0
- package/lib/modules/Order/index.d.ts +16 -12
- package/lib/modules/Order/index.js +23 -51
- package/lib/modules/Order/types.d.ts +18 -41
- package/lib/modules/Payment/index.d.ts +0 -2
- package/lib/modules/Payment/index.js +6 -17
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Product/types.d.ts +48 -1
- package/lib/modules/ProductList/index.d.ts +1 -0
- package/lib/modules/ProductList/index.js +4 -0
- package/lib/modules/ProductList/types.d.ts +1 -0
- package/lib/modules/Resource/types.d.ts +6 -2
- package/lib/modules/Rules/index.d.ts +32 -0
- package/lib/modules/Rules/index.js +283 -0
- package/lib/modules/Rules/types.d.ts +46 -0
- package/lib/modules/Rules/types.js +33 -0
- package/lib/modules/Summary/index.d.ts +13 -0
- package/lib/modules/Summary/index.js +49 -0
- package/lib/modules/Summary/types.d.ts +13 -0
- package/lib/modules/Summary/types.js +17 -0
- package/lib/modules/Summary/utils.d.ts +19 -0
- package/lib/modules/Summary/utils.js +79 -0
- package/lib/plugins/index.d.ts +3 -2
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/request.d.ts +4 -3
- package/lib/plugins/request.js +4 -20
- package/lib/plugins/shopStore.d.ts +4 -0
- package/lib/plugins/shopStore.js +17 -0
- package/lib/solution/BookingByStep/index.d.ts +73 -12
- package/lib/solution/BookingByStep/index.js +451 -24
- package/lib/solution/BookingByStep/types.d.ts +2 -0
- package/lib/solution/BookingByStep/types.js +3 -0
- package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/products.js +60 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/lib/solution/BookingByStep/utils/resources.js +106 -49
- package/lib/solution/ShopDiscount/index.d.ts +50 -0
- package/lib/solution/ShopDiscount/index.js +321 -0
- package/lib/solution/ShopDiscount/types.d.ts +24 -0
- package/lib/solution/ShopDiscount/types.js +38 -0
- package/lib/solution/ShopDiscount/utils.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +32 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +4 -4
|
@@ -34,12 +34,14 @@ var AccountModule = class extends import_BaseModule.BaseModule {
|
|
|
34
34
|
this.isGuest = false;
|
|
35
35
|
this.store = {
|
|
36
36
|
currentAccount: null,
|
|
37
|
-
isLoggedIn: false
|
|
37
|
+
isLoggedIn: false,
|
|
38
|
+
active: false
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
async initialize(core, options) {
|
|
41
42
|
this.core = core;
|
|
42
43
|
this.store = options == null ? void 0 : options.store;
|
|
44
|
+
this.store.isLoggedIn = false;
|
|
43
45
|
}
|
|
44
46
|
getId() {
|
|
45
47
|
var _a;
|
|
@@ -92,14 +94,23 @@ var AccountModule = class extends import_BaseModule.BaseModule {
|
|
|
92
94
|
}
|
|
93
95
|
async updatePassword(oldPassword, newPassword) {
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
getLoginStatus() {
|
|
96
98
|
return this.store.isLoggedIn;
|
|
97
99
|
}
|
|
98
|
-
|
|
100
|
+
getAccount() {
|
|
99
101
|
return this.store.currentAccount;
|
|
100
102
|
}
|
|
101
103
|
setAccountInfo(account) {
|
|
102
104
|
this.store.currentAccount = account;
|
|
105
|
+
if (account.isGuest) {
|
|
106
|
+
this.isGuest = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
setActive(active) {
|
|
110
|
+
this.store.active = active;
|
|
111
|
+
}
|
|
112
|
+
isActive() {
|
|
113
|
+
return this.store.active;
|
|
103
114
|
}
|
|
104
115
|
};
|
|
105
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -15,4 +15,6 @@ export declare class AccountListModule extends BaseModule implements Module {
|
|
|
15
15
|
getAccount(id: string): AccountModule | null;
|
|
16
16
|
clearAccounts(): Promise<void>;
|
|
17
17
|
getState(): AccountListState;
|
|
18
|
+
setActiveAccount(id: string | number): void;
|
|
19
|
+
getActiveAccount(): AccountModule | null;
|
|
18
20
|
}
|
|
@@ -50,9 +50,14 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
|
|
|
50
50
|
}
|
|
51
51
|
const accountModule = new import_Account.AccountModule(`account_${account.id}`);
|
|
52
52
|
this.core.registerModule(accountModule);
|
|
53
|
+
accountModule.setAccountInfo(account);
|
|
53
54
|
this.store.accounts = [...this.store.accounts, accountModule];
|
|
54
55
|
await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
|
|
56
|
+
if (this.store.accounts.length === 1) {
|
|
57
|
+
this.setActiveAccount(accountModule.getId());
|
|
58
|
+
}
|
|
55
59
|
} catch (error) {
|
|
60
|
+
console.error(error);
|
|
56
61
|
this.store.error = error instanceof Error ? error.message : "Failed to add account";
|
|
57
62
|
await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
|
|
58
63
|
} finally {
|
|
@@ -119,6 +124,18 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
|
|
|
119
124
|
getState() {
|
|
120
125
|
return { ...this.store };
|
|
121
126
|
}
|
|
127
|
+
setActiveAccount(id) {
|
|
128
|
+
this.store.accounts.forEach((account) => {
|
|
129
|
+
if (account.getId() === id) {
|
|
130
|
+
account.setActive(true);
|
|
131
|
+
} else {
|
|
132
|
+
account.setActive(false);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getActiveAccount() {
|
|
137
|
+
return this.store.accounts.find((account) => account.isActive()) || null;
|
|
138
|
+
}
|
|
122
139
|
};
|
|
123
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
141
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Module, PisellCore, ModuleOptions } from
|
|
2
|
-
import { BaseModule } from
|
|
3
|
-
import { CartItem, CartModuleAPI } from
|
|
4
|
-
export * from
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from "../../types";
|
|
2
|
+
import { BaseModule } from "../BaseModule";
|
|
3
|
+
import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from "./types";
|
|
4
|
+
export * from "./types";
|
|
5
5
|
/**
|
|
6
6
|
* 购物车模块实现
|
|
7
7
|
*/
|
|
@@ -18,18 +18,24 @@ export declare class CartModule extends BaseModule implements Module {
|
|
|
18
18
|
*/
|
|
19
19
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* 添加商品到购物车
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
addItem(params: IAddItemParams): Promise<void>;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* 更新购物车信息
|
|
26
|
+
*/
|
|
27
|
+
updateItem(params: IUpdateItemParams): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* 批量设置购物车数据
|
|
26
30
|
*/
|
|
27
|
-
|
|
31
|
+
batchSetItems(items: CartItem[]): Promise<void>;
|
|
28
32
|
getItemCount(): number;
|
|
29
33
|
getTotalPrice(): number;
|
|
30
|
-
getItems():
|
|
31
|
-
updateItem(id: string, item: CartItem): Promise<void>;
|
|
34
|
+
getItems(): CartItem[];
|
|
32
35
|
removeItem(id: string): Promise<void>;
|
|
33
36
|
storeTemp(key: string, value: any): Promise<void>;
|
|
34
|
-
getTemp(key?: string):
|
|
37
|
+
getTemp(key?: string): any;
|
|
38
|
+
clear(): void;
|
|
39
|
+
clearCartByAccount(account_id: string): void;
|
|
40
|
+
getCartByAccount(account_id: string | number): CartItem[];
|
|
35
41
|
}
|
|
@@ -25,6 +25,7 @@ __export(Cart_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(Cart_exports);
|
|
26
26
|
var import_BaseModule = require("../BaseModule");
|
|
27
27
|
var import_types = require("./types");
|
|
28
|
+
var import_utils = require("./utils");
|
|
28
29
|
__reExport(Cart_exports, require("./types"), module.exports);
|
|
29
30
|
var CartModule = class extends import_BaseModule.BaseModule {
|
|
30
31
|
constructor(name, version) {
|
|
@@ -48,6 +49,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
48
49
|
async initialize(core, options) {
|
|
49
50
|
this.core = core;
|
|
50
51
|
this.store = options.store;
|
|
52
|
+
this.store.list = [];
|
|
51
53
|
this.request = core.getPlugin("request");
|
|
52
54
|
this.window = core.getPlugin("window");
|
|
53
55
|
if (!this.request) {
|
|
@@ -60,52 +62,101 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
60
62
|
console.log("[CartModule] 初始化完成");
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
|
-
*
|
|
65
|
+
* 添加商品到购物车
|
|
64
66
|
*/
|
|
65
|
-
async
|
|
66
|
-
|
|
67
|
+
async addItem(params) {
|
|
68
|
+
const { account, product, bundle, options } = params;
|
|
69
|
+
let cartItem = {
|
|
70
|
+
_id: (0, import_utils.getUniqueId)(),
|
|
71
|
+
_origin: (0, import_utils.createCartItemOrigin)(),
|
|
72
|
+
_productOrigin: product
|
|
73
|
+
};
|
|
74
|
+
if (product) {
|
|
75
|
+
cartItem = (0, import_utils.formatProductToCartItem)({ cartItem, product, bundle, options });
|
|
76
|
+
}
|
|
77
|
+
if (account) {
|
|
78
|
+
cartItem = (0, import_utils.formatAccountToCartItem)({ cartItem, account });
|
|
79
|
+
}
|
|
80
|
+
const items = [...this.store.list, cartItem];
|
|
81
|
+
this.store.list = items;
|
|
82
|
+
await this.core.effects.emit(import_types.CartHooks.OnAddItem, cartItem);
|
|
83
|
+
await this.core.effects.emit(`${this.name}:changed`, items);
|
|
67
84
|
}
|
|
68
85
|
/**
|
|
69
|
-
*
|
|
86
|
+
* 更新购物车信息
|
|
70
87
|
*/
|
|
71
|
-
async
|
|
72
|
-
|
|
88
|
+
async updateItem(params) {
|
|
89
|
+
var _a;
|
|
90
|
+
const { _id, cartItem, account, product, resources, note } = params;
|
|
91
|
+
let tempCartItem = this.store.list.find((i) => i._id === _id);
|
|
92
|
+
if (!tempCartItem) {
|
|
93
|
+
console.warn("[CartModule] 更新购物车商品失败,商品不存在");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (cartItem) {
|
|
97
|
+
tempCartItem = cartItem;
|
|
98
|
+
}
|
|
99
|
+
if (product) {
|
|
100
|
+
tempCartItem = (0, import_utils.formatProductToCartItem)({ cartItem: tempCartItem, product });
|
|
101
|
+
}
|
|
102
|
+
if (account) {
|
|
103
|
+
tempCartItem = (0, import_utils.formatAccountToCartItem)({ cartItem: tempCartItem, account });
|
|
104
|
+
}
|
|
105
|
+
if (resources) {
|
|
106
|
+
tempCartItem = (0, import_utils.formatResourceToCartItem)({ cartItem: tempCartItem, resources });
|
|
107
|
+
}
|
|
108
|
+
if (note && ((_a = tempCartItem._origin) == null ? void 0 : _a.product)) {
|
|
109
|
+
tempCartItem.note = note;
|
|
110
|
+
tempCartItem._origin.product.note = note;
|
|
111
|
+
}
|
|
112
|
+
const items = this.store.list.map((item) => {
|
|
113
|
+
if (item._id === (tempCartItem == null ? void 0 : tempCartItem._id)) {
|
|
114
|
+
return tempCartItem;
|
|
115
|
+
}
|
|
116
|
+
return item;
|
|
117
|
+
});
|
|
73
118
|
this.store.list = items;
|
|
74
|
-
await this.core.effects.emit(
|
|
75
|
-
|
|
119
|
+
await this.core.effects.emit(`${this.name}:changed`, items);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 批量设置购物车数据
|
|
123
|
+
*/
|
|
124
|
+
async batchSetItems(items) {
|
|
125
|
+
this.store.list = items || [];
|
|
76
126
|
}
|
|
77
127
|
getItemCount() {
|
|
78
128
|
return this.store.list.length;
|
|
79
129
|
}
|
|
80
130
|
getTotalPrice() {
|
|
81
|
-
return
|
|
131
|
+
return 0;
|
|
82
132
|
}
|
|
83
|
-
|
|
133
|
+
getItems() {
|
|
84
134
|
return this.store.list;
|
|
85
135
|
}
|
|
86
|
-
async updateItem(id, item) {
|
|
87
|
-
const items = this.store.list;
|
|
88
|
-
const itemIndex = items.findIndex((i) => i.id === id);
|
|
89
|
-
if (itemIndex !== -1) {
|
|
90
|
-
items[itemIndex] = item;
|
|
91
|
-
this.store.list = items;
|
|
92
|
-
await this.core.effects.emit(import_types.CartHooks.OnCartUpdateItem, items);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
136
|
async removeItem(id) {
|
|
96
|
-
const items = this.store.list.filter((i) => i.
|
|
137
|
+
const items = this.store.list.filter((i) => i._id !== id);
|
|
97
138
|
this.store.list = items;
|
|
98
139
|
await this.core.effects.emit(import_types.CartHooks.OnCartRemove, items);
|
|
99
140
|
}
|
|
100
141
|
async storeTemp(key, value) {
|
|
101
142
|
this.store.temp[key] = value;
|
|
143
|
+
await this.core.effects.emit(`${this.name}:changed`, this.store.temp);
|
|
102
144
|
}
|
|
103
|
-
|
|
145
|
+
getTemp(key) {
|
|
104
146
|
if (!key) {
|
|
105
147
|
return this.store.temp;
|
|
106
148
|
}
|
|
107
149
|
return this.store.temp[key];
|
|
108
150
|
}
|
|
151
|
+
clear() {
|
|
152
|
+
this.store.list = [];
|
|
153
|
+
}
|
|
154
|
+
clearCartByAccount(account_id) {
|
|
155
|
+
this.store.list = this.store.list.filter((item) => item.holder_id !== account_id);
|
|
156
|
+
}
|
|
157
|
+
getCartByAccount(account_id) {
|
|
158
|
+
return this.store.list.filter((item) => item.holder_id === account_id);
|
|
159
|
+
}
|
|
109
160
|
};
|
|
110
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
162
|
0 && (module.exports = {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ProductData } from
|
|
1
|
+
import { ProductData } from "../Product/types";
|
|
2
|
+
import { Account } from "../Account/types";
|
|
3
|
+
import { Resource } from "../Resource/types";
|
|
2
4
|
export declare enum CartHooks {
|
|
3
5
|
OnAddItem = "card:onAddItem",
|
|
4
6
|
OnCartChange = "card:onCartChange",
|
|
@@ -9,16 +11,69 @@ export declare enum CartHooks {
|
|
|
9
11
|
* 购物车商品接口
|
|
10
12
|
*/
|
|
11
13
|
export interface CartItem {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** 购物车ID */
|
|
15
|
+
_id: string;
|
|
16
|
+
/** 商品ID */
|
|
17
|
+
id?: number;
|
|
18
|
+
/** 商品名称 */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** 商品价格 */
|
|
21
|
+
price?: number | string;
|
|
22
|
+
/** 商品总价 */
|
|
23
|
+
total?: number | string;
|
|
24
|
+
/** 商品原价总价,排除原始价格为0的场景 */
|
|
25
|
+
origin_total?: number | string;
|
|
26
|
+
/** 商品数量 */
|
|
27
|
+
num?: number;
|
|
28
|
+
/** 商品图片 */
|
|
29
|
+
image?: string;
|
|
30
|
+
/** 商品时长 */
|
|
31
|
+
duration?: {
|
|
32
|
+
type: string;
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
/** 是否显示备注 */
|
|
36
|
+
isShowNote?: boolean;
|
|
37
|
+
/** 备注 */
|
|
38
|
+
note?: string;
|
|
39
|
+
/** 点赞状态 */
|
|
40
|
+
like_status?: "like" | "common";
|
|
41
|
+
/** 用户名称 */
|
|
42
|
+
holder_title?: string;
|
|
43
|
+
/** 用户ID */
|
|
44
|
+
holder_id?: number | string;
|
|
45
|
+
/** 符号 */
|
|
46
|
+
symbol?: string;
|
|
47
|
+
/** 开始日期 */
|
|
48
|
+
start_date?: string;
|
|
49
|
+
/** 开始时间 */
|
|
50
|
+
start_time?: string;
|
|
51
|
+
/** 结束日期 */
|
|
52
|
+
end_date?: string;
|
|
53
|
+
/** 结束时间 */
|
|
54
|
+
end_time?: string;
|
|
55
|
+
/** 是否收取税费 */
|
|
56
|
+
is_charge_tax?: number;
|
|
57
|
+
/** 商品套餐信息 */
|
|
58
|
+
bundle?: any[];
|
|
59
|
+
/** 商品规格信息 */
|
|
60
|
+
options?: any[];
|
|
61
|
+
/** 是否为普通商品 */
|
|
62
|
+
isNormalProduct?: boolean;
|
|
63
|
+
/** 资源ID */
|
|
64
|
+
resource_id?: string | number;
|
|
65
|
+
/** 资源名称 */
|
|
66
|
+
relation_form_name?: string;
|
|
67
|
+
/** 原始数据 */
|
|
68
|
+
_origin: any;
|
|
69
|
+
/** 商品原始数据 */
|
|
70
|
+
_productOrigin: ProductData;
|
|
16
71
|
}
|
|
17
72
|
/**
|
|
18
73
|
* 购物车状态接口
|
|
19
74
|
*/
|
|
20
75
|
export interface CartState {
|
|
21
|
-
list:
|
|
76
|
+
list: CartItem[];
|
|
22
77
|
total: number;
|
|
23
78
|
temp: Record<string, any>;
|
|
24
79
|
}
|
|
@@ -26,10 +81,44 @@ export interface CartState {
|
|
|
26
81
|
* 购物车模块 API
|
|
27
82
|
*/
|
|
28
83
|
export interface CartModuleAPI {
|
|
29
|
-
addItem: (item:
|
|
84
|
+
addItem: (item: IAddItemParams) => Promise<void>;
|
|
30
85
|
getItemCount: () => number;
|
|
31
86
|
getTotalPrice: () => number;
|
|
32
|
-
getItems: () =>
|
|
33
|
-
updateItem: (
|
|
87
|
+
getItems: () => CartItem[];
|
|
88
|
+
updateItem: (params: IUpdateItemParams) => Promise<void>;
|
|
34
89
|
removeItem: (id: string) => Promise<void>;
|
|
35
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* 添加商品到购物车参数
|
|
93
|
+
*/
|
|
94
|
+
export interface IAddItemParams {
|
|
95
|
+
/** 账户 */
|
|
96
|
+
account: Account;
|
|
97
|
+
/** 商品 */
|
|
98
|
+
product: ProductData;
|
|
99
|
+
/** 数量 */
|
|
100
|
+
quantity?: number;
|
|
101
|
+
/** 商品套餐信息 */
|
|
102
|
+
bundle?: any[];
|
|
103
|
+
/** 商品规格信息 */
|
|
104
|
+
options?: any[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 更新购物车信息参数
|
|
108
|
+
*/
|
|
109
|
+
export interface IUpdateItemParams {
|
|
110
|
+
/** 购物车_id字段 */
|
|
111
|
+
_id?: string;
|
|
112
|
+
/** 购物车商品 */
|
|
113
|
+
cartItem?: CartItem;
|
|
114
|
+
/** 账户 */
|
|
115
|
+
account?: Account;
|
|
116
|
+
/** 商品 */
|
|
117
|
+
product?: ProductData;
|
|
118
|
+
/** 数量 */
|
|
119
|
+
quantity?: number;
|
|
120
|
+
/** 资源 */
|
|
121
|
+
resources?: Resource[];
|
|
122
|
+
/** 备注 */
|
|
123
|
+
note?: string;
|
|
124
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Account } from "../Account";
|
|
2
|
+
import { ProductData } from "../Product/types";
|
|
3
|
+
import { Resource } from "../Resource/types";
|
|
4
|
+
import { CartItem } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* 生成一个唯一的 ID
|
|
7
|
+
*/
|
|
8
|
+
export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
|
|
9
|
+
/**
|
|
10
|
+
* 创建购物车原始数据
|
|
11
|
+
*/
|
|
12
|
+
export declare const createCartItemOrigin: () => {
|
|
13
|
+
id: number;
|
|
14
|
+
number: number;
|
|
15
|
+
registration_type: string;
|
|
16
|
+
relation_products: never[];
|
|
17
|
+
is_all: boolean;
|
|
18
|
+
product: null;
|
|
19
|
+
sub_type: null;
|
|
20
|
+
duration: null;
|
|
21
|
+
like_status: string;
|
|
22
|
+
relation_type: string;
|
|
23
|
+
resources: null;
|
|
24
|
+
schedule_id: number;
|
|
25
|
+
start_date: null;
|
|
26
|
+
start_time: null;
|
|
27
|
+
select_date: null;
|
|
28
|
+
end_time: null;
|
|
29
|
+
end_date: null;
|
|
30
|
+
metadata: {};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 格式化商品到购物车
|
|
34
|
+
* @param product 商品
|
|
35
|
+
* @returns 格式化后的商品
|
|
36
|
+
*/
|
|
37
|
+
export declare const formatProductToCartItem: (params: {
|
|
38
|
+
cartItem: CartItem;
|
|
39
|
+
product: ProductData;
|
|
40
|
+
bundle?: any;
|
|
41
|
+
options?: any;
|
|
42
|
+
}) => CartItem;
|
|
43
|
+
export declare const formatProductToCartItemOrigin: (params: {
|
|
44
|
+
cartItem: CartItem;
|
|
45
|
+
product: ProductData;
|
|
46
|
+
bundle?: any;
|
|
47
|
+
options?: any;
|
|
48
|
+
}) => any;
|
|
49
|
+
/**
|
|
50
|
+
* 格式化账户到购物车
|
|
51
|
+
* @param account 账户
|
|
52
|
+
* @returns 格式化后的账户
|
|
53
|
+
*/
|
|
54
|
+
export declare const formatAccountToCartItem: (params: {
|
|
55
|
+
cartItem: CartItem;
|
|
56
|
+
account: Account;
|
|
57
|
+
}) => CartItem;
|
|
58
|
+
export declare const formatAccountToCartItemOrigin: (params: {
|
|
59
|
+
cartItem: CartItem;
|
|
60
|
+
account: Account;
|
|
61
|
+
}) => any;
|
|
62
|
+
/**
|
|
63
|
+
* 格式化资源到购物车
|
|
64
|
+
* @param resource 资源
|
|
65
|
+
* @returns 格式化后的资源
|
|
66
|
+
*/
|
|
67
|
+
export declare const formatResourceToCartItem: (params: {
|
|
68
|
+
cartItem: CartItem;
|
|
69
|
+
resources: Resource[];
|
|
70
|
+
}) => CartItem;
|
|
71
|
+
export declare const formatResourceToCartItemOrigin: (params: {
|
|
72
|
+
cartItem: CartItem;
|
|
73
|
+
resources: Resource[];
|
|
74
|
+
}) => any;
|
|
75
|
+
/**
|
|
76
|
+
* 格式化套餐规格信息
|
|
77
|
+
* @param options 套餐规格信息
|
|
78
|
+
* @returns 格式化后的套餐规格信息
|
|
79
|
+
*/
|
|
80
|
+
export declare const formatOptions: (options: any) => any;
|
|
81
|
+
export declare const formatOptionsToOrigin: (options: any) => any;
|
|
82
|
+
/**
|
|
83
|
+
* 格式化商品套餐信息
|
|
84
|
+
* @param bundle 商品套餐信息
|
|
85
|
+
* @returns 格式化后的商品套餐信息
|
|
86
|
+
*/
|
|
87
|
+
export declare const formatBundle: (bundle: any) => any;
|
|
88
|
+
export declare const formatBundleToOrigin: (bundle: any) => any;
|
|
89
|
+
/**
|
|
90
|
+
* 判断是否是普通商品
|
|
91
|
+
* @param product 商品
|
|
92
|
+
* @returns 是否是普通商品
|
|
93
|
+
*/
|
|
94
|
+
export declare const isNormalProduct: (product: any) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 获取商品总价
|
|
97
|
+
* @param item 商品
|
|
98
|
+
* @returns 商品总价
|
|
99
|
+
*/
|
|
100
|
+
export declare const getProductTotalPrice: (params: {
|
|
101
|
+
product: ProductData;
|
|
102
|
+
bundle?: any;
|
|
103
|
+
options?: any;
|
|
104
|
+
}) => number;
|
|
105
|
+
/**
|
|
106
|
+
* 获取商品原始总价
|
|
107
|
+
* @param item 商品
|
|
108
|
+
* @returns 商品原始总价
|
|
109
|
+
*/
|
|
110
|
+
export declare const getProductOriginTotalPrice: (params: {
|
|
111
|
+
product: ProductData;
|
|
112
|
+
bundle?: any;
|
|
113
|
+
options?: any;
|
|
114
|
+
}) => number | undefined;
|