coolcare-lite-scada-component 1.0.68 → 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.
@@ -21,7 +21,7 @@ import { DownHistoryDataToExcelOrPdf, GetPointHistoryData, GetTdIndicatorHistory
21
21
  import Echarts from "../ECharts";
22
22
  import base64ToBlob from "../../utils/dataURItoBlob";
23
23
  // @ts-ignore
24
- import { saveAs } from 'file-saver';
24
+
25
25
  import styles from "./index.css";
26
26
  import ModalChoosePoint from "../ModalChoosePoint";
27
27
  import { dateDiff } from "../../utils/date";
@@ -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;
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,25 +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
- debugger;
139
- blobUrl = window.URL.createObjectURL(res);
140
- saveAs(blobUrl, "history_".concat(moment(dateRange[0]).format('YYYY-MM-DD HH:mm:ss'), "_").concat(moment(dateRange[1]).format('YYYY-MM-DD HH:mm:ss'), ".zip"));
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
+ }
141
165
  setExcelDownloading(false);
142
- _context.next = 18;
166
+ _context.next = 16;
143
167
  break;
144
- case 13:
145
- _context.prev = 13;
168
+ case 11:
169
+ _context.prev = 11;
146
170
  _context.t0 = _context["catch"](0);
147
171
  console.log(_context.t0);
148
172
  message.error('下载excel失败');
149
173
  setExcelDownloading(false);
150
- case 18:
174
+ case 16:
151
175
  case "end":
152
176
  return _context.stop();
153
177
  }
154
- }, _callee, null, [[0, 13]]);
178
+ }, _callee, null, [[0, 11]]);
155
179
  }));
156
180
  return function downloadExcel() {
157
181
  return _ref2.apply(this, arguments);
@@ -160,12 +184,38 @@ var DialogPointHistory = function DialogPointHistory(_ref) {
160
184
 
161
185
  /** 下载图表 */
162
186
  var downloadImg = function downloadImg() {
163
- var _chart$current, _chart$current$getEch;
164
- // @ts-ignore
165
- 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);
166
- saveAs(base64ToBlob(_myChart.getDataURL({
167
- backgroundColor: '#fff'
168
- })), 'chart.jpg');
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
+ }
169
219
  };
170
220
  var closeModal = function closeModal() {
171
221
  form.resetFields();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coolcare-lite-scada-component",
3
- "version": "1.0.68",
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",