hrsass-components 2.4.3 → 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.
- package/lib/hrsass-components.js +159 -63
- package/lib/hrsass-components.min.js +1 -1
- package/package.json +1 -1
- package/rollup.build.css +10492 -0
package/lib/hrsass-components.js
CHANGED
|
@@ -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.
|
|
68
|
+
var version = "2.4.5";
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* 版本号
|
|
@@ -12056,78 +12056,101 @@ var index$6 = {
|
|
|
12056
12056
|
}
|
|
12057
12057
|
});
|
|
12058
12058
|
},
|
|
12059
|
+
// 计算导出图片的 scale
|
|
12060
|
+
calcExportScale: function calcExportScale(svgWidth, svgHeight) {
|
|
12061
|
+
var realZoom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
12062
|
+
// 屏幕宽高
|
|
12063
|
+
var screenW = window.screen.width;
|
|
12064
|
+
var screenH = window.screen.height;
|
|
12065
|
+
// 目标导出宽度为屏幕宽度的3倍,最高不超过4倍
|
|
12066
|
+
var targetW = screenW * 4;
|
|
12067
|
+
var scale = targetW / svgWidth;
|
|
12068
|
+
// 如果svg很高,按高度再限制一次
|
|
12069
|
+
if (svgHeight * scale > screenH * 4.5) {
|
|
12070
|
+
scale = screenH * 4.5 / svgHeight;
|
|
12071
|
+
if (scale < 1) scale = 1;
|
|
12072
|
+
}
|
|
12073
|
+
// 限制scale范围,防止过大或过小
|
|
12074
|
+
// if (scale < 1) scale = 1;
|
|
12075
|
+
// if (scale > 10) scale = 10;
|
|
12076
|
+
// 叠加当前svgPanZoom缩放
|
|
12077
|
+
scale = scale / realZoom;
|
|
12078
|
+
return scale;
|
|
12079
|
+
},
|
|
12080
|
+
// 导出图片
|
|
12059
12081
|
exportSvg: function exportSvg(fileName) {
|
|
12060
|
-
var svg = this.$refs.hrOrgChartSvg;
|
|
12061
|
-
var bBox = svg.getBBox();
|
|
12062
|
-
// 克隆SVG,设置viewBox和宽高,确保全部内容
|
|
12063
|
-
var clonedSvg = svg.cloneNode(true);
|
|
12064
|
-
clonedSvg.setAttribute('width', bBox.width);
|
|
12065
|
-
clonedSvg.setAttribute('height', bBox.height);
|
|
12066
|
-
clonedSvg.setAttribute('viewBox', "".concat(bBox.x, " ").concat(bBox.y, " ").concat(bBox.width, " ").concat(bBox.height));
|
|
12067
|
-
// 生成完整SVG字符串
|
|
12068
|
-
var svgStr = new XMLSerializer().serializeToString(clonedSvg);
|
|
12069
|
-
var options = {
|
|
12070
|
-
scale: 1,
|
|
12071
|
-
width: bBox.width,
|
|
12072
|
-
height: bBox.height,
|
|
12073
|
-
left: 0,
|
|
12074
|
-
top: 0
|
|
12075
|
-
};
|
|
12076
|
-
this.svgToPng(svgStr, options);
|
|
12077
|
-
// this.setState({
|
|
12078
|
-
// loading: true,
|
|
12079
|
-
// isDownload: true,
|
|
12080
|
-
// })
|
|
12081
|
-
// svgAsDataUri(this.$refs.hrOrgChartSvg, options).then(url => {
|
|
12082
|
-
// let dataUrL = url.split('base64,')[1]
|
|
12083
|
-
// this.$axios.post('/business/org/Company/getOrgDiagram.data', { 'base64Str': dataUrL, name: fileName || 'org.png' }).then(res => {
|
|
12084
|
-
// window.open(`${process.env.VUE_APP_API_BASE_URL}/file.nolog?method=download&fileId=${res}`);
|
|
12085
|
-
// this.setState({
|
|
12086
|
-
// loading: false,
|
|
12087
|
-
// isDownload: false
|
|
12088
|
-
// })
|
|
12089
|
-
// })
|
|
12090
|
-
// });
|
|
12091
|
-
// saveSvgAsPng(this.$refs.hrOrgChartSvg, fileName || 'org.png', {
|
|
12092
|
-
// scale: 1,
|
|
12093
|
-
// width: bBox.width,
|
|
12094
|
-
// height: bBox.height,
|
|
12095
|
-
// top: bBox.y,
|
|
12096
|
-
// left: bBox.x,
|
|
12097
|
-
// });
|
|
12098
|
-
},
|
|
12099
|
-
svgToPng: function svgToPng(svgStr, options) {
|
|
12100
12082
|
var _this6 = this;
|
|
12101
12083
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
12102
|
-
var
|
|
12084
|
+
var svg, bBox, clonedSvg, svgStr, realZoom, scale, options;
|
|
12103
12085
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
12104
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) {
|
|
12105
12127
|
case 0:
|
|
12106
12128
|
blob = new Blob([svgStr], {
|
|
12107
12129
|
type: 'image/svg+xml'
|
|
12108
12130
|
});
|
|
12109
|
-
|
|
12110
|
-
return
|
|
12131
|
+
_context2.next = 3;
|
|
12132
|
+
return _this7.blobToDataUrl(blob);
|
|
12111
12133
|
case 3:
|
|
12112
|
-
url =
|
|
12113
|
-
|
|
12114
|
-
return
|
|
12134
|
+
url = _context2.sent;
|
|
12135
|
+
_context2.next = 6;
|
|
12136
|
+
return _this7.drawToCanvas(url, options);
|
|
12115
12137
|
case 6:
|
|
12116
|
-
imgData =
|
|
12117
|
-
|
|
12138
|
+
imgData = _context2.sent;
|
|
12139
|
+
_this7.downloadFile(imgData, fileName || 'org.png');
|
|
12118
12140
|
case 8:
|
|
12119
12141
|
case "end":
|
|
12120
|
-
return
|
|
12142
|
+
return _context2.stop();
|
|
12121
12143
|
}
|
|
12122
|
-
},
|
|
12144
|
+
}, _callee2);
|
|
12123
12145
|
}))();
|
|
12124
12146
|
},
|
|
12147
|
+
// 生成图片数据url
|
|
12125
12148
|
blobToDataUrl: function blobToDataUrl(blob) {
|
|
12126
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
12127
|
-
return _regeneratorRuntime.wrap(function
|
|
12128
|
-
while (1) switch (
|
|
12149
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
12150
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
12151
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
12129
12152
|
case 0:
|
|
12130
|
-
return
|
|
12153
|
+
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
12131
12154
|
var reader = new FileReader();
|
|
12132
12155
|
reader.onload = function () {
|
|
12133
12156
|
resolve(reader.result);
|
|
@@ -12137,17 +12160,89 @@ var index$6 = {
|
|
|
12137
12160
|
}));
|
|
12138
12161
|
case 1:
|
|
12139
12162
|
case "end":
|
|
12140
|
-
return
|
|
12163
|
+
return _context3.stop();
|
|
12141
12164
|
}
|
|
12142
|
-
},
|
|
12165
|
+
}, _callee3);
|
|
12143
12166
|
}))();
|
|
12144
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
|
|
12145
12240
|
drawToCanvas: function drawToCanvas(url, options) {
|
|
12146
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
12147
|
-
return _regeneratorRuntime.wrap(function
|
|
12148
|
-
while (1) switch (
|
|
12241
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
12242
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
12243
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
12149
12244
|
case 0:
|
|
12150
|
-
return
|
|
12245
|
+
return _context6.abrupt("return", new Promise(function (resolve, reject) {
|
|
12151
12246
|
var img = new Image();
|
|
12152
12247
|
img.setAttribute('crossOrigin', 'anonymous');
|
|
12153
12248
|
img.onload = function () {
|
|
@@ -12178,11 +12273,12 @@ var index$6 = {
|
|
|
12178
12273
|
}));
|
|
12179
12274
|
case 1:
|
|
12180
12275
|
case "end":
|
|
12181
|
-
return
|
|
12276
|
+
return _context6.stop();
|
|
12182
12277
|
}
|
|
12183
|
-
},
|
|
12278
|
+
}, _callee6);
|
|
12184
12279
|
}))();
|
|
12185
12280
|
},
|
|
12281
|
+
// 下载文件
|
|
12186
12282
|
downloadFile: function downloadFile(data, fileName) {
|
|
12187
12283
|
var a = document.createElement('a');
|
|
12188
12284
|
a.href = data;
|