From 5ef299dfcfca4c036c193df863137e30065fcf91 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 1 Jun 2021 13:40:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E8=BE=91=E4=BB=AA=E8=A1=A8?= =?UTF-8?q?=E7=9B=98=E5=90=8C=E6=97=B6=E6=94=AF=E6=8C=81=E8=87=AA=E9=80=82?= =?UTF-8?q?=E5=BA=94=E7=94=BB=E5=B8=83=E5=8C=BA=E5=9F=9F=E5=92=8C=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E7=94=BB=E5=B8=83=E5=A4=A7=E5=B0=8F=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canvas/components/Editor/Area.vue | 37 +- .../canvas/components/Editor/index.vue | 107 ++++- .../components/canvas/components/Toolbar.vue | 24 +- .../utils/calculateComponentPositonAndSize.js | 450 +++++++++--------- .../src/components/canvas/utils/translate.js | 28 +- frontend/src/store/index.js | 16 +- frontend/src/views/panel/edit/index.vue | 51 +- frontend/src/views/panel/list/PanelList.vue | 14 +- frontend/src/views/panel/panel.js | 7 +- 9 files changed, 450 insertions(+), 284 deletions(-) diff --git a/frontend/src/components/canvas/components/Editor/Area.vue b/frontend/src/components/canvas/components/Editor/Area.vue index a9e6d30e61..c9d5efb1a7 100644 --- a/frontend/src/components/canvas/components/Editor/Area.vue +++ b/frontend/src/components/canvas/components/Editor/Area.vue @@ -1,25 +1,28 @@ @@ -28,4 +31,4 @@ export default { border: 1px solid #70c0ff; position: absolute; } - \ No newline at end of file + diff --git a/frontend/src/components/canvas/components/Editor/index.vue b/frontend/src/components/canvas/components/Editor/index.vue index 224e01ae75..16e73a204f 100644 --- a/frontend/src/components/canvas/components/Editor/index.vue +++ b/frontend/src/components/canvas/components/Editor/index.vue @@ -14,13 +14,15 @@ + + ' + JSON.stringify(style)) + if (this.canvasStyleData.openCommonStyle) { if (this.canvasStyleData.panel.backgroundType === 'image' && this.canvasStyleData.panel.imageUrl) { style = { - width: this.changeStyleWithScale(this.canvasStyleData.width) + 'px', - height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px', - background: `url(${this.canvasStyleData.panel.imageUrl}) no-repeat` + background: `url(${this.canvasStyleData.panel.imageUrl}) no-repeat`, + ...style } } else { style = { - width: this.changeStyleWithScale(this.canvasStyleData.width) + 'px', - height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px', - background: this.canvasStyleData.panel.color + background: this.canvasStyleData.panel.color, + ...style } } } - return style }, panelInfo() { @@ -153,7 +187,6 @@ export default { }, methods: { changeStyleWithScale, - handleMouseDown(e) { // 如果没有选中组件 在画布上点击时需要调用 e.preventDefault() 防止触发 drop 事件 if (!this.curComponent || (this.curComponent.component !== 'v-text' && this.curComponent.component !== 'rect-shape')) { @@ -218,8 +251,10 @@ export default { // 根据选中区域和区域中每个组件的位移信息来创建 Group 组件 // 要遍历选择区域的每个组件,获取它们的 left top right bottom 信息来进行比较 - let top = Infinity; let left = Infinity - let right = -Infinity; let bottom = -Infinity + let top = Infinity + let left = Infinity + let right = -Infinity + let bottom = -Infinity areaData.forEach(component => { let style = {} if (component.component === 'Group') { @@ -303,19 +338,34 @@ export default { getShapeStyle(style) { const result = {}; - ['width', 'height', 'top', 'left', 'rotate'].forEach(attr => { - if (attr !== 'rotate') { - result[attr] = style[attr] + 'px' - } else { - result.transform = 'rotate(' + style[attr] + 'deg)' - } + ['width', 'left'].forEach(attr => { + result[attr] = this.format(style[attr], this.scaleWidth) + 'px' + }); + ['height', 'top'].forEach(attr => { + result[attr] = this.format(style[attr], this.scaleHeight) + 'px' }) + result.transform = 'rotate(' + style['rotate'] + 'deg)' + + return result + }, + + getShapeStyleInt(style) { + const result = {}; + ['width', 'left'].forEach(attr => { + result[attr] = this.format(style[attr], this.scaleWidth) + }); + ['height', 'top'].forEach(attr => { + result[attr] = this.format(style[attr], this.scaleHeight) + }) + result['rotate'] = style['rotate'] + result['borderWidth'] = style['borderWidth'] + result['opacity'] = style['opacity'] return result }, getComponentStyle(style) { - // return getStyle(style, ['top', 'left', 'width', 'height', 'rotate']) + // return getStyle(style, ['top', 'left', 'width', 'height', 'rotate']) return style }, @@ -368,6 +418,21 @@ export default { }, executeSearch() { console.log('当前查询条件是: ' + JSON.stringify(this.conditions)) + }, + format(value, scale) { + // 自适应画布区域 返回原值 + if (this.canvasStyleData.selfAdaption) { + return parseInt(value * parseInt(scale) / 100) + } else { + return parseInt(value) + } + }, + changeScale() { + if (this.outStyle.width && this.outStyle.height) { + this.scaleWidth = parseInt(this.outStyle.width * 100 / this.canvasStyleData.width) + this.scaleHeight = parseInt(this.outStyle.height * 100 / this.canvasStyleData.height) + this.$store.commit('setCurCanvasScale', { scaleWidth: this.scaleWidth, scaleHeight: this.scaleHeight }) + } } } } diff --git a/frontend/src/components/canvas/components/Toolbar.vue b/frontend/src/components/canvas/components/Toolbar.vue index 36c6cdf466..306fd10128 100644 --- a/frontend/src/components/canvas/components/Toolbar.vue +++ b/frontend/src/components/canvas/components/Toolbar.vue @@ -1,11 +1,17 @@