Skip to content

Commit 3300b40

Browse files
update
1 parent 2798985 commit 3300b40

File tree

3 files changed

+16
-58
lines changed

3 files changed

+16
-58
lines changed

src/core/mixins/visual.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Vue.mixin({
2020
setCanvasStyle(canvasRef, parentRef, space = 0) {
2121
this.$nextTick(() => {
2222
let canvas = this.$refs[canvasRef];
23+
const parent = this.$refs[parentRef];
2324
console.log("====setCanvasStyle", JSON.stringify(this.canvasStyle))
2425
if (this.canvasStyle.intWidth) {
2526
canvas.style.setProperty("--w", this.canvasStyle.intWidth + "px");
@@ -28,6 +29,7 @@ Vue.mixin({
2829
canvas.style.setProperty("--h", this.canvasStyle.intHeight + "px");
2930
}
3031
if (this.canvasStyle.backgroundColor) {
32+
parent.style.setProperty("--color", this.canvasStyle.backgroundColor);
3133
canvas.style.setProperty("--color", this.canvasStyle.backgroundColor);
3234
}
3335
this.defaultScale = this.getScale(parentRef, space);
@@ -40,28 +42,18 @@ Vue.mixin({
4042
if (cpt.style.height) cpt.point.h = cpt.style.height;
4143
return cpt.style;
4244
},
43-
setZoom(step) {
44-
if (this.defaultScale >= 1.5 && step > 0) return;
45-
if (this.defaultScale <= 0.5 && step < 0) return;
46-
this.defaultScale += step;
47-
console.log("====setZoom", step)
48-
let droppable = document.getElementById("droppable")
49-
droppable.style.transform = "scale(" + this.defaultScale + ")";
50-
},
5145
getScale(refName, space) {
5246
const parent = this.$refs[refName];
5347
// 画布父容器宽度
5448
const parentW = parent.offsetWidth;
5549
// 画布父容器高度
5650
const parentH = parent.offsetHeight;
5751
console.log("====parent", parent.offsetWidth, parent.offsetHeight)
58-
let scaleX = (parentW + space) / this.canvasStyle.intWidth;
59-
let scaleY = (parentH + space) / this.canvasStyle.intHeight;
60-
if (space > 0) {
61-
return Math.max(scaleX, scaleY);
62-
} else {
63-
return Math.min(scaleX, scaleY);
64-
}
52+
console.log("====window", window.innerWidth, window.innerHeight)
53+
let scaleX = (parentW - space) / this.canvasStyle.intWidth;
54+
let scaleY = (parentH - space) / this.canvasStyle.intHeight;
55+
56+
return Math.min(scaleX, scaleY);
6557
},
6658
handleUnselect(cptId) {
6759
const unselect = (cptId) => {

src/view/pages/visual/display/index.vue

+6-40
Original file line numberDiff line numberDiff line change
@@ -101,40 +101,12 @@ export default {
101101
this.canvasStyle[key] = jsonObj.canvasStyle[key];
102102
}
103103
}
104-
this.setCanvasStyle("canvasDisplay", "canvasContainer", 40);
104+
this.setCanvasStyle("canvasDisplay", "canvasContainer");
105105
this.refresh(this.fullData);
106106
}
107107
})
108108
},
109109
methods: {
110-
/**
111-
* 获取自适应的scale
112-
* @param fullData
113-
* @returns {number}
114-
*/
115-
// getScale(fullData) {
116-
// let left = null, right = null, top = null, bottom = null;
117-
// fullData.forEach(item => {
118-
// let point = item.point;
119-
// if (!left || left > point.x) left = point.x;
120-
// if (!right || right < (point.x + point.w)) right = point.x + point.w;
121-
// if (!top || top > point.y) top = point.y;
122-
// if (!bottom || bottom < (point.y + point.h)) bottom = point.y + point.h;
123-
// })
124-
// // 宽 = 最右 - 最左
125-
// let fitW = right - left;
126-
// // 高 = 最下 - 最上
127-
// let fitH = bottom - top;
128-
// let canvasDisplay = document.getElementById("canvas_display");
129-
// canvasDisplay.style.width = fitW + "px";
130-
// canvasDisplay.style.height = fitH + "px";
131-
//
132-
// const w = window.innerWidth / fitW
133-
// const h = window.innerHeight / fitH
134-
// // 宽度与高度的比例取最小的,以确保屏幕可以完全显示
135-
// let scale = Math.min(w, h)
136-
// return scale;
137-
// },
138110
/**
139111
* 放大
140112
*/
@@ -149,14 +121,6 @@ export default {
149121
this.scale -= 0.1;
150122
this.setZoom(this.scale);
151123
},
152-
// /**
153-
// * 缩放
154-
// * @param scale
155-
// */
156-
// setZoom(scale) {
157-
// let canvasDisplay = document.getElementById("canvas_display")
158-
// canvasDisplay.style.transform = "scale(" + scale + ")";
159-
// },
160124
getChartStyle(item) {
161125
return {
162126
borderRadius: "10px",
@@ -220,14 +184,16 @@ export default {
220184
<style scoped lang="scss">
221185
.canvas-container {
222186
position: relative;
223-
width: 100%;
187+
width: 100%!important;
224188
height: 100%!important;
225189
padding: 0;
226190
margin: 0;
191+
background-color: var(--color);
227192
.canvas-display {
228-
width: 100%;
229-
height: 100%;
193+
width: var(--w);
194+
height: var(--h);
230195
background-color: var(--color);
196+
transform-origin: 0 0;
231197
}
232198
.draggable-class {
233199
position: absolute;

src/view/pages/visual/editor/canvas/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default {
138138
this.canvasStyle[key] = newValue.canvasStyle[key];
139139
}
140140
}
141-
this.setCanvasStyle("droppable", "canvas_container");
141+
this.setCanvasStyle("droppable", "canvas_container", 40);
142142
// 默认显示页面设置面板
143143
bus.$emit("share", {type: "background", ...this.canvasStyle})
144144
},
@@ -162,7 +162,7 @@ export default {
162162
});
163163
164164
window.addEventListener("resize", () => {
165-
this.setCanvasStyle("droppable", "canvas_container");
165+
this.setCanvasStyle("droppable", "canvas_container", 40);
166166
167167
}, null);
168168
// 默认显示页面设置面板
@@ -189,7 +189,7 @@ export default {
189189
if (style.intHeight) this.canvasStyle.intHeight = style.intHeight
190190
if (style.backgroundColor) this.canvasStyle.backgroundColor = style.backgroundColor;
191191
console.log("====changeStyle", style)
192-
this.setCanvasStyle("droppable", "canvas_container");
192+
this.setCanvasStyle("droppable", "canvas_container", 40);
193193
} else {
194194
// 组件设置
195195
let index = this.fullData.findIndex(item => item.cptId == cptId)

0 commit comments

Comments
 (0)