@pisell/pisellos 0.0.53 → 0.0.54

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.
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from './types';
3
+ import { CartItem, CartModuleAPI, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
4
4
  export * from './types';
5
5
  /**
6
6
  * 购物车模块实现
@@ -57,8 +57,10 @@ export declare class CartModule extends BaseModule implements Module, CartModule
57
57
  clearCartByAccount(account_id: string): void;
58
58
  /**
59
59
  * 清除购物车商品中的信息
60
+ * @param type 清除购物车商品中的信息类型
61
+ * @param _id 购物车商品ID
60
62
  */
61
- deleteCartItemInfo(types: 'resource' | 'time' | 'relationForms'): void;
63
+ deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
62
64
  /**
63
65
  * 清除购物车
64
66
  */
@@ -22,7 +22,8 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
22
22
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
23
23
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
24
  import { BaseModule } from "../BaseModule";
25
- import { createCartItemOrigin, deleteRelationFormsFromCartItem, deleteResourceFromCartItem, deleteTimeFromCartItem, formatAccountToCartItem, formatDateToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatRelationFormsToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
25
+ import { ECartItemInfoType } from "./types";
26
+ import { createCartItemOrigin, deleteHolderFromCartItem, deleteRelationFormsFromCartItem, deleteResourceFromCartItem, deleteTimeFromCartItem, formatAccountToCartItem, formatDateToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatRelationFormsToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
26
27
  import { cloneDeep } from 'lodash-es';
27
28
  export * from "./types";
28
29
 
@@ -379,20 +380,36 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
379
380
 
380
381
  /**
381
382
  * 清除购物车商品中的信息
383
+ * @param type 清除购物车商品中的信息类型
384
+ * @param _id 购物车商品ID
382
385
  */
383
386
  }, {
384
387
  key: "deleteCartItemInfo",
385
- value: function deleteCartItemInfo(types) {
388
+ value: function deleteCartItemInfo(type, _id) {
386
389
  var list = this.store.list.map(function (item) {
387
- // 清除购物车商品中的资源信息
388
- if (types === 'resource') {
389
- item = deleteResourceFromCartItem(item);
390
- } else if (types === 'time') {
391
- // 清除购物车商品中的时间信息
392
- item = deleteTimeFromCartItem(item);
393
- } else if (types === 'relationForms') {
394
- // 清除购物车商品中的关联表单信息
395
- item = deleteRelationFormsFromCartItem(item);
390
+ var needDelete = _id ? item._id === _id : true;
391
+
392
+ // 如果存在_id,则只需要操作对应的购物车数据,否则操作所有
393
+ if (!needDelete) {
394
+ return item;
395
+ }
396
+ switch (type) {
397
+ case ECartItemInfoType.Resource:
398
+ // 清除购物车商品中的资源信息
399
+ item = deleteResourceFromCartItem(item);
400
+ break;
401
+ case ECartItemInfoType.Time:
402
+ // 清除购物车商品中的时间信息
403
+ item = deleteTimeFromCartItem(item);
404
+ break;
405
+ case ECartItemInfoType.RelationForms:
406
+ // 清除购物车商品中的关联表单信息
407
+ item = deleteRelationFormsFromCartItem(item);
408
+ break;
409
+ case ECartItemInfoType.Holder:
410
+ // 清除购物车商品中的账户信息
411
+ item = deleteHolderFromCartItem(item);
412
+ break;
396
413
  }
397
414
  return item;
398
415
  });
@@ -7,6 +7,19 @@ export declare enum CartHooks {
7
7
  OnCartUpdateItem = "card:onCartUpdateItem",
8
8
  OnCartRemove = "card:onCartRemove"
9
9
  }
10
+ /**
11
+ * 购物车商品信息类型
12
+ */
13
+ export declare enum ECartItemInfoType {
14
+ /** 资源信息 */
15
+ Resource = "resource",
16
+ /** 时间信息 */
17
+ Time = "time",
18
+ /** 关联表单信息 */
19
+ RelationForms = "relationForms",
20
+ /** 账户信息 */
21
+ Holder = "holder"
22
+ }
10
23
  export interface CartModuleAPI {
11
24
  /** 添加商品到购物车 */
12
25
  addItem: (item: IAddItemParams) => Promise<void>;
@@ -26,6 +39,8 @@ export interface CartModuleAPI {
26
39
  getCartByAccount: (account_id: string) => CartItem[];
27
40
  /** 清除购物车 */
28
41
  clear: () => void;
42
+ /** 清除购物车商品中的信息 */
43
+ deleteCartItemInfo: (type: ECartItemInfoType, _id?: string) => void;
29
44
  }
30
45
  /**
31
46
  * 购物车商品接口
@@ -6,6 +6,17 @@ export var CartHooks = /*#__PURE__*/function (CartHooks) {
6
6
  return CartHooks;
7
7
  }({});
8
8
 
9
+ /**
10
+ * 购物车商品信息类型
11
+ */
12
+ export var ECartItemInfoType = /*#__PURE__*/function (ECartItemInfoType) {
13
+ ECartItemInfoType["Resource"] = "resource";
14
+ ECartItemInfoType["Time"] = "time";
15
+ ECartItemInfoType["RelationForms"] = "relationForms";
16
+ ECartItemInfoType["Holder"] = "holder";
17
+ return ECartItemInfoType;
18
+ }({});
19
+
9
20
  /**
10
21
  * 购物车商品接口
11
22
  */
@@ -251,3 +251,4 @@ export declare const deleteTimeFromCartItem: (cartItem: CartItem) => CartItem;
251
251
  * @returns 删除后的购物车
252
252
  */
253
253
  export declare const deleteRelationFormsFromCartItem: (cartItem: CartItem) => CartItem;
254
+ export declare const deleteHolderFromCartItem: (cartItem: CartItem) => CartItem;
@@ -671,4 +671,13 @@ export var deleteRelationFormsFromCartItem = function deleteRelationFormsFromCar
671
671
  // 删除原始数据
672
672
  cartItem._origin.relation_forms = null;
673
673
  return cartItem;
674
+ };
675
+ export var deleteHolderFromCartItem = function deleteHolderFromCartItem(cartItem) {
676
+ // 删除UI层的数据
677
+ cartItem.holder_id = undefined;
678
+ cartItem.holder_title = undefined;
679
+
680
+ // 删除原始数据
681
+ cartItem._origin.holder = null;
682
+ return cartItem;
674
683
  };
@@ -2,7 +2,7 @@ import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { Response } from '../../plugins';
4
4
  import { BookingByStepState } from './types';
5
- import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem } from '../../modules';
5
+ import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem, ECartItemInfoType } from '../../modules';
6
6
  import { Account } from '../../modules/Account/types';
7
7
  import { IStep } from '../../modules/Step/tyeps';
8
8
  import { TimeSliceItem } from './utils/resources';
@@ -130,7 +130,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
130
130
  /**
131
131
  * 从购物车中按类别删除信息
132
132
  */
133
- deleteCartItemInfo(types: 'resource' | 'time' | 'relationForms'): void;
133
+ deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
134
134
  destroy(): void;
135
135
  getResourcesList(): any[];
136
136
  getResourcesListByCartItem(id: string | number): {
@@ -1063,8 +1063,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1063
1063
  */
1064
1064
  }, {
1065
1065
  key: "deleteCartItemInfo",
1066
- value: function deleteCartItemInfo(types) {
1067
- this.store.cart.deleteCartItemInfo(types);
1066
+ value: function deleteCartItemInfo(type, _id) {
1067
+ this.store.cart.deleteCartItemInfo(type, _id);
1068
1068
  }
1069
1069
  }, {
1070
1070
  key: "destroy",
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from './types';
3
+ import { CartItem, CartModuleAPI, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
4
4
  export * from './types';
5
5
  /**
6
6
  * 购物车模块实现
@@ -57,8 +57,10 @@ export declare class CartModule extends BaseModule implements Module, CartModule
57
57
  clearCartByAccount(account_id: string): void;
58
58
  /**
59
59
  * 清除购物车商品中的信息
60
+ * @param type 清除购物车商品中的信息类型
61
+ * @param _id 购物车商品ID
60
62
  */
61
- deleteCartItemInfo(types: 'resource' | 'time' | 'relationForms'): void;
63
+ deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
62
64
  /**
63
65
  * 清除购物车
64
66
  */
@@ -24,6 +24,7 @@ __export(Cart_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(Cart_exports);
26
26
  var import_BaseModule = require("../BaseModule");
27
+ var import_types = require("./types");
27
28
  var import_utils = require("./utils");
28
29
  var import_lodash_es = require("lodash-es");
29
30
  __reExport(Cart_exports, require("./types"), module.exports);
@@ -226,15 +227,28 @@ var CartModule = class extends import_BaseModule.BaseModule {
226
227
  }
227
228
  /**
228
229
  * 清除购物车商品中的信息
230
+ * @param type 清除购物车商品中的信息类型
231
+ * @param _id 购物车商品ID
229
232
  */
230
- deleteCartItemInfo(types) {
233
+ deleteCartItemInfo(type, _id) {
231
234
  const list = this.store.list.map((item) => {
232
- if (types === "resource") {
233
- item = (0, import_utils.deleteResourceFromCartItem)(item);
234
- } else if (types === "time") {
235
- item = (0, import_utils.deleteTimeFromCartItem)(item);
236
- } else if (types === "relationForms") {
237
- item = (0, import_utils.deleteRelationFormsFromCartItem)(item);
235
+ const needDelete = _id ? item._id === _id : true;
236
+ if (!needDelete) {
237
+ return item;
238
+ }
239
+ switch (type) {
240
+ case import_types.ECartItemInfoType.Resource:
241
+ item = (0, import_utils.deleteResourceFromCartItem)(item);
242
+ break;
243
+ case import_types.ECartItemInfoType.Time:
244
+ item = (0, import_utils.deleteTimeFromCartItem)(item);
245
+ break;
246
+ case import_types.ECartItemInfoType.RelationForms:
247
+ item = (0, import_utils.deleteRelationFormsFromCartItem)(item);
248
+ break;
249
+ case import_types.ECartItemInfoType.Holder:
250
+ item = (0, import_utils.deleteHolderFromCartItem)(item);
251
+ break;
238
252
  }
239
253
  return item;
240
254
  });
@@ -7,6 +7,19 @@ export declare enum CartHooks {
7
7
  OnCartUpdateItem = "card:onCartUpdateItem",
8
8
  OnCartRemove = "card:onCartRemove"
9
9
  }
10
+ /**
11
+ * 购物车商品信息类型
12
+ */
13
+ export declare enum ECartItemInfoType {
14
+ /** 资源信息 */
15
+ Resource = "resource",
16
+ /** 时间信息 */
17
+ Time = "time",
18
+ /** 关联表单信息 */
19
+ RelationForms = "relationForms",
20
+ /** 账户信息 */
21
+ Holder = "holder"
22
+ }
10
23
  export interface CartModuleAPI {
11
24
  /** 添加商品到购物车 */
12
25
  addItem: (item: IAddItemParams) => Promise<void>;
@@ -26,6 +39,8 @@ export interface CartModuleAPI {
26
39
  getCartByAccount: (account_id: string) => CartItem[];
27
40
  /** 清除购物车 */
28
41
  clear: () => void;
42
+ /** 清除购物车商品中的信息 */
43
+ deleteCartItemInfo: (type: ECartItemInfoType, _id?: string) => void;
29
44
  }
30
45
  /**
31
46
  * 购物车商品接口
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/modules/Cart/types.ts
20
20
  var types_exports = {};
21
21
  __export(types_exports, {
22
- CartHooks: () => CartHooks
22
+ CartHooks: () => CartHooks,
23
+ ECartItemInfoType: () => ECartItemInfoType
23
24
  });
24
25
  module.exports = __toCommonJS(types_exports);
25
26
  var CartHooks = /* @__PURE__ */ ((CartHooks2) => {
@@ -29,7 +30,15 @@ var CartHooks = /* @__PURE__ */ ((CartHooks2) => {
29
30
  CartHooks2["OnCartRemove"] = "card:onCartRemove";
30
31
  return CartHooks2;
31
32
  })(CartHooks || {});
33
+ var ECartItemInfoType = /* @__PURE__ */ ((ECartItemInfoType2) => {
34
+ ECartItemInfoType2["Resource"] = "resource";
35
+ ECartItemInfoType2["Time"] = "time";
36
+ ECartItemInfoType2["RelationForms"] = "relationForms";
37
+ ECartItemInfoType2["Holder"] = "holder";
38
+ return ECartItemInfoType2;
39
+ })(ECartItemInfoType || {});
32
40
  // Annotate the CommonJS export names for ESM import in node:
33
41
  0 && (module.exports = {
34
- CartHooks
42
+ CartHooks,
43
+ ECartItemInfoType
35
44
  });
@@ -251,3 +251,4 @@ export declare const deleteTimeFromCartItem: (cartItem: CartItem) => CartItem;
251
251
  * @returns 删除后的购物车
252
252
  */
253
253
  export declare const deleteRelationFormsFromCartItem: (cartItem: CartItem) => CartItem;
254
+ export declare const deleteHolderFromCartItem: (cartItem: CartItem) => CartItem;
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  createCartItemOrigin: () => createCartItemOrigin,
33
+ deleteHolderFromCartItem: () => deleteHolderFromCartItem,
33
34
  deleteRelationFormsFromCartItem: () => deleteRelationFormsFromCartItem,
34
35
  deleteResourceFromCartItem: () => deleteResourceFromCartItem,
35
36
  deleteTimeFromCartItem: () => deleteTimeFromCartItem,
@@ -511,9 +512,16 @@ var deleteRelationFormsFromCartItem = (cartItem) => {
511
512
  cartItem._origin.relation_forms = null;
512
513
  return cartItem;
513
514
  };
515
+ var deleteHolderFromCartItem = (cartItem) => {
516
+ cartItem.holder_id = void 0;
517
+ cartItem.holder_title = void 0;
518
+ cartItem._origin.holder = null;
519
+ return cartItem;
520
+ };
514
521
  // Annotate the CommonJS export names for ESM import in node:
515
522
  0 && (module.exports = {
516
523
  createCartItemOrigin,
524
+ deleteHolderFromCartItem,
517
525
  deleteRelationFormsFromCartItem,
518
526
  deleteResourceFromCartItem,
519
527
  deleteTimeFromCartItem,
@@ -2,7 +2,7 @@ import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { Response } from '../../plugins';
4
4
  import { BookingByStepState } from './types';
5
- import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem } from '../../modules';
5
+ import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem, ECartItemInfoType } from '../../modules';
6
6
  import { Account } from '../../modules/Account/types';
7
7
  import { IStep } from '../../modules/Step/tyeps';
8
8
  import { TimeSliceItem } from './utils/resources';
@@ -130,7 +130,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
130
130
  /**
131
131
  * 从购物车中按类别删除信息
132
132
  */
133
- deleteCartItemInfo(types: 'resource' | 'time' | 'relationForms'): void;
133
+ deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
134
134
  destroy(): void;
135
135
  getResourcesList(): any[];
136
136
  getResourcesListByCartItem(id: string | number): {
@@ -516,8 +516,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
516
516
  /**
517
517
  * 从购物车中按类别删除信息
518
518
  */
519
- deleteCartItemInfo(types) {
520
- this.store.cart.deleteCartItemInfo(types);
519
+ deleteCartItemInfo(type, _id) {
520
+ this.store.cart.deleteCartItemInfo(type, _id);
521
521
  }
522
522
  destroy() {
523
523
  var _a, _b, _c, _d, _e, _f;
@@ -983,17 +983,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
983
983
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
984
984
  submitTimeSlot(timeSlots) {
985
985
  const cartItems = this.store.cart.getItems();
986
- const itemsByAccount = cartItems.reduce(
987
- (acc, item) => {
988
- const holderId = item.holder_id;
989
- if (!acc[holderId]) {
990
- acc[holderId] = [];
991
- }
992
- acc[holderId].push(item);
993
- return acc;
994
- },
995
- {}
996
- );
986
+ const itemsByAccount = cartItems.reduce((acc, item) => {
987
+ const holderId = item.holder_id;
988
+ if (!acc[holderId]) {
989
+ acc[holderId] = [];
990
+ }
991
+ acc[holderId].push(item);
992
+ return acc;
993
+ }, {});
997
994
  Object.values(itemsByAccount).forEach((accountItems) => {
998
995
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
999
996
  accountItems.forEach((item, index) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.53",
4
+ "version": "0.0.54",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",