coolcare-lite-scada-component 1.0.69 → 1.0.71

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.
@@ -103,15 +103,14 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
103
103
  /** 下载excel、pdf */
104
104
  var downloadExcel = /*#__PURE__*/function () {
105
105
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
106
- var _form$getFieldsValue, dateRange, interval, res, blobUrl, link;
106
+ var _form$getFieldsValue, dateRange, interval, res, fileName, blobUrl, link, _e$response, _e$message;
107
107
  return _regeneratorRuntime().wrap(function _callee$(_context) {
108
108
  while (1) switch (_context.prev = _context.next) {
109
109
  case 0:
110
110
  _context.prev = 0;
111
111
  setExcelDownloading(true);
112
112
  _form$getFieldsValue = form.getFieldsValue(), dateRange = _form$getFieldsValue.dateRange, interval = _form$getFieldsValue.interval;
113
- debugger;
114
- _context.next = 6;
113
+ _context.next = 5;
115
114
  return DownHistoryDataToExcelOrPdf({
116
115
  pointIdList: pointIdList,
117
116
  timeInterval: interval,
@@ -133,30 +132,65 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
133
132
  'Content-Type': 'application/json'
134
133
  }
135
134
  });
136
- case 6:
135
+ case 5:
137
136
  res = _context.sent;
138
- blobUrl = window.URL.createObjectURL(res); // 使用原生方式下载,兼容 npm 插件环境
139
- link = document.createElement('a');
140
- link.href = blobUrl;
141
- link.download = "history_".concat(moment(dateRange[0]).format('YYYY-MM-DD HH:mm:ss'), "_").concat(moment(dateRange[1]).format('YYYY-MM-DD HH:mm:ss'), ".zip");
142
- document.body.appendChild(link);
143
- link.click();
144
- document.body.removeChild(link);
145
- window.URL.revokeObjectURL(blobUrl);
137
+ if (!(!res || res.size === 0)) {
138
+ _context.next = 10;
139
+ break;
140
+ }
141
+ message.error('服务器返回空文件,请稍后重试');
142
+ setExcelDownloading(false);
143
+ return _context.abrupt("return");
144
+ case 10:
145
+ // 安全的下载方式,避免权限问题
146
+ fileName = "history_".concat(moment(dateRange[0]).format('YYYY-MM-DD HH:mm:ss'), "_").concat(moment(dateRange[1]).format('YYYY-MM-DD HH:mm:ss'), ".zip");
147
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
148
+ // IE浏览器
149
+ window.navigator.msSaveOrOpenBlob(res, fileName);
150
+ } else {
151
+ blobUrl = window.URL.createObjectURL(res);
152
+ link = document.createElement('a');
153
+ link.style.display = 'none';
154
+ link.href = blobUrl;
155
+ link.download = fileName;
156
+ link.target = '_blank';
157
+
158
+ // 确保在用户交互上下文中执行
159
+ document.body.appendChild(link);
160
+
161
+ // 使用 setTimeout 确保在下一个事件循环中执行
162
+ setTimeout(function () {
163
+ try {
164
+ link.click();
165
+ } catch (clickError) {
166
+ // 如果点击失败,尝试打开新窗口
167
+ window.open(blobUrl, '_blank');
168
+ }
169
+ document.body.removeChild(link);
170
+ window.URL.revokeObjectURL(blobUrl);
171
+ }, 100);
172
+ }
146
173
  setExcelDownloading(false);
147
- _context.next = 23;
174
+ _context.next = 20;
148
175
  break;
149
- case 18:
150
- _context.prev = 18;
176
+ case 15:
177
+ _context.prev = 15;
151
178
  _context.t0 = _context["catch"](0);
152
179
  console.log(_context.t0);
153
- message.error('下载excel失败');
180
+ // 检查是否是网络错误或API错误
181
+ if (_context.t0 === null || _context.t0 === void 0 ? void 0 : (_e$response = _context.t0.response) === null || _e$response === void 0 ? void 0 : _e$response.status) {
182
+ message.error("\u4E0B\u8F7D\u5931\u8D25: HTTP ".concat(_context.t0.response.status));
183
+ } else if (_context.t0 === null || _context.t0 === void 0 ? void 0 : (_e$message = _context.t0.message) === null || _e$message === void 0 ? void 0 : _e$message.includes('response')) {
184
+ message.error('服务器响应异常,请检查网络连接');
185
+ } else {
186
+ message.error('下载excel失败');
187
+ }
154
188
  setExcelDownloading(false);
155
- case 23:
189
+ case 20:
156
190
  case "end":
157
191
  return _context.stop();
158
192
  }
159
- }, _callee, null, [[0, 18]]);
193
+ }, _callee, null, [[0, 15]]);
160
194
  }));
