hrsass-components 2.4.3 → 2.4.4

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.
@@ -65,7 +65,7 @@ var contentStyle = _interopDefault(require('!!raw-loader!tinymce/skins/content/d
65
65
  var SvgPanZoom = _interopDefault(require('svg-pan-zoom'));
66
66
  var saveSvgAsPng = require('save-svg-as-png');
67
67
 
68
- var version = "2.4.3";
68
+ var version = "2.4.4";
69
69
 
70
70
  /**
71
71
  * 版本号
@@ -12056,24 +12056,42 @@ var index$6 = {
12056
12056
  }
12057
12057
  });
12058
12058
  },
12059
+ // 计算导出图片的 scale
12060
+ calcExportScale: function calcExportScale(svgWidth, svgHeight) {
12061
+ // 屏幕宽高
12062
+ var screenW = window.screen.width;
12063
+ var screenH = window.screen.height;
12064
+ // 目标导出宽度为屏幕宽度的2倍,最高不超过3倍
12065
+ var targetW = screenW;
12066
+ var scale = svgWidth / targetW;
12067
+ // 如果svg很高,按高度再限制一次
12068
+ var targetH = screenH * 1.5;
12069
+ if (targetH * scale < svgHeight) {
12070
+ scale = svgHeight / targetH;
12071
+ }
12072
+ // 限制scale范围,防止过大或过小
12073
+ if (scale < 1) scale = 1;
12074
+ if (scale > 3) scale = 3;
12075
+ return Math.round(scale);
12076
+ },
12059
12077
  exportSvg: function exportSvg(fileName) {
12060
12078
  var svg = this.$refs.hrOrgChartSvg;
12061
12079
  var bBox = svg.getBBox();
12062
- // 克隆SVG,设置viewBox和宽高,确保全部内容
12063
12080
  var clonedSvg = svg.cloneNode(true);
12064
12081
  clonedSvg.setAttribute('width', bBox.width);
12065
12082
  clonedSvg.setAttribute('height', bBox.height);
12066
12083
  clonedSvg.setAttribute('viewBox', "".concat(bBox.x, " ").concat(bBox.y, " ").concat(bBox.width, " ").concat(bBox.height));
12067
- // 生成完整SVG字符串
12068
12084
  var svgStr = new XMLSerializer().serializeToString(clonedSvg);
12085
+ // 使用自适应scale
12086
+ var scale = this.calcExportScale(bBox.width, bBox.height);
12069
12087
  var options = {
12070
- scale: 1,
12088
+ scale: scale,
12071
12089
  width: bBox.width,
12072
12090
  height: bBox.height,
12073
12091
  left: 0,
12074
12092
  top: 0
12075
12093
  };
12076
- this.svgToPng(svgStr, options);
12094
+ this.svgToPng(svgStr, options, fileName);
12077
12095
  // this.setState({
12078
12096
  // loading: true,
12079
12097
  // isDownload: true,
@@ -12096,7 +12114,7 @@ var index$6 = {
12096
12114
  // left: bBox.x,
12097
12115
  // });
12098
12116
  },
12099
- svgToPng: function svgToPng(svgStr, options) {
12117
+ svgToPng: function svgToPng(svgStr, options, fileName) {
12100
12118
  var _this6 = this;
12101
12119
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
12102
12120
  var blob, url, imgData;
@@ -12114,7 +12132,7 @@ var index$6 = {
12114
12132
  return _this6.drawToCanvas(url, options);
12115
12133
  case 6:
12116
12134
  imgData = _context.sent;
12117
- _this6.downloadFile(imgData, 'org.png');
12135
+ _this6.downloadFile(imgData, fileName || 'org.png');
12118
12136
  case 8:
12119
12137
  case "end":
12120
12138
  return _context.stop();