@pisell/pisellos 0.0.41 → 0.0.42

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.
@@ -180,7 +180,7 @@ export declare const getProductDeposit: (params: {
180
180
  options?: any;
181
181
  num?: number;
182
182
  }) => {
183
- total: string;
183
+ total: number;
184
184
  protocols: {
185
185
  id: number;
186
186
  title: string;
@@ -113,7 +113,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
113
113
  }
114
114
 
115
115
  // 如果商品有定金规则,则计算定金
116
- if (product !== null && product !== void 0 && (_product$custom_depos = product.custom_deposit_data) !== null && _product$custom_depos !== void 0 && _product$custom_depos.has_deposit) {
116
+ if ((product === null || product === void 0 || (_product$custom_depos = product.custom_deposit_data) === null || _product$custom_depos === void 0 ? void 0 : _product$custom_depos.has_deposit) == 1) {
117
117
  cartItem.deposit = getProductDeposit({
118
118
  cartItem: cartItem,
119
119
  product: product,
@@ -532,6 +532,7 @@ export var getProductDeposit = function getProductDeposit(params) {
532
532
  deposit_fixed = _ref.deposit_fixed,
533
533
  deposit_percentage = _ref.deposit_percentage,
534
534
  deposit_policy_data = _ref.deposit_policy_data;
535
+ // 协议数据
535
536
  protocols.push.apply(protocols, _toConsumableArray(deposit_policy_data || []));
536
537
  // 判断主商品是否有定金规则
537
538
  if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
@@ -563,7 +564,7 @@ export var getProductDeposit = function getProductDeposit(params) {
563
564
  }
564
565
  }
565
566
  return {
566
- total: total.toFixed(2),
567
+ total: total.toNumber(),
567
568
  protocols: protocols
568
569
  };
569
570
  }
@@ -7,11 +7,18 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
7
7
  protected defaultVersion: string;
8
8
  private shopStore;
9
9
  private store;
10
+ private request;
10
11
  private cacheId;
11
12
  private openCache;
12
13
  private fatherModule;
13
14
  constructor(name?: string, version?: string);
14
15
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
15
16
  getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
17
+ /**
18
+ * 获取协议
19
+ * @param protocolId 协议ID
20
+ * @returns 协议
21
+ */
22
+ getProtocol(protocolId: string): Promise<any>;
16
23
  storeChange(): void;
17
24
  }
@@ -28,6 +28,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
28
28
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
29
29
  _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
30
30
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
31
32
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
32
33
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
33
34
  _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
@@ -44,6 +45,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
44
45
  this.core = core;
45
46
  this.store = options.store;
46
47
  this.shopStore = this.core.getPlugin("shopStore");
48
+ this.request = this.core.getPlugin("request");
47
49
  if (options.initialState) {
48
50
  this.store.summary = options.initialState.summary;
49
51
  }
@@ -55,11 +57,11 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
55
57
  this.fatherModule = options.otherParams.fatherModule;
56
58
  }
57
59
  if (this.shopStore) {
58
- _context.next = 8;
60
+ _context.next = 9;
59
61
  break;
60
62
  }
61
63
  throw new Error("SummaryModule 需要 shopStore 插件支持");
62
- case 8:
64
+ case 9:
63
65
  case "end":
64
66
  return _context.stop();
65
67
  }
@@ -94,6 +96,30 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
94
96
  }
95
97
  return getSummary;
96
98
  }()
99
+ /**
100
+ * 获取协议
101
+ * @param protocolId 协议ID
102
+ * @returns 协议
103
+ */
104
+ }, {
105
+ key: "getProtocol",
106
+ value: (function () {
107
+ var _getProtocol = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(protocolId) {
108
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
109
+ while (1) switch (_context3.prev = _context3.next) {
110
+ case 0:
111
+ return _context3.abrupt("return", this.request.get("/shop-policy/".concat(protocolId)));
112
+ case 1:
113
+ case "end":
114
+ return _context3.stop();
115
+ }
116
+ }, _callee3, this);
117
+ }));
118
+ function getProtocol(_x4) {
119
+ return _getProtocol.apply(this, arguments);
120
+ }
121
+ return getProtocol;
122
+ }())
97
123
  }, {
98
124
  key: "storeChange",
99
125
  value: function storeChange() {
@@ -102,7 +128,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
102
128
  cacheId: this.cacheId,
103
129
  fatherModule: this.fatherModule,
104
130
  store: this.store,
105
- cacheKey: ['summary']
131
+ cacheKey: ["summary"]
106
132
  });
