hrsass-components 2.4.1 → 2.4.3

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.1";
68
+ var version = "2.4.3";
69
69
 
70
70
  /**
71
71
  * 版本号
@@ -3353,7 +3353,7 @@ var HrAppendix = {
3353
3353
  if (_this.listType === "picture-card" && file.status === "done") {
3354
3354
  var response = file.response,
3355
3355
  rest = _objectWithoutProperties(file, _excluded);
3356
- response.fileId && (rest.uid = response.fileId);
3356
+ response && response.fileId && (rest.uid = response.fileId);
3357
3357
  return rest;
3358
3358
  } else {
3359
3359
  return file;
@@ -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 max = item.x;
11899
- for (var i = level; i < item.property.departmentLevel; i++) {
11900
- if (map.has(i + 1)) {
11901
- if (item.x > map.get(i + 1)) {
11902
- map.set(i + 1, item.x);
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
- max = map.get(i + 1);
11920
+ _max = map.get(_i + 1);
11905
11921
  }
11906
11922
  } else {
11907
- map.set(i + 1, item.x);
11923
+ map.set(_i + 1, item.x);
11908
11924
  }
11909
11925
  }
11910
- if (max !== item.x) {
11911
- item.x = max + width + gutter;
11912
- item.pointX = max + width + gutter;
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
- return h("g", [item.property.open && children.length > 0 && _this4._renderOrgChartLine(parseInt(item.property.departmentLevel || item.level) + 1, children), h(Comp, {
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,
@@ -12039,32 +12057,37 @@ var index$6 = {
12039
12057
  });
12040
12058
  },
12041
12059
  exportSvg: function exportSvg(fileName) {
12042
- var _this6 = this;
12043
- var bBox = this.$refs.hrOrgChartSvg.getBBox(),
12044
- options = {
12045
- scale: 1,
12046
- width: bBox.width,
12047
- height: bBox.height,
12048
- top: bBox.y,
12049
- left: bBox.x
12050
- };
12051
- this.setState({
12052
- loading: true,
12053
- isDownload: true
12054
- });
12055
- saveSvgAsPng.svgAsDataUri(this.$refs.hrOrgChartSvg, options).then(function (url) {
12056
- var dataUrL = url.split('base64,')[1];
12057
- _this6.$axios.post('/business/org/Company/getOrgDiagram.data', {
12058
- 'base64Str': dataUrL,
12059
- name: fileName || 'org.png'
12060
- }).then(function (res) {
12061
- window.open("".concat(process.env.VUE_APP_API_BASE_URL, "/file.nolog?method=download&fileId=").concat(res));
12062
- _this6.setState({
12063
- loading: false,
12064
- isDownload: false
12065
- });
12066
- });
12067
- });
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
+ // });
12068
12091
  // saveSvgAsPng(this.$refs.hrOrgChartSvg, fileName || 'org.png', {
12069
12092
  // scale: 1,
12070
12093
  // width: bBox.width,
@@ -12073,6 +12096,99 @@ var index$6 = {
12073
12096
  // left: bBox.x,
12074
12097
  // });
12075
12098
  },
12099
+ svgToPng: function svgToPng(svgStr, options) {
12100
+ var _this6 = this;
12101
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
12102
+ var blob, url, imgData;
12103
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
12104
+ while (1) switch (_context.prev = _context.next) {
12105
+ case 0:
12106
+ blob = new Blob([svgStr], {
12107
+ type: 'image/svg+xml'
12108
+ });
12109
+ _context.next = 3;
12110
+ return _this6.blobToDataUrl(blob);
12111
+ case 3:
12112
+ url = _context.sent;
12113
+ _context.next = 6;
12114
+ return _this6.drawToCanvas(url, options);
12115
+ case 6:
12116
+ imgData = _context.sent;
12117
+ _this6.downloadFile(imgData, 'org.png');
12118
+ case 8:
12119
+ case "end":
12120
+ return _context.stop();
12121
+ }
12122
+ }, _callee);
12123
+ }))();
12124
+ },
12125
+ blobToDataUrl: function blobToDataUrl(blob) {
12126
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
12127
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
12128
+ while (1) switch (_context2.prev = _context2.next) {
12129
+ case 0:
12130
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
12131
+ var reader = new FileReader();
12132
+ reader.onload = function () {
12133
+ resolve(reader.result);
12134
+ };
12135
+ reader.onerror = reject;
12136
+ reader.readAsDataURL(blob);
12137
+ }));
12138
+ case 1:
12139
+ case "end":
12140
+ return _context2.stop();
12141
+ }
12142
+ }, _callee2);
12143
+ }))();
12144
+ },
12145
+ drawToCanvas: function drawToCanvas(url, options) {
12146
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
12147
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
12148
+ while (1) switch (_context3.prev = _context3.next) {
12149
+ case 0:
12150
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
12151
+ var img = new Image();
12152
+ img.setAttribute('crossOrigin', 'anonymous');
12153
+ img.onload = function () {
12154
+ var canvas = document.createElement('canvas');
12155
+ var ctx = canvas.getContext('2d');
12156
+ var scale = options.scale || 1;
12157
+ // 关键:用bBox的left/top做偏移,宽高用bBox的width/height
12158
+ var width = options.width * scale;
12159
+ var height = options.height * scale;
12160
+ canvas.width = width;
12161
+ canvas.height = height;
12162
+ // 填充白色背景(可选)
12163
+ ctx.fillStyle = "#fff";
12164
+ ctx.fillRect(0, 0, width, height);
12165
+ // 关键:drawImage的第二组参数,控制源区域
12166
+ ctx.drawImage(img, 0, 0, width, height // 目标区域(canvas全部)
12167
+ );
12168
+ canvas.toBlob(function (blob) {
12169
+ if (blob) {
12170
+ resolve(URL.createObjectURL(blob));
12171
+ } else {
12172
+ reject('Failed to convert canvas to blob');
12173
+ }
12174
+ }, 'image/png');
12175
+ };
12176
+ img.onerror = reject;
12177
+ img.src = url;
12178
+ }));
12179
+ case 1:
12180
+ case "end":
12181
+ return _context3.stop();
12182
+ }
12183
+ }, _callee3);
12184
+ }))();
12185
+ },
12186
+ downloadFile: function downloadFile(data, fileName) {
12187
+ var a = document.createElement('a');
12188
+ a.href = data;
12189
+ a.download = fileName;
12190
+ a.click();
12191
+ },
12076
12192
  /**
12077
12193
  * 获取当前缩放比例
12078
12194
  */