161
195
  return function downloadExcel() {
162
196
  return _ref2.apply(this, arguments);
@@ -165,22 +199,38 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
165
199
 
166
200
  /** 下载图表 */
167
201
  var downloadImg = function downloadImg() {
168
- var _chart$current, _chart$current$getEch;
169
- // @ts-ignore
170
- var _myChart = chart === null || chart === void 0 ? void 0 : (_chart$current = chart.current) === null || _chart$current === void 0 ? void 0 : (_chart$current$getEch = _chart$current.getEchartsInstance) === null || _chart$current$getEch === void 0 ? void 0 : _chart$current$getEch.call(_chart$current);
171
- var blob = base64ToBlob(_myChart.getDataURL({
172
- backgroundColor: '#fff'
173
- }));
174
- var blobUrl = window.URL.createObjectURL(blob);
175
-
176
- // 使用原生方式下载,兼容 npm 插件环境
177
- var link = document.createElement('a');
178
- link.href = blobUrl;
179
- link.download = 'chart.jpg';
180
- document.body.appendChild(link);
181
- link.click();
182
- document.body.removeChild(link);
183
- window.URL.revokeObjectURL(blobUrl);
202
+ try {
203
+ var _chart$current, _chart$current$getEch;
204
+ // @ts-ignore
205
+ var _myChart = chart === null || chart === void 0 ? void 0 : (_chart$current = chart.current) === null || _chart$current === void 0 ? void 0 : (_chart$current$getEch = _chart$current.getEchartsInstance) === null || _chart$current$getEch === void 0 ? void 0 : _chart$current$getEch.call(_chart$current);
206
+ var blob = base64ToBlob(_myChart.getDataURL({
207
+ backgroundColor: '#fff'
208
+ }));
209
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
210
+ // IE浏览器
211
+ window.navigator.msSaveOrOpenBlob(blob, 'chart.jpg');
212
+ } else {
213
+ var blobUrl = window.URL.createObjectURL(blob);
214
+ var link = document.createElement('a');
215
+ link.style.display = 'none';
216
+ link.href = blobUrl;
217
+ link.download = 'chart.jpg';
218
+ link.target = '_blank';
219
+ document.body.appendChild(link);
220
+ setTimeout(function () {
221
+ try {
222
+ link.click();
223
+ } catch (clickError) {
224
+ window.open(blobUrl, '_blank');
225
+ }
226
+ document.body.removeChild(link);
227
+ window.URL.revokeObjectURL(blobUrl);
228
+ }, 100);
229
+ }
230
+ } catch (e) {
231
+ console.error('下载图表失败:', e);
232
+ message.error('下载图表失败');
233
+ }
184
234
  };
185
235
  var closeModal = function closeModal() {
186
236
  form.resetFields();
@@ -174,7 +174,7 @@ requestClient.interceptors.response.use(/*#__PURE__*/function () {
174
174
  break;
175
175
  }
176
176
  _context2.next = 7;
177
- return response.clone().blob();
177
+ return response.blob();
178
178
  case 7:
179
179
  return _context2.abrupt("return", _context2.sent);
180
180
  case 8:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coolcare-lite-scada-component",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "scripts": {
5
5
  "start": " PORT=8000 UMI_ENV=prod umi dev",
6
6
  "build:prod": "UMI_ENV=prod umi build",