@pisell/pisellos 3.0.93 → 3.0.95

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.
Files changed (53) hide show
  1. package/dist/modules/Cart/utils/changePrice.js +16 -9
  2. package/dist/modules/Holder/index.d.ts +48 -0
  3. package/dist/modules/Holder/index.js +640 -0
  4. package/dist/modules/Holder/types.d.ts +123 -0
  5. package/dist/modules/Holder/types.js +1 -0
  6. package/dist/modules/Holder/utils.d.ts +13 -0
  7. package/dist/modules/Holder/utils.js +34 -0
  8. package/dist/modules/Order/index.d.ts +1 -0
  9. package/dist/modules/Order/index.js +18 -1
  10. package/dist/modules/Order/types.d.ts +2 -0
  11. package/dist/modules/Order/utils.d.ts +10 -0
  12. package/dist/modules/Order/utils.js +35 -3
  13. package/dist/modules/Product/index.d.ts +1 -1
  14. package/dist/modules/Product/types.d.ts +7 -0
  15. package/dist/modules/index.d.ts +1 -0
  16. package/dist/modules/index.js +2 -1
  17. package/dist/plugins/window.d.ts +1 -0
  18. package/dist/solution/BookingByStep/index.d.ts +16 -1
  19. package/dist/solution/BookingByStep/index.js +276 -204
  20. package/dist/solution/BookingByStep/types.d.ts +2 -1
  21. package/dist/solution/BookingByStep/types.js +3 -1
  22. package/dist/solution/ScanOrder/types.d.ts +1 -0
  23. package/dist/solution/VenueBooking/index.d.ts +19 -0
  24. package/dist/solution/VenueBooking/index.js +978 -748
  25. package/dist/solution/VenueBooking/types.d.ts +2 -0
  26. package/dist/types/index.d.ts +1 -0
  27. package/lib/modules/Cart/utils/changePrice.js +13 -9
  28. package/lib/modules/Holder/index.d.ts +48 -0
  29. package/lib/modules/Holder/index.js +402 -0
  30. package/lib/modules/Holder/types.d.ts +123 -0
  31. package/lib/modules/Holder/types.js +17 -0
  32. package/lib/modules/Holder/utils.d.ts +13 -0
  33. package/lib/modules/Holder/utils.js +71 -0
  34. package/lib/modules/Order/index.d.ts +1 -0
  35. package/lib/modules/Order/index.js +14 -0
  36. package/lib/modules/Order/types.d.ts +2 -0
  37. package/lib/modules/Order/utils.d.ts +10 -0
  38. package/lib/modules/Order/utils.js +36 -5
  39. package/lib/modules/Product/index.d.ts +1 -1
  40. package/lib/modules/Product/types.d.ts +7 -0
  41. package/lib/modules/index.d.ts +1 -0
  42. package/lib/modules/index.js +3 -1
  43. package/lib/plugins/window.d.ts +1 -0
  44. package/lib/solution/BookingByStep/index.d.ts +16 -1
  45. package/lib/solution/BookingByStep/index.js +39 -0
  46. package/lib/solution/BookingByStep/types.d.ts +2 -1
  47. package/lib/solution/BookingByStep/types.js +5 -0
  48. package/lib/solution/ScanOrder/types.d.ts +1 -0
  49. package/lib/solution/VenueBooking/index.d.ts +19 -0
  50. package/lib/solution/VenueBooking/index.js +134 -16
  51. package/lib/solution/VenueBooking/types.d.ts +2 -0
  52. package/lib/types/index.d.ts +1 -0
  53. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, DateModule, ScheduleModule, QuotationModule, OpenDataModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
+ import { HolderModule } from '../../modules/Holder';
3
4
  export type { ScanOrderOrderProductIdentity, ScanOrderOrderProduct, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder, ScanOrderSubmitPayload, } from '../ScanOrder/types';
