@pisell/pisellos 2.0.44 → 2.0.45

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.
@@ -93,11 +93,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
93
93
  key: "getResourceDates",
94
94
  value: function () {
95
95
  var _getResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
96
- var _params$query;
97
- var currentDateList, currentDateListMap, resourceIds, hasResource, dates;
96
+ var _params$query, currentDateList, currentDateListMap, resourceIds, hasResource, dates;
98
97
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
99
98
  while (1) switch (_context2.prev = _context2.next) {
100
99
  case 0:
100
+ if (!params.useCache) {
101
+ _context2.next = 7;
102
+ break;
103
+ }
101
104
  // 发请求之前,做一道检测,看 dateList 里是否有对应日期,且对应日期里是否都有对应 resource_ids 的资源
102
105
  currentDateList = this.getDateList() || [];
103
106
  currentDateListMap = new Map(currentDateList.map(function (item) {
@@ -112,18 +115,18 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
112
115
  });
113
116
  });
114
117
  if (!hasResource) {
115
- _context2.next = 6;
118
+ _context2.next = 7;
116
119
  break;
117
120
  }
118
121
  return _context2.abrupt("return", currentDateList);
119
- case 6:
120
- _context2.next = 8;
122
+ case 7:
123
+ _context2.next = 9;
121
124
  return this.getResourceAvailableTimeList(params);
122
- case 8:
125
+ case 9:
123
126
  dates = _context2.sent;
124
127
  this.setDateList(dates);
125
128
  return _context2.abrupt("return", dates);
126
- case 11:
129
+ case 12:
127
130
  case "end":
128
131
  return _context2.stop();
129
132
  }
@@ -151,7 +154,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
151
154
  return n.date === item.date;
152
155
  });
153
156
  if (currentItemIndex !== -1) {
154
- var _item$resource;
157
+ var _item$resource, _currentItem$resource3;
155
158
  var currentItem = currentDateList[currentItemIndex];
156
159
  // 看那一天的数据有没有相同的,把不同的资源合并进去即可
157
160
  var newResource = (_item$resource = item.resource) === null || _item$resource === void 0 ? void 0 : _item$resource.filter(function (n) {
@@ -160,6 +163,16 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
160
163
  return m.id === n.id;
161
164
  }));
162
165
  });
166
+ // 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
167
+ (_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
168
+ var _item$resource2;
169
+ var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.find(function (m) {
170
+ return m.id === n.id;
171
+ });
172
+ if (newResource) {
173
+ n.times = newResource.times;
174
+ }
175
+ });
163
176
  currentItem.resource = [].concat(_toConsumableArray(currentItem.resource || []), _toConsumableArray(newResource || []));
164
177
  currentDateList[currentItemIndex] = currentItem;
165
178
  } else {
@@ -172,11 +185,11 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
172
185
  key: "fetchResourceDates",
173
186
  value: function () {
174
187
  var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
175
- var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
188
+ var url, query, _params$useCache, useCache, fetchUrl, _ref, start_date, end_date, resource_ids, res;
176
189
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
177
190
  while (1) switch (_context3.prev = _context3.next) {
178
191
  case 0:
179
- url = params.url, query = params.query;
192
+ url = params.url, query = params.query, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache;
180
193
  fetchUrl = url || '/schedule/resource/list';
181
194
  _ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
182
195
  _context3.prev = 3;
@@ -185,9 +198,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
185
198
  start_date: start_date,
186
199
  end_date: end_date,
187
200
  resource_ids: resource_ids,
188
- front_end_cache_id: this.cacheId
201
+ front_end_cache_id: useCache && this.cacheId
189
202
  }, {
190
- useCache: true
203
+ useCache: useCache
191
204
  });
192
205
  case 6:
193
206
  res = _context3.sent;
@@ -43,6 +43,8 @@ export interface DateModuleAPI {
43
43
  }
44
44
  export interface IGetAvailableTimeListParams {
45
45
  url?: string;
46
+ /** 是否使用缓存 */
47
+ useCache?: boolean;
46
48
  /** 查询参数 */
47
49
  query?: {
48
50
  /** 开始日期 */
@@ -131,6 +131,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
131
131
  getCart(): CartItem[];
132
132
  getAvailableDate(params?: {
133
133
  url?: string;
134
+ useCache?: boolean;
134
135
  products?: ProductData[];
135
136
  startDate?: string;
136
137
  endDate?: string;
@@ -681,6 +681,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
681
681
  startDate,
682
682
  endDate,
683
683
  type,
684
+ _params$useCache,
685
+ useCache,
684
686
  tempProducts,
685
687
  dateRange,
686
688
  tempStartDate,
@@ -696,7 +698,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
696
698
  case 0:
697
699
  params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
698
700
  // 开始日期如果小于今天,直接以今天当做开始日期
699
- products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
701
+ products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
700
702
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
701
703
  startDate = dayjs().format('YYYY-MM-DD');
702
704
  }
@@ -738,7 +740,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
738
740
  resource_ids: resourceIds
739
741
  },
740
742
  rules: rules,
741
- type: type
743
+ type: type,
744
+ useCache: useCache
742
745
  });
743
746
  case 15:
744
747
  res = _context12.sent;
@@ -1292,7 +1295,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1292
1295
  var originResource = allOriginResources.find(function (n) {
1293
1296
  return n.id === targetRes.id;
1294
1297
  });
1295
- var canUse = checkResourceCanUseByCapacity(currentResourcesCapacityMap[m.id], currentCapacity, originResource === null || originResource === void 0 ? void 0 : originResource.capacity);
1298
+ var canUse = checkResourceCanUseByCapacity(currentResourcesCapacityMap[m.id] || 0, currentCapacity, originResource === null || originResource === void 0 ? void 0 : originResource.capacity);
1296
1299
  if (canUse) currentResourcesCapacityMap[m.id] += currentCapacity;
1297
1300
  return !canUse;
1298
1301
  }