107
133
  }
108
134
  }
@@ -25,4 +25,5 @@ export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Deci
25
25
  export declare const calculateDeposit: (items: CartItem[]) => {
26
26
  total: string;
27
27
  protocols: any[];
28
+ hasDeposit: never;
28
29
  } | undefined;
@@ -68,13 +68,14 @@ export var calculateDeposit = function calculateDeposit(items) {
68
68
  return undefined;
69
69
  }
70
70
  var protocols = [];
71
+ var hasDeposit = false;
71
72
  var total = items.reduce(function (sum, item) {
72
- var _item$deposit;
73
- if (item !== null && item !== void 0 && (_item$deposit = item.deposit) !== null && _item$deposit !== void 0 && (_item$deposit = _item$deposit.protocols) !== null && _item$deposit !== void 0 && _item$deposit.length) {
74
- var _item$deposit2, _item$deposit3;
75
- var cartItemTotalPrice = new Decimal((item === null || item === void 0 || (_item$deposit2 = item.deposit) === null || _item$deposit2 === void 0 ? void 0 : _item$deposit2.total) || 0);
73
+ if (item !== null && item !== void 0 && item.deposit) {
74
+ var _item$deposit, _item$deposit2;
75
+ hasDeposit = true;
76
+ var cartItemTotalPrice = new Decimal((item === null || item === void 0 || (_item$deposit = item.deposit) === null || _item$deposit === void 0 ? void 0 : _item$deposit.total) || 0);
76
77
  // 将协议数据去重合并
77
- item === null || item === void 0 || (_item$deposit3 = item.deposit) === null || _item$deposit3 === void 0 || (_item$deposit3 = _item$deposit3.protocols) === null || _item$deposit3 === void 0 || _item$deposit3.forEach(function (protocol) {
78
+ item === null || item === void 0 || (_item$deposit2 = item.deposit) === null || _item$deposit2 === void 0 || (_item$deposit2 = _item$deposit2.protocols) === null || _item$deposit2 === void 0 || _item$deposit2.forEach(function (protocol) {
78
79
  if (protocols.findIndex(function (p) {
79
80
  return p.id === protocol.id;
80
81
  }) === -1) {
@@ -85,8 +86,12 @@ export var calculateDeposit = function calculateDeposit(items) {
85
86
  }
86
87
  return sum;
87
88
  }, new Decimal(0));
88
- return {
89
- total: total.toFixed(2),
90
- protocols: protocols
91
- };
89
+ if (hasDeposit) {
90
+ return {
91
+ total: total.toFixed(2),
92
+ protocols: protocols,
93
+ hasDeposit: hasDeposit
94
+ };
95
+ }
96
+ return undefined;
92
97
  };
@@ -180,7 +180,7 @@ export declare const getProductDeposit: (params: {
180
180
  options?: any;
181
181
  num?: number;
182
182
  }) => {
183
- total: string;
183
+ total: number;
184
184
  protocols: {
185
185
  id: number;
186
186
  title: string;
@@ -125,7 +125,7 @@ var formatProductToCartItem = (params) => {
125
125
  if (options == null ? void 0 : options.length) {
126
126
  cartItem.options = formatOptions(options);
127
127
  }
128
- if ((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) {
128
+ if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
129
129
  cartItem.deposit = getProductDeposit({ cartItem, product, bundle, options, num });
130
130
  }
131
131
  const oringin = formatProductToCartItemOrigin(params);
@@ -439,7 +439,7 @@ var getProductDeposit = (params) => {
439
439
  }, new import_decimal.default(0));
440
440
  }
441
441
  }
442
- return { total: total.toFixed(2), protocols };
442
+ return { total: total.toNumber(), protocols };
443
443
  }
444
444
  return null;
445
445
  };
@@ -7,11 +7,18 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
7
7
  protected defaultVersion: string;
8
8
  private shopStore;
9
9
  private store;
10
+ private request;
10
11
  private cacheId;
11
12
  private openCache;
12
13
  private fatherModule;
13
14
  constructor(name?: string, version?: string);
14
15
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
15
16
  getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
17
+ /**
18
+ * 获取协议
19
+ * @param protocolId 协议ID
20
+ * @returns 协议
21
+ */
22
+ getProtocol(protocolId: string): Promise<any>;
16
23
  storeChange(): void;
17
24
  }
@@ -36,6 +36,7 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
36
36
  this.core = core;
37
37
  this.store = options.store;
38
38
  this.shopStore = this.core.getPlugin("shopStore");
39
+ this.request = this.core.getPlugin("request");
39
40
  if (options.initialState) {
40
41
  this.store.summary = options.initialState.summary;
41
42
  }
@@ -57,9 +58,22 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
57
58
  this.store.summary = summary;
58
59
  return this.store.summary;
59
60
  }
61
+ /**
62
+ * 获取协议
63
+ * @param protocolId 协议ID
64
+ * @returns 协议
65
+ */
66
+ async getProtocol(protocolId) {
67
+ return this.request.get(`/shop-policy/${protocolId}`);
68
+ }
60
69
  storeChange() {
61
70
  if (this.openCache) {
62
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["summary"] });
71
+ this.checkSaveCache({
72
+ cacheId: this.cacheId,
73
+ fatherModule: this.fatherModule,
74
+ store: this.store,
75
+ cacheKey: ["summary"]
76
+ });
63
77
  }
64
78
  }
65
79
  };