4
5
  export declare enum VenueBookingHooks {
5
6
  onInited = "venueBooking:onInited",
@@ -145,6 +146,7 @@ export interface VenueBookingState {
145
146
  passed: boolean | null;
146
147
  failures: QuantityCheckResult[];
147
148
  };
149
+ holder?: HolderModule;
148
150
  }
149
151
  export interface VenueBookingLoggerRuntimeConfig {
150
152
  provider?: ScanOrderLoggerProviderType;
@@ -6,6 +6,7 @@ export interface Plugin {
6
6
  version: string;
7
7
  initialize: () => Promise<void> | void;
8
8
  destroy?: () => Promise<void> | void;
9
+ getLocalStorage?: (key: string) => string | null;
9
10
  }
10
11
  export interface PluginOptions {
11
12
  dependencies?: string[];
@@ -34,7 +34,7 @@ __export(changePrice_exports, {
34
34
  module.exports = __toCommonJS(changePrice_exports);
35
35
  var import_decimal = __toESM(require("decimal.js"));
36
36
  async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
37
- var _a, _b;
37
+ var _a, _b, _c, _d, _e, _f;
38
38
  for (const item of cartItems) {
39
39
  const targetProduct = priceData.find((n) => n.id === item.id);
40
40
  const cartProduct = await getProduct(
@@ -44,10 +44,14 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
44
44
  if (!productInfo) {
45
45
  productInfo = item._productOrigin;
46
46
  }
47
+ const variantId = ((_a = item == null ? void 0 : item._productOrigin) == null ? void 0 : _a.product_variant_id) ?? ((_c = (_b = item == null ? void 0 : item._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.product_variant_id);
48
+ const targetVariant = (_d = targetProduct == null ? void 0 : targetProduct.variant) == null ? void 0 : _d.find(
49
+ (variant) => Number(variant.id) === Number(variantId)
50
+ );
47
51
  let bundle = item._bundleOrigin;
48
- productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
49
- productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
50
- productInfo.product_variant_id = (_a = item._productOrigin) == null ? void 0 : _a.product_variant_id;
52
+ productInfo.price = (targetVariant == null ? void 0 : targetVariant.price) ?? (targetProduct == null ? void 0 : targetProduct.price) ?? productInfo.price;
53
+ productInfo.base_price = (targetVariant == null ? void 0 : targetVariant.base_price) ?? (targetProduct == null ? void 0 : targetProduct.base_price) ?? productInfo.base_price;
54
+ productInfo.product_variant_id = (_e = item._productOrigin) == null ? void 0 : _e.product_variant_id;
51
55
  bundle = bundle == null ? void 0 : bundle.map((n) => {
52
56
  var _a2;
53
57
  const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
@@ -76,14 +80,14 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
76
80
  return n;
77
81
  });
78
82
  if (targetProduct == null ? void 0 : targetProduct.variant) {
79
- productInfo.variant = (_b = productInfo.variant) == null ? void 0 : _b.map((n) => {
83
+ productInfo.variant = (_f = productInfo.variant) == null ? void 0 : _f.map((n) => {
80
84
  var _a2;
81
- const targetVariant = (_a2 = targetProduct.variant) == null ? void 0 : _a2.find((m) => m.id === n.id);
82
- if (targetVariant) {
85
+ const targetVariant2 = (_a2 = targetProduct.variant) == null ? void 0 : _a2.find((m) => m.id === n.id);
86
+ if (targetVariant2) {
83
87
  return {
84
88
  ...n,
85
- price: targetVariant.price,
86
- base_price: targetVariant.base_price
89
+ price: targetVariant2.price,
90
+ base_price: targetVariant2.base_price
87
91
  };
88
92
  }
89
93
  return n;
@@ -0,0 +1,48 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { IFormInfo, IFormRecord, IFormItemData, IFetchFormInfoParams, IFetchFormRecordsParams, IAddFormRecordParams, IAppendFormRecordParams, IEnsureFormDataParams, IEnsureFormByProductParams, IRefreshAllFormRecordsParams, HolderModuleAPI, HolderFormMap } from './types';
4
+ export * from './types';
5
+ export * from './utils';
6
+ export declare class HolderModule extends BaseModule implements Module, HolderModuleAPI {
7
+ protected defaultName: string;
8
+ protected defaultVersion: string;
9
+ private store;
10
+ private request;
11
+ private cacheId;
12
+ private openCache;
13
+ private fatherModule;
14
+ private isLoading;
15
+ private error;
16
+ /** 已加载过表单数据的 form_id 缓存标记 */
17
+ private loadedFormIds;
18
+ private window;
19
+ constructor(name?: string, version?: string);
20
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
21
+ /** 统一提交 formMap,仅此处触发 store changed */
22
+ private commitFormMap;
23
+ /** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
24
+ private notifyFormMapChanged;
25
+ getHolderFormMap(): HolderFormMap;
26
+ getHolderFormData(formId: number | string): IFormItemData | undefined;
27
+ setFormData(formId: number | string, data: Partial<IFormItemData>): void;
28
+ private ensureFormItem;
29
+ private hasFormData;
30
+ private patchFormMap;
31
+ fetchFormInfo(params: IFetchFormInfoParams): Promise<IFormInfo | IFormInfo[]>;
32
+ fetchRecords(params: IFetchFormRecordsParams): Promise<any>;
33
+ ensureFormData(params: IEnsureFormDataParams): Promise<IFormItemData>;
34
+ ensureFormByProduct(params: IEnsureFormByProductParams): Promise<IFormItemData | null>;
35
+ addFormRecord(params: IAddFormRecordParams): Promise<any>;
36
+ /**
37
+ * UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
38
+ */
39
+ appendFormRecord(params: IAppendFormRecordParams): IFormRecord;
40
+ removeFormRecord(formId: number | string, formRecordId: number): void;
41
+ clearFormData(formId?: number | string): void;
42
+ /**
43
+ * 登录后按当前 holderMap 批量刷新所有表单的 records。
44
+ * 遍历 holderMap,从 form.form 中读取 form_id、shop_id,结合 customer_id 重新拉取记录。
45
+ */
46
+ refreshAllFormRecords(params?: IRefreshAllFormRecordsParams): Promise<HolderFormMap>;
47
+ storeChange(path?: string): void;
48
+ }
@@ -0,0 +1,402 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/Holder/index.ts
21
+ var Holder_exports = {};
22
+ __export(Holder_exports, {
23
+ HolderModule: () => HolderModule
24
+ });
25
+ module.exports = __toCommonJS(Holder_exports);
26
+ var import_lodash_es = require("lodash-es");
27
+ var import_BaseModule = require("../BaseModule");
28
+ var import_utils = require("./utils");
29
+ __reExport(Holder_exports, require("./types"), module.exports);
30
+ __reExport(Holder_exports, require("./utils"), module.exports);
31
+ var HolderModule = class extends import_BaseModule.BaseModule {
32
+ constructor(name, version) {
33
+ super(name, version);
34
+ this.defaultName = "holder";
35
+ this.defaultVersion = "1.0.0";
36
+ this.openCache = false;
37
+ this.isLoading = false;
38
+ this.error = null;
39
+ /** 已加载过表单数据的 form_id 缓存标记 */
40
+ this.loadedFormIds = /* @__PURE__ */ new Set();
41
+ }
42
+ async initialize(core, options) {
43
+ var _a, _b, _c;
44
+ this.core = core;
45
+ this.store = options.store;
46
+ this.request = this.core.getPlugin("request");
47
+ this.window = this.core.getPlugin("window");
48
+ if ((_a = options.initialState) == null ? void 0 : _a.holderMap) {
49
+ this.commitFormMap((0, import_lodash_es.cloneDeep)(options.initialState.holderMap));
50
+ Object.keys(this.store.holderMap).forEach((formId) => {
51
+ if (this.hasFormData(formId)) {
52
+ this.loadedFormIds.add(formId);
53
+ }
54
+ });
55
+ }
56
+ if (!this.store.holderMap || typeof this.store.holderMap !== "object") {
57
+ this.store.holderMap = {};
58
+ }
59
+ if ((_b = options.otherParams) == null ? void 0 : _b.cacheId) {
60
+ this.openCache = options.otherParams.openCache;
61
+ this.cacheId = options.otherParams.cacheId;
62
+ }
63
+ if ((_c = options.otherParams) == null ? void 0 : _c.fatherModule) {
64
+ this.fatherModule = options.otherParams.fatherModule;
65
+ }
66
+ }
67
+ /** 统一提交 formMap,仅此处触发 store changed */
68
+ commitFormMap(holderMap) {
69
+ this.store.holderMap = holderMap;
70
+ }
71
+ /** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
72
+ notifyFormMapChanged() {
73
+ this.commitFormMap({ ...this.store.holderMap });
74
+ }
75
+ getHolderFormMap() {
76
+ return (0, import_lodash_es.cloneDeep)(this.store.holderMap);
77
+ }
78
+ getHolderFormData(formId) {
79
+ const formData = this.store.holderMap[(0, import_utils.normalizeFormId)(formId)];
80
+ return formData ? (0, import_lodash_es.cloneDeep)(formData) : void 0;
81
+ }
82
+ setFormData(formId, data) {
83
+ const key = (0, import_utils.normalizeFormId)(formId);
84
+ const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
85
+ this.commitFormMap({
86
+ ...this.store.holderMap,
87
+ [key]: {
88
+ records: data.records ?? current.records,
89
+ form: data.form ?? current.form
90
+ }
91
+ });
92
+ }
93
+ ensureFormItem(formId, holderMap = this.store.holderMap) {
94
+ const key = (0, import_utils.normalizeFormId)(formId);
95
+ if (!holderMap[key]) {
96
+ holderMap[key] = (0, import_utils.createEmptyFormItemData)();
97
+ }
98
+ return holderMap[key];
99
+ }
100
+ hasFormData(formId) {
101
+ const item = this.store.holderMap[formId];
102
+ return !!item && (Object.keys(item.form || {}).length > 0 || item.records.length > 0);
103
+ }
104
+ patchFormMap(holderMap, formId, patch) {
105
+ const current = this.ensureFormItem(formId, holderMap);
106
+ holderMap[formId] = {
107
+ records: patch.records ?? current.records,
108
+ form: patch.form ?? current.form
109
+ };
110
+ }
111
+ async fetchFormInfo(params) {
112
+ const { form_id } = params.query || {};
113
+ const url = params.url || `/form/${form_id}`;
114
+ const useCache = params.useCache !== false;
115
+ this.isLoading = true;
116
+ this.error = null;
117
+ try {
118
+ const res = await this.request.get(url, {}, { useCache });
119
+ const formData = res == null ? void 0 : res.data;
120
+ const formList = Array.isArray(formData == null ? void 0 : formData.list) ? formData.list : formData ? [formData] : [];
121
+ const nextFormMap = { ...this.store.holderMap };
122
+ formList.forEach((form) => {
123
+ const key = (0, import_utils.normalizeFormId)(form.form_id ?? form_id ?? form.id);
124
+ this.patchFormMap(nextFormMap, key, { form });
125
+ });
126
+ if (!formList.length && form_id !== void 0) {
127
+ const key = (0, import_utils.normalizeFormId)(form_id);
128
+ this.patchFormMap(nextFormMap, key, { form: formData || {} });
129
+ }
130
+ this.commitFormMap(nextFormMap);
131
+ return formList.length === 1 ? formList[0] : formList;
132
+ } catch (error) {
133
+ this.error = error instanceof Error ? error.message : String(error);
134
+ throw error;
135
+ } finally {
136
+ this.isLoading = false;
137
+ }
138
+ }
139
+ async fetchRecords(params) {
140
+ var _a, _b, _c;
141
+ const url = params.url || "/form/data/v1";
142
+ const { form_id, shop_id, num, skip, customer_id, ...rest } = params.query || {};
143
+ const formId = (0, import_utils.normalizeFormId)(form_id);
144
+ const useCache = params.useCache !== false;
145
+ const customer = JSON.parse(((_b = (_a = this.window) == null ? void 0 : _a.getLocalStorage) == null ? void 0 : _b.call(_a, "customer")) || "{}");
146
+ const customerId = customer_id ?? customer.id;
147
+ if (!customerId)
148
+ return [];
149
+ this.isLoading = true;
150
+ this.error = null;
151
+ try {
152
+ const res = await this.request.get(
153
+ url,
154
+ {
155
+ customer_id: customerId,
156
+ form_id,
157
+ shop_id,
158
+ num: num || 100,
159
+ skip: skip || 1,
160
+ front_end_cache_id: useCache && this.cacheId,
161
+ ...rest
162
+ },
163
+ { useCache }
164
+ );
165
+ const records = ((_c = res == null ? void 0 : res.data) == null ? void 0 : _c.list) || [];
166
+ const nextFormMap = { ...this.store.holderMap };
167
+ this.patchFormMap(nextFormMap, formId, { records });
168
+ this.commitFormMap(nextFormMap);
169
+ return records;
170
+ } catch (error) {
171
+ this.error = error instanceof Error ? error.message : String(error);
172
+ throw error;
173
+ } finally {
174
+ this.isLoading = false;
175
+ }
176
+ }
177
+ async ensureFormData(params) {
178
+ const formId = (0, import_utils.normalizeFormId)(params.form_id);
179
+ const useCache = params.useCache !== false;
180
+ if (useCache && !params.forceRefresh && this.loadedFormIds.has(formId)) {
181
+ this.notifyFormMapChanged();
182
+ return this.ensureFormItem(formId);
183
+ }
184
+ const current = this.ensureFormItem(formId);
185
+ const tasks = [];
186
+ if (params.forceRefresh || !Object.keys(current.form || {}).length) {
187
+ tasks.push(
188
+ this.fetchFormInfo({
189
+ url: params.formInfoUrl,
190
+ query: {
191
+ form_id: params.form_id
192
+ },
193
+ useCache
194
+ })
195
+ );
196
+ }
197
+ if (params.forceRefresh || !current.records.length) {
198
+ tasks.push(
199
+ this.fetchRecords({
200
+ url: params.recordsUrl,
201
+ query: {
202
+ form_id: params.form_id,
203
+ shop_id: params.shop_id,
204
+ customer_id: params.customer_id
205
+ },
206
+ useCache
207
+ })
208
+ );
209
+ }
210
+ if (!tasks.length) {
211
+ this.notifyFormMapChanged();
212
+ } else {
213
+ await Promise.all(tasks);
214
+ }
215
+ this.loadedFormIds.add(formId);
216
+ return this.ensureFormItem(formId);
217
+ }
218
+ async ensureFormByProduct(params) {
219
+ const holderConfig = (0, import_utils.getProductHolderConfig)(params.product);
220
+ if (!holderConfig)
221
+ return null;
222
+ const formId = (0, import_utils.getFormIdFromHolderConfig)(holderConfig);
223
+ const shopId = params.shop_id ?? params.product.shop_id;
224
+ return this.ensureFormData({
225
+ form_id: formId,
226
+ shop_id: shopId,
227
+ customer_id: params.customer_id,
228
+ useCache: params.useCache,
229
+ skip: 1,
230
+ num: 100
231
+ });
232
+ }
233
+ async addFormRecord(params) {
234
+ const url = params.url || "/form/record";
235
+ const formId = (0, import_utils.normalizeFormId)(params.body.form_id);
236
+ this.isLoading = true;
237
+ this.error = null;
238
+ try {
239
+ await this.request.post(url, params.body);
240
+ const records = await this.fetchRecords({
241
+ query: {
242
+ form_id: params.body.form_id,
243
+ shop_id: params.body.shop_id,
244
+ customer_id: params.body.customer_id
245
+ },
246
+ useCache: false
247
+ });
248
+ this.loadedFormIds.add(formId);
249
+ return records[records.length - 1];
250
+ } catch (error) {
251
+ this.error = error instanceof Error ? error.message : String(error);
252
+ throw error;
253
+ } finally {
254
+ this.isLoading = false;
255
+ }
256
+ }
257
+ /**
258
+ * UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
259
+ */
260
+ appendFormRecord(params) {
261
+ let record = params.record;
262
+ if ((record == null ? void 0 : record.data) && record.form_record_id === void 0) {
263
+ record = record.data;
264
+ }
265
+ const normalizedRecord = (0, import_lodash_es.cloneDeep)(record);
266
+ const formId = (0, import_utils.normalizeFormId)(
267
+ params.form_id ?? normalizedRecord.form_id
268
+ );
269
+ if (!formId) {
270
+ throw new Error("[HolderModule] appendFormRecord: form_id is required");
271
+ }
272
+ if (!normalizedRecord.form_record_id) {
273
+ throw new Error(
274
+ "[HolderModule] appendFormRecord: form_record_id is required"
275
+ );
276
+ }
277
+ normalizedRecord.form_id = Number(formId) || normalizedRecord.form_id;
278
+ const nextFormMap = { ...this.store.holderMap };
279
+ const current = this.ensureFormItem(formId, nextFormMap);
280
+ const recordIndex = current.records.findIndex(
281
+ (item) => item.form_record_id === normalizedRecord.form_record_id
282
+ );
283
+ const records = recordIndex >= 0 ? current.records.map(
284
+ (item, index) => index === recordIndex ? { ...item, ...normalizedRecord } : item
285
+ ) : [...current.records, normalizedRecord];
286
+ this.patchFormMap(nextFormMap, formId, { records });
287
+ this.commitFormMap(nextFormMap);
288
+ this.loadedFormIds.add(formId);
289
+ return normalizedRecord;
290
+ }
291
+ removeFormRecord(formId, formRecordId) {
292
+ const key = (0, import_utils.normalizeFormId)(formId);
293
+ const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
294
+ const nextFormMap = { ...this.store.holderMap };
295
+ this.patchFormMap(nextFormMap, key, {
296
+ records: current.records.filter(
297
+ (record) => record.form_record_id !== formRecordId
298
+ )
299
+ });
300
+ this.commitFormMap(nextFormMap);
301
+ }
302
+ clearFormData(formId) {
303
+ if (formId !== void 0) {
304
+ const key = (0, import_utils.normalizeFormId)(formId);
305
+ const nextFormMap = { ...this.store.holderMap };
306
+ delete nextFormMap[key];
307
+ this.loadedFormIds.delete(key);
308
+ this.commitFormMap(nextFormMap);
309
+ } else {
310
+ this.loadedFormIds.clear();
311
+ this.commitFormMap({});
312
+ }
313
+ }
314
+ /**
315
+ * 登录后按当前 holderMap 批量刷新所有表单的 records。
316
+ * 遍历 holderMap,从 form.form 中读取 form_id、shop_id,结合 customer_id 重新拉取记录。
317
+ */
318
+ async refreshAllFormRecords(params = {}) {
319
+ const { customer_id, recordsUrl, num, skip } = params;
320
+ const useCache = params.useCache ?? false;
321
+ if (!customer_id) {
322
+ return this.getHolderFormMap();
323
+ }
324
+ const entries = Object.entries(this.store.holderMap);
325
+ if (!entries.length) {
326
+ return this.getHolderFormMap();
327
+ }
328
+ const url = recordsUrl || "/form/data/v1";
329
+ this.isLoading = true;
330
+ this.error = null;
331
+ try {
332
+ const results = await Promise.all(
333
+ entries.map(async ([mapKey, item]) => {
334
+ var _a;
335
+ const meta = (0, import_utils.resolveFormMetaFromHolderItem)(mapKey, item);
336
+ if (!meta)
337
+ return null;
338
+ try {
339
+ const res = await this.request.get(
340
+ url,
341
+ {
342
+ customer_id,
343
+ form_id: meta.form_id,
344
+ shop_id: meta.shop_id,
345
+ num: num || 100,
346
+ skip: skip || 1,
347
+ front_end_cache_id: useCache && this.cacheId
348
+ },
349
+ { useCache }
350
+ );
351
+ return {
352
+ formId: meta.form_id,
353
+ records: ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || []
354
+ };
355
+ } catch (error) {
356
+ console.error(
357
+ `[HolderModule] refreshAllFormRecords failed for form ${meta.form_id}`,
358
+ error
359
+ );
360
+ return null;
361
+ }
362
+ })
363
+ );
364
+ const nextFormMap = { ...this.store.holderMap };
365
+ results.forEach((result) => {
366
+ if (!result)
367
+ return;
368
+ this.patchFormMap(nextFormMap, result.formId, {
369
+ records: result.records
370
+ });
371
+ this.loadedFormIds.add(result.formId);
372
+ });
373
+ this.commitFormMap(nextFormMap);
374
+ return (0, import_lodash_es.cloneDeep)(nextFormMap);
375
+ } catch (error) {
376
+ this.error = error instanceof Error ? error.message : String(error);
377
+ throw error;
378
+ } finally {
379
+ this.isLoading = false;
380
+ }
381
+ }
382
+ storeChange(path) {
383
+ if (path !== "holderMap" && path !== void 0) {
384
+ return;
385
+ }
386
+ if (this.openCache) {
387
+ const store = (0, import_lodash_es.cloneDeep)(this.store);
388
+ this.checkSaveCache({
389
+ cacheId: this.cacheId,
390
+ fatherModule: this.fatherModule,
391
+ store,
392
+ cacheKey: ["holderMap"]
393
+ });
394
+ }
395
+ }
396
+ };
397
+ // Annotate the CommonJS export names for ESM import in node:
398
+ 0 && (module.exports = {
399
+ HolderModule,
400
+ ...require("./types"),
401
+ ...require("./utils")
402
+ });
@@ -0,0 +1,123 @@
1
+ import { ProductData } from '../Product/types';
2
+ /**
3
+ * 商品 holder 配置
4
+ */
5
+ export interface IHolderConfig {
6
+ required?: number;
7
+ resource_id: number;
8
+ status?: string;
9
+ [key: string]: any;
10
+ }
11
+ /**
12
+ * 表单记录
13
+ */
14
+ export interface IFormRecord {
15
+ form_id: number;
16
+ form_record_id: number;
17
+ main_field: string;
18
+ customer_cover?: string;
19
+ created_at?: string;
20
+ customer_id?: number;
21
+ [key: string]: any;
22
+ }
23
+ /**
24
+ * 表单配置/定义
25
+ */
26
+ export interface IFormInfo {
27
+ form_id: number;
28
+ name: string;
29
+ fields?: Record<string, any>[];
30
+ [key: string]: any;
31
+ }
32
+ /**
33
+ * 单个 form_id 下的数据结构
34
+ */
35
+ export interface IFormItemData {
36
+ records: IFormRecord[];
37
+ form: IFormInfo | Record<string, any>;
38
+ }
39
+ /**
40
+ * form_id 为 key 的 map 结构,如 948: { records: [], form: {} }
41
+ */
42
+ export type HolderFormMap = Record<string, IFormItemData>;
43
+ /**
44
+ * Holder 模块 reactive store,仅 holderMap 会触发 changed 事件
45
+ */
46
+ export interface HolderState {
47
+ holderMap: HolderFormMap;
48
+ }
49
+ export interface IFetchFormInfoParams {
50
+ url?: string;
51
+ query: {
52
+ form_id: string | number;
53
+ };
54
+ useCache?: boolean;
55
+ }
56
+ export interface IFetchFormRecordsParams {
57
+ url?: string;
58
+ query: {
59
+ customer_id?: number;
60
+ form_id: string | number;
61
+ shop_id: string | number;
62
+ num?: number;
63
+ skip?: number;
64
+ [key: string]: any;
65
+ };
66
+ useCache?: boolean;
67
+ }
68
+ export interface IAddFormRecordParams {
69
+ url?: string;
70
+ body: {
71
+ form_id: number;
72
+ shop_id: number | string;
73
+ customer_id?: number;
74
+ [key: string]: any;
75
+ };
76
+ }
77
+ /**
78
+ * UI 层自行调用添加接口后,将返回记录写入 holderMap
79
+ */
80
+ export interface IAppendFormRecordParams {
81
+ /** 接口返回的 data,或完整响应 { data: {...} } */
82
+ record: IFormRecord | Record<string, any>;
83
+ /** 可选,未传则从 record.form_id 读取 */
84
+ form_id?: number | string;
85
+ }
86
+ export interface IEnsureFormDataParams {
87
+ form_id: number | string;
88
+ shop_id: number | string;
89
+ customer_id?: number;
90
+ useCache?: boolean;
91
+ forceRefresh?: boolean;
92
+ formInfoUrl?: string;
93
+ recordsUrl?: string;
94
+ skip?: number;
95
+ num?: number;
96
+ }
97
+ export interface IEnsureFormByProductParams {
98
+ product: ProductData | Record<string, any>;
99
+ customer_id?: number;
100
+ shop_id?: number | string;
101
+ useCache?: boolean;
102
+ }
103
+ export interface IRefreshAllFormRecordsParams {
104
+ customer_id?: number;
105
+ useCache?: boolean;
106
+ recordsUrl?: string;
107
+ num?: number;
108
+ skip?: number;
109
+ }
110
+ export interface HolderModuleAPI {
111
+ getHolderFormMap: () => HolderFormMap;
112
+ getHolderFormData: (formId: number | string) => IFormItemData | undefined;
113
+ setFormData: (formId: number | string, data: Partial<IFormItemData>) => void;
114
+ fetchFormInfo: (params: IFetchFormInfoParams) => Promise<IFormInfo | IFormInfo[]>;
115
+ fetchRecords: (params: IFetchFormRecordsParams) => Promise<IFormRecord[]>;
116
+ ensureFormData: (params: IEnsureFormDataParams) => Promise<IFormItemData>;
117
+ ensureFormByProduct: (params: IEnsureFormByProductParams) => Promise<IFormItemData | null>;
118
+ addFormRecord: (params: IAddFormRecordParams) => Promise<IFormRecord>;
119
+ appendFormRecord: (params: IAppendFormRecordParams) => IFormRecord;
120
+ removeFormRecord: (formId: number | string, formRecordId: number) => void;
121
+ clearFormData: (formId?: number | string) => void;
122
+ refreshAllFormRecords: (params?: IRefreshAllFormRecordsParams) => Promise<HolderFormMap>;
123
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/modules/Holder/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,13 @@
1
+ import { ProductData } from '../Product/types';
2
+ import { IFormItemData, IHolderConfig } from './types';
3
+ export declare function getProductHolderConfig(product?: ProductData | Record<string, any> | null): IHolderConfig | null;
4
+ export declare function getFormIdFromHolderConfig(config: IHolderConfig): number;
5
+ export declare function normalizeFormId(formId: number | string): number;
6
+ export declare function createEmptyFormItemData(): {
7
+ records: any[];
8
+ form: Record<string, any>;
9
+ };
10
+ export declare function resolveFormMetaFromHolderItem(mapKey: string, item: IFormItemData): {
11
+ form_id: number | string;
12
+ shop_id: number | string;
13
+ } | null;