@pisell/pisellos 0.0.546 → 0.0.549
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Holder/index.d.ts +42 -0
- package/dist/modules/Holder/index.js +500 -0
- package/dist/modules/Holder/types.d.ts +115 -0
- package/dist/modules/Holder/types.js +1 -0
- package/dist/modules/Holder/utils.d.ts +9 -0
- package/dist/modules/Holder/utils.js +20 -0
- package/dist/modules/Product/types.d.ts +7 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +2 -1
- package/dist/solution/BookingByStep/index.d.ts +9 -0
- package/dist/solution/BookingByStep/index.js +32 -2
- package/dist/solution/BookingByStep/types.d.ts +2 -1
- package/dist/solution/BookingByStep/types.js +3 -1
- package/dist/solution/ScanOrder/index.d.ts +6 -5
- package/dist/solution/ScanOrder/index.js +529 -400
- package/lib/modules/Holder/index.d.ts +42 -0
- package/lib/modules/Holder/index.js +329 -0
- package/lib/modules/Holder/types.d.ts +115 -0
- package/lib/modules/Holder/types.js +17 -0
- package/lib/modules/Holder/utils.d.ts +9 -0
- package/lib/modules/Holder/utils.js +57 -0
- package/lib/modules/Product/types.d.ts +7 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +3 -1
- package/lib/solution/BookingByStep/index.d.ts +9 -0
- package/lib/solution/BookingByStep/index.js +23 -0
- package/lib/solution/BookingByStep/types.d.ts +2 -1
- package/lib/solution/BookingByStep/types.js +5 -0
- package/lib/solution/ScanOrder/index.d.ts +6 -5
- package/lib/solution/ScanOrder/index.js +114 -56
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
|
+
import { BaseModule } from '../BaseModule';
|
|
3
|
+
import { IFormInfo, IFormRecord, IFormItemData, IFetchFormInfoParams, IFetchFormRecordsParams, IAddFormRecordParams, IAppendFormRecordParams, IEnsureFormDataParams, IEnsureFormByProductParams, 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
|
+
constructor(name?: string, version?: string);
|
|
19
|
+
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
20
|
+
/** 统一提交 formMap,仅此处触发 store changed */
|
|
21
|
+
private commitFormMap;
|
|
22
|
+
/** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
|
|
23
|
+
private notifyFormMapChanged;
|
|
24
|
+
getHolderFormMap(): HolderFormMap;
|
|
25
|
+
getHolderFormData(formId: number | string): IFormItemData | undefined;
|
|
26
|
+
setFormData(formId: number | string, data: Partial<IFormItemData>): void;
|
|
27
|
+
private ensureFormItem;
|
|
28
|
+
private hasFormData;
|
|
29
|
+
private patchFormMap;
|
|
30
|
+
fetchFormInfo(params: IFetchFormInfoParams): Promise<IFormInfo | IFormInfo[]>;
|
|
31
|
+
fetchRecords(params: IFetchFormRecordsParams): Promise<any>;
|
|
32
|
+
ensureFormData(params: IEnsureFormDataParams): Promise<IFormItemData>;
|
|
33
|
+
ensureFormByProduct(params: IEnsureFormByProductParams): Promise<IFormItemData | null>;
|
|
34
|
+
addFormRecord(params: IAddFormRecordParams): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
|
|
37
|
+
*/
|
|
38
|
+
appendFormRecord(params: IAppendFormRecordParams): IFormRecord;
|
|
39
|
+
removeFormRecord(formId: number | string, formRecordId: number): void;
|
|
40
|
+
clearFormData(formId?: number | string): void;
|
|
41
|
+
storeChange(path?: string): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
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
|
+
if ((_a = options.initialState) == null ? void 0 : _a.holderMap) {
|
|
48
|
+
this.commitFormMap((0, import_lodash_es.cloneDeep)(options.initialState.holderMap));
|
|
49
|
+
Object.keys(this.store.holderMap).forEach((formId) => {
|
|
50
|
+
if (this.hasFormData(formId)) {
|
|
51
|
+
this.loadedFormIds.add(formId);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (!this.store.holderMap || typeof this.store.holderMap !== "object") {
|
|
56
|
+
this.store.holderMap = {};
|
|
57
|
+
}
|
|
58
|
+
if ((_b = options.otherParams) == null ? void 0 : _b.cacheId) {
|
|
59
|
+
this.openCache = options.otherParams.openCache;
|
|
60
|
+
this.cacheId = options.otherParams.cacheId;
|
|
61
|
+
}
|
|
62
|
+
if ((_c = options.otherParams) == null ? void 0 : _c.fatherModule) {
|
|
63
|
+
this.fatherModule = options.otherParams.fatherModule;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** 统一提交 formMap,仅此处触发 store changed */
|
|
67
|
+
commitFormMap(holderMap) {
|
|
68
|
+
this.store.holderMap = holderMap;
|
|
69
|
+
}
|
|
70
|
+
/** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
|
|
71
|
+
notifyFormMapChanged() {
|
|
72
|
+
this.commitFormMap({ ...this.store.holderMap });
|
|
73
|
+
}
|
|
74
|
+
getHolderFormMap() {
|
|
75
|
+
return (0, import_lodash_es.cloneDeep)(this.store.holderMap);
|
|
76
|
+
}
|
|
77
|
+
getHolderFormData(formId) {
|
|
78
|
+
const formData = this.store.holderMap[(0, import_utils.normalizeFormId)(formId)];
|
|
79
|
+
return formData ? (0, import_lodash_es.cloneDeep)(formData) : void 0;
|
|
80
|
+
}
|
|
81
|
+
setFormData(formId, data) {
|
|
82
|
+
const key = (0, import_utils.normalizeFormId)(formId);
|
|
83
|
+
const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
|
|
84
|
+
this.commitFormMap({
|
|
85
|
+
...this.store.holderMap,
|
|
86
|
+
[key]: {
|
|
87
|
+
records: data.records ?? current.records,
|
|
88
|
+
form: data.form ?? current.form
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
ensureFormItem(formId, holderMap = this.store.holderMap) {
|
|
93
|
+
const key = (0, import_utils.normalizeFormId)(formId);
|
|
94
|
+
if (!holderMap[key]) {
|
|
95
|
+
holderMap[key] = (0, import_utils.createEmptyFormItemData)();
|
|
96
|
+
}
|
|
97
|
+
return holderMap[key];
|
|
98
|
+
}
|
|
99
|
+
hasFormData(formId) {
|
|
100
|
+
const item = this.store.holderMap[formId];
|
|
101
|
+
return !!item && (Object.keys(item.form || {}).length > 0 || item.records.length > 0);
|
|
102
|
+
}
|
|
103
|
+
patchFormMap(holderMap, formId, patch) {
|
|
104
|
+
const current = this.ensureFormItem(formId, holderMap);
|
|
105
|
+
holderMap[formId] = {
|
|
106
|
+
records: patch.records ?? current.records,
|
|
107
|
+
form: patch.form ?? current.form
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async fetchFormInfo(params) {
|
|
111
|
+
const { form_id } = params.query || {};
|
|
112
|
+
const url = params.url || `/form/${form_id}`;
|
|
113
|
+
const useCache = params.useCache !== false;
|
|
114
|
+
this.isLoading = true;
|
|
115
|
+
this.error = null;
|
|
116
|
+
try {
|
|
117
|
+
const res = await this.request.get(url, {}, { useCache });
|
|
118
|
+
const formData = res == null ? void 0 : res.data;
|
|
119
|
+
const formList = Array.isArray(formData == null ? void 0 : formData.list) ? formData.list : formData ? [formData] : [];
|
|
120
|
+
const nextFormMap = { ...this.store.holderMap };
|
|
121
|
+
formList.forEach((form) => {
|
|
122
|
+
const key = (0, import_utils.normalizeFormId)(form.form_id ?? form_id ?? form.id);
|
|
123
|
+
this.patchFormMap(nextFormMap, key, { form });
|
|
124
|
+
});
|
|
125
|
+
if (!formList.length && form_id !== void 0) {
|
|
126
|
+
const key = (0, import_utils.normalizeFormId)(form_id);
|
|
127
|
+
this.patchFormMap(nextFormMap, key, { form: formData || {} });
|
|
128
|
+
}
|
|
129
|
+
this.commitFormMap(nextFormMap);
|
|
130
|
+
return formList.length === 1 ? formList[0] : formList;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
133
|
+
throw error;
|
|
134
|
+
} finally {
|
|
135
|
+
this.isLoading = false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async fetchRecords(params) {
|
|
139
|
+
var _a;
|
|
140
|
+
const url = params.url || "/form/data/v1";
|
|
141
|
+
const { form_id, shop_id, num, skip, customer_id, ...rest } = params.query || {};
|
|
142
|
+
const formId = (0, import_utils.normalizeFormId)(form_id);
|
|
143
|
+
const useCache = params.useCache !== false;
|
|
144
|
+
this.isLoading = true;
|
|
145
|
+
this.error = null;
|
|
146
|
+
try {
|
|
147
|
+
const res = await this.request.get(
|
|
148
|
+
url,
|
|
149
|
+
{
|
|
150
|
+
customer_id,
|
|
151
|
+
form_id,
|
|
152
|
+
shop_id,
|
|
153
|
+
num: num || 100,
|
|
154
|
+
skip: skip || 1,
|
|
155
|
+
front_end_cache_id: useCache && this.cacheId,
|
|
156
|
+
...rest
|
|
157
|
+
},
|
|
158
|
+
{ useCache }
|
|
159
|
+
);
|
|
160
|
+
const records = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || [];
|
|
161
|
+
const nextFormMap = { ...this.store.holderMap };
|
|
162
|
+
this.patchFormMap(nextFormMap, formId, { records });
|
|
163
|
+
this.commitFormMap(nextFormMap);
|
|
164
|
+
return records;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
167
|
+
throw error;
|
|
168
|
+
} finally {
|
|
169
|
+
this.isLoading = false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async ensureFormData(params) {
|
|
173
|
+
const formId = (0, import_utils.normalizeFormId)(params.form_id);
|
|
174
|
+
const useCache = params.useCache !== false;
|
|
175
|
+
if (useCache && !params.forceRefresh && this.loadedFormIds.has(formId)) {
|
|
176
|
+
this.notifyFormMapChanged();
|
|
177
|
+
return this.ensureFormItem(formId);
|
|
178
|
+
}
|
|
179
|
+
const current = this.ensureFormItem(formId);
|
|
180
|
+
const tasks = [];
|
|
181
|
+
if (params.forceRefresh || !Object.keys(current.form || {}).length) {
|
|
182
|
+
tasks.push(
|
|
183
|
+
this.fetchFormInfo({
|
|
184
|
+
url: params.formInfoUrl,
|
|
185
|
+
query: {
|
|
186
|
+
form_id: params.form_id
|
|
187
|
+
},
|
|
188
|
+
useCache
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
if (params.forceRefresh || !current.records.length) {
|
|
193
|
+
tasks.push(
|
|
194
|
+
this.fetchRecords({
|
|
195
|
+
url: params.recordsUrl,
|
|
196
|
+
query: {
|
|
197
|
+
form_id: params.form_id,
|
|
198
|
+
shop_id: params.shop_id,
|
|
199
|
+
customer_id: params.customer_id
|
|
200
|
+
},
|
|
201
|
+
useCache
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (!tasks.length) {
|
|
206
|
+
this.notifyFormMapChanged();
|
|
207
|
+
} else {
|
|
208
|
+
await Promise.all(tasks);
|
|
209
|
+
}
|
|
210
|
+
this.loadedFormIds.add(formId);
|
|
211
|
+
return this.ensureFormItem(formId);
|
|
212
|
+
}
|
|
213
|
+
async ensureFormByProduct(params) {
|
|
214
|
+
const holderConfig = (0, import_utils.getProductHolderConfig)(params.product);
|
|
215
|
+
if (!holderConfig)
|
|
216
|
+
return null;
|
|
217
|
+
const formId = (0, import_utils.getFormIdFromHolderConfig)(holderConfig);
|
|
218
|
+
const shopId = params.shop_id ?? params.product.shop_id;
|
|
219
|
+
return this.ensureFormData({
|
|
220
|
+
form_id: formId,
|
|
221
|
+
shop_id: shopId,
|
|
222
|
+
customer_id: params.customer_id,
|
|
223
|
+
useCache: params.useCache,
|
|
224
|
+
skip: 1,
|
|
225
|
+
num: 100
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async addFormRecord(params) {
|
|
229
|
+
const url = params.url || "/form/record";
|
|
230
|
+
const formId = (0, import_utils.normalizeFormId)(params.body.form_id);
|
|
231
|
+
this.isLoading = true;
|
|
232
|
+
this.error = null;
|
|
233
|
+
try {
|
|
234
|
+
await this.request.post(url, params.body);
|
|
235
|
+
const records = await this.fetchRecords({
|
|
236
|
+
query: {
|
|
237
|
+
form_id: params.body.form_id,
|
|
238
|
+
shop_id: params.body.shop_id,
|
|
239
|
+
customer_id: params.body.customer_id
|
|
240
|
+
},
|
|
241
|
+
useCache: false
|
|
242
|
+
});
|
|
243
|
+
this.loadedFormIds.add(formId);
|
|
244
|
+
return records[records.length - 1];
|
|
245
|
+
} catch (error) {
|
|
246
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
247
|
+
throw error;
|
|
248
|
+
} finally {
|
|
249
|
+
this.isLoading = false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
|
|
254
|
+
*/
|
|
255
|
+
appendFormRecord(params) {
|
|
256
|
+
let record = params.record;
|
|
257
|
+
if ((record == null ? void 0 : record.data) && record.form_record_id === void 0) {
|
|
258
|
+
record = record.data;
|
|
259
|
+
}
|
|
260
|
+
const normalizedRecord = (0, import_lodash_es.cloneDeep)(record);
|
|
261
|
+
const formId = (0, import_utils.normalizeFormId)(
|
|
262
|
+
params.form_id ?? normalizedRecord.form_id
|
|
263
|
+
);
|
|
264
|
+
if (!formId) {
|
|
265
|
+
throw new Error("[HolderModule] appendFormRecord: form_id is required");
|
|
266
|
+
}
|
|
267
|
+
if (!normalizedRecord.form_record_id) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
"[HolderModule] appendFormRecord: form_record_id is required"
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
normalizedRecord.form_id = Number(formId) || normalizedRecord.form_id;
|
|
273
|
+
const nextFormMap = { ...this.store.holderMap };
|
|
274
|
+
const current = this.ensureFormItem(formId, nextFormMap);
|
|
275
|
+
const recordIndex = current.records.findIndex(
|
|
276
|
+
(item) => item.form_record_id === normalizedRecord.form_record_id
|
|
277
|
+
);
|
|
278
|
+
const records = recordIndex >= 0 ? current.records.map(
|
|
279
|
+
(item, index) => index === recordIndex ? { ...item, ...normalizedRecord } : item
|
|
280
|
+
) : [...current.records, normalizedRecord];
|
|
281
|
+
this.patchFormMap(nextFormMap, formId, { records });
|
|
282
|
+
this.commitFormMap(nextFormMap);
|
|
283
|
+
this.loadedFormIds.add(formId);
|
|
284
|
+
return normalizedRecord;
|
|
285
|
+
}
|
|
286
|
+
removeFormRecord(formId, formRecordId) {
|
|
287
|
+
const key = (0, import_utils.normalizeFormId)(formId);
|
|
288
|
+
const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
|
|
289
|
+
const nextFormMap = { ...this.store.holderMap };
|
|
290
|
+
this.patchFormMap(nextFormMap, key, {
|
|
291
|
+
records: current.records.filter(
|
|
292
|
+
(record) => record.form_record_id !== formRecordId
|
|
293
|
+
)
|
|
294
|
+
});
|
|
295
|
+
this.commitFormMap(nextFormMap);
|
|
296
|
+
}
|
|
297
|
+
clearFormData(formId) {
|
|
298
|
+
if (formId !== void 0) {
|
|
299
|
+
const key = (0, import_utils.normalizeFormId)(formId);
|
|
300
|
+
const nextFormMap = { ...this.store.holderMap };
|
|
301
|
+
delete nextFormMap[key];
|
|
302
|
+
this.loadedFormIds.delete(key);
|
|
303
|
+
this.commitFormMap(nextFormMap);
|
|
304
|
+
} else {
|
|
305
|
+
this.loadedFormIds.clear();
|
|
306
|
+
this.commitFormMap({});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
storeChange(path) {
|
|
310
|
+
if (path !== "holderMap" && path !== void 0) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (this.openCache) {
|
|
314
|
+
const store = (0, import_lodash_es.cloneDeep)(this.store);
|
|
315
|
+
this.checkSaveCache({
|
|
316
|
+
cacheId: this.cacheId,
|
|
317
|
+
fatherModule: this.fatherModule,
|
|
318
|
+
store,
|
|
319
|
+
cacheKey: ["holderMap"]
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
325
|
+
0 && (module.exports = {
|
|
326
|
+
HolderModule,
|
|
327
|
+
...require("./types"),
|
|
328
|
+
...require("./utils")
|
|
329
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
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 | string;
|
|
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 HolderModuleAPI {
|
|
104
|
+
getHolderFormMap: () => HolderFormMap;
|
|
105
|
+
getHolderFormData: (formId: number | string) => IFormItemData | undefined;
|
|
106
|
+
setFormData: (formId: number | string, data: Partial<IFormItemData>) => void;
|
|
107
|
+
fetchFormInfo: (params: IFetchFormInfoParams) => Promise<IFormInfo | IFormInfo[]>;
|
|
108
|
+
fetchRecords: (params: IFetchFormRecordsParams) => Promise<IFormRecord[]>;
|
|
109
|
+
ensureFormData: (params: IEnsureFormDataParams) => Promise<IFormItemData>;
|
|
110
|
+
ensureFormByProduct: (params: IEnsureFormByProductParams) => Promise<IFormItemData | null>;
|
|
111
|
+
addFormRecord: (params: IAddFormRecordParams) => Promise<IFormRecord>;
|
|
112
|
+
appendFormRecord: (params: IAppendFormRecordParams) => IFormRecord;
|
|
113
|
+
removeFormRecord: (formId: number | string, formRecordId: number) => void;
|
|
114
|
+
clearFormData: (formId?: number | string) => void;
|
|
115
|
+
}
|
|
@@ -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,9 @@
|
|
|
1
|
+
import { ProductData } from '../Product/types';
|
|
2
|
+
import { IHolderConfig } from './types';
|
|
3
|
+
export declare function getProductHolderConfig(product?: ProductData | Record<string, any> | null): IHolderConfig | null;
|
|
4
|
+
export declare function getFormIdFromHolderConfig(config: IHolderConfig): string;
|
|
5
|
+
export declare function normalizeFormId(formId: number | string): string;
|
|
6
|
+
export declare function createEmptyFormItemData(): {
|
|
7
|
+
records: any[];
|
|
8
|
+
form: Record<string, any>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/Holder/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
createEmptyFormItemData: () => createEmptyFormItemData,
|
|
23
|
+
getFormIdFromHolderConfig: () => getFormIdFromHolderConfig,
|
|
24
|
+
getProductHolderConfig: () => getProductHolderConfig,
|
|
25
|
+
normalizeFormId: () => normalizeFormId
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
function getProductHolderConfig(product) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!product)
|
|
31
|
+
return null;
|
|
32
|
+
const config = (product == null ? void 0 : product.holder_config) ?? ((_a = product == null ? void 0 : product.origin) == null ? void 0 : _a.holder_config);
|
|
33
|
+
if ((config == null ? void 0 : config.status) && (config == null ? void 0 : config.status) !== "enable")
|
|
34
|
+
return null;
|
|
35
|
+
if (!(config == null ? void 0 : config.resource_id))
|
|
36
|
+
return null;
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
function getFormIdFromHolderConfig(config) {
|
|
40
|
+
return String(config == null ? void 0 : config.resource_id);
|
|
41
|
+
}
|
|
42
|
+
function normalizeFormId(formId) {
|
|
43
|
+
return String(formId);
|
|
44
|
+
}
|
|
45
|
+
function createEmptyFormItemData() {
|
|
46
|
+
return {
|
|
47
|
+
records: [],
|
|
48
|
+
form: {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
createEmptyFormItemData,
|
|
54
|
+
getFormIdFromHolderConfig,
|
|
55
|
+
getProductHolderConfig,
|
|
56
|
+
normalizeFormId
|
|
57
|
+
});
|
|
@@ -210,6 +210,13 @@ export interface ProductData {
|
|
|
210
210
|
option_group_count: number;
|
|
211
211
|
/** 服务时长 */
|
|
212
212
|
service_times?: any;
|
|
213
|
+
/** holder 表单配置 */
|
|
214
|
+
holder_config?: {
|
|
215
|
+
required?: number;
|
|
216
|
+
resource_id?: number;
|
|
217
|
+
status?: string;
|
|
218
|
+
[key: string]: any;
|
|
219
|
+
};
|
|
213
220
|
}
|
|
214
221
|
/**
|
|
215
222
|
* 商品媒体信息接口
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __reExport(modules_exports, require("./Schedule"), module.exports);
|
|
|
34
34
|
__reExport(modules_exports, require("./Quotation"), module.exports);
|
|
35
35
|
__reExport(modules_exports, require("./ScanOrderLogger"), module.exports);
|
|
36
36
|
__reExport(modules_exports, require("./OpenData"), module.exports);
|
|
37
|
+
__reExport(modules_exports, require("./Holder"), module.exports);
|
|
37
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
39
|
0 && (module.exports = {
|
|
39
40
|
...require("./Product"),
|
|
@@ -53,5 +54,6 @@ __reExport(modules_exports, require("./OpenData"), module.exports);
|
|
|
53
54
|
...require("./Schedule"),
|
|
54
55
|
...require("./Quotation"),
|
|
55
56
|
...require("./ScanOrderLogger"),
|
|
56
|
-
...require("./OpenData")
|
|
57
|
+
...require("./OpenData"),
|
|
58
|
+
...require("./Holder")
|
|
57
59
|
});
|
|
@@ -10,6 +10,7 @@ import { ITime } from '../../modules/Date/types';
|
|
|
10
10
|
import dayjs from 'dayjs';
|
|
11
11
|
import { LoadScheduleAvailableDateParams } from '../../modules/Schedule/types';
|
|
12
12
|
import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
|
|
13
|
+
import { IAppendFormRecordParams } from '../../modules/Holder/types';
|
|
13
14
|
export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
14
15
|
protected defaultName: string;
|
|
15
16
|
protected defaultVersion: string;
|
|
@@ -126,6 +127,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
126
127
|
* @param params
|
|
127
128
|
*/
|
|
128
129
|
fetchHolderAccountsAsync(params: IFetchHolderAccountsParams): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* 获取 holder 表单 map
|
|
132
|
+
*/
|
|
133
|
+
getHolderFormMap(): import("../../modules").HolderFormMap;
|
|
134
|
+
/**
|
|
135
|
+
* 添加表单记录
|
|
136
|
+
*/
|
|
137
|
+
appendFormRecord(params: IAppendFormRecordParams): import("../../modules").IFormRecord;
|
|
129
138
|
setDateRange(dateRange: ITime[]): Promise<void>;
|
|
130
139
|
clearDateRange(): void;
|
|
131
140
|
getDateRange(): Promise<ITime[]>;
|
|
@@ -89,6 +89,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
89
89
|
}
|
|
90
90
|
const moduleArr = [
|
|
91
91
|
"accountList",
|
|
92
|
+
"holder",
|
|
92
93
|
"cart",
|
|
93
94
|
"schedule",
|
|
94
95
|
"summary",
|
|
@@ -379,6 +380,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
379
380
|
}
|
|
380
381
|
return this.store.accountList.fetchHolderAccounts(params);
|
|
381
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* 获取 holder 表单 map
|
|
385
|
+
*/
|
|
386
|
+
getHolderFormMap() {
|
|
387
|
+
return this.store.holder.getHolderFormMap();
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* 添加表单记录
|
|
391
|
+
*/
|
|
392
|
+
appendFormRecord(params) {
|
|
393
|
+
return this.store.holder.appendFormRecord(params);
|
|
394
|
+
}
|
|
382
395
|
// 设置日期范围,注入到日期模块中
|
|
383
396
|
async setDateRange(dateRange) {
|
|
384
397
|
this.store.date.setDateRange(dateRange);
|
|
@@ -630,6 +643,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
630
643
|
account = activeAccount;
|
|
631
644
|
}
|
|
632
645
|
}
|
|
646
|
+
try {
|
|
647
|
+
this.store.holder.ensureFormByProduct({
|
|
648
|
+
product: productData,
|
|
649
|
+
customer_id: (account == null ? void 0 : account.id) ? Number(account.id) : 16121,
|
|
650
|
+
shop_id: (productData == null ? void 0 : productData.shop_id) || "",
|
|
651
|
+
useCache: true
|
|
652
|
+
});
|
|
653
|
+
} catch (error) {
|
|
654
|
+
console.error("[BookingByStep] 加载 holder 表单失败", error);
|
|
655
|
+
}
|
|
633
656
|
const flag = this.store.cart.mergeCartItemByRowKey({
|
|
634
657
|
rowKey,
|
|
635
658
|
quantity,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule } from '../../modules';
|
|
1
|
+
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule, HolderModule } from '../../modules';
|
|
2
2
|
export interface BookingByStepState {
|
|
3
3
|
cart: CartModule;
|
|
4
4
|
summary: SummaryModule;
|
|
@@ -16,6 +16,7 @@ export interface BookingByStepState {
|
|
|
16
16
|
schedule: ScheduleModule;
|
|
17
17
|
salesSummary?: SalesSummaryModule;
|
|
18
18
|
scanOrderLogger?: ScanOrderLoggerModule;
|
|
19
|
+
holder: HolderModule;
|
|
19
20
|
}
|
|
20
21
|
export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
|
|
21
22
|
export declare enum BookingByStepHooks {
|