@pisell/pisellos 0.0.33 → 0.0.34

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.
@@ -157,7 +157,8 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
157
157
  return this.request.get(fetchUrl, {
158
158
  start_date: start_date,
159
159
  end_date: end_date,
160
- resource_ids: resource_ids
160
+ resource_ids: resource_ids,
161
+ front_end_cache_id: this.cacheId
161
162
  }, {
162
163
  useCache: true
163
164
  });
@@ -206,7 +207,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
206
207
  cacheId: this.cacheId,
207
208
  fatherModule: this.fatherModule,
208
209
  store: this.store,
209
- cacheKey: ['dateRange', 'dateList']
210
+ cacheKey: ["dateRange", "dateList"]
210
211
  });
211
212
  }
212
213
  }
@@ -16,6 +16,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
16
16
  private shopStore;
17
17
  private store;
18
18
  private otherParams;
19
+ private cacheId;
19
20
  initialize(core: PisellCore, options: any): Promise<void>;
20
21
  initStep(stepList: (keyof BookingByStepState)[]): void;
21
22
  getCurrentStep(): {
@@ -106,7 +107,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
106
107
  timeSlots: any[];
107
108
  selectedResource: any;
108
109
  } | undefined;
109
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
110
+ autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, }: {
110
111
  holder_id: string;
111
112
  resources_code: string | number;
112
113
  timeSlots?: TimeSliceItem;
@@ -49,6 +49,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
49
49
  _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
50
50
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
51
51
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
52
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
52
53
  return _this;
53
54
  }
54
55
  _createClass(BookingByStepImpl, [{
@@ -56,6 +57,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
56
57
  value: function () {
57
58
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
58
59
  var _this$otherParams,
60
+ _this$otherParams2,
59
61
  _this2 = this;
60
62
  var targetCacheData, sessionData, data, moduleArr;
61
63
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -78,7 +80,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
78
80
  // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
79
81
  // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
80
82
  targetCacheData = {};
81
- if ((_this$otherParams = this.otherParams) !== null && _this$otherParams !== void 0 && _this$otherParams.cacheId) {
83
+ this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
84
+ if ((_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.cacheId) {
82
85
  sessionData = this.window.sessionStorage.getItem(this.name);
83
86
  if (sessionData) {
84
87
  data = JSON.parse(sessionData); // 匹配 cacheid,如果匹配不到,直接把 sessionData 清掉即可
@@ -105,7 +108,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
105
108
  }
106
109
  });
107
110
  this.core.effects.emit(BookingByStepHooks.onInited, {});
108
- case 14:
111
+ case 15:
109
112
  case "end":
110
113
  return _context.stop();
111
114
  }
@@ -183,7 +186,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
183
186
  skip: 1,
184
187
  category_ids: category_ids,
185
188
  ids: product_ids,
186
- collection: collection
189
+ collection: collection,
190
+ front_end_cache_id: this.cacheId
187
191
  }, {
188
192
  useCache: true
189
193
  });
@@ -368,7 +372,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
368
372
  key: "getAvailableDate",
369
373
  value: function () {
370
374
  var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
371
- var _this$otherParams2, _this$otherParams3;
375
+ var _this$otherParams3, _this$otherParams4;
372
376
  var params,
373
377
  products,
374
378
  startDate,
@@ -391,8 +395,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
391
395
  tempProducts = products || this.store.cart.getItems().map(function (p) {
392
396
  return p._productOrigin;
393
397
  });
394
- tempStartDate = startDate || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 || (_this$otherParams2 = _this$otherParams2.dateRange) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2[0]);
395
- tempEndDate = endDate || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 || (_this$otherParams3 = _this$otherParams3.dateRange) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3[1]);
398
+ tempStartDate = startDate || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 || (_this$otherParams3 = _this$otherParams3.dateRange) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3[0]);
399
+ tempEndDate = endDate || ((_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 || (_this$otherParams4 = _this$otherParams4.dateRange) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4[1]);
396
400
  if (tempProducts.length) {
397
401
  _context8.next = 7;
398
402
  break;
@@ -1055,7 +1059,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1055
1059
  timeSlots: recordTimeSlots,
1056
1060
  countMap: selectResourcesMap
1057
1061
  });
1058
- // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1062
+ // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1059
1063
  // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
1060
1064
  // return
1061
1065
  // }
@@ -1089,7 +1093,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1089
1093
  })) === null || _productResources$fin === void 0 ? void 0 : _productResources$fin.renderList;
1090
1094
  if (targetRenderList && targetRenderList.length > 0) {
1091
1095
  var _item$_origin$resourc2;
1092
- // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1096
+ // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1093
1097
  if ((_item$_origin$resourc2 = item._origin.resources) !== null && _item$_origin$resourc2 !== void 0 && _item$_origin$resourc2.some(function (n) {
1094
1098
  return n.form_id === targetRenderList[0].form_id;
1095
1099
  })) {
@@ -89,7 +89,16 @@ var DateModule = class extends import_BaseModule.BaseModule {
89
89
  return (0, import_utils.disableAllDates)(dates);
90
90
  }
91
91
  try {
92
- const res = await this.request.get(fetchUrl, { start_date, end_date, resource_ids }, { useCache: true });
92
+ const res = await this.request.get(
93
+ fetchUrl,
94
+ {
95
+ start_date,
96
+ end_date,
97
+ resource_ids,
98
+ front_end_cache_id: this.cacheId
99
+ },
100
+ { useCache: true }
101
+ );
93
102
  if (!((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.length)) {
94
103
  return (0, import_utils.disableAllDates)(dates);
95
104
  }
@@ -108,7 +117,12 @@ var DateModule = class extends import_BaseModule.BaseModule {
108
117
  }
109
118
  storeChange() {
110
119
  if (this.openCache) {
111
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["dateRange", "dateList"] });
120
+ this.checkSaveCache({
121
+ cacheId: this.cacheId,
122
+ fatherModule: this.fatherModule,
123
+ store: this.store,
124
+ cacheKey: ["dateRange", "dateList"]
125
+ });
112
126
  }
113
127
  }
114
128
  };
@@ -16,6 +16,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
16
16
  private shopStore;
17
17
  private store;
18
18
  private otherParams;
19
+ private cacheId;
19
20
  initialize(core: PisellCore, options: any): Promise<void>;
20
21
  initStep(stepList: (keyof BookingByStepState)[]): void;
21
22
  getCurrentStep(): {
@@ -106,7 +107,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
106
107
  timeSlots: any[];
107
108
  selectedResource: any;
108
109
  } | undefined;
109
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
110
+ autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, }: {
110
111
  holder_id: string;
111
112
  resources_code: string | number;
112
113
  timeSlots?: TimeSliceItem;
@@ -48,7 +48,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
48
48
  this.otherParams = {};
49
49
  }
