@pisell/pisellos 0.0.205 → 0.0.207
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/effects/index.d.ts +1 -1
- package/dist/modules/Order/utils.js +8 -2
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +9 -9
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/lib/core/index.js +27 -28
- package/lib/effects/index.d.ts +1 -1
- package/lib/effects/index.js +3 -7
- package/lib/modules/Account/index.js +9 -10
- package/lib/modules/AccountList/index.js +14 -11
- package/lib/modules/BaseModule.js +6 -3
- package/lib/modules/Cart/index.js +14 -9
- package/lib/modules/Cart/utils/cartProduct.js +3 -6
- package/lib/modules/Date/index.js +8 -4
- package/lib/modules/Date/types.js +1 -0
- package/lib/modules/Discount/index.js +11 -6
- package/lib/modules/Guests/index.js +10 -15
- package/lib/modules/Order/index.js +4 -2
- package/lib/modules/Order/utils.js +3 -2
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +98 -86
- package/lib/modules/Payment/wallet.js +1 -1
- package/lib/modules/Product/index.js +6 -5
- package/lib/modules/ProductList/index.js +5 -4
- package/lib/modules/Resource/index.js +8 -12
- package/lib/modules/Rules/index.js +10 -13
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +8 -5
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +2 -4
- package/lib/modules/Step/index.js +7 -4
- package/lib/modules/Summary/index.js +9 -4
- package/lib/plugins/request.js +34 -33
- package/lib/plugins/window.js +101 -113
- package/lib/solution/BookingByStep/index.js +44 -69
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +4 -8
- package/lib/solution/BookingByStep/utils/timeslots.js +6 -12
- package/lib/solution/BuyTickets/index.js +15 -15
- package/lib/solution/ShopDiscount/index.js +15 -11
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -26,13 +26,14 @@ module.exports = __toCommonJS(Product_exports);
|
|
|
26
26
|
var import_BaseModule = require("../BaseModule");
|
|
27
27
|
__reExport(Product_exports, require("./types"), module.exports);
|
|
28
28
|
var Product = class extends import_BaseModule.BaseModule {
|
|
29
|
+
defaultName = "product";
|
|
30
|
+
defaultVersion = "1.0.0";
|
|
31
|
+
store;
|
|
32
|
+
otherParams = {
|
|
33
|
+
scheduler: []
|
|
34
|
+
};
|
|
29
35
|
constructor(name, version) {
|
|
30
36
|
super(name, version);
|
|
31
|
-
this.defaultName = "product";
|
|
32
|
-
this.defaultVersion = "1.0.0";
|
|
33
|
-
this.otherParams = {
|
|
34
|
-
scheduler: []
|
|
35
|
-
};
|
|
36
37
|
}
|
|
37
38
|
async initialize(core, options) {
|
|
38
39
|
this.core = core;
|
|
@@ -29,10 +29,12 @@ var import_types = require("./types");
|
|
|
29
29
|
var import_lodash_es = require("lodash-es");
|
|
30
30
|
__reExport(ProductList_exports, require("./types"), module.exports);
|
|
31
31
|
var ProductList = class extends import_BaseModule.BaseModule {
|
|
32
|
+
defaultName = "productList";
|
|
33
|
+
defaultVersion = "1.0.0";
|
|
34
|
+
store;
|
|
35
|
+
request;
|
|
32
36
|
constructor(name, version) {
|
|
33
37
|
super(name, version);
|
|
34
|
-
this.defaultName = "productList";
|
|
35
|
-
this.defaultVersion = "1.0.0";
|
|
36
38
|
}
|
|
37
39
|
async initialize(core, options) {
|
|
38
40
|
var _a;
|
|
@@ -140,8 +142,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
140
142
|
this.store.list
|
|
141
143
|
);
|
|
142
144
|
const product = this.store.productMap.get(`${id}`);
|
|
143
|
-
if (product)
|
|
144
|
-
return product;
|
|
145
|
+
if (product) return product;
|
|
145
146
|
return void 0;
|
|
146
147
|
}
|
|
147
148
|
async addProduct(products) {
|
|
@@ -25,10 +25,11 @@ module.exports = __toCommonJS(Resource_exports);
|
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
26
|
var import_types = require("./types");
|
|
27
27
|
var ResourceListModule = class extends import_BaseModule.BaseModule {
|
|
28
|
+
defaultName = "resourceList";
|
|
29
|
+
defaultVersion = "1.0.0";
|
|
30
|
+
store;
|
|
28
31
|
constructor(name, version) {
|
|
29
32
|
super(name, version);
|
|
30
|
-
this.defaultName = "resourceList";
|
|
31
|
-
this.defaultVersion = "1.0.0";
|
|
32
33
|
}
|
|
33
34
|
async initialize(core, options) {
|
|
34
35
|
this.core = core;
|
|
@@ -39,8 +40,7 @@ var ResourceListModule = class extends import_BaseModule.BaseModule {
|
|
|
39
40
|
}
|
|
40
41
|
async selectResource(resourceId) {
|
|
41
42
|
const resource = this.store.list.find((r) => r.id === resourceId);
|
|
42
|
-
if (!resource)
|
|
43
|
-
return;
|
|
43
|
+
if (!resource) return;
|
|
44
44
|
this.store.selectedResource = resource;
|
|
45
45
|
await this.core.effects.emit(import_types.ResourceHooks.OnResourceSelect, resource);
|
|
46
46
|
}
|
|
@@ -49,22 +49,19 @@ var ResourceListModule = class extends import_BaseModule.BaseModule {
|
|
|
49
49
|
}
|
|
50
50
|
async checkAvailability(resourceId, start, end) {
|
|
51
51
|
const resource = this.store.list.find((r) => r.id === resourceId);
|
|
52
|
-
if (!resource)
|
|
53
|
-
return false;
|
|
52
|
+
if (!resource) return false;
|
|
54
53
|
return resource.timeSlots.some(
|
|
55
54
|
(slot) => slot.start.getTime() <= start.getTime() && slot.end.getTime() >= end.getTime() && slot.availableCapacity > 0
|
|
56
55
|
);
|
|
57
56
|
}
|
|
58
57
|
async getAvailableTimeSlots(resourceId) {
|
|
59
58
|
const resource = this.store.list.find((r) => r.id === resourceId);
|
|
60
|
-
if (!resource)
|
|
61
|
-
return [];
|
|
59
|
+
if (!resource) return [];
|
|
62
60
|
return resource.timeSlots.filter((slot) => slot.availableCapacity > 0);
|
|
63
61
|
}
|
|
64
62
|
getAvailableCapacity(resourceId, timeSlot) {
|
|
65
63
|
const resource = this.store.list.find((r) => r.id === resourceId);
|
|
66
|
-
if (!resource)
|
|
67
|
-
return 0;
|
|
64
|
+
if (!resource) return 0;
|
|
68
65
|
const slot = resource.timeSlots.find(
|
|
69
66
|
(s) => s.start.getTime() === timeSlot.start.getTime() && s.end.getTime() === timeSlot.end.getTime()
|
|
70
67
|
);
|
|
@@ -72,8 +69,7 @@ var ResourceListModule = class extends import_BaseModule.BaseModule {
|
|
|
72
69
|
}
|
|
73
70
|
async updateResource(resourceId, updates) {
|
|
74
71
|
const index = this.store.list.findIndex((r) => r.id === resourceId);
|
|
75
|
-
if (index === -1)
|
|
76
|
-
return;
|
|
72
|
+
if (index === -1) return;
|
|
77
73
|
this.store.list[index] = {
|
|
78
74
|
...this.store.list[index],
|
|
79
75
|
...updates
|
|
@@ -38,10 +38,12 @@ var import_utils = require("../../solution/ShopDiscount/utils");
|
|
|
38
38
|
var import_utils2 = require("../Cart/utils");
|
|
39
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
40
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
41
|
+
defaultName = "rules";
|
|
42
|
+
defaultVersion = "1.0.0";
|
|
43
|
+
store;
|
|
44
|
+
hooks;
|
|
41
45
|
constructor(name, version) {
|
|
42
46
|
super(name, version);
|
|
43
|
-
this.defaultName = "rules";
|
|
44
|
-
this.defaultVersion = "1.0.0";
|
|
45
47
|
this.hooks = {};
|
|
46
48
|
}
|
|
47
49
|
async initialize(core, options) {
|
|
@@ -131,10 +133,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
131
133
|
return !discount.isManualSelect;
|
|
132
134
|
});
|
|
133
135
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
134
|
-
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
135
|
-
|
|
136
|
-
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
137
|
-
return 1;
|
|
136
|
+
if (a.tag === "good_pass" && b.tag !== "good_pass") return -1;
|
|
137
|
+
if (b.tag === "good_pass" && a.tag !== "good_pass") return 1;
|
|
138
138
|
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
139
139
|
return compareByExpireTime(a, b);
|
|
140
140
|
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
@@ -215,16 +215,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
215
215
|
}
|
|
216
216
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
217
217
|
var _a2;
|
|
218
|
-
if ((Number(product.price) === 0 || !product.price) && (discount.tag || discount.type) === "good_pass")
|
|
219
|
-
return false;
|
|
218
|
+
if ((Number(product.price) === 0 || !product.price) && (discount.tag || discount.type) === "good_pass") return false;
|
|
220
219
|
if ((Number(product.total) === 0 || !product.total) && !((_a2 = product.discount_list) == null ? void 0 : _a2.find((n) => {
|
|
221
220
|
var _a3;
|
|
222
221
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
223
|
-
})) && (discount.tag || discount.type) !== "good_pass")
|
|
224
|
-
return false;
|
|
222
|
+
})) && (discount.tag || discount.type) !== "good_pass") return false;
|
|
225
223
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
226
|
-
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
227
|
-
return false;
|
|
224
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass") return false;
|
|
228
225
|
const limitedData = discount.limited_relation_product_data;
|
|
229
226
|
if (limitedData.type === "product_all") {
|
|
230
227
|
return true;
|
|
@@ -453,7 +450,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
453
450
|
async destroy() {
|
|
454
451
|
this.core.effects.offByModuleDestroy(this.name);
|
|
455
452
|
await this.core.effects.emit(import_types.RulesHooks.OnDestroy, {});
|
|
456
|
-
console.log("[Rules]
|
|
453
|
+
console.log("[Rules] \u5DF2\u9500\u6BC1");
|
|
457
454
|
}
|
|
458
455
|
async clear() {
|
|
459
456
|
console.log("[Rules] clear");
|
|
@@ -41,19 +41,22 @@ var import_utils = require("../Date/utils");
|
|
|
41
41
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
42
42
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
43
43
|
var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
44
|
+
defaultName = "schedule";
|
|
45
|
+
defaultVersion = "1.0.0";
|
|
46
|
+
request;
|
|
47
|
+
store = {};
|
|
48
|
+
cacheId;
|
|
49
|
+
openCache = false;
|
|
50
|
+
fatherModule;
|
|
44
51
|
constructor(name, version) {
|
|
45
52
|
super(name, version);
|
|
46
|
-
this.defaultName = "schedule";
|
|
47
|
-
this.defaultVersion = "1.0.0";
|
|
48
|
-
this.store = {};
|
|
49
|
-
this.openCache = false;
|
|
50
53
|
}
|
|
51
54
|
async initialize(core, options) {
|
|
52
55
|
var _a, _b;
|
|
53
56
|
this.core = core;
|
|
54
57
|
this.request = core.getPlugin("request");
|
|
55
58
|
if (!this.request) {
|
|
56
|
-
throw new Error("ScheduleModule
|
|
59
|
+
throw new Error("ScheduleModule \u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
|
|
57
60
|
}
|
|
58
61
|
this.store = options == null ? void 0 : options.store;
|
|
59
62
|
if (options.initialState) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ScheduleItem = {
|
|
1
|
+
export declare type ScheduleItem = {
|
|
2
2
|
/** 颜色 */
|
|
3
3
|
color: string;
|
|
4
4
|
/** 创建时间 */
|
|
@@ -65,7 +65,7 @@ export type ScheduleItem = {
|
|
|
65
65
|
schedule_id: number;
|
|
66
66
|
}[];
|
|
67
67
|
};
|
|
68
|
-
export type ScheduleFormOtherValue = {
|
|
68
|
+
export declare type ScheduleFormOtherValue = {
|
|
69
69
|
/** 截止模式
|
|
70
70
|
* 1: 永不截止
|
|
71
71
|
* 2: 按日期截止
|
|
@@ -79,11 +79,11 @@ export type ScheduleFormOtherValue = {
|
|
|
79
79
|
includeStatus: boolean;
|
|
80
80
|
type: 'standard' | 'time-slots' | 'designation';
|
|
81
81
|
};
|
|
82
|
-
export type ExcIncDate = {
|
|
82
|
+
export declare type ExcIncDate = {
|
|
83
83
|
start: string;
|
|
84
84
|
end: string;
|
|
85
85
|
};
|
|
86
|
-
export type ScheduleFormData = {
|
|
86
|
+
export declare type ScheduleFormData = {
|
|
87
87
|
/** 颜色 */
|
|
88
88
|
color: string;
|
|
89
89
|
/** 日程名称 */
|
|
@@ -131,20 +131,20 @@ export type ScheduleFormData = {
|
|
|
131
131
|
start_time: any;
|
|
132
132
|
end_time: any;
|
|
133
133
|
};
|
|
134
|
-
export type CalendarDataItem = {
|
|
134
|
+
export declare type CalendarDataItem = {
|
|
135
135
|
date: string;
|
|
136
136
|
color: string[];
|
|
137
137
|
isExcluded: boolean;
|
|
138
138
|
schedule_ids?: number[];
|
|
139
139
|
[key: string]: any;
|
|
140
140
|
};
|
|
141
|
-
export type RequestData<Data> = {
|
|
141
|
+
export declare type RequestData<Data> = {
|
|
142
142
|
data: Data;
|
|
143
143
|
status: boolean;
|
|
144
144
|
message: string;
|
|
145
145
|
code: number;
|
|
146
146
|
};
|
|
147
|
-
export type ResponseListData<Data> = {
|
|
147
|
+
export declare type ResponseListData<Data> = {
|
|
148
148
|
status: boolean;
|
|
149
149
|
message: string;
|
|
150
150
|
code: number;
|
|
@@ -4,7 +4,7 @@ export interface ScheduleState {
|
|
|
4
4
|
availabilityDateList: ScheduleAvailabilityDateItem[];
|
|
5
5
|
otherProductsIds: number[];
|
|
6
6
|
}
|
|
7
|
-
export type ScheduleAvailabilityDateItem = {
|
|
7
|
+
export declare type ScheduleAvailabilityDateItem = {
|
|
8
8
|
date: string;
|
|
9
9
|
schedule_id: number[];
|
|
10
10
|
product_ids: number[];
|
|
@@ -24,7 +24,7 @@ export interface LoadScheduleAvailableDateParams {
|
|
|
24
24
|
}
|
|
25
25
|
export interface ScheduleModuleAPI {
|
|
26
26
|
}
|
|
27
|
-
export type ScheduleItem = {
|
|
27
|
+
export declare type ScheduleItem = {
|
|
28
28
|
/** 颜色 */
|
|
29
29
|
color: string;
|
|
30
30
|
/** 创建时间 */
|
|
@@ -91,7 +91,7 @@ export type ScheduleItem = {
|
|
|
91
91
|
schedule_id: number;
|
|
92
92
|
}[];
|
|
93
93
|
};
|
|
94
|
-
export type ScheduleFormOtherValue = {
|
|
94
|
+
export declare type ScheduleFormOtherValue = {
|
|
95
95
|
/** 截止模式
|
|
96
96
|
* 1: 永不截止
|
|
97
97
|
* 2: 按日期截止
|
|
@@ -105,11 +105,11 @@ export type ScheduleFormOtherValue = {
|
|
|
105
105
|
includeStatus: boolean;
|
|
106
106
|
type: 'standard' | 'time-slots' | 'designation';
|
|
107
107
|
};
|
|
108
|
-
export type ExcIncDate = {
|
|
108
|
+
export declare type ExcIncDate = {
|
|
109
109
|
start: string;
|
|
110
110
|
end: string;
|
|
111
111
|
};
|
|
112
|
-
export type ScheduleFormData = {
|
|
112
|
+
export declare type ScheduleFormData = {
|
|
113
113
|
/** 颜色 */
|
|
114
114
|
color: string;
|
|
115
115
|
/** 日程名称 */
|
|
@@ -157,20 +157,20 @@ export type ScheduleFormData = {
|
|
|
157
157
|
start_time: any;
|
|
158
158
|
end_time: any;
|
|
159
159
|
};
|
|
160
|
-
export type CalendarDataItem = {
|
|
160
|
+
export declare type CalendarDataItem = {
|
|
161
161
|
date: string;
|
|
162
162
|
color: string[];
|
|
163
163
|
isExcluded: boolean;
|
|
164
164
|
schedule_ids?: number[];
|
|
165
165
|
[key: string]: any;
|
|
166
166
|
};
|
|
167
|
-
export type RequestData<Data> = {
|
|
167
|
+
export declare type RequestData<Data> = {
|
|
168
168
|
data: Data;
|
|
169
169
|
status: boolean;
|
|
170
170
|
message: string;
|
|
171
171
|
code: number;
|
|
172
172
|
};
|
|
173
|
-
export type ResponseListData<Data> = {
|
|
173
|
+
export declare type ResponseListData<Data> = {
|
|
174
174
|
status: boolean;
|
|
175
175
|
message: string;
|
|
176
176
|
code: number;
|
|
@@ -181,7 +181,7 @@ export type ResponseListData<Data> = {
|
|
|
181
181
|
skip: number;
|
|
182
182
|
};
|
|
183
183
|
};
|
|
184
|
-
export type ScheduleAllMap = Record<string, {
|
|
184
|
+
export declare type ScheduleAllMap = Record<string, {
|
|
185
185
|
minTime: dayjs.Dayjs | null;
|
|
186
186
|
maxTime: dayjs.Dayjs | null;
|
|
187
187
|
minTimeStr: string | null;
|
|
@@ -343,8 +343,7 @@ var calcCalendarDataByTimeSlots = (values, others, isGetRange) => {
|
|
|
343
343
|
time_slot
|
|
344
344
|
} = values;
|
|
345
345
|
const { endRadio, excludedStatus, includeStatus } = others;
|
|
346
|
-
if (!start_time)
|
|
347
|
-
return [];
|
|
346
|
+
if (!start_time) return [];
|
|
348
347
|
const start = (0, import_dayjs.default)(start_time);
|
|
349
348
|
const end = (0, import_dayjs.default)(start_time);
|
|
350
349
|
return processDateRange(
|
|
@@ -578,8 +577,7 @@ function getAllSortedDateRanges(schedules) {
|
|
|
578
577
|
}
|
|
579
578
|
let sortedDateRanges = allDateRanges.sort((a, b) => {
|
|
580
579
|
const startTimeCompare = (0, import_dayjs.default)(a.start).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
|
|
581
|
-
if (startTimeCompare !== 0)
|
|
582
|
-
return startTimeCompare;
|
|
580
|
+
if (startTimeCompare !== 0) return startTimeCompare;
|
|
583
581
|
const durationA = (0, import_dayjs.default)(a.end).valueOf() - (0, import_dayjs.default)(a.start).valueOf();
|
|
584
582
|
const durationB = (0, import_dayjs.default)(b.end).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
|
|
585
583
|
return durationA - durationB;
|
|
@@ -24,11 +24,14 @@ __export(Step_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(Step_exports);
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
26
|
var StepModule = class extends import_BaseModule.BaseModule {
|
|
27
|
+
defaultName = "step";
|
|
28
|
+
defaultVersion = "1.0.0";
|
|
29
|
+
store;
|
|
30
|
+
cacheId;
|
|
31
|
+
openCache = false;
|
|
32
|
+
fatherModule;
|
|
27
33
|
constructor(name, version) {
|
|
28
34
|
super(name, version);
|
|
29
|
-
this.defaultName = "step";
|
|
30
|
-
this.defaultVersion = "1.0.0";
|
|
31
|
-
this.openCache = false;
|
|
32
35
|
}
|
|
33
36
|
async initialize(core, options) {
|
|
34
37
|
var _a, _b;
|
|
@@ -113,7 +116,7 @@ var StepModule = class extends import_BaseModule.BaseModule {
|
|
|
113
116
|
let stepList = this.store.stepList;
|
|
114
117
|
const index = stepList.findIndex((n) => n.key === step.key);
|
|
115
118
|
if (index !== -1) {
|
|
116
|
-
console.log("[StepModule]
|
|
119
|
+
console.log("[StepModule] \u6B65\u9AA4\u5DF2\u5B58\u5728\uFF0C\u6DFB\u52A0\u5931\u8D25");
|
|
117
120
|
return;
|
|
118
121
|
}
|
|
119
122
|
if (key) {
|
|
@@ -25,11 +25,16 @@ module.exports = __toCommonJS(Summary_exports);
|
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
26
|
var import_utils = require("./utils");
|
|
27
27
|
var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
28
|
+
defaultName = "summary";
|
|
29
|
+
defaultVersion = "1.0.0";
|
|
30
|
+
shopStore;
|
|
31
|
+
store;
|
|
32
|
+
request;
|
|
33
|
+
cacheId;
|
|
34
|
+
openCache = false;
|
|
35
|
+
fatherModule;
|
|
28
36
|
constructor(name, version) {
|
|
29
37
|
super(name, version);
|
|
30
|
-
this.defaultName = "summary";
|
|
31
|
-
this.defaultVersion = "1.0.0";
|
|
32
|
-
this.openCache = false;
|
|
33
38
|
}
|
|
34
39
|
async initialize(core, options) {
|
|
35
40
|
var _a, _b;
|
|
@@ -48,7 +53,7 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
48
53
|
this.fatherModule = options.otherParams.fatherModule;
|
|
49
54
|
}
|
|
50
55
|
if (!this.shopStore) {
|
|
51
|
-
throw new Error("SummaryModule
|
|
56
|
+
throw new Error("SummaryModule \u9700\u8981 shopStore \u63D2\u4EF6\u652F\u6301");
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
async getSummary(cartItems) {
|
package/lib/plugins/request.js
CHANGED
|
@@ -24,6 +24,9 @@ __export(request_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(request_exports);
|
|
26
26
|
var RequestError = class extends Error {
|
|
27
|
+
response;
|
|
28
|
+
request;
|
|
29
|
+
config;
|
|
27
30
|
constructor(message, config, request, response) {
|
|
28
31
|
super(message);
|
|
29
32
|
this.name = "RequestError";
|
|
@@ -33,38 +36,36 @@ var RequestError = class extends Error {
|
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
var RequestPluginImpl = class {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
}
|
|
39
|
+
name = "request";
|
|
40
|
+
version = "1.0.0";
|
|
41
|
+
core = null;
|
|
42
|
+
/**
|
|
43
|
+
* 默认请求选项
|
|
44
|
+
*/
|
|
45
|
+
defaultOptions = {
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
},
|
|
50
|
+
timeout: 3e4,
|
|
51
|
+
responseType: "json"
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 全局拦截器
|
|
55
|
+
*/
|
|
56
|
+
interceptors = {
|
|
57
|
+
request: [],
|
|
58
|
+
response: [],
|
|
59
|
+
error: []
|
|
60
|
+
};
|
|
60
61
|
// 初始化方法
|
|
61
62
|
initialize() {
|
|
62
63
|
this.core = globalThis.pisellOS;
|
|
63
|
-
console.log("[RequestPlugin]
|
|
64
|
+
console.log("[RequestPlugin] \u521D\u59CB\u5316\u5B8C\u6210");
|
|
64
65
|
}
|
|
65
66
|
// 销毁方法
|
|
66
67
|
destroy() {
|
|
67
|
-
console.log("[RequestPlugin]
|
|
68
|
+
console.log("[RequestPlugin] \u5DF2\u9500\u6BC1");
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* 添加请求拦截器
|
|
@@ -149,7 +150,7 @@ var RequestPluginImpl = class {
|
|
|
149
150
|
config = await Promise.resolve(interceptor(config));
|
|
150
151
|
} catch (error) {
|
|
151
152
|
const requestError = error instanceof RequestError ? error : new RequestError(
|
|
152
|
-
error instanceof Error ? error.message : "
|
|
153
|
+
error instanceof Error ? error.message : "\u8BF7\u6C42\u62E6\u622A\u5668\u9519\u8BEF",
|
|
153
154
|
config
|
|
154
155
|
);
|
|
155
156
|
let processedError = requestError;
|
|
@@ -174,7 +175,7 @@ var RequestPluginImpl = class {
|
|
|
174
175
|
);
|
|
175
176
|
} catch (error) {
|
|
176
177
|
const requestError = error instanceof RequestError ? error : new RequestError(
|
|
177
|
-
error instanceof Error ? error.message : "
|
|
178
|
+
error instanceof Error ? error.message : "\u54CD\u5E94\u62E6\u622A\u5668\u9519\u8BEF",
|
|
178
179
|
config,
|
|
179
180
|
null,
|
|
180
181
|
response
|
|
@@ -194,7 +195,7 @@ var RequestPluginImpl = class {
|
|
|
194
195
|
return processedResponse.data;
|
|
195
196
|
} catch (error) {
|
|
196
197
|
const requestError = error instanceof RequestError ? error : new RequestError(
|
|
197
|
-
error instanceof Error ? error.message : "
|
|
198
|
+
error instanceof Error ? error.message : "\u8BF7\u6C42\u9519\u8BEF",
|
|
198
199
|
config
|
|
199
200
|
);
|
|
200
201
|
let processedError = requestError;
|
|
@@ -225,7 +226,7 @@ var RequestPluginImpl = class {
|
|
|
225
226
|
withCredentials
|
|
226
227
|
} = config;
|
|
227
228
|
if (!url) {
|
|
228
|
-
throw new RequestError("URL
|
|
229
|
+
throw new RequestError("URL\u4E0D\u80FD\u4E3A\u7A7A", config);
|
|
229
230
|
}
|
|
230
231
|
let fullUrl = url;
|
|
231
232
|
if (params && Object.keys(params).length > 0) {
|
|
@@ -255,13 +256,13 @@ var RequestPluginImpl = class {
|
|
|
255
256
|
const timeoutPromise = new Promise((_, reject) => {
|
|
256
257
|
if (timeout) {
|
|
257
258
|
timeoutId = setTimeout(() => {
|
|
258
|
-
reject(new RequestError(
|
|
259
|
+
reject(new RequestError(`\u8BF7\u6C42\u8D85\u65F6: ${timeout}ms`, config));
|
|
259
260
|
}, timeout);
|
|
260
261
|
}
|
|
261
262
|
});
|
|
262
263
|
try {
|
|
263
264
|
const fetchPromise = typeof fetch !== "undefined" ? fetch(fullUrl, fetchOptions) : Promise.reject(
|
|
264
|
-
new RequestError("
|
|
265
|
+
new RequestError("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 fetch API", config)
|
|
265
266
|
);
|
|
266
267
|
const response = await Promise.race([fetchPromise, timeoutPromise]);
|
|
267
268
|
const responseHeaders = {};
|
|
@@ -297,7 +298,7 @@ var RequestPluginImpl = class {
|
|
|
297
298
|
};
|
|
298
299
|
if (!response.ok) {
|
|
299
300
|
throw new RequestError(
|
|
300
|
-
|
|
301
|
+
`\u8BF7\u6C42\u5931\u8D25\uFF0C\u72B6\u6001\u7801: ${response.status}`,
|
|
301
302
|
config,
|
|
302
303
|
fetchOptions,
|
|
303
304
|
result
|