@@ -70,18 +70,20 @@ var DateModule = class extends import_BaseModule.BaseModule {
70
70
  }
71
71
  async getResourceDates(params) {
72
72
  var _a;
73
- const currentDateList = this.getDateList() || [];
74
- const currentDateListMap = new Map(
75
- currentDateList.map((item) => [item.date, item])
76
- );
77
- const resourceIds = ((_a = params.query) == null ? void 0 : _a.resource_ids) || [];
78
- const hasResource = resourceIds.every((id) => {
79
- var _a2;
80
- const currentItem = currentDateListMap.get(id.toString());
81
- return (_a2 = currentItem == null ? void 0 : currentItem.resource) == null ? void 0 : _a2.some((n) => n.id === id);
82
- });
83
- if (hasResource) {
84
- return currentDateList;
73
+ if (params.useCache) {
74
+ const currentDateList = this.getDateList() || [];
75
+ const currentDateListMap = new Map(
76
+ currentDateList.map((item) => [item.date, item])
77
+ );
78
+ const resourceIds = ((_a = params.query) == null ? void 0 : _a.resource_ids) || [];
79
+ const hasResource = resourceIds.every((id) => {
80
+ var _a2;
81
+ const currentItem = currentDateListMap.get(id.toString());
82
+ return (_a2 = currentItem == null ? void 0 : currentItem.resource) == null ? void 0 : _a2.some((n) => n.id === id);
83
+ });
84
+ if (hasResource) {
85
+ return currentDateList;
86
+ }
85
87
  }
86
88
  const dates = await this.getResourceAvailableTimeList(params);
87
89
  this.setDateList(dates);
@@ -93,7 +95,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
93
95
  setDateList(dateList) {
94
96
  const currentDateList = (0, import_cloneDeep.default)(this.store.dateList) || [];
95
97
  dateList.forEach((item) => {
96
- var _a;
98
+ var _a, _b;
97
99
  const currentItemIndex = currentDateList.findIndex(
98
100
  (n) => n.date === item.date
99
101
  );
@@ -105,6 +107,13 @@ var DateModule = class extends import_BaseModule.BaseModule {
105
107
  return !((_a2 = currentItem.resource) == null ? void 0 : _a2.some((m) => m.id === n.id));
106
108
  }
107
109
  );
110
+ (_b = currentItem.resource) == null ? void 0 : _b.forEach((n) => {
111
+ var _a2;
112
+ const newResource2 = (_a2 = item.resource) == null ? void 0 : _a2.find((m) => m.id === n.id);
113
+ if (newResource2) {
114
+ n.times = newResource2.times;
115
+ }
116
+ });
108
117
  currentItem.resource = [
109
118
  ...currentItem.resource || [],
110
119
  ...newResource || []
@@ -117,22 +126,18 @@ var DateModule = class extends import_BaseModule.BaseModule {
117
126
  this.store.dateList = currentDateList;
118
127
  }
119
128
  async fetchResourceDates(params) {
120
- const { url, query } = params;
129
+ const { url, query, useCache = true } = params;
121
130
  const fetchUrl = url || "/schedule/resource/list";
122
131
  const { start_date, end_date, resource_ids } = query || {};
123
132
  try {
124
- const res = await this.request.get(
125
- fetchUrl,
126
- {
127
- start_date,
128
- end_date,
129
- resource_ids,
130
- front_end_cache_id: this.cacheId
131
- },
132
- {
133
- useCache: true
134
- }
135
- );
133
+ const res = await this.request.get(fetchUrl, {
134
+ start_date,
135
+ end_date,
136
+ resource_ids,
137
+ front_end_cache_id: useCache && this.cacheId
138
+ }, {
139
+ useCache
140
+ });
136
141
  return res;
137
142
  } catch (error) {
138
143
  console.error(error);
@@ -43,6 +43,8 @@ export interface DateModuleAPI {
43
43
  }
44
44
  export interface IGetAvailableTimeListParams {
45
45
  url?: string;
46
+ /** 是否使用缓存 */
47
+ useCache?: boolean;
46
48
  /** 查询参数 */
47
49
  query?: {
48
50
  /** 开始日期 */
@@ -131,6 +131,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
131
131
  getCart(): CartItem[];
132
132
  getAvailableDate(params?: {
133
133
  url?: string;
134
+ useCache?: boolean;
134
135
  products?: ProductData[];
135
136
  startDate?: string;
136
137
  endDate?: string;
@@ -388,7 +388,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
388
388
  // 获取商品/服务的可用日期
389
389
  async getAvailableDate(params = {}) {
390
390
  var _a, _b, _c;
391
- let { products, startDate, endDate, type } = params;
391
+ let { products, startDate, endDate, type, useCache = true } = params;
392
392
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
393
393
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
394
394
  }
@@ -425,7 +425,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
425
425
  resource_ids: resourceIds
426
426
  },
427
427
  rules,
428
- type
428
+ type,
429
+ useCache
429
430
  });
430
431
  return res;
431
432
  }
@@ -718,7 +719,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
718
719
  (n) => n.id === targetRes.id
719
720
  );
720
721
  const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
721
- currentResourcesCapacityMap[m.id],
722
+ currentResourcesCapacityMap[m.id] || 0,
722
723
  currentCapacity,
723
724
  originResource == null ? void 0 : originResource.capacity
724
725
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.44",
4
+ "version": "2.0.45",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",