coolcare-lite-scada-component 1.0.69 → 1.0.70

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;
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,50 @@ 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
+ // 安全的下载方式,避免权限问题
138
+ 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");
139
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
140
+ // IE浏览器
141
+ window.navigator.msSaveOrOpenBlob(res, fileName);
142
+ } else {
143
+ blobUrl = window.URL.createObjectURL(res);
144
+ link = document.createElement('a');
145
+ link.style.display = 'none';
146
+ link.href = blobUrl;
147
+ link.download = fileName;
148
+ link.target = '_blank';
149
+
150
+ // 确保在用户交互上下文中执行
151
+ document.body.appendChild(link);
152
+
153
+ // 使用 setTimeout 确保在下一个事件循环中执行
154
+ setTimeout(function () {
155
+ try {
156
+ link.click();
157
+ } catch (clickError) {
158
+ // 如果点击失败,尝试打开新窗口
159
+ window.open(blobUrl, '_blank');
160
+ }
161
+ document.body.removeChild(link);
162
+ window.URL.revokeObjectURL(blobUrl);
163
+ }, 100);
164
+ }
146
165
  setExcelDownloading(false);
147
- _context.next = 23;
166
+ _context.next = 16;
148
167
  break;
149
- case 18:
150
- _context.prev = 18;
168
+ case 11:
169
+ _context.prev = 11;
151
170
  _context.t0 = _context["catch"](0);
152
171
  console.log(_context.t0);
153
172
  message.error('下载excel失败');
154
173
  setExcelDownloading(false);
155
- case 23:
174
+ case 16:
156
175
  case "end":
157
176
  return _context.stop();
158
177
  }
159
- }, _callee, null, [[0, 18]]);
178
+ }, _callee, null, [[0, 11]]);
160
179
  }));
161
180
  return function downloadExcel() {
162
181
  return _ref2.apply(this, arguments);
@@ -165,22 +184,38 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
165
184
 
166
185
  /** 下载图表 */
167
186
  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);
187
+ try {
188
+ var _chart$current, _chart$current$getEch;
189
+ // @ts-ignore
190
+ 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);
191
+ var blob = base64ToBlob(_myChart.getDataURL({
192
+ backgroundColor: '#fff'
193
+ }));
194
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
195
+ // IE浏览器
196
+ window.navigator.msSaveOrOpenBlob(blob, 'chart.jpg');
197
+ } else {
198
+ var blobUrl = window.URL.createObjectURL(blob);
199
+ var link = document.createElement('a');
200
+ link.style.display = 'none';
201
+ link.href = blobUrl;
202
+ link.download = 'chart.jpg';
203
+ link.target = '_blank';
204
+ document.body.appendChild(link);
205
+ setTimeout(function () {
206
+ try {
207
+ link.click();
208
+ } catch (clickError) {
209
+ window.open(blobUrl, '_blank');
210
+ }
211
+ document.body.removeChild(link);
212
+ window.URL.revokeObjectURL(blobUrl);
213
+ }, 100);
214
+ }
215
+ } catch (e) {
216
+ console.error('下载图表失败:', e);
217
+ message.error('下载图表失败');
218
+ }
184
219
  };
185
220
  var closeModal = function closeModal() {
186
221
  form.resetFields();
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.70",
4
4
  "scripts": {
5
5
  "start": " PORT=8000 UMI_ENV=prod umi dev",
6
6
  "build:prod": "UMI_ENV=prod umi build",