|
@@ -49,6 +49,9 @@ export default {
|
|
|
computed: {
|
|
computed: {
|
|
|
isEmpty(){
|
|
isEmpty(){
|
|
|
return this.data.length === 0
|
|
return this.data.length === 0
|
|
|
|
|
+ },
|
|
|
|
|
+ this_canvas(){
|
|
|
|
|
+ return this.data[this.select]
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
@@ -64,18 +67,37 @@ export default {
|
|
|
methods: {
|
|
methods: {
|
|
|
// 初始化
|
|
// 初始化
|
|
|
async init() {
|
|
async init() {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //不存在数据
|
|
|
if(this.isEmpty ){
|
|
if(this.isEmpty ){
|
|
|
this.addCanvas()
|
|
this.addCanvas()
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //画布下不存在模板OSS地址
|
|
|
|
|
+
|
|
|
|
|
+ if(this.this_canvas.tpl_url){
|
|
|
|
|
+ console.log(this.select);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ this.$emit('canvasStyle:update',{
|
|
|
|
|
+ width: this.this_canvas.width,
|
|
|
|
|
+ height: this.this_canvas.height
|
|
|
|
|
+ })
|
|
|
|
|
+ console.log(this.this_canvas);
|
|
|
await this.viewInit()
|
|
await this.viewInit()
|
|
|
await this.$nextTick()
|
|
await this.$nextTick()
|
|
|
this.fcanvas = new fabric.Canvas('marketing-canvas', {
|
|
this.fcanvas = new fabric.Canvas('marketing-canvas', {
|
|
|
- backgroundColor:"#ffffff",
|
|
|
|
|
|
|
+ backgroundColor: this.this_canvas.bg_color,
|
|
|
containerClass:"fcanvas",
|
|
containerClass:"fcanvas",
|
|
|
// 元素对象被选中时保持在当前z轴,不会跳到最顶层
|
|
// 元素对象被选中时保持在当前z轴,不会跳到最顶层
|
|
|
preserveObjectStacking:true,
|
|
preserveObjectStacking:true,
|
|
|
- width: this.canvasStyle.width,
|
|
|
|
|
- height: this.canvasStyle.height
|
|
|
|
|
|
|
+ width: this.this_canvas.width,
|
|
|
|
|
+ height: this.this_canvas.height
|
|
|
})
|
|
})
|
|
|
//保留最初的状态
|
|
//保留最初的状态
|
|
|
this.updateCanvasState()
|
|
this.updateCanvasState()
|
|
@@ -89,43 +111,57 @@ export default {
|
|
|
addCanvas(){
|
|
addCanvas(){
|
|
|
|
|
|
|
|
this.canvasForm.type = 'add'
|
|
this.canvasForm.type = 'add'
|
|
|
- this.canvasForm.name = '画布_'+new Date().getTime()
|
|
|
|
|
|
|
+ this.canvasForm.name = '画布_'+new Date().getTime().toString().substr(8)+Math.round(100)
|
|
|
this.canvasForm.width = 1024
|
|
this.canvasForm.width = 1024
|
|
|
this.canvasForm.height = 1024
|
|
this.canvasForm.height = 1024
|
|
|
- this.canvasForm.color = '#fff'
|
|
|
|
|
|
|
+ this.canvasForm.bg_color = '#fff'
|
|
|
this.canvasForm.visible = true;
|
|
this.canvasForm.visible = true;
|
|
|
},
|
|
},
|
|
|
handleAdjustCanvas() {
|
|
handleAdjustCanvas() {
|
|
|
this.canvasForm.type = 'edit'
|
|
this.canvasForm.type = 'edit'
|
|
|
- this.canvasForm.name = this.canvas.name
|
|
|
|
|
- this.canvasForm.width = this.canvas.width
|
|
|
|
|
- this.canvasForm.height = this.canvas.height
|
|
|
|
|
- this.canvasForm.color = this.canvas.color
|
|
|
|
|
|
|
+ this.canvasForm.name = this.this_canvas.name
|
|
|
|
|
+ this.canvasForm.width = this.this_canvas.width
|
|
|
|
|
+ this.canvasForm.height = this.this_canvas.height
|
|
|
|
|
+ this.canvasForm.bg_color = this.this_canvas.bg_color
|
|
|
this.canvasForm.visible = true;
|
|
this.canvasForm.visible = true;
|
|
|
},
|
|
},
|
|
|
submitCanvasInfo() {
|
|
submitCanvasInfo() {
|
|
|
// 假设 this.canvasForm 包含最新的 width, height 和 color
|
|
// 假设 this.canvasForm 包含最新的 width, height 和 color
|
|
|
|
|
|
|
|
- if(this.canvasForm)
|
|
|
|
|
|
|
+ if(this.canvasForm.type === 'add'){
|
|
|
|
|
+ this.data.push({
|
|
|
|
|
+ tpl_url:"",
|
|
|
|
|
+ image_path:"",
|
|
|
|
|
+ name:this.canvasForm.name,
|
|
|
|
|
+ width:this.canvasForm.width,
|
|
|
|
|
+ height:this.canvasForm.height,
|
|
|
|
|
+ bg_color:this.canvasForm.bg_color,
|
|
|
|
|
+ })
|
|
|
|
|
+ this.$emit('select:update',this.data.length - 1)
|
|
|
|
|
+/* this.select = this.data.length - 1*/
|
|
|
|
|
+ this.canvasForm.visible = false;
|
|
|
|
|
+ this.init();
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- this.canvas.name = this.canvasForm.name;
|
|
|
|
|
- this.canvas.width = this.canvasForm.width;
|
|
|
|
|
- this.canvas.height = this.canvasForm.height;
|
|
|
|
|
- this.canvas.color = this.canvasForm.color;
|
|
|
|
|
- const newWidth = this.canvasForm.width;
|
|
|
|
|
- const newHeight = this.canvasForm.height;
|
|
|
|
|
- const newColor = this.canvasForm.color;
|
|
|
|
|
|
|
+ const newWidth = this.canvasForm.width;
|
|
|
|
|
+ const newHeight = this.canvasForm.height;
|
|
|
|
|
+ const newColor = this.canvasForm.color;
|
|
|
|
|
|
|
|
- // 更新 fcanvas 的宽度和高度
|
|
|
|
|
- this.fcanvas.setWidth(newWidth);
|
|
|
|
|
- this.fcanvas.setHeight(newHeight);
|
|
|
|
|
|
|
+ // 更新 fcanvas 的宽度和高度
|
|
|
|
|
+ if(newWidth !== this.this_canvas.width)this.fcanvas.setWidth(newWidth);
|
|
|
|
|
+ if(newHeight !== this.this_canvas.height)this.fcanvas.setHeight(newHeight);
|
|
|
|
|
+ if(newColor !== this.this_canvas.bg_color)this.fcanvas.setBackgroundColor(newColor);
|
|
|
|
|
|
|
|
- // 更新 fcanvas 的背景颜色
|
|
|
|
|
- this.fcanvas.setBackgroundColor(newColor);
|
|
|
|
|
|
|
+ this.data[this.select].name = this.canvasForm.name
|
|
|
|
|
+ this.data[this.select].width = this.canvasForm.width
|
|
|
|
|
+ this.data[this.select].height = this.canvasForm.height
|
|
|
|
|
+ this.data[this.select].bg_color = this.canvasForm.bg_color
|
|
|
|
|
+ // 重新渲染以应用更改
|
|
|
|
|
+ this.fcanvas.renderAll();
|
|
|
|
|
+ this.canvasForm.visible = false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 重新渲染以应用更改
|
|
|
|
|
- this.fcanvas.renderAll();
|
|
|
|
|
- this.canvasForm.visible = false;
|
|
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
resizeCanvas(width, height) {
|
|
resizeCanvas(width, height) {
|