@pisell/pisellos 2.2.78 → 2.2.80
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/core/index.d.ts +2 -2
- package/dist/modules/ProductList/index.d.ts +3 -0
- package/dist/modules/ProductList/index.js +9 -7
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +27 -2
- package/dist/server/index.js +499 -295
- package/dist/server/modules/products/index.d.ts +101 -3
- package/dist/server/modules/products/index.js +1381 -242
- package/dist/server/modules/products/types.d.ts +24 -1
- package/dist/server/modules/products/types.js +3 -0
- package/dist/server/utils/product.d.ts +1 -0
- package/dist/server/utils/product.js +35 -25
- package/dist/solution/BookingTicket/index.d.ts +9 -1
- package/dist/solution/BookingTicket/index.js +41 -28
- package/dist/types/index.d.ts +3 -0
- package/lib/core/index.d.ts +2 -2
- package/lib/modules/ProductList/index.d.ts +3 -0
- package/lib/modules/ProductList/index.js +2 -2
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +27 -2
- package/lib/server/index.js +172 -95
- package/lib/server/modules/products/index.d.ts +101 -3
- package/lib/server/modules/products/index.js +596 -52
- package/lib/server/modules/products/types.d.ts +24 -1
- package/lib/server/modules/products/types.js +1 -0
- package/lib/server/utils/product.d.ts +1 -0
- package/lib/server/utils/product.js +27 -11
- package/lib/solution/BookingTicket/index.d.ts +9 -1
- package/lib/solution/BookingTicket/index.js +10 -2
- package/lib/types/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -77,7 +77,30 @@ export declare enum ProductsHooks {
|
|
|
77
77
|
onProductsLoaded = "products:onProductsLoaded",
|
|
78
78
|
onProductsChanged = "products:onProductsChanged",
|
|
79
79
|
onProductSelected = "products:onProductSelected",
|
|
80
|
-
onProductsPriceApplied = "products:onProductsPriceApplied"
|
|
80
|
+
onProductsPriceApplied = "products:onProductsPriceApplied",
|
|
81
|
+
/** pubsub 同步批次处理完成后触发,Server 层监听此事件重新计算并推送 */
|
|
82
|
+
onProductsSyncCompleted = "products:onProductsSyncCompleted"
|
|
83
|
+
}
|
|
84
|
+
/** pubsub 商品同步消息结构 */
|
|
85
|
+
export interface ProductSyncMessage {
|
|
86
|
+
shop_id?: number;
|
|
87
|
+
module?: string;
|
|
88
|
+
action?: string;
|
|
89
|
+
id?: number;
|
|
90
|
+
/** 批量操作的商品 ID 列表 */
|
|
91
|
+
ids?: number[];
|
|
92
|
+
/** 完整商品数据(普通字段修改时携带) */
|
|
93
|
+
body?: any;
|
|
94
|
+
/** 操作类型(如 "delete" 表示删除) */
|
|
95
|
+
operation?: string;
|
|
96
|
+
/** 变更字段类型(如 ["price"]、["stock"]) */
|
|
97
|
+
change_types?: string[];
|
|
98
|
+
/** 关联商品 ID(product_collection / product_category / product_quotation 变更时携带) */
|
|
99
|
+
relation_product_ids?: number[];
|
|
100
|
+
message_uuid?: string;
|
|
101
|
+
timestamp?: string;
|
|
102
|
+
/** 内部标记:来源频道 key */
|
|
103
|
+
_channelKey?: string;
|
|
81
104
|
}
|
|
82
105
|
/**
|
|
83
106
|
* 商品格式化器上下文
|
|
@@ -27,6 +27,7 @@ var ProductsHooks = /* @__PURE__ */ ((ProductsHooks2) => {
|
|
|
27
27
|
ProductsHooks2["onProductsChanged"] = "products:onProductsChanged";
|
|
28
28
|
ProductsHooks2["onProductSelected"] = "products:onProductSelected";
|
|
29
29
|
ProductsHooks2["onProductsPriceApplied"] = "products:onProductsPriceApplied";
|
|
30
|
+
ProductsHooks2["onProductsSyncCompleted"] = "products:onProductsSyncCompleted";
|
|
30
31
|
return ProductsHooks2;
|
|
31
32
|
})(ProductsHooks || {});
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProductData } from '../../modules/Product/types';
|
|
2
2
|
import { FormattedProductData, LoadProductsPriceData, ProductFormatterContext } from '../modules/products/types';
|
|
3
|
+
export declare function perfMark(label: string, durationMs: number, meta?: Record<string, any>): void;
|
|
3
4
|
/**
|
|
4
5
|
* 将价格数据应用到商品列表(高性能版本)
|
|
5
6
|
* 通过预构建 Map 索引,将时间复杂度从 O(n×m) 优化到 O(n+m)
|
|
@@ -21,11 +21,23 @@ var product_exports = {};
|
|
|
21
21
|
__export(product_exports, {
|
|
22
22
|
applyDetailValueToProducts: () => applyDetailValueToProducts,
|
|
23
23
|
applyPriceDataToProducts: () => applyPriceDataToProducts,
|
|
24
|
-
getIsSessionProduct: () => getIsSessionProduct
|
|
24
|
+
getIsSessionProduct: () => getIsSessionProduct,
|
|
25
|
+
perfMark: () => perfMark
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(product_exports);
|
|
27
28
|
var import_utils = require("../modules/schedule/utils");
|
|
28
29
|
var import_utils2 = require("../../modules/Cart/utils");
|
|
30
|
+
function perfMark(label, durationMs, meta) {
|
|
31
|
+
try {
|
|
32
|
+
const w = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : null;
|
|
33
|
+
if (!w)
|
|
34
|
+
return;
|
|
35
|
+
if (!w.__PERF__)
|
|
36
|
+
w.__PERF__ = { records: [] };
|
|
37
|
+
w.__PERF__.records.push({ label, duration: Math.round(durationMs * 100) / 100, ts: Date.now(), ...meta });
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
29
41
|
function buildPriceIndexMap(priceData) {
|
|
30
42
|
const priceMap = new Map(
|
|
31
43
|
priceData.map((p) => [p.id, p])
|
|
@@ -42,7 +54,7 @@ function buildPriceIndexMap(priceData) {
|
|
|
42
54
|
if (p.bundle_group && p.bundle_group.length > 0) {
|
|
43
55
|
const groupMap = /* @__PURE__ */ new Map();
|
|
44
56
|
p.bundle_group.forEach((bg) => {
|
|
45
|
-
const itemMap = new Map(bg.bundle_item.map((bi) => [bi.id, bi]));
|
|
57
|
+
const itemMap = new Map((bg.bundle_item || []).map((bi) => [bi.id, bi]));
|
|
46
58
|
groupMap.set(bg.id, itemMap);
|
|
47
59
|
});
|
|
48
60
|
bundleMap.set(p.id, groupMap);
|
|
@@ -51,14 +63,15 @@ function buildPriceIndexMap(priceData) {
|
|
|
51
63
|
return { priceMap, variantMap, bundleMap };
|
|
52
64
|
}
|
|
53
65
|
function applyPriceDataToProducts(products, priceData) {
|
|
66
|
+
const t0 = performance.now();
|
|
54
67
|
if (!priceData || priceData.length === 0) {
|
|
55
68
|
console.log("[applyPriceDataToProducts] 没有价格数据,返回原商品");
|
|
56
69
|
return products;
|
|
57
70
|
}
|
|
71
|
+
const t1 = performance.now();
|
|
58
72
|
const { priceMap, variantMap, bundleMap } = buildPriceIndexMap(priceData);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
73
|
+
perfMark("buildPriceIndexMap", performance.now() - t1, { priceCount: priceData.length });
|
|
74
|
+
const t2 = performance.now();
|
|
62
75
|
const updatedProducts = products.map((product) => {
|
|
63
76
|
const priceInfo = priceMap.get(product.id);
|
|
64
77
|
if (!priceInfo) {
|
|
@@ -112,9 +125,11 @@ function applyPriceDataToProducts(products, priceData) {
|
|
|
112
125
|
}
|
|
113
126
|
return updatedProduct;
|
|
114
127
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
perfMark("applyPriceDataToProducts.mapProducts", performance.now() - t2, { count: products.length });
|
|
129
|
+
perfMark("applyPriceDataToProducts", performance.now() - t0, {
|
|
130
|
+
productCount: products.length,
|
|
131
|
+
priceCount: priceData.length
|
|
132
|
+
});
|
|
118
133
|
return updatedProducts;
|
|
119
134
|
}
|
|
120
135
|
var getIsSessionProduct = (product) => {
|
|
@@ -221,6 +236,7 @@ var genCartDetailValue = (product, scheduleTimeSlots) => {
|
|
|
221
236
|
return formatDataKey(params);
|
|
222
237
|
};
|
|
223
238
|
function applyDetailValueToProducts(products, context) {
|
|
239
|
+
const t0 = performance.now();
|
|
224
240
|
const newProducts = products.map((product) => {
|
|
225
241
|
const { isOpenDetailModal, scheduleTimeSlots } = getIsOpenDetailModal(
|
|
226
242
|
product,
|
|
@@ -232,17 +248,17 @@ function applyDetailValueToProducts(products, context) {
|
|
|
232
248
|
}
|
|
233
249
|
return {
|
|
234
250
|
...product,
|
|
235
|
-
// 是否打开详情弹窗
|
|
236
251
|
isOpenDetailModal,
|
|
237
|
-
// 购物车详情值
|
|
238
252
|
cartDetailValue
|
|
239
253
|
};
|
|
240
254
|
});
|
|
255
|
+
perfMark("applyDetailValueToProducts", performance.now() - t0, { count: products.length });
|
|
241
256
|
return newProducts;
|
|
242
257
|
}
|
|
243
258
|
// Annotate the CommonJS export names for ESM import in node:
|
|
244
259
|
0 && (module.exports = {
|
|
245
260
|
applyDetailValueToProducts,
|
|
246
261
|
applyPriceDataToProducts,
|
|
247
|
-
getIsSessionProduct
|
|
262
|
+
getIsSessionProduct,
|
|
263
|
+
perfMark
|
|
248
264
|
});
|
|
@@ -21,7 +21,15 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
21
21
|
* @param params 包含 schedule_date 的参数
|
|
22
22
|
* @returns 商品列表
|
|
23
23
|
*/
|
|
24
|
-
loadProducts(params?: ILoadProductsParams
|
|
24
|
+
loadProducts(params?: ILoadProductsParams, options?: {
|
|
25
|
+
callback?: (result: any) => void;
|
|
26
|
+
subscriberId?: string;
|
|
27
|
+
}): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* 取消商品查询订阅
|
|
30
|
+
* @param subscriberId 订阅时传入的 subscriberId
|
|
31
|
+
*/
|
|
32
|
+
unsubscribeProductQuery(subscriberId?: string): void;
|
|
25
33
|
/**
|
|
26
34
|
* 初始化外设扫码结果监听
|
|
27
35
|
*/
|
|
@@ -106,7 +106,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
106
106
|
* @param params 包含 schedule_date 的参数
|
|
107
107
|
* @returns 商品列表
|
|
108
108
|
*/
|
|
109
|
-
async loadProducts(params = {}) {
|
|
109
|
+
async loadProducts(params = {}, options) {
|
|
110
110
|
const { schedule_date, customer_id, menu_list_ids, schedule_datetime } = params;
|
|
111
111
|
try {
|
|
112
112
|
const result = await this.store.products.loadProducts({
|
|
@@ -114,7 +114,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
114
114
|
with_schedule: 1,
|
|
115
115
|
...params,
|
|
116
116
|
cacheId: this.cacheId
|
|
117
|
-
});
|
|
117
|
+
}, options);
|
|
118
118
|
this.core.effects.emit(`${this.name}:onProductsLoaded`, result);
|
|
119
119
|
return result;
|
|
120
120
|
} catch (error) {
|
|
@@ -122,6 +122,14 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
122
122
|
throw error;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* 取消商品查询订阅
|
|
127
|
+
* @param subscriberId 订阅时传入的 subscriberId
|
|
128
|
+
*/
|
|
129
|
+
unsubscribeProductQuery(subscriberId) {
|
|
130
|
+
var _a;
|
|
131
|
+
(_a = this.core.server) == null ? void 0 : _a.removeProductQuerySubscriber(subscriberId);
|
|
132
|
+
}
|
|
125
133
|
/**
|
|
126
134
|
* 初始化外设扫码结果监听
|
|
127
135
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export interface PisellCore {
|
|
|
50
50
|
};
|
|
51
51
|
context: BusinessContext;
|
|
52
52
|
validateContext: (config: ModuleContextConfig) => boolean;
|
|
53
|
+
serverOptions?: ServerOptions;
|
|
54
|
+
server?: any;
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
57
|
* 业务上下文接口
|
|
@@ -90,6 +92,7 @@ export interface ServerModuleConfig {
|
|
|
90
92
|
* Server 配置选项
|
|
91
93
|
*/
|
|
92
94
|
export interface ServerOptions {
|
|
95
|
+
All_DATA_SOURCES: Record<string, any>;
|
|
93
96
|
/** 要启用的模块列表 */
|
|
94
97
|
modules?: string[] | ServerModuleConfig[];
|
|
95
98
|
/** 是否自动初始化数据 */
|