@pisell/pisellos 1.0.43 → 1.0.46
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/Cart/index.d.ts +1 -0
- package/dist/modules/Cart/index.js +42 -14
- package/dist/modules/Cart/utils/changePrice.d.ts +1 -1
- package/dist/modules/Cart/utils/changePrice.js +11 -3
- package/dist/modules/Order/index.js +2 -2
- package/dist/modules/Payment/types.d.ts +2 -2
- package/dist/modules/Rules/index.js +0 -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/index.js +2 -0
- 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 +28 -27
- package/lib/effects/index.d.ts +1 -1
- package/lib/effects/index.js +7 -3
- package/lib/modules/Account/index.js +10 -9
- package/lib/modules/AccountList/index.js +11 -14
- package/lib/modules/BaseModule.js +3 -6
- package/lib/modules/Cart/index.d.ts +1 -0
- package/lib/modules/Cart/index.js +19 -14
- package/lib/modules/Cart/utils/cartProduct.js +6 -3
- package/lib/modules/Cart/utils/changePrice.d.ts +1 -1
- package/lib/modules/Cart/utils/changePrice.js +9 -2
- package/lib/modules/Date/index.js +4 -8
- package/lib/modules/Date/types.js +0 -1
- package/lib/modules/Discount/index.js +6 -11
- package/lib/modules/Guests/index.js +15 -10
- package/lib/modules/Order/index.js +4 -6
- package/lib/modules/Payment/index.js +14 -10
- package/lib/modules/Payment/types.d.ts +2 -2
- package/lib/modules/Product/index.js +5 -6
- package/lib/modules/ProductList/index.js +4 -5
- package/lib/modules/Resource/index.js +12 -8
- package/lib/modules/Rules/index.js +13 -10
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +5 -8
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +4 -2
- package/lib/modules/Step/index.js +4 -7
- package/lib/modules/Summary/index.js +4 -9
- package/lib/plugins/request.js +33 -34
- package/lib/plugins/window.js +113 -101
- package/lib/solution/BookingByStep/index.js +71 -47
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +8 -4
- package/lib/solution/BookingByStep/utils/timeslots.js +12 -6
- package/lib/solution/BuyTickets/index.js +15 -15
- package/lib/solution/ShopDiscount/index.js +11 -15
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +4 -1
package/dist/effects/index.d.ts
CHANGED
|
@@ -211,11 +211,39 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
211
211
|
return _updateItem.apply(this, arguments);
|
|
212
212
|
}
|
|
213
213
|
return updateItem;
|
|
214
|
+
}() // 更新购物车中商品的初始信息
|
|
215
|
+
// 为什么会有这个操作,主要服务于报价单和商品券
|
|
216
|
+
// 商品券那边会使用 init 的 price 做计算,而报价单那边就需要修改 init 的 price 来辅助商品计算
|
|
217
|
+
)
|
|
218
|
+
}, {
|
|
219
|
+
key: "updateItemInitInfo",
|
|
220
|
+
value: function () {
|
|
221
|
+
var _updateItemInitInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
222
|
+
var _id, product, cartItem;
|
|
223
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
224
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
225
|
+
case 0:
|
|
226
|
+
_id = params._id, product = params.product;
|
|
227
|
+
cartItem = this.store.list.find(function (i) {
|
|
228
|
+
return i._id === _id;
|
|
229
|
+
});
|
|
230
|
+
if (cartItem) {
|
|
231
|
+
cartItem._productInit = cloneDeep(product);
|
|
232
|
+
}
|
|
233
|
+
case 3:
|
|
234
|
+
case "end":
|
|
235
|
+
return _context4.stop();
|
|
236
|
+
}
|
|
237
|
+
}, _callee4, this);
|
|
238
|
+
}));
|
|
239
|
+
function updateItemInitInfo(_x5) {
|
|
240
|
+
return _updateItemInitInfo.apply(this, arguments);
|
|
241
|
+
}
|
|
242
|
+
return updateItemInitInfo;
|
|
214
243
|
}()
|
|
215
244
|
/**
|
|
216
245
|
* 格式化数据到购物车
|
|
217
246
|
*/
|
|
218
|
-
)
|
|
219
247
|
}, {
|
|
220
248
|
key: "formatCartItem",
|
|
221
249
|
value: function formatCartItem(params) {
|
|
@@ -305,18 +333,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
305
333
|
}, {
|
|
306
334
|
key: "batchSetItems",
|
|
307
335
|
value: (function () {
|
|
308
|
-
var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
309
|
-
return _regeneratorRuntime().wrap(function
|
|
310
|
-
while (1) switch (
|
|
336
|
+
var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(items) {
|
|
337
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
338
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
311
339
|
case 0:
|
|
312
340
|
this.store.list = _toConsumableArray(items || []);
|
|
313
341
|
case 1:
|
|
314
342
|
case "end":
|
|
315
|
-
return
|
|
343
|
+
return _context5.stop();
|
|
316
344
|
}
|
|
317
|
-
},
|
|
345
|
+
}, _callee5, this);
|
|
318
346
|
}));
|
|
319
|
-
function batchSetItems(
|
|
347
|
+
function batchSetItems(_x6) {
|
|
320
348
|
return _batchSetItems.apply(this, arguments);
|
|
321
349
|
}
|
|
322
350
|
return batchSetItems;
|
|
@@ -359,24 +387,24 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
359
387
|
}, {
|
|
360
388
|
key: "removeItem",
|
|
361
389
|
value: (function () {
|
|
362
|
-
var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
390
|
+
var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
|
|
363
391
|
var items;
|
|
364
|
-
return _regeneratorRuntime().wrap(function
|
|
365
|
-
while (1) switch (
|
|
392
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
393
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
366
394
|
case 0:
|
|
367
395
|
items = this.store.list.filter(function (i) {
|
|
368
396
|
return i._id !== id;
|
|
369
397
|
});
|
|
370
398
|
this.store.list = items;
|
|
371
|
-
|
|
399
|
+
_context6.next = 4;
|
|
372
400
|
return this.core.effects.emit("".concat(this.name, ":onRemoveItem"), items);
|
|
373
401
|
case 4:
|
|
374
402
|
case "end":
|
|
375
|
-
return
|
|
403
|
+
return _context6.stop();
|
|
376
404
|
}
|
|
377
|
-
},
|
|
405
|
+
}, _callee6, this);
|
|
378
406
|
}));
|
|
379
|
-
function removeItem(
|
|
407
|
+
function removeItem(_x7) {
|
|
380
408
|
return _removeItem.apply(this, arguments);
|
|
381
409
|
}
|
|
382
410
|
return removeItem;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Product } from "../../Product";
|
|
2
2
|
import { CartItem, IUpdateItemParams } from "../types";
|
|
3
|
-
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
|
|
3
|
+
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
|
|
@@ -11,11 +11,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
11
11
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
12
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
13
|
import Decimal from "decimal.js";
|
|
14
|
-
export function updateAllCartItemPrice(_x, _x2, _x3, _x4) {
|
|
14
|
+
export function updateAllCartItemPrice(_x, _x2, _x3, _x4, _x5) {
|
|
15
15
|
return _updateAllCartItemPrice.apply(this, arguments);
|
|
16
16
|
}
|
|
17
17
|
function _updateAllCartItemPrice() {
|
|
18
|
-
_updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart) {
|
|
18
|
+
_updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
|
|
19
19
|
var _iterator, _step, _loop;
|
|
20
20
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
21
21
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -37,6 +37,9 @@ function _updateAllCartItemPrice() {
|
|
|
37
37
|
case 4:
|
|
38
38
|
cartProduct = _context.sent;
|
|
39
39
|
productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
|
|
40
|
+
if (!productInfo) {
|
|
41
|
+
productInfo = item._productOrigin;
|
|
42
|
+
}
|
|
40
43
|
bundle = item._bundleOrigin;
|
|
41
44
|
productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
|
|
42
45
|
productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
|
|
@@ -79,13 +82,18 @@ function _updateAllCartItemPrice() {
|
|
|
79
82
|
return n;
|
|
80
83
|
});
|
|
81
84
|
}
|
|
85
|
+
// 先把商品原始信息更新了
|
|
86
|
+
updateItemInitInfo({
|
|
87
|
+
_id: item._id,
|
|
88
|
+
product: productInfo
|
|
89
|
+
});
|
|
82
90
|
updateCart({
|
|
83
91
|
_id: item._id,
|
|
84
92
|
product: productInfo,
|
|
85
93
|
bundle: bundle,
|
|
86
94
|
options: item._optionsOrigin
|
|
87
95
|
});
|
|
88
|
-
case
|
|
96
|
+
case 15:
|
|
89
97
|
case "end":
|
|
90
98
|
return _context.stop();
|
|
91
99
|
}
|
|
@@ -62,9 +62,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
62
62
|
key: "createOrder",
|
|
63
63
|
value: function createOrder(params) {
|
|
64
64
|
var order = {
|
|
65
|
-
type: params.type || 'appointment_booking',
|
|
65
|
+
type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
|
|
66
66
|
// 要从外面拿,virtual
|
|
67
|
-
platform: params.platform === 'pc' ? 'PC' : 'H5',
|
|
67
|
+
platform: (params === null || params === void 0 ? void 0 : params.platform) === 'pc' ? 'PC' : 'H5',
|
|
68
68
|
sales_channel: 'my_pisel',
|
|
69
69
|
order_sales_channel: 'online_store',
|
|
70
70
|
bookings: [],
|
|
@@ -7,11 +7,11 @@ export declare enum PaymentHooks {
|
|
|
7
7
|
/**
|
|
8
8
|
* 支付方式
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type PaymentMethod = 'credit_card' | 'debit_card' | 'paypal' | 'alipay' | 'wechat_pay' | 'bank_transfer';
|
|
11
11
|
/**
|
|
12
12
|
* 支付状态
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export type PaymentStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'refunded';
|
|
15
15
|
/**
|
|
16
16
|
* 支付信息
|
|
17
17
|
*/
|
|
@@ -165,8 +165,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
165
165
|
var _this3 = this;
|
|
166
166
|
var discountList = _ref2.discountList,
|
|
167
167
|
productList = _ref2.productList;
|
|
168
|
-
// debugger
|
|
169
|
-
|
|
170
168
|
// 识别出来是不是在编辑的界面里又新增了商品
|
|
171
169
|
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
172
170
|
var isEditModeAddNewProduct = productList.find(function (n) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ScheduleItem = {
|
|
2
2
|
/** 颜色 */
|
|
3
3
|
color: string;
|
|
4
4
|
/** 创建时间 */
|
|
@@ -65,7 +65,7 @@ export declare type ScheduleItem = {
|
|
|
65
65
|
schedule_id: number;
|
|
66
66
|
}[];
|
|
67
67
|
};
|
|
68
|
-
export
|
|
68
|
+
export type ScheduleFormOtherValue = {
|
|
69
69
|
/** 截止模式
|
|
70
70
|
* 1: 永不截止
|
|
71
71
|
* 2: 按日期截止
|
|
@@ -79,11 +79,11 @@ export declare type ScheduleFormOtherValue = {
|
|
|
79
79
|
includeStatus: boolean;
|
|
80
80
|
type: 'standard' | 'time-slots' | 'designation';
|
|
81
81
|
};
|
|
82
|
-
export
|
|
82
|
+
export type ExcIncDate = {
|
|
83
83
|
start: string;
|
|
84
84
|
end: string;
|
|
85
85
|
};
|
|
86
|
-
export
|
|
86
|
+
export type ScheduleFormData = {
|
|
87
87
|
/** 颜色 */
|
|
88
88
|
color: string;
|
|
89
89
|
/** 日程名称 */
|
|
@@ -131,20 +131,20 @@ export declare type ScheduleFormData = {
|
|
|
131
131
|
start_time: any;
|
|
132
132
|
end_time: any;
|
|
133
133
|
};
|
|
134
|
-
export
|
|
134
|
+
export 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
|
|
141
|
+
export type RequestData<Data> = {
|
|
142
142
|
data: Data;
|
|
143
143
|
status: boolean;
|
|
144
144
|
message: string;
|
|
145
145
|
code: number;
|
|
146
146
|
};
|
|
147
|
-
export
|
|
147
|
+
export 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
|
|
7
|
+
export 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
|
|
27
|
+
export type ScheduleItem = {
|
|
28
28
|
/** 颜色 */
|
|
29
29
|
color: string;
|
|
30
30
|
/** 创建时间 */
|
|
@@ -91,7 +91,7 @@ export declare type ScheduleItem = {
|
|
|
91
91
|
schedule_id: number;
|
|
92
92
|
}[];
|
|
93
93
|
};
|
|
94
|
-
export
|
|
94
|
+
export type ScheduleFormOtherValue = {
|
|
95
95
|
/** 截止模式
|
|
96
96
|
* 1: 永不截止
|
|
97
97
|
* 2: 按日期截止
|
|
@@ -105,11 +105,11 @@ export declare type ScheduleFormOtherValue = {
|
|
|
105
105
|
includeStatus: boolean;
|
|
106
106
|
type: 'standard' | 'time-slots' | 'designation';
|
|
107
107
|
};
|
|
108
|
-
export
|
|
108
|
+
export type ExcIncDate = {
|
|
109
109
|
start: string;
|
|
110
110
|
end: string;
|
|
111
111
|
};
|
|
112
|
-
export
|
|
112
|
+
export type ScheduleFormData = {
|
|
113
113
|
/** 颜色 */
|
|
114
114
|
color: string;
|
|
115
115
|
/** 日程名称 */
|
|
@@ -157,20 +157,20 @@ export declare type ScheduleFormData = {
|
|
|
157
157
|
start_time: any;
|
|
158
158
|
end_time: any;
|
|
159
159
|
};
|
|
160
|
-
export
|
|
160
|
+
export 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
|
|
167
|
+
export type RequestData<Data> = {
|
|
168
168
|
data: Data;
|
|
169
169
|
status: boolean;
|
|
170
170
|
message: string;
|
|
171
171
|
code: number;
|
|
172
172
|
};
|
|
173
|
-
export
|
|
173
|
+
export type ResponseListData<Data> = {
|
|
174
174
|
status: boolean;
|
|
175
175
|
message: string;
|
|
176
176
|
code: number;
|
|
@@ -181,7 +181,7 @@ export declare type ResponseListData<Data> = {
|
|
|
181
181
|
skip: number;
|
|
182
182
|
};
|
|
183
183
|
};
|
|
184
|
-
export
|
|
184
|
+
export type ScheduleAllMap = Record<string, {
|
|
185
185
|
minTime: dayjs.Dayjs | null;
|
|
186
186
|
maxTime: dayjs.Dayjs | null;
|
|
187
187
|
minTimeStr: string | null;
|
|
@@ -378,6 +378,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
378
378
|
return _this3.store.products.getProduct(id);
|
|
379
379
|
}, function (params) {
|
|
380
380
|
return _this3.store.cart.updateItem(params);
|
|
381
|
+
}, function (params) {
|
|
382
|
+
return _this3.store.cart.updateItemInitInfo(params);
|
|
381
383
|
});
|
|
382
384
|
case 10:
|
|
383
385
|
this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
|
|
@@ -6,7 +6,7 @@ import { CartItem, ProductData } from '../../../modules';
|
|
|
6
6
|
* 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
type DateType = Dayjs;
|
|
10
10
|
export interface TimeSliceItem {
|
|
11
11
|
start_time: string;
|
|
12
12
|
end_time: string;
|
|
@@ -10,7 +10,7 @@ export declare enum ShopDiscountHooks {
|
|
|
10
10
|
onRulesListChange = "shopDiscount:onRulesListChange",
|
|
11
11
|
onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type Customer = {
|
|
14
14
|
id: string | number;
|
|
15
15
|
name: string;
|
|
16
16
|
email: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface ModuleOptions {
|
|
|
27
27
|
initialState?: Record<string, any>;
|
|
28
28
|
otherParams?: Record<string, any>;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type EventHandler = (data?: any) => void;
|
|
31
31
|
export interface PisellCore {
|
|
32
32
|
registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
|
|
33
33
|
getPlugin: <T extends Plugin>(name: string) => T | null;
|
package/lib/core/index.js
CHANGED
|
@@ -26,13 +26,13 @@ module.exports = __toCommonJS(core_exports);
|
|
|
26
26
|
var import_createStore = require("../store/createStore");
|
|
27
27
|
var import_effects = require("../effects");
|
|
28
28
|
var PisellOSCore = class {
|
|
29
|
-
plugins = /* @__PURE__ */ new Map();
|
|
30
|
-
modules = /* @__PURE__ */ new Map();
|
|
31
|
-
stores = /* @__PURE__ */ new Map();
|
|
32
|
-
effects = new import_effects.EffectsManager();
|
|
33
|
-
debug = false;
|
|
34
|
-
context = {};
|
|
35
29
|
constructor(options) {
|
|
30
|
+
this.plugins = /* @__PURE__ */ new Map();
|
|
31
|
+
this.modules = /* @__PURE__ */ new Map();
|
|
32
|
+
this.stores = /* @__PURE__ */ new Map();
|
|
33
|
+
this.effects = new import_effects.EffectsManager();
|
|
34
|
+
this.debug = false;
|
|
35
|
+
this.context = {};
|
|
36
36
|
this.debug = (options == null ? void 0 : options.debug) || false;
|
|
37
37
|
this.context = (options == null ? void 0 : options.context) || {};
|
|
38
38
|
this.initialize(options);
|
|
@@ -48,7 +48,7 @@ var PisellOSCore = class {
|
|
|
48
48
|
this.registerModule(item.module, item.options);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
this.log("PisellOS
|
|
51
|
+
this.log("PisellOS 核心初始化完成");
|
|
52
52
|
}
|
|
53
53
|
// 日志方法
|
|
54
54
|
log(message, level = "info") {
|
|
@@ -71,12 +71,12 @@ var PisellOSCore = class {
|
|
|
71
71
|
// 插件相关方法
|
|
72
72
|
registerPlugin(plugin, options) {
|
|
73
73
|
if (this.plugins.has(plugin.name)) {
|
|
74
|
-
this.log(
|
|
74
|
+
this.log(`插件 ${plugin.name} 已经注册过,将被覆盖`, "warn");
|
|
75
75
|
}
|
|
76
76
|
if (options == null ? void 0 : options.dependencies) {
|
|
77
77
|
for (const dep of options.dependencies) {
|
|
78
78
|
if (!this.plugins.has(dep)) {
|
|
79
|
-
throw new Error(
|
|
79
|
+
throw new Error(`注册插件 ${plugin.name} 失败:缺少依赖插件 ${dep}`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -84,14 +84,14 @@ var PisellOSCore = class {
|
|
|
84
84
|
const result = plugin.initialize();
|
|
85
85
|
if (result instanceof Promise) {
|
|
86
86
|
result.catch((err) => {
|
|
87
|
-
this.log(
|
|
87
|
+
this.log(`插件 ${plugin.name} 初始化失败: ${err.message}`, "error");
|
|
88
88
|
throw err;
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
this.plugins.set(plugin.name, plugin);
|
|
92
|
-
this.log(
|
|
92
|
+
this.log(`插件 ${plugin.name} v${plugin.version} 注册成功`);
|
|
93
93
|
} catch (error) {
|
|
94
|
-
this.log(
|
|
94
|
+
this.log(`插件 ${plugin.name} 初始化过程中出错: ${error}`, "error");
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -104,12 +104,12 @@ var PisellOSCore = class {
|
|
|
104
104
|
// 模块相关方法
|
|
105
105
|
registerModule(module2, options) {
|
|
106
106
|
if (this.modules.has(module2.name)) {
|
|
107
|
-
this.log(
|
|
107
|
+
this.log(`模块 ${module2.name} 已经注册过,将被覆盖`, "warn");
|
|
108
108
|
}
|
|
109
109
|
if (options == null ? void 0 : options.dependencies) {
|
|
110
110
|
for (const dep of options.dependencies) {
|
|
111
111
|
if (!this.modules.has(dep)) {
|
|
112
|
-
throw new Error(
|
|
112
|
+
throw new Error(`注册模块 ${module2.name} 失败:缺少依赖模块 ${dep}`);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ var PisellOSCore = class {
|
|
|
117
117
|
for (const plugin of options.plugins) {
|
|
118
118
|
if (!this.plugins.has(plugin)) {
|
|
119
119
|
throw new Error(
|
|
120
|
-
|
|
120
|
+
`注册模块 ${module2.name} 失败:缺少依赖插件 ${plugin}`
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -126,9 +126,10 @@ var PisellOSCore = class {
|
|
|
126
126
|
(options == null ? void 0 : options.initialState) || {},
|
|
127
127
|
module2.name,
|
|
128
128
|
(path, value) => {
|
|
129
|
-
console.log("core
|
|
129
|
+
console.log("core 检测到模块值更新", module2.name, path, value);
|
|
130
130
|
this.effects.emit(`${module2.name}:changed`, { path, value });
|
|
131
|
-
if (module2.storeChange)
|
|
131
|
+
if (module2.storeChange)
|
|
132
|
+
module2.storeChange(path, value);
|
|
132
133
|
}
|
|
133
134
|
);
|
|
134
135
|
this.stores.set(module2.name, proxy);
|
|
@@ -136,14 +137,14 @@ var PisellOSCore = class {
|
|
|
136
137
|
const result = module2.initialize(this, { store: proxy, ...options });
|
|
137
138
|
if (result instanceof Promise) {
|
|
138
139
|
result.catch((err) => {
|
|
139
|
-
this.log(
|
|
140
|
+
this.log(`模块 ${module2.name} 初始化失败: ${err.message}`, "error");
|
|
140
141
|
throw err;
|
|
141
142
|
});
|
|
142
143
|
}
|
|
143
144
|
this.modules.set(module2.name, module2);
|
|
144
|
-
this.log(
|
|
145
|
+
this.log(`模块 ${module2.name} v${module2.version} 注册成功`);
|
|
145
146
|
} catch (error) {
|
|
146
|
-
this.log(
|
|
147
|
+
this.log(`模块 ${module2.name} 初始化过程中出错: ${error}`, "error");
|
|
147
148
|
throw error;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
@@ -167,9 +168,9 @@ var PisellOSCore = class {
|
|
|
167
168
|
if (module2.destroy) {
|
|
168
169
|
try {
|
|
169
170
|
await Promise.resolve(module2.destroy());
|
|
170
|
-
this.log(
|
|
171
|
+
this.log(`模块 ${name} 已销毁`);
|
|
171
172
|
} catch (error) {
|
|
172
|
-
this.log(
|
|
173
|
+
this.log(`销毁模块 ${name} 时出错: ${error}`, "error");
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
}
|
|
@@ -178,14 +179,14 @@ var PisellOSCore = class {
|
|
|
178
179
|
if (plugin.destroy) {
|
|
179
180
|
try {
|
|
180
181
|
await Promise.resolve(plugin.destroy());
|
|
181
|
-
this.log(
|
|
182
|
+
this.log(`插件 ${name} 已销毁`);
|
|
182
183
|
} catch (error) {
|
|
183
|
-
this.log(
|
|
184
|
+
this.log(`销毁插件 ${name} 时出错: ${error}`, "error");
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
this.plugins.clear();
|
|
188
|
-
this.log("PisellOS
|
|
189
|
+
this.log("PisellOS 核心已销毁");
|
|
189
190
|
}
|
|
190
191
|
/**
|
|
191
192
|
* 验证上下文参数
|
|
@@ -195,7 +196,7 @@ var PisellOSCore = class {
|
|
|
195
196
|
const value = this.context[rule.name];
|
|
196
197
|
if (rule.required && (value === void 0 || value === null)) {
|
|
197
198
|
this.log(
|
|
198
|
-
|
|
199
|
+
`模块 ${config.name} 缺少必需的上下文参数: ${rule.name}`,
|
|
199
200
|
"error"
|
|
200
201
|
);
|
|
201
202
|
return false;
|
|
@@ -203,7 +204,7 @@ var PisellOSCore = class {
|
|
|
203
204
|
if (rule.validate && value !== void 0 && value !== null) {
|
|
204
205
|
if (!rule.validate(value)) {
|
|
205
206
|
this.log(
|
|
206
|
-
|
|
207
|
+
`模块 ${config.name} 上下文参数验证失败: ${rule.name} - ${rule.message || "验证失败"}`,
|
|
207
208
|
"error"
|
|
208
209
|
);
|
|
209
210
|
return false;
|
package/lib/effects/index.d.ts
CHANGED
package/lib/effects/index.js
CHANGED
|
@@ -23,10 +23,13 @@ __export(effects_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(effects_exports);
|
|
25
25
|
var EffectsManager = class {
|
|
26
|
-
|
|
26
|
+
constructor() {
|
|
27
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
28
|
+
}
|
|
27
29
|
on(event, callback) {
|
|
28
30
|
var _a;
|
|
29
|
-
if (!this.listeners.has(event))
|
|
31
|
+
if (!this.listeners.has(event))
|
|
32
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
30
33
|
(_a = this.listeners.get(event)) == null ? void 0 : _a.add(callback);
|
|
31
34
|
}
|
|
32
35
|
off(event, callback) {
|
|
@@ -50,7 +53,8 @@ var EffectsManager = class {
|
|
|
50
53
|
}
|
|
51
54
|
async emit(event, payload) {
|
|
52
55
|
const callbacks = this.listeners.get(event);
|
|
53
|
-
if (!callbacks)
|
|
56
|
+
if (!callbacks)
|
|
57
|
+
return { status: true, data: [] };
|
|
54
58
|
return new Promise(async (resolve) => {
|
|
55
59
|
const res = [];
|
|
56
60
|
for (const cb of callbacks) {
|
|
@@ -27,16 +27,16 @@ var import_BaseModule = require("../BaseModule");
|
|
|
27
27
|
var import_types = require("./types");
|
|
28
28
|
__reExport(Account_exports, require("./types"), module.exports);
|
|
29
29
|
var AccountModule = class extends import_BaseModule.BaseModule {
|
|
30
|
-
defaultName = "account";
|
|
31
|
-
defaultVersion = "1.0.0";
|
|
32
|
-
isGuest = false;
|
|
33
|
-
store = {
|
|
34
|
-
accountInfo: null,
|
|
35
|
-
isLoggedIn: false,
|
|
36
|
-
active: false
|
|
37
|
-
};
|
|
38
30
|
constructor(name, version) {
|
|
39
31
|
super(name, version);
|
|
32
|
+
this.defaultName = "account";
|
|
33
|
+
this.defaultVersion = "1.0.0";
|
|
34
|
+
this.isGuest = false;
|
|
35
|
+
this.store = {
|
|
36
|
+
accountInfo: null,
|
|
37
|
+
isLoggedIn: false,
|
|
38
|
+
active: false
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
async initialize(core, options) {
|
|
42
42
|
this.core = core;
|
|
@@ -65,7 +65,8 @@ var AccountModule = class extends import_BaseModule.BaseModule {
|
|
|
65
65
|
return this.store.accountInfo;
|
|
66
66
|
}
|
|
67
67
|
async updateProfile(updates) {
|
|
68
|
-
if (!this.store.accountInfo)
|
|
68
|
+
if (!this.store.accountInfo)
|
|
69
|
+
return;
|
|
69
70
|
this.store.accountInfo = {
|
|
70
71
|
...this.store.accountInfo,
|
|
71
72
|
...updates
|
|
@@ -28,22 +28,19 @@ var import_BaseModule = require("../BaseModule");
|
|
|
28
28
|
var import_types = require("./types");
|
|
29
29
|
var import_utils = require("./utils");
|
|
30
30
|
var AccountListModule = class extends import_BaseModule.BaseModule {
|
|
31
|
-
defaultName = "accountList";
|
|
32
|
-
defaultVersion = "1.0.0";
|
|
33
|
-
store = {
|
|
34
|
-
accountList: [],
|
|
35
|
-
// 账号的纯数据列表
|
|
36
|
-
accounts: [],
|
|
37
|
-
// 账号的 module 列表
|
|
38
|
-
isLoading: false,
|
|
39
|
-
error: null
|
|
40
|
-
};
|
|
41
|
-
request;
|
|
42
|
-
cacheId;
|
|
43
|
-
openCache = false;
|
|
44
|
-
fatherModule;
|
|
45
31
|
constructor(name, version) {
|
|
46
32
|
super(name, version);
|
|
33
|
+
this.defaultName = "accountList";
|
|
34
|
+
this.defaultVersion = "1.0.0";
|
|
35
|
+
this.store = {
|
|
36
|
+
accountList: [],
|
|
37
|
+
// 账号的纯数据列表
|
|
38
|
+
accounts: [],
|
|
39
|
+
// 账号的 module 列表
|
|
40
|
+
isLoading: false,
|
|
41
|
+
error: null
|
|
42
|
+
};
|
|
43
|
+
this.openCache = false;
|
|
47
44
|
}
|
|
48
45
|
async initialize(core, options) {
|
|
49
46
|
var _a, _b, _c;
|
|
@@ -23,13 +23,10 @@ __export(BaseModule_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(BaseModule_exports);
|
|
25
25
|
var BaseModule = class {
|
|
26
|
-
defaultName = "baseModule";
|
|
27
|
-
defaultVersion = "1.0.0";
|
|
28
|
-
name;
|
|
29
|
-
version;
|
|
30
|
-
isSolution = false;
|
|
31
|
-
core;
|
|
32
26
|
constructor(name, version) {
|
|
27
|
+
this.defaultName = "baseModule";
|
|
28
|
+
this.defaultVersion = "1.0.0";
|
|
29
|
+
this.isSolution = false;
|
|
33
30
|
this.name = name || this.defaultName;
|
|
34
31
|
this.version = version || this.defaultVersion;
|
|
35
32
|
}
|