hrsass-components 2.4.2 → 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.
- package/lib/hrsass-components.js +172 -38
- package/lib/hrsass-components.min.js +1 -1
- package/package.json +1 -1
- package/rollup.build.css +15738 -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.4";
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* 版本号
|
|
@@ -11882,6 +11882,22 @@ var index$6 = {
|
|
|
11882
11882
|
_this3._reSetX(parent, map);
|
|
11883
11883
|
}
|
|
11884
11884
|
}
|
|
11885
|
+
if (item.property.departmentLevel > level) {
|
|
11886
|
+
var _dx = 0,
|
|
11887
|
+
max = 0;
|
|
11888
|
+
for (var i = level + 1; i <= item.property.departmentLevel; i++) {
|
|
11889
|
+
if (map.has(i) && map.get(i) > max) {
|
|
11890
|
+
max = map.get(i);
|
|
11891
|
+
}
|
|
11892
|
+
}
|
|
11893
|
+
if (max !== 0) {
|
|
11894
|
+
_dx = max + width + gutter;
|
|
11895
|
+
}
|
|
11896
|
+
if (_dx !== 0 && item.x < _dx) {
|
|
11897
|
+
item.x = _dx;
|
|
11898
|
+
item.pointX = _dx;
|
|
11899
|
+
}
|
|
11900
|
+
}
|
|
11885
11901
|
if (map.has(level)) {
|
|
11886
11902
|
if (item.x > map.get(level)) {
|
|
11887
11903
|
map.set(level, item.x);
|
|
@@ -11895,21 +11911,21 @@ var index$6 = {
|
|
|
11895
11911
|
//对比层级和level,进行高度计算和map维护
|
|
11896
11912
|
if (item.property.departmentLevel > level) {
|
|
11897
11913
|
item.y = (height + lineHeight * 2) * item.property.departmentLevel;
|
|
11898
|
-
var
|
|
11899
|
-
for (var
|
|
11900
|
-
if (map.has(
|
|
11901
|
-
if (item.x > map.get(
|
|
11902
|
-
map.set(
|
|
11914
|
+
var _max = item.x;
|
|
11915
|
+
for (var _i = level; _i < item.property.departmentLevel; _i++) {
|
|
11916
|
+
if (map.has(_i + 1)) {
|
|
11917
|
+
if (item.x > map.get(_i + 1)) {
|
|
11918
|
+
map.set(_i + 1, item.x);
|
|
11903
11919
|
} else {
|
|
11904
|
-
|
|
11920
|
+
_max = map.get(_i + 1);
|
|
11905
11921
|
}
|
|
11906
11922
|
} else {
|
|
11907
|
-
map.set(
|
|
11923
|
+
map.set(_i + 1, item.x);
|
|
11908
11924
|
}
|
|
11909
11925
|
}
|
|
11910
|
-
if (
|
|
11911
|
-
item.x =
|
|
11912
|
-
item.pointX =
|
|
11926
|
+
if (_max !== item.x) {
|
|
11927
|
+
item.x = _max + width + gutter;
|
|
11928
|
+
item.pointX = _max + width + gutter;
|
|
11913
11929
|
_this3._reSetX(parent, map);
|
|
11914
11930
|
}
|
|
11915
11931
|
}
|
|
@@ -11963,7 +11979,9 @@ var index$6 = {
|
|
|
11963
11979
|
return h("g", [data.map(function (item) {
|
|
11964
11980
|
var children = item.children || [];
|
|
11965
11981
|
var Comp = _this4._getComponent(type);
|
|
11966
|
-
|
|
11982
|
+
var departmentLevel = parseInt(item.property.departmentLevel) || 0;
|
|
11983
|
+
var level = parseInt(item.level) || 0;
|
|
11984
|
+
return h("g", [item.property.open && children.length > 0 && _this4._renderOrgChartLine((departmentLevel > level ? departmentLevel : level) + 1, children), h(Comp, {
|
|
11967
11985
|
attrs: {
|
|
11968
11986
|
data: item,
|
|
11969
11987
|
width: width,
|
|
@@ -12038,33 +12056,56 @@ var index$6 = {
|
|
|
12038
12056
|
}
|
|
12039
12057
|
});
|
|
12040
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
|
+
},
|
|
12041
12077
|
exportSvg: function exportSvg(fileName) {
|
|
12042
|
-
var
|
|
12043
|
-
var bBox =
|
|
12044
|
-
|
|
12045
|
-
|
|
12046
|
-
|
|
12047
|
-
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
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
|
+
// });
|
|
12068
12109
|
// saveSvgAsPng(this.$refs.hrOrgChartSvg, fileName || 'org.png', {
|
|
12069
12110
|
// scale: 1,
|
|
12070
12111
|
// width: bBox.width,
|
|
@@ -12073,6 +12114,99 @@ var index$6 = {
|
|
|
12073
12114
|
// left: bBox.x,
|
|
12074
12115
|
// });
|
|
12075
12116
|
},
|
|
12117
|
+
svgToPng: function svgToPng(svgStr, options, fileName) {
|
|
12118
|
+
var _this6 = this;
|
|
12119
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
12120
|
+
var blob, url, imgData;
|
|
12121
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
12122
|
+
while (1) switch (_context.prev = _context.next) {
|
|
12123
|
+
case 0:
|
|
12124
|
+
blob = new Blob([svgStr], {
|
|
12125
|
+
type: 'image/svg+xml'
|
|
12126
|
+
});
|
|
12127
|
+
_context.next = 3;
|
|
12128
|
+
return _this6.blobToDataUrl(blob);
|
|
12129
|
+
case 3:
|
|
12130
|
+
url = _context.sent;
|
|
12131
|
+
_context.next = 6;
|
|
12132
|
+
return _this6.drawToCanvas(url, options);
|
|
12133
|
+
case 6:
|
|
12134
|
+
imgData = _context.sent;
|
|
12135
|
+
_this6.downloadFile(imgData, fileName || 'org.png');
|
|
12136
|
+
case 8:
|
|
12137
|
+
case "end":
|
|
12138
|
+
return _context.stop();
|
|
12139
|
+
}
|
|
12140
|
+
}, _callee);
|
|
12141
|
+
}))();
|
|
12142
|
+
},
|
|
12143
|
+
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) {
|
|
12147
|
+
case 0:
|
|
12148
|
+
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
12149
|
+
var reader = new FileReader();
|
|
12150
|
+
reader.onload = function () {
|
|
12151
|
+
resolve(reader.result);
|
|
12152
|
+
};
|
|
12153
|
+
reader.onerror = reject;
|
|
12154
|
+
reader.readAsDataURL(blob);
|
|
12155
|
+
}));
|
|
12156
|
+
case 1:
|
|
12157
|
+
case "end":
|
|
12158
|
+
return _context2.stop();
|
|
12159
|
+
}
|
|
12160
|
+
}, _callee2);
|
|
12161
|
+
}))();
|
|
12162
|
+
},
|
|
12163
|
+
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) {
|
|
12167
|
+
case 0:
|
|
12168
|
+
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
12169
|
+
var img = new Image();
|
|
12170
|
+
img.setAttribute('crossOrigin', 'anonymous');
|
|
12171
|
+
img.onload = function () {
|
|
12172
|
+
var canvas = document.createElement('canvas');
|
|
12173
|
+
var ctx = canvas.getContext('2d');
|
|
12174
|
+
var scale = options.scale || 1;
|
|
12175
|
+
// 关键:用bBox的left/top做偏移,宽高用bBox的width/height
|
|
12176
|
+
var width = options.width * scale;
|
|
12177
|
+
var height = options.height * scale;
|
|
12178
|
+
canvas.width = width;
|
|
12179
|
+
canvas.height = height;
|
|
12180
|
+
// 填充白色背景(可选)
|
|
12181
|
+
ctx.fillStyle = "#fff";
|
|
12182
|
+
ctx.fillRect(0, 0, width, height);
|
|
12183
|
+
// 关键:drawImage的第二组参数,控制源区域
|
|
12184
|
+
ctx.drawImage(img, 0, 0, width, height // 目标区域(canvas全部)
|
|
12185
|
+
);
|
|
12186
|
+
canvas.toBlob(function (blob) {
|
|
12187
|
+
if (blob) {
|
|
12188
|
+
resolve(URL.createObjectURL(blob));
|
|
12189
|
+
} else {
|
|
12190
|
+
reject('Failed to convert canvas to blob');
|
|
12191
|
+
}
|
|
12192
|
+
}, 'image/png');
|
|
12193
|
+
};
|
|
12194
|
+
img.onerror = reject;
|
|
12195
|
+
img.src = url;
|
|
12196
|
+
}));
|
|
12197
|
+
case 1:
|
|
12198
|
+
case "end":
|
|
12199
|
+
return _context3.stop();
|
|
12200
|
+
}
|
|
12201
|
+
}, _callee3);
|
|
12202
|
+
}))();
|
|
12203
|
+
},
|
|
12204
|
+
downloadFile: function downloadFile(data, fileName) {
|
|
12205
|
+
var a = document.createElement('a');
|
|
12206
|
+
a.href = data;
|
|
12207
|
+
a.download = fileName;
|
|
12208
|
+
a.click();
|
|
12209
|
+
},
|
|
12076
12210
|
/**
|
|
12077
12211
|
* 获取当前缩放比例
|
|
12078
12212
|
*/
|