|
|
@@ -17,6 +17,19 @@ export default {
|
|
|
y:0,
|
|
|
vague:0,
|
|
|
color:'#000',
|
|
|
+ },
|
|
|
+
|
|
|
+ clipSettings: {
|
|
|
+ shape: 'rect', // 形状类型
|
|
|
+ width: 100, // 矩形宽度
|
|
|
+ height: 100, // 矩形高度
|
|
|
+ radius: 50, // 圆形半径
|
|
|
+ offsetX: 0, // 水平偏移
|
|
|
+ offsetY: 0, // 垂直偏移
|
|
|
+ showClipStroke: true, // 是否显示描边
|
|
|
+ strokeColor: '#000000', // 描边颜色
|
|
|
+ strokeWidth: 2, // 描边宽度
|
|
|
+ rectRadius: 0 // 矩形圆角
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
@@ -234,6 +247,107 @@ export default {
|
|
|
this.options = this.TextboxConfig.fontFamily
|
|
|
}
|
|
|
},
|
|
|
+ applyClipPath() {
|
|
|
+ if (!this.judge()) return;
|
|
|
+
|
|
|
+ const { shape, width, height, radius, offsetX, offsetY, rectRadius } = this.clipSettings;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 创建纯剪裁区域(不带描边)
|
|
|
+ let clipObj;
|
|
|
+ if (shape === 'rect') {
|
|
|
+ if (width <= 0 || height <= 0) throw new Error('尺寸必须大于0');
|
|
|
+
|
|
|
+ clipObj = new fabric.Rect({
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ left: offsetX,
|
|
|
+ top: offsetY,
|
|
|
+ rx: rectRadius,
|
|
|
+ ry: rectRadius,
|
|
|
+ absolutePositioned: true
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ if (radius <= 0) throw new Error('半径必须大于0');
|
|
|
+
|
|
|
+ clipObj = new fabric.Circle({
|
|
|
+ radius: radius,
|
|
|
+ left: offsetX,
|
|
|
+ top: offsetY,
|
|
|
+ absolutePositioned: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用剪裁区域
|
|
|
+ this.editLayer.set({ clipPath: clipObj });
|
|
|
+
|
|
|
+ // 更新画布
|
|
|
+ this.updateClipStroke()
|
|
|
+ this.updateCanvasState();
|
|
|
+ this.fcanvas.requestRenderAll();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('剪裁区域创建失败:', error);
|
|
|
+ this.$message.error('剪裁设置错误: ' + error.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ updateClipStroke() {
|
|
|
+ if (!this.judge() || !this.clipSettings.showClipStroke) return;
|
|
|
+
|
|
|
+ const { shape, width, height, radius, offsetX, offsetY,
|
|
|
+ strokeColor, strokeWidth, rectRadius } = this.clipSettings;
|
|
|
+
|
|
|
+ // 移除旧的描边图形
|
|
|
+ this.removeClipStroke();
|
|
|
+
|
|
|
+ // 创建新的描边图形
|
|
|
+ let strokeObj;
|
|
|
+ if (shape === 'rect') {
|
|
|
+ strokeObj = new fabric.Rect({
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ left: offsetX,
|
|
|
+ top: offsetY,
|
|
|
+ rx: rectRadius,
|
|
|
+ ry: rectRadius,
|
|
|
+ stroke: strokeColor,
|
|
|
+ strokeWidth: strokeWidth,
|
|
|
+ fill: null,
|
|
|
+ selectable: false,
|
|
|
+ evented: false
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ strokeObj = new fabric.Circle({
|
|
|
+ radius: radius,
|
|
|
+ left: offsetX,
|
|
|
+ top: offsetY,
|
|
|
+ stroke: strokeColor,
|
|
|
+ strokeWidth: strokeWidth,
|
|
|
+ fill: null,
|
|
|
+ selectable: false,
|
|
|
+ evented: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加到画布
|
|
|
+ this.fcanvas.add(strokeObj);
|
|
|
+ this.clipStrokeObject = strokeObj;
|
|
|
+ this.fcanvas.requestRenderAll();
|
|
|
+ },
|
|
|
+ removeClipStroke() {
|
|
|
+ if (this.clipStrokeObject) {
|
|
|
+ this.fcanvas.remove(this.clipStrokeObject);
|
|
|
+ this.clipStrokeObject = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ clearClipPath() {
|
|
|
+ if (!this.judge()) return;
|
|
|
+
|
|
|
+ this.editLayer.set({ clipPath: null });
|
|
|
+ this.updateCanvasState();
|
|
|
+ this.fcanvas.requestRenderAll();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|