@pisell/pisellos 2.1.75 → 2.1.77

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.
@@ -85,6 +85,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
85
85
  }, {
86
86
  key: "setDateRange",
87
87
  value: function setDateRange(dateRange) {
88
+ var _this2 = this;
89
+ // 如果 dateRange 传入的日期里没有 resource,但是本地有的,要尝试补充下
90
+ dateRange.forEach(function (item) {
91
+ var _item$resource;
92
+ if (!((_item$resource = item.resource) !== null && _item$resource !== void 0 && _item$resource.length)) {
93
+ item.resource = _this2.getResourcesListByDate(item.date);
94
+ }
95
+ });
88
96
  this.store.dateRange = dateRange;
89
97
  }
90
98
  }, {
@@ -157,10 +165,10 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
157
165
  return n.date === item.date;
158
166
  });
159
167
  if (currentItemIndex !== -1) {
160
- var _item$resource, _currentItem$resource3;
168
+ var _item$resource2, _currentItem$resource3;
161
169
  var currentItem = currentDateList[currentItemIndex];
162
170
  // 看那一天的数据有没有相同的,把不同的资源合并进去即可
163
- var newResource = (_item$resource = item.resource) === null || _item$resource === void 0 ? void 0 : _item$resource.filter(function (n) {
171
+ var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.filter(function (n) {
164
172
  var _currentItem$resource2;
165
173
  return !((_currentItem$resource2 = currentItem.resource) !== null && _currentItem$resource2 !== void 0 && _currentItem$resource2.some(function (m) {
166
174
  return m.id === n.id;
@@ -168,8 +176,8 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
168
176
  });
169
177
  // 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
170
178
  (_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
171
- var _item$resource2;
172
- var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.find(function (m) {
179
+ var _item$resource3;
180
+ var newResource = (_item$resource3 = item.resource) === null || _item$resource3 === void 0 ? void 0 : _item$resource3.find(function (m) {
173
181
  return m.id === n.id;
174
182
  });
175
183
  if (newResource) {
@@ -261,7 +269,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
261
269
  }, {
262
270
  key: "correctResourceTimeSlots",
263
271
  value: function correctResourceTimeSlots(resourcesData) {
264
- var _this2 = this;
272
+ var _this3 = this;
265
273
  return resourcesData.map(function (resource) {
266
274
  // 检查资源是否有 times 数组和 start_time
267
275
  if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
@@ -284,7 +292,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
284
292
  // 如果 start_at 早于资源的 start_time,需要修正
285
293
  if (startAt.isBefore(resourceStartTime)) {
286
294
  // 将 start_time 向上取整到下一个10分钟整数
287
- var roundedStartTime = _this2.roundUpToNext10Minutes(resourceStartTime);
295
+ var roundedStartTime = _this3.roundUpToNext10Minutes(resourceStartTime);
288
296
  var roundedStartTimeDayjs = dayjs(roundedStartTime);
289
297
  console.log("[DateModule] \u4FEE\u6B63\u65F6\u95F4\u6BB5\u5F00\u59CB\u65F6\u95F4: ".concat(timeSlot.start_at, " -> ").concat(roundedStartTime, " (\u8D44\u6E90ID: ").concat(resource.id, ", \u539F\u59CBstart_time: ").concat(resource.start_time, ")"));
290
298
 
@@ -2135,6 +2135,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2135
2135
  }
2136
2136
  });
2137
2137
  }
2138
+
2139
+ // 如果依然 resources 空的,则证明他是切换日期了,此时直接从 date 模块里取
2140
+ if (resources.length === 0) {
2141
+ resources.push.apply(resources, _toConsumableArray(this.store.date.getResourcesListByDate(dateRange[0].date) || []));
2142
+ }
2138
2143
  var resourcesMap = getResourcesMap(resources);
2139
2144
  var duration = 0;
2140
2145
  // duration = 不同账号的最长时间
@@ -2214,12 +2219,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2214
2219
  var _item$_resourceOrigin;
2215
2220
  return ((_item$_resourceOrigin = item._resourceOrigin) === null || _item$_resourceOrigin === void 0 ? void 0 : _item$_resourceOrigin[0].id) === firstResource;
2216
2221
  }).length;
2217
- if (sameResourceLength !== items.length) {
2222
+ if (sameResourceLength === items.length) {
2218
2223
  return 1;
2219
2224
  }
2220
- return items.reduce(function (total, item) {
2221
- return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2222
- }, 0);
2225
+ // 找出单个购物车里最大的需求 capacity 即可
2226
+ return Math.max.apply(Math, _toConsumableArray(items.map(function (item) {
2227
+ return getCapacityInfoByCartItem(item).currentCapacity || 1;
2228
+ })));
2229
+ // return items.reduce((total, item) => {
2230
+ // return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2231
+ // }, 0);
2223
2232
  };
2224
2233
 
2225
2234
  // 如果是多个人预约,去要求出几个 holder 下最大的商品需求容量capacity
@@ -2387,9 +2396,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2387
2396
  if (sameResourceLength !== items.length) {
2388
2397
  return 1;
2389
2398
  }
2390
- return items.reduce(function (total, item) {
2391
- return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2392
- }, 0);
2399
+ // 找出单个购物车里最大的需求 capacity 即可
2400
+ return Math.max.apply(Math, _toConsumableArray(items.map(function (item) {
2401
+ return getCapacityInfoByCartItem(item).currentCapacity || 1;
2402
+ })));
2393
2403
  }; // 如果是多个预约,去要求出几个 holder 下最大的需求容量capacity
2394
2404
  maxCapacity = 1;
2395
2405
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
@@ -3152,6 +3162,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3152
3162
  itemsByResourceType[resourceCode] = [];
3153
3163
  }
3154
3164
  // 避免重复添加同一个商品
3165
+ // 如果之前添加过的依赖相同资源的跟我现在是同一个 holder,也不需要重复添加
3166
+ if (itemsByResourceType[resourceCode].find(function (item) {
3167
+ return item.holder_id === cartItem.holder_id;
3168
+ })) {
3169
+ return;
3170
+ }
3155
3171
  if (!itemsByResourceType[resourceCode].find(function (item) {
3156
3172
  return item._id === cartItem._id;
3157
3173
  })) {
@@ -4274,6 +4290,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4274
4290
  }
4275
4291
  }
4276
4292
  });
4293
+ // 可能存在 renderList 没有的情况,则需要判断 resource.optional_resource 和 resource.default_resource 是否存在那个资源,如果不存在也打上 onlyComputed 的标记
4294
+ currentResourcesList.forEach(function (item) {
4295
+ var _resource$optional_re, _resource$default_res;
4296
+ if (!((_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.includes(item.id)) && !((_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.includes(item.id))) {
4297
+ item.onlyComputed = true;
4298
+ }
4299
+ });
4277
4300
  // currentResourcesList 排序,onlyComputed 的资源排在前面先计算
4278
4301
  currentResourcesList.sort(function (a, b) {
4279
4302
  return a.onlyComputed ? -1 : 1;
@@ -64,6 +64,12 @@ var DateModule = class extends import_BaseModule.BaseModule {
64
64
  }
65
65
  }
66
66
  setDateRange(dateRange) {
67
+ dateRange.forEach((item) => {
68
+ var _a;
69
+ if (!((_a = item.resource) == null ? void 0 : _a.length)) {
70
+ item.resource = this.getResourcesListByDate(item.date);
71
+ }
72
+ });
67
73
  this.store.dateRange = dateRange;
68
74
  }
69
75
  getDateRange() {
@@ -1461,6 +1461,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1461
1461
  }
1462
1462
  });
1463
1463
  }
1464
+ if (resources.length === 0) {
1465
+ resources.push(...this.store.date.getResourcesListByDate(dateRange[0].date) || []);
1466
+ }
1464
1467
  const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1465
1468
  let duration = 0;
1466
1469
  const accountList = this.store.accountList.getAccounts();
@@ -1535,12 +1538,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1535
1538
  var _a3;
1536
1539
  return ((_a3 = item._resourceOrigin) == null ? void 0 : _a3[0].id) === firstResource;
1537
1540
  }).length;
1538
- if (sameResourceLength !== items.length) {
1541
+ if (sameResourceLength === items.length) {
1539
1542
  return 1;
1540
1543
  }
1541
- return items.reduce((total, item) => {
1542
- return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
1543
- }, 0);
1544
+ return Math.max(...items.map((item) => (0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1544
1545
  };
1545
1546
  let maxCapacity = 1;
1546
1547
  if (cartItems == null ? void 0 : cartItems[0].holder_id) {
@@ -1673,9 +1674,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1673
1674
  if (sameResourceLength !== items.length) {
1674
1675
  return 1;
1675
1676
  }
1676
- return items.reduce((total, item) => {
1677
- return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
1678
- }, 0);
1677
+ return Math.max(...items.map((item) => (0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1679
1678
  };
1680
1679
  let maxCapacity = 1;
1681
1680
  if (cartItems == null ? void 0 : cartItems[0].holder_id) {
@@ -2264,6 +2263,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2264
2263
  if (!itemsByResourceType[resourceCode]) {
2265
2264
  itemsByResourceType[resourceCode] = [];
2266
2265
  }
2266
+ if (itemsByResourceType[resourceCode].find((item) => item.holder_id === cartItem.holder_id)) {
2267
+ return;
2268
+ }
2267
2269
  if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
2268
2270
  itemsByResourceType[resourceCode].push(cartItem);
2269
2271
  }
@@ -2992,6 +2994,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2992
2994
  }
2993
2995
  }
2994
2996
  });
2997
+ currentResourcesList.forEach((item2) => {
2998
+ var _a3, _b2;
2999
+ if (!((_a3 = resource.optional_resource) == null ? void 0 : _a3.includes(item2.id)) && !((_b2 = resource.default_resource) == null ? void 0 : _b2.includes(item2.id))) {
3000
+ item2.onlyComputed = true;
3001
+ }
3002
+ });
2995
3003
  currentResourcesList.sort((a, b) => {
2996
3004
  return a.onlyComputed ? -1 : 1;
2997
3005
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.75",
4
+ "version": "2.1.77",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",