@pisell/pisellos 0.0.21 → 0.0.22

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.
@@ -321,10 +321,17 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
321
321
  key: "storeChange",
322
322
  value: function storeChange() {
323
323
  if (this.openCache) {
324
+ var store = cloneDeep(this.store);
325
+ // store里的 accountList 要主动基于 id 做下去重,避免重复写入
326
+ store.accountList = store.accountList.filter(function (account, index, self) {
327
+ return index === self.findIndex(function (t) {
328
+ return t.id === account.id;
329
+ });
330
+ });
324
331
  this.checkSaveCache({
325
332
  cacheId: this.cacheId,
326
333
  fatherModule: this.fatherModule,
327
- store: this.store,
334
+ store: store,
328
335
  cacheKey: ['accountList']
329
336
  });
330
337
  }
@@ -379,11 +379,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
379
379
  key: "storeChange",
380
380
  value: function storeChange() {
381
381
  if (this.openCache) {
382
+ var store = cloneDeep(this.store);
383
+ // store里的 list 要主动基于 id 做下去重,避免重复写入
384
+ store.list = store.list.filter(function (item, index, self) {
385
+ return index === self.findIndex(function (t) {
386
+ return t._id === item._id;
387
+ });
388
+ });
382
389
  this.checkSaveCache({
383
390
  cacheId: this.cacheId,
384
391
  fatherModule: this.fatherModule,
385
- store: this.store,
386
- cacheKey: ['list']
392
+ store: store,
393
+ cacheKey: ["list"]
387
394
  });
388
395
  }
389
396
  }
@@ -1057,15 +1057,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1057
1057
  var cartItems = this.store.cart.getItems();
1058
1058
  var resourceIds = [];
1059
1059
  cartItems.forEach(function (item) {
1060
- var _item$_productOrigin2, _item$_origin$resourc2;
1060
+ var _item$_productOrigin2;
1061
1061
  (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 || _item$_productOrigin2.forEach(function (n) {
1062
1062
  if (n.code === resources_code) {
1063
1063
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1064
1064
  }
1065
1065
  });
1066
- (_item$_origin$resourc2 = item._origin.resources) === null || _item$_origin$resourc2 === void 0 || _item$_origin$resourc2.forEach(function (n) {
1067
- resourceIds.push(n.relation_id);
1068
- });
1066
+ // item._origin.resources?.forEach((n: any) => {
1067
+ // resourceIds.push(n.relation_id);
1068
+ // });
1069
+ if (item.resource_id) {
1070
+ resourceIds.push(item.resource_id);
1071
+ }
1069
1072
  });
1070
1073
  var resourcesMap = getResourcesMap(resources);
1071
1074
  var duration = 0;
@@ -164,7 +164,11 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
164
164
  }
165
165
  storeChange() {
166
166
  if (this.openCache) {
167
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["accountList"] });
167
+ const store = (0, import_lodash_es.cloneDeep)(this.store);
168
+ store.accountList = store.accountList.filter(
169
+ (account, index, self) => index === self.findIndex((t) => t.id === account.id)
170
+ );
171
+ this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store, cacheKey: ["accountList"] });
168
172
  }
169
173
  }
170
174
  };
@@ -76,7 +76,12 @@ var CartModule = class extends import_BaseModule.BaseModule {
76
76
  };
77
77
  if (product) {
78
78
  cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
79
- cartItem = (0, import_utils.formatProductToCartItem)({ cartItem, product, bundle, options });
79
+ cartItem = (0, import_utils.formatProductToCartItem)({
80
+ cartItem,
81
+ product,
82
+ bundle,
83
+ options
84
+ });
80
85
  }
81
86
  if (account) {
82
87
  cartItem = (0, import_utils.formatAccountToCartItem)({ cartItem, account });
@@ -117,16 +122,28 @@ var CartModule = class extends import_BaseModule.BaseModule {
117
122
  }
118
123
  if (product) {
119
124
  tempCartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
120
- tempCartItem = (0, import_utils.formatProductToCartItem)({ cartItem: tempCartItem, product });
125
+ tempCartItem = (0, import_utils.formatProductToCartItem)({
126
+ cartItem: tempCartItem,
127
+ product
128
+ });
121
129
  }
122
130
  if (discounts) {
123
- tempCartItem = (0, import_utils.formatDiscountToCartItem)({ cartItem: tempCartItem, discounts });
131
+ tempCartItem = (0, import_utils.formatDiscountToCartItem)({
132
+ cartItem: tempCartItem,
133
+ discounts
134
+ });
124
135
  }
125
136
  if (account) {
126
- tempCartItem = (0, import_utils.formatAccountToCartItem)({ cartItem: tempCartItem, account });
137
+ tempCartItem = (0, import_utils.formatAccountToCartItem)({
138
+ cartItem: tempCartItem,
139
+ account
140
+ });
127
141
  }
128
142
  if (resources) {
129
- tempCartItem = (0, import_utils.formatResourceToCartItem)({ cartItem: tempCartItem, resources });
143
+ tempCartItem = (0, import_utils.formatResourceToCartItem)({
144
+ cartItem: tempCartItem,
145
+ resources
146
+ });
130
147
  }
131
148
  if (note) {
132
149
  tempCartItem = (0, import_utils.formatNoteToCartItem)({ cartItem: tempCartItem, note });
@@ -155,7 +172,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
155
172
  * 根据账户ID获取购物车
156
173
  */
157
174
  getCartByAccount(account_id) {
158
- return this.store.list.filter((item) => item.holder_id === account_id);
175
+ return this.store.list.filter(
176
+ (item) => item.holder_id === account_id
177
+ );
159
178
  }
160
179
  /**
161
180
  * 移除购物车商品
@@ -169,7 +188,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
169
188
  * 根据账户ID清除购物车
170
189
  */
171
190
  clearCartByAccount(account_id) {
172
- const items = this.store.list.filter((item) => item.holder_id !== account_id);
191
+ const items = this.store.list.filter(
192
+ (item) => item.holder_id !== account_id
193
+ );
173
194
  this.store.list = [...items || []];
174
195
  }
175
196
  /**
@@ -194,7 +215,16 @@ var CartModule = class extends import_BaseModule.BaseModule {
194
215
  }
195
216
  storeChange() {
196
217
  if (this.openCache) {
197
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["list"] });
218
+ const store = (0, import_lodash_es.cloneDeep)(this.store);
219
+ store.list = store.list.filter(
220
+ (item, index, self) => index === self.findIndex((t) => t._id === item._id)
221
+ );
222
+ this.checkSaveCache({
223
+ cacheId: this.cacheId,
224
+ fatherModule: this.fatherModule,
225
+ store,
226
+ cacheKey: ["list"]
227
+ });
198
228
  }
199
229
  }
200
230
  };
@@ -598,15 +598,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
598
598
  const cartItems = this.store.cart.getItems();
599
599
  const resourceIds = [];
600
600
  cartItems.forEach((item) => {
601
- var _a, _b, _c, _d;
601
+ var _a, _b, _c;
602
602
  (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
603
603
  if (n.code === resources_code) {
604
604
  resources.push(...n.renderList || []);
605
605
  }
606
606
  });
607
- (_d = item._origin.resources) == null ? void 0 : _d.forEach((n) => {
608
- resourceIds.push(n.relation_id);
609
- });
607
+ if (item.resource_id) {
608
+ resourceIds.push(item.resource_id);
609
+ }
610
610
  });
611
611
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
612
612
  let duration = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.21",
4
+ "version": "0.0.22",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",