|
|
@@ -10,8 +10,10 @@ import colorMixins from '@/views/components/PictureEditor/mixin/color/index'
|
|
|
import editMixins from '@/views/components/PictureEditor/mixin/edit/index'
|
|
|
import { uploadBaseImg } from '@/apis/other'
|
|
|
import {markRaw} from "vue";
|
|
|
+import goods from './goods.json'
|
|
|
+import canvas from './canvas.json'
|
|
|
|
|
|
-const FIXED_CANVAS_WIDTH = 800
|
|
|
+const FIXED_CANVAS_WIDTH = 395
|
|
|
export default {
|
|
|
name: 'marketingImageEditor',
|
|
|
mixins: [ viewMixins,actionsMixins,layerMixins,colorMixins,editMixins],
|
|
|
@@ -88,7 +90,6 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
- console.log(this.$route?.params?.id);
|
|
|
if(this.$route?.name === 'editTpl'){
|
|
|
this.loadTemplate()
|
|
|
}
|
|
|
@@ -101,31 +102,7 @@ export default {
|
|
|
methods: {
|
|
|
loadTemplate(){
|
|
|
if(this.hasLoadedTpl) return
|
|
|
- const tpl = [
|
|
|
- {
|
|
|
- index: 0,
|
|
|
- preview: "https://ossimg.valimart.net/uploads/20251202/176466246730872.png",
|
|
|
- canvas_json: "{\"version\":\"5.2.1\",\"objects\":[{\"type\":\"image\",\"version\":\"5.2.1\",\"originX\":\"left\",\"originY\":\"top\",\"left\":125.14,\"top\":128.86,\"width\":960,\"height\":1280,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.17,\"scaleY\":0.17,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"erasable\":false,\"cropX\":0,\"cropY\":0,\"name\":\"image\",\"sort\":10,\"id\":\"1764662402644_1793_1\",\"selectable\":true,\"data-key\":\"俯视\",\"data-value\":\"https://ossimg.valimart.net/uploads/vali_ai/20250613/174979820315694.png\",\"src\":\"https://ossimg.valimart.net/uploads/vali_ai/20250613/174979820315694.png\",\"crossOrigin\":\"anonymous\",\"filters\":[]}],\"background\":\"#fff\"}",
|
|
|
- width: 800,
|
|
|
- height: 500,
|
|
|
- bg_color: "#fff",
|
|
|
- name: "画布_95086100",
|
|
|
- tpl_url: "",
|
|
|
- image_path: ""
|
|
|
- },
|
|
|
- {
|
|
|
- index: 1,
|
|
|
- preview: "https://ossimg.valimart.net/uploads/20251202/176466246756126.png",
|
|
|
- canvas_json: "{\"version\":\"5.2.1\",\"objects\":[{\"type\":\"image\",\"version\":\"5.2.1\",\"originX\":\"left\",\"originY\":\"top\",\"left\":476,\"top\":16,\"width\":960,\"height\":1280,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.13,\"scaleY\":0.13,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"erasable\":false,\"cropX\":0,\"cropY\":0,\"name\":\"image\",\"sort\":10,\"id\":\"1764662460778_4314_2\",\"selectable\":true,\"data-key\":\"侧视\",\"data-value\":\"https://ossimg.valimart.net/uploads/vali_ai/20250613/174979823853439.png\",\"src\":\"https://ossimg.valimart.net/uploads/vali_ai/20250613/174979823853439.png\",\"crossOrigin\":\"anonymous\",\"filters\":[]}],\"background\":\"#fff\"}",
|
|
|
- width: 800,
|
|
|
- height: 200,
|
|
|
- bg_color: "#fff",
|
|
|
- name: "画布_07492100",
|
|
|
- tpl_url: "",
|
|
|
- image_path: ""
|
|
|
- }
|
|
|
- ]
|
|
|
- this.data.splice(0, this.data.length, ...tpl)
|
|
|
+ this.data.splice(0, this.data.length, ...JSON.parse(JSON.stringify(canvas)))
|
|
|
this.$emit('update:index', 0)
|
|
|
this.hasLoadedTpl = true
|
|
|
},
|
|
|
@@ -293,21 +270,52 @@ export default {
|
|
|
|
|
|
|
|
|
const newWidth = FIXED_CANVAS_WIDTH;
|
|
|
- const newHeight = this.canvasForm.height;
|
|
|
+ const newHeight = Number(this.canvasForm.height) || this.this_canvas.height;
|
|
|
+ const oldHeight = Number(this.this_canvas.height) || 0;
|
|
|
const newColor = this.canvasForm.bg_color;
|
|
|
|
|
|
// 更新 fcanvas 的宽度和高度
|
|
|
if(this.fcanvas){
|
|
|
- if(newWidth !== this.this_canvas.width)this.fcanvas.setWidth(newWidth);
|
|
|
- if(newHeight !== this.this_canvas.height)this.fcanvas.setHeight(newHeight);
|
|
|
+ // 更新画布尺寸
|
|
|
+ // 注意:Fabric.js 中对象的坐标是相对于画布左上角的,所以当画布高度变化时
|
|
|
+ // 对象的 top 值会自动保持相对于顶部的距离不变,实现从底部扩展/收缩的效果
|
|
|
+
|
|
|
+
|
|
|
+ if(newWidth !== this.this_canvas.width || newHeight !== oldHeight){
|
|
|
+ this.fcanvas.setDimensions({ width: newWidth, height: newHeight });
|
|
|
+ }
|
|
|
+ /* if(newHeight !== oldHeight){
|
|
|
+ this.fcanvas.setHeight(newHeight);
|
|
|
+ // 高度变小:检查是否有对象超出新高度
|
|
|
+ if(newHeight < oldHeight){
|
|
|
+ const objects = this.fcanvas.getObjects();
|
|
|
+ const outOfBounds = objects.filter(obj => {
|
|
|
+ const objBottom = obj.top + (obj.height * obj.scaleY || 0);
|
|
|
+ return objBottom > newHeight;
|
|
|
+ });
|
|
|
+ if(outOfBounds.length > 0){
|
|
|
+ this.$message.warning(`有 ${outOfBounds.length} 个对象超出新画布高度,请手动调整位置`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
if(newColor !== this.this_canvas.bg_color)this.fcanvas.setBackgroundColor(newColor);
|
|
|
+ let objects = this.fcanvas.getObjects();
|
|
|
+
|
|
|
+ objects.forEach(function(object) {
|
|
|
+ // 调整对象的位置
|
|
|
+ object.left = object.left;
|
|
|
+ object.top = object.top ;
|
|
|
+ object.controls = fabric.Object.prototype.controls
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
// 重新渲染以应用更改
|
|
|
- this.fcanvas.renderAll();
|
|
|
+ this.fcanvas.requestRenderAll();
|
|
|
}
|
|
|
|
|
|
this.data[this.index].name = this.canvasForm.name
|
|
|
this.data[this.index].width = FIXED_CANVAS_WIDTH
|
|
|
- this.data[this.index].height = this.canvasForm.height
|
|
|
+ this.data[this.index].height = newHeight
|
|
|
this.data[this.index].bg_color = this.canvasForm.bg_color
|
|
|
this.data[this.index].multi_goods_mode = this.canvasForm.multi_goods_mode || ''
|
|
|
this.canvasForm.visible = false;
|
|
|
@@ -404,6 +412,11 @@ export default {
|
|
|
}
|
|
|
}))
|
|
|
this.$emit('save', payload)
|
|
|
+ return payload;
|
|
|
+ },
|
|
|
+ async createImg(){
|
|
|
+ let canvas_json = JSON.parse(JSON.stringify(canvas))
|
|
|
+ let goodsData = JSON.parse(JSON.stringify(goods))
|
|
|
},
|
|
|
saveCanvasSnapshot(targetIndex){
|
|
|
const snapshotIndex = typeof targetIndex === 'number' ? targetIndex : this.index
|