50
50
  async initialize(core, options) {
51
- var _a;
51
+ var _a, _b;
52
52
  this.core = core;
53
53
  this.store = options.store || {};
54
54
  this.otherParams = options.otherParams || {};
@@ -60,34 +60,29 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
60
60
  throw new Error("bookingByStep解决方案需要 request 插件支持");
61
61
  }
62
62
  let targetCacheData = {};
63
- if ((_a = this.otherParams) == null ? void 0 : _a.cacheId) {
63
+ this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
64
+ if ((_b = this.otherParams) == null ? void 0 : _b.cacheId) {
64
65
  const sessionData = this.window.sessionStorage.getItem(this.name);
65
66
  if (sessionData) {
66
67
  const data = JSON.parse(sessionData);
67
68
  targetCacheData = data[this.otherParams.cacheId];
68
69
  }
69
70
  }
70
- const moduleArr = [
71
- "accountList",
72
- "cart",
73
- "summary",
74
- "step",
75
- "products",
76
- "date",
77
- "order",
78
- "payment"
79
- ];
71
+ const moduleArr = ["accountList", "cart", "summary", "step", "products", "date", "order", "payment"];
80
72
  moduleArr.forEach((step) => {
81
- var _a2, _b;
73
+ var _a2, _b2;
82
74
  const targetModule = (0, import_types.createModule)(step, this.name);
83
75
  if (targetModule) {
84
76
  this.store[step] = targetModule;
85
- this.core.registerModule(targetModule, { initialState: targetCacheData == null ? void 0 : targetCacheData[targetModule.name], otherParams: {
86
- ...this.otherParams,
87
- fatherModule: this.name,
88
- openCache: ((_a2 = this.otherParams) == null ? void 0 : _a2.cacheId) ? true : false,
89
- cacheId: (_b = this.otherParams) == null ? void 0 : _b.cacheId
90
- } });
77
+ this.core.registerModule(targetModule, {
78
+ initialState: targetCacheData == null ? void 0 : targetCacheData[targetModule.name],
79
+ otherParams: {
80
+ ...this.otherParams,
81
+ fatherModule: this.name,
82
+ openCache: ((_a2 = this.otherParams) == null ? void 0 : _a2.cacheId) ? true : false,
83
+ cacheId: (_b2 = this.otherParams) == null ? void 0 : _b2.cacheId
84
+ }
85
+ });
91
86
  } else {
92
87
  throw new Error(`模块 ${step} 不存在`);
93
88
  }
@@ -130,18 +125,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
130
125
  product_ids = [],
131
126
  collection = []
132
127
  }) {
133
- const productsData = await this.request.post(`/product/query`, {
134
- open_quotation: 1,
135
- open_bundle: 1,
136
- extension_type: ["product_appointment", "appointment_ticket"],
137
- with: ["category", "collection"],
138
- status: "published",
139
- num: 500,
140
- skip: 1,
141
- category_ids,
142
- ids: product_ids,
143
- collection
144
- }, { useCache: true });
128
+ const productsData = await this.request.post(
129
+ `/product/query`,
130
+ {
131
+ open_quotation: 1,
132
+ open_bundle: 1,
133
+ extension_type: ["product_appointment", "appointment_ticket"],
134
+ with: ["category", "collection"],
135
+ status: "published",
136
+ num: 500,
137
+ skip: 1,
138
+ category_ids,
139
+ ids: product_ids,
140
+ collection,
141
+ front_end_cache_id: this.cacheId
142
+ },
143
+ { useCache: true }
144
+ );
145
145
  this.store.products.addProduct(productsData.data.list);
146
146
  return productsData.data.list;
147
147
  }
@@ -560,8 +560,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
560
560
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
561
561
  if (timeSlots) {
562
562
  if (index !== 0 && recordTimeSlots) {
563
- let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes");
564
- let end_at = start_at.add(((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0, ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes");
563
+ let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
564
+ ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
565
+ ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
566
+ );
567
+ let end_at = start_at.add(
568
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
569
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
570
+ );
565
571
  recordTimeSlots = {
566
572
  start_time: start_at.format("HH:mm"),
567
573
  end_time: end_at.format("HH:mm"),
@@ -680,7 +686,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
680
686
  newResources.forEach((resource) => {
681
687
  var _a, _b, _c, _d;
682
688
  resource.startTime = currentStartTime;
683
- resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes").format("YYYY-MM-DD HH:mm");
689
+ resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
690
+ ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
691
+ ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
692
+ ).format("YYYY-MM-DD HH:mm");
684
693
  delete resource.times;
685
694
  });
686
695
  this.store.cart.updateItem({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.33",
4
+ "version": "0.0.34",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",