hrsass-components 2.4.4 → 2.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.
@@ -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.4";
68
+ var version = "2.4.5";
69
69
 
70
70
  /**
71
71
  * 版本号
@@ -12058,94 +12058,99 @@ var index$6 = {
12058
12058
  },
12059
12059
  // 计算导出图片的 scale
12060
12060
  calcExportScale: function calcExportScale(svgWidth, svgHeight) {
12061
+ var realZoom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
12061
12062
  // 屏幕宽高
12062
12063
  var screenW = window.screen.width;
12063
12064
  var screenH = window.screen.height;
12064
- // 目标导出宽度为屏幕宽度的2倍,最高不超过3
12065
- var targetW = screenW;
12066
- var scale = svgWidth / targetW;
12065
+ // 目标导出宽度为屏幕宽度的3倍,最高不超过4
12066
+ var targetW = screenW * 4;
12067
+ var scale = targetW / svgWidth;
12067
12068
  // 如果svg很高,按高度再限制一次
12068
- var targetH = screenH * 1.5;
12069
- if (targetH * scale < svgHeight) {
12070
- scale = svgHeight / targetH;
12069
+ if (svgHeight * scale > screenH * 4.5) {
12070
+ scale = screenH * 4.5 / svgHeight;
12071
+ if (scale < 1) scale = 1;
12071
12072
  }
12072
12073
  // 限制scale范围,防止过大或过小
12073
- if (scale < 1) scale = 1;
12074
- if (scale > 3) scale = 3;
12075
- return Math.round(scale);
12074
+ // if (scale < 1) scale = 1;
12075
+ // if (scale > 10) scale = 10;
12076
+ // 叠加当前svgPanZoom缩放
12077
+ scale = scale / realZoom;
12078
+ return scale;
12076
12079
  },
12080
+ // 导出图片
12077
12081
  exportSvg: function exportSvg(fileName) {
12078
- var svg = this.$refs.hrOrgChartSvg;
12079
- var bBox = svg.getBBox();
12080
- var clonedSvg = svg.cloneNode(true);
12081
- clonedSvg.setAttribute('width', bBox.width);
12082
- clonedSvg.setAttribute('height', bBox.height);
12083
- clonedSvg.setAttribute('viewBox', "".concat(bBox.x, " ").concat(bBox.y, " ").concat(bBox.width, " ").concat(bBox.height));
12084
- var svgStr = new XMLSerializer().serializeToString(clonedSvg);
12085
- // 使用自适应scale
12086
- var scale = this.calcExportScale(bBox.width, bBox.height);
12087
- var options = {
12088
- scale: scale,
12089
- width: bBox.width,
12090
- height: bBox.height,
12091
- left: 0,
12092
- top: 0
12093
- };
12094
- this.svgToPng(svgStr, options, fileName);
12095
- // this.setState({
12096
- // loading: true,
12097
- // isDownload: true,
12098
- // })
12099
- // svgAsDataUri(this.$refs.hrOrgChartSvg, options).then(url => {
12100
- // let dataUrL = url.split('base64,')[1]
12101
- // this.$axios.post('/business/org/Company/getOrgDiagram.data', { 'base64Str': dataUrL, name: fileName || 'org.png' }).then(res => {
12102
- // window.open(`${process.env.VUE_APP_API_BASE_URL}/file.nolog?method=download&fileId=${res}`);
12103
- // this.setState({
12104
- // loading: false,
12105
- // isDownload: false
12106
- // })
12107
- // })
12108
- // });
12109
- // saveSvgAsPng(this.$refs.hrOrgChartSvg, fileName || 'org.png', {
12110
- // scale: 1,
12111
- // width: bBox.width,
12112
- // height: bBox.height,
12113
- // top: bBox.y,
12114
- // left: bBox.x,
12115
- // });
12116
- },
12117
- svgToPng: function svgToPng(svgStr, options, fileName) {
12118
12082
  var _this6 = this;
12119
12083
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
12120
- var blob, url, imgData;
12084
+ var svg, bBox, clonedSvg, svgStr, realZoom, scale, options;
12121
12085
  return _regeneratorRuntime.wrap(function _callee$(_context) {
12122
12086
  while (1) switch (_context.prev = _context.next) {
12087
+ case 0:
12088
+ svg = _this6.$refs.hrOrgChartSvg;
12089
+ bBox = svg.getBBox();
12090
+ clonedSvg = svg.cloneNode(true);
12091
+ clonedSvg.setAttribute('width', bBox.width);
12092
+ clonedSvg.setAttribute('height', bBox.height);
12093
+ clonedSvg.setAttribute('viewBox', "".concat(bBox.x, " ").concat(bBox.y, " ").concat(bBox.width, " ").concat(bBox.height));
12094
+ _context.next = 8;
12095
+ return _this6.transformImage(clonedSvg);
12096
+ case 8:
12097
+ clonedSvg = _context.sent;
12098
+ svgStr = new XMLSerializer().serializeToString(clonedSvg); // 获取当前svgPanZoom缩放比例
12099
+ realZoom = 1;
12100
+ if (_this6.svgPanZoom) {
12101
+ realZoom = _this6.svgPanZoom.getSizes().realZoom || 1;
12102
+ }
12103
+ // 使用自适应scale
12104
+ scale = _this6.calcExportScale(bBox.width, bBox.height, realZoom);
12105
+ options = {
12106
+ scale: scale,
12107
+ width: bBox.width,
12108
+ height: bBox.height,
12109
+ left: 0,
12110
+ top: 0
12111
+ };
12112
+ _this6.svgToPng(svgStr, options, fileName);
12113
+ case 15:
12114
+ case "end":
12115
+ return _context.stop();
12116
+ }
12117
+ }, _callee);
12118
+ }))();
12119
+ },
12120
+ // svg转png
12121
+ svgToPng: function svgToPng(svgStr, options, fileName) {
12122
+ var _this7 = this;
12123
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
12124
+ var blob, url, imgData;
12125
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
12126
+ while (1) switch (_context2.prev = _context2.next) {
12123
12127
  case 0:
12124
12128
  blob = new Blob([svgStr], {
12125
12129
  type: 'image/svg+xml'
12126
12130
  });
12127
- _context.next = 3;
12128
- return _this6.blobToDataUrl(blob);
12131
+ _context2.next = 3;
12132
+ return _this7.blobToDataUrl(blob);
12129
12133
  case 3:
12130
- url = _context.sent;
12131
- _context.next = 6;
12132
- return _this6.drawToCanvas(url, options);
12134
+ url = _context2.sent;
12135
+ _context2.next = 6;
12136
+ return _this7.drawToCanvas(url, options);
12133
12137
  case 6:
12134
- imgData = _context.sent;
12135
- _this6.downloadFile(imgData, fileName || 'org.png');
12138
+ imgData = _context2.sent;
12139
+ _this7.downloadFile(imgData, fileName || 'org.png');
12136
12140
  case 8:
12137
12141
  case "end":
12138
- return _context.stop();
12142
+ return _context2.stop();
12139
12143
  }
12140
- }, _callee);
12144
+ }, _callee2);
12141
12145
  }))();
12142
12146
  },
12147
+ // 生成图片数据url
12143
12148
  blobToDataUrl: function blobToDataUrl(blob) {
12144
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
12145
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
12146
- while (1) switch (_context2.prev = _context2.next) {
12149
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
12150
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
12151
+ while (1) switch (_context3.prev = _context3.next) {
12147
12152
  case 0:
12148
- return _context2.abrupt("return", new Promise(function (resolve, reject) {
12153
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
12149
12154
  var reader = new FileReader();
12150
12155
  reader.onload = function () {
12151
12156
  resolve(reader.result);
@@ -12155,17 +12160,89 @@ var index$6 = {
12155
12160
  }));
12156
12161
  case 1:
12157
12162
  case "end":
12158
- return _context2.stop();
12163
+ return _context3.stop();
12159
12164
  }
12160
- }, _callee2);
12165
+ }, _callee3);
12161
12166
  }))();
12162
12167
  },
12168
+ // 处理图片
12169
+ transformImage: function transformImage(svgNode) {
12170
+ var _this8 = this;
12171
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
12172
+ var imageList, tasks;
12173
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
12174
+ while (1) switch (_context5.prev = _context5.next) {
12175
+ case 0:
12176
+ imageList = _toConsumableArray(svgNode.getElementsByTagName('image') || []);
12177
+ tasks = imageList.map( /*#__PURE__*/function () {
12178
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(image) {
12179
+ var href, imgData, imgUrl;
12180
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
12181
+ while (1) switch (_context4.prev = _context4.next) {
12182
+ case 0:
12183
+ href = image.getAttribute('href') || image.getAttributeNS('http://www.w3.org/1999/xlink', 'href');
12184
+ if (!href) {
12185
+ _context4.next = 11;
12186
+ break;
12187
+ }
12188
+ if (!href.startsWith('data:image/')) {
12189
+ _context4.next = 4;
12190
+ break;
12191
+ }
12192
+ return _context4.abrupt("return");
12193
+ case 4:
12194
+ _context4.next = 6;
12195
+ return _this8.requestImage(href);
12196
+ case 6:
12197
+ imgData = _context4.sent;
12198
+ _context4.next = 9;
12199
+ return _this8.blobToDataUrl(imgData);
12200
+ case 9:
12201
+ imgUrl = _context4.sent;
12202
+ image.setAttribute('href', imgUrl);
12203
+ case 11:
12204
+ case "end":
12205
+ return _context4.stop();
12206
+ }
12207
+ }, _callee4);
12208
+ }));
12209
+ return function (_x2) {
12210
+ return _ref.apply(this, arguments);
12211
+ };
12212
+ }());
12213
+ _context5.next = 4;
12214
+ return Promise.all(tasks);
12215
+ case 4:
12216
+ return _context5.abrupt("return", svgNode);
12217
+ case 5:
12218
+ case "end":
12219
+ return _context5.stop();
12220
+ }
12221
+ }, _callee5);
12222
+ }))();
12223
+ },
12224
+ requestImage: function requestImage(url) {
12225
+ var _this9 = this;
12226
+ if (url.startsWith('/platform_web_portal_war_exploded')) {
12227
+ url = url.replace('/platform_web_portal_war_exploded', '');
12228
+ }
12229
+ return new Promise(function (resolve, reject) {
12230
+ _this9.$axios.get(url, {
12231
+ responseType: 'blob'
12232
+ }).then(function (res) {
12233
+ resolve(res);
12234
+ })["catch"](function (err) {
12235
+ reject(err);
12236
+ });
12237
+ });
12238
+ },
12239
+ // 绘制图片到canvas
12163
12240
  drawToCanvas: function drawToCanvas(url, options) {
12164
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
12165
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
12166
- while (1) switch (_context3.prev = _context3.next) {
12241
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
12242
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
12243
+ while (1) switch (_context6.prev = _context6.next) {
12167
12244
  case 0:
12168
- return _context3.abrupt("return", new Promise(function (resolve, reject) {
12245
+ return _context6.abrupt("return", new Promise(function (resolve, reject) {
12169
12246
  var img = new Image();
12170
12247
  img.setAttribute('crossOrigin', 'anonymous');
12171
12248
  img.onload = function () {
@@ -12196,11 +12273,12 @@ var index$6 = {
12196
12273
  }));
12197
12274
  case 1:
12198
12275
  case "end":
12199
- return _context3.stop();
12276
+ return _context6.stop();
12200
12277
  }
12201
- }, _callee3);
12278
+ }, _callee6);
12202
12279
  }))();
12203
12280
  },
12281
+ // 下载文件
12204
12282
  downloadFile: function downloadFile(data, fileName) {
12205
12283
  var a = document.createElement('a');
12206
12284
  a.href = data;