@@ -25,4 +25,5 @@ export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Deci
25
25
  export declare const calculateDeposit: (items: CartItem[]) => {
26
26
  total: string;
27
27
  protocols: any[];
28
+ hasDeposit: never;
28
29
  } | undefined;
@@ -78,11 +78,13 @@ var calculateDeposit = (items) => {
78
78
  return void 0;
79
79
  }
80
80
  const protocols = [];
81
+ let hasDeposit = false;
81
82
  const total = items.reduce((sum, item) => {
82
- var _a, _b, _c, _d, _e;
83
- if ((_b = (_a = item == null ? void 0 : item.deposit) == null ? void 0 : _a.protocols) == null ? void 0 : _b.length) {
84
- const cartItemTotalPrice = new import_decimal.default(((_c = item == null ? void 0 : item.deposit) == null ? void 0 : _c.total) || 0);
85
- (_e = (_d = item == null ? void 0 : item.deposit) == null ? void 0 : _d.protocols) == null ? void 0 : _e.forEach((protocol) => {
83
+ var _a, _b, _c;
84
+ if (item == null ? void 0 : item.deposit) {
85
+ hasDeposit = true;
86
+ const cartItemTotalPrice = new import_decimal.default(((_a = item == null ? void 0 : item.deposit) == null ? void 0 : _a.total) || 0);
87
+ (_c = (_b = item == null ? void 0 : item.deposit) == null ? void 0 : _b.protocols) == null ? void 0 : _c.forEach((protocol) => {
86
88
  if (protocols.findIndex((p) => p.id === protocol.id) === -1) {
87
89
  protocols.push(protocol);
88
90
  }
@@ -91,10 +93,10 @@ var calculateDeposit = (items) => {
91
93
  }
92
94
  return sum;
93
95
  }, new import_decimal.default(0));
94
- return {
95
- total: total.toFixed(2),
96
- protocols
97
- };
96
+ if (hasDeposit) {
97
+ return { total: total.toFixed(2), protocols, hasDeposit };
98
+ }
99
+ return void 0;
98
100
  };
99
101
  // Annotate the CommonJS export names for ESM import in node:
100
102
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.41",
4
+ "version": "0.0.42",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",