@bchr/bchr-front-lib 0.4.1 → 0.4.2

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.
@@ -9,6 +9,8 @@ var _jquery = _interopRequireDefault(require("jquery"));
9
9
 
10
10
  var _antd = require("antd");
11
11
 
12
+ var _fileSaver = require("file-saver");
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
15
 
14
16
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -473,6 +475,84 @@ var HttpService = /*#__PURE__*/function () {
473
475
  return _jquery["default"].ajax(ajaxOptions);
474
476
  }
475
477
  }, {
478
+ key: "downloadFileByPostJSON",
479
+ value: function downloadFileByPostJSON(options, paramObject, saveFileName) {
480
+ var rpcMethodName = "";
481
+ var ajaxOptions = {};
482
+
483
+ if (_jquery["default"].isPlainObject(options)) {
484
+ rpcMethodName = options.rpcMethodName;
485
+ ajaxOptions = options;
486
+ } else {
487
+ rpcMethodName = options;
488
+ }
489
+
490
+ if (!rpcMethodName) {
491
+ rpcMethodName = "";
492
+ }
493
+
494
+ ajaxOptions.type = "post";
495
+ ajaxOptions.dataType = "*";
496
+
497
+ if (_jquery["default"].isPlainObject(paramObject)) {
498
+ ajaxOptions.data = paramObject;
499
+ }
500
+
501
+ if (!ajaxOptions.data) {
502
+ ajaxOptions.data = {};
503
+ }
504
+
505
+ if (!ajaxOptions.data.euts) {
506
+ ajaxOptions.data.euts = new Date().getTime();
507
+ }
508
+
509
+ if (!ajaxOptions.url) {
510
+ ajaxOptions.url = this.requestContextPath + rpcMethodName;
511
+ }
512
+
513
+ ajaxOptions.xhrFields = {
514
+ responseType: "blob"
515
+ };
516
+
517
+ ajaxOptions.success = function (result, request, xhr) {
518
+ var fileName = "下载文件-" + new Date().getTime();
519
+
520
+ if (saveFileName) {
521
+ fileName = saveFileName;
522
+ } else {
523
+ var contentDisposition = xhr.getResponseHeader('Content-Disposition');
524
+
525
+ if (contentDisposition && contentDisposition.split) {
526
+ var parts = contentDisposition.split(';');
527
+
528
+ if (parts.length >= 1) {
529
+ var fileInfo = parts[1];
530
+ var fileInfoArray = fileInfo.split('=');
531
+
532
+ if (fileInfoArray.length >= 1) {
533
+ fileName = fileInfoArray[1];
534
+ fileName = decodeURIComponent(fileName);
535
+ fileName = fileName.replaceAll("\"", "");
536
+ }
537
+ }
538
+ }
539
+ }
540
+
541
+ var type = xhr.getResponseHeader("content-type");
542
+
543
+ if (!type) {
544
+ type = "application/octet-stream";
545
+ }
546
+
547
+ var blob = new Blob([result], {
548
+ type: type
549
+ });
550
+ (0, _fileSaver.saveAs)(blob, fileName);
551
+ };
552
+
553
+ return _jquery["default"].ajax(ajaxOptions);
554
+ }
555
+ }, {
476
556
  key: "__getJSONForMock",
477
557
  value: function __getJSONForMock(mockOptions) {
478
558
  var waitTime = mockOptions.waitTime ? mockOptions.waitTime : 600;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -44,6 +44,7 @@
44
44
  "@progress/kendo-react-progressbars": "^3.15.0",
45
45
  "@progress/kendo-treeview-react-wrapper": "^2019.4.1014",
46
46
  "antd": "^4.5.4",
47
+ "file-saver": "^2.0.5",
47
48
  "handsontable": "^7.2.2",
48
49
  "jquery": "^3.5.1",
49
50
  "moment": "^2.27.0",
@@ -1,5 +1,6 @@
1
1
  import $ from 'jquery';
2
2
  import { message} from 'antd';
3
+ import {saveAs} from "file-saver";
3
4
 
4
5
  /**
5
6
  * * ajaxURL = back_service_host_name + back_service_context_path + ajaxBasePath
@@ -450,6 +451,75 @@ class HttpService {
450
451
  return $.ajax(ajaxOptions);
451
452
  }
452
453
 
454
+ downloadFileByPostJSON(options, paramObject, saveFileName) {
455
+ let rpcMethodName = "";
456
+ let ajaxOptions = {};
457
+ if ($.isPlainObject(options)) {
458
+ rpcMethodName = options.rpcMethodName;
459
+ ajaxOptions = options;
460
+ }
461
+ else {
462
+ rpcMethodName = options;
463
+ }
464
+
465
+ if (!rpcMethodName) {
466
+ rpcMethodName = "";
467
+ }
468
+
469
+ ajaxOptions.type = "post";
470
+ ajaxOptions.dataType = "*";
471
+ if ($.isPlainObject(paramObject)) {
472
+ ajaxOptions.data = paramObject;
473
+ }
474
+
475
+ if (!ajaxOptions.data){
476
+ ajaxOptions.data = {};
477
+ }
478
+
479
+ if (!ajaxOptions.data.euts) {
480
+ ajaxOptions.data.euts = (new Date()).getTime();
481
+ }
482
+
483
+ if (!ajaxOptions.url) {
484
+ ajaxOptions.url = this.requestContextPath + rpcMethodName;
485
+ }
486
+
487
+ ajaxOptions.xhrFields = {
488
+ responseType: "blob"
489
+ }
490
+
491
+ ajaxOptions.success = function (result, request, xhr) {
492
+ let fileName = "下载文件-" + new Date().getTime();
493
+ if (saveFileName) {
494
+ fileName = saveFileName
495
+ }
496
+ else {
497
+ let contentDisposition = xhr.getResponseHeader('Content-Disposition');
498
+ if (contentDisposition && contentDisposition.split) {
499
+ let parts = contentDisposition.split(';');
500
+ if (parts.length >= 1) {
501
+ let fileInfo = parts[1]
502
+ let fileInfoArray = fileInfo.split('=');
503
+ if (fileInfoArray.length >= 1) {
504
+ fileName = fileInfoArray[1];
505
+ fileName = decodeURIComponent(fileName)
506
+ fileName = fileName.replaceAll("\"", "")
507
+ }
508
+ }
509
+ }
510
+ }
511
+
512
+ let type = xhr.getResponseHeader("content-type")
513
+ if (!type) {
514
+ type = "application/octet-stream";
515
+ }
516
+ let blob = new Blob([result], { type: type })
517
+ saveAs(blob, fileName)
518
+ }
519
+
520
+ return $.ajax(ajaxOptions);
521
+ }
522
+
453
523
  __getJSONForMock(mockOptions) {
454
524
 
455
525
  let waitTime = mockOptions.waitTime ? mockOptions.waitTime : 600;