@pisell/pisellos 0.0.176 → 0.0.178
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.
- package/dist/modules/Date/index.js +21 -8
- package/lib/modules/Date/index.js +22 -13
- package/package.json +1 -1
|
@@ -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 =
|
|
118
|
+
_context2.next = 7;
|
|
116
119
|
break;
|
|
117
120
|
}
|
|
118
121
|
return _context2.abrupt("return", currentDateList);
|
|
119
|
-
case
|
|
120
|
-
_context2.next =
|
|
122
|
+
case 7:
|
|
123
|
+
_context2.next = 9;
|
|
121
124
|
return this.getResourceAvailableTimeList(params);
|
|
122
|
-
case
|
|
125
|
+
case 9:
|
|
123
126
|
dates = _context2.sent;
|
|
124
127
|
this.setDateList(dates);
|
|
125
128
|
return _context2.abrupt("return", dates);
|
|
126
|
-
case
|
|
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 {
|
|
@@ -70,18 +70,20 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
70
70
|
}
|
|
71
71
|
async getResourceDates(params) {
|
|
72
72
|
var _a;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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 || []
|