@bchr/bchr-front-lib 0.4.3 → 0.4.5

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/README.md CHANGED
@@ -1,2 +1,3 @@
1
1
  # BCHR-FRONT-LIB
2
2
 
3
+ ## 1. update react page component ref use mode
@@ -94,7 +94,7 @@ var Page = /*#__PURE__*/function (_React$Component) {
94
94
  _createClass(Page, [{
95
95
  key: "componentDidMount",
96
96
  value: function componentDidMount() {
97
- this.pageRef = this.refs.pageRef;
97
+ this.pageRef = this.pageRef.current;
98
98
  }
99
99
  }, {
100
100
  key: "render",
@@ -103,35 +103,35 @@ var Page = /*#__PURE__*/function (_React$Component) {
103
103
 
104
104
  if (this.props.page_type === 'start_page_view') {
105
105
  pageContainer = /*#__PURE__*/_react["default"].createElement(_StartPageView["default"], _extends({
106
- ref: "pageRef"
106
+ ref: this.pageRef
107
107
  }, this.props));
108
108
  } else if (this.props.page_type === 'default_list_view') {
109
109
  pageContainer = /*#__PURE__*/_react["default"].createElement(_DefaultListView["default"], _extends({
110
- ref: "pageRef"
110
+ ref: this.pageRef
111
111
  }, this.props));
112
112
  } else if (this.props.page_type === 'left_right_view') {
113
113
  pageContainer = /*#__PURE__*/_react["default"].createElement(_LeftRightView["default"], _extends({
114
- ref: "pageRef"
114
+ ref: this.pageRef
115
115
  }, this.props));
116
116
  } else if (this.props.page_type === 'custom_list_view') {
117
117
  pageContainer = /*#__PURE__*/_react["default"].createElement(_CustomListView["default"], _extends({
118
- ref: "pageRef"
118
+ ref: this.pageRef
119
119
  }, this.props));
120
120
  } else if (this.props.page_type === 'custom_left_right_view') {
121
121
  pageContainer = /*#__PURE__*/_react["default"].createElement(_CustomLeftRightView["default"], _extends({
122
- ref: "pageRef"
122
+ ref: this.pageRef
123
123
  }, this.props));
124
124
  } else if (this.props.page_type === 'default_card_view') {
125
125
  pageContainer = /*#__PURE__*/_react["default"].createElement(_DefaultCardView["default"], _extends({
126
- ref: "pageRef"
126
+ ref: this.pageRef
127
127
  }, this.props));
128
128
  } else if (this.props.page_type === 'default_fluid_card_view') {
129
129
  pageContainer = /*#__PURE__*/_react["default"].createElement(_DefaultFluidCardView["default"], _extends({
130
- ref: "pageRef"
130
+ ref: this.pageRef
131
131
  }, this.props));
132
132
  } else if (this.props.page_type === 'affix_fluid_card_view') {
133
133
  pageContainer = /*#__PURE__*/_react["default"].createElement(_AffixFluidCardView["default"], _extends({
134
- ref: "pageRef"
134
+ ref: this.pageRef
135
135
  }, this.props));
136
136
  }
137
137
 
@@ -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.3",
3
+ "version": "0.4.5",
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",
@@ -15,7 +15,7 @@ class Page extends React.Component {
15
15
  }
16
16
 
17
17
  componentDidMount() {
18
- this.pageRef = this.refs.pageRef
18
+ this.pageRef = this.pageRef.current;
19
19
  }
20
20
 
21
21
  showLoading = (state) => {
@@ -42,21 +42,21 @@ class Page extends React.Component {
42
42
  let pageContainer = "";
43
43
 
44
44
  if (this.props.page_type === 'start_page_view') {
45
- pageContainer = <StartPageView ref="pageRef" {...this.props}/>;
45
+ pageContainer = <StartPageView ref={this.pageRef} {...this.props}/>;
46
46
  } else if (this.props.page_type === 'default_list_view') {
47
- pageContainer = <DefaultListView ref="pageRef" {...this.props}/>;
47
+ pageContainer = <DefaultListView ref={this.pageRef} {...this.props}/>;
48
48
  } else if (this.props.page_type === 'left_right_view') {
49
- pageContainer = <LeftRightView ref="pageRef" {...this.props}/>;
49
+ pageContainer = <LeftRightView ref={this.pageRef} {...this.props}/>;
50
50
  } else if (this.props.page_type === 'custom_list_view') {
51
- pageContainer = <CustomListView ref="pageRef" {...this.props}/>;
51
+ pageContainer = <CustomListView ref={this.pageRef} {...this.props}/>;
52
52
  } else if (this.props.page_type === 'custom_left_right_view') {
53
- pageContainer = <CustomLeftRightView ref="pageRef" {...this.props}/>;
53
+ pageContainer = <CustomLeftRightView ref={this.pageRef} {...this.props}/>;
54
54
  } else if (this.props.page_type === 'default_card_view') {
55
- pageContainer = <DefaultCardView ref="pageRef" {...this.props}/>;
55
+ pageContainer = <DefaultCardView ref={this.pageRef} {...this.props}/>;
56
56
  } else if (this.props.page_type === 'default_fluid_card_view') {
57
- pageContainer = <DefaultFluidCardView ref="pageRef" {...this.props}/>;
57
+ pageContainer = <DefaultFluidCardView ref={this.pageRef} {...this.props}/>;
58
58
  } else if (this.props.page_type === 'affix_fluid_card_view') {
59
- pageContainer = <AffixFluidCardView ref="pageRef" {...this.props}/>;
59
+ pageContainer = <AffixFluidCardView ref={this.pageRef} {...this.props}/>;
60
60
  }
61
61
 
62
62
  return pageContainer
@@ -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;