Skip to content

Commit

Permalink
fix(画布): 画布尺寸修改
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaojob committed Feb 20, 2024
1 parent f192033 commit 2596883
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/components/setSize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 秦少卫
* @Date: 2022-09-03 19:16:55
* @LastEditors: 秦少卫
* @LastEditTime: 2023-11-19 15:58:59
* @LastEditTime: 2024-02-20 13:11:30
* @Description: 尺寸设置
-->

Expand Down Expand Up @@ -100,9 +100,9 @@ let presetSize = reactive([

onMounted(() => {
canvasEditor.setSize(width.value, height.value);
canvasEditor.on('sizeChange', (width, height) => {
width.value = width;
height.value = height;
canvasEditor.on('sizeChange', (w, h) => {
width.value = w;
height.value = h;
});

// canvas.editor.editorWorkspace.setSize(width.value, height.value);
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ServersPlugin from './ServersPlugin';
import { AsyncSeriesHook } from 'tapable';

class Editor extends EventEmitter {
canvas: fabric.Canvas | undefined;
canvas!: fabric.Canvas;
contextMenu: any;
private pluginMap: {
[propName: string]: IPluginTempl;
Expand Down
7 changes: 4 additions & 3 deletions src/core/plugin/WorkspacePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 秦少卫
* @Date: 2023-06-27 12:26:41
* @LastEditors: 秦少卫
* @LastEditTime: 2024-02-20 12:54:10
* @LastEditTime: 2024-02-20 13:04:10
* @Description: 画布区域插件
*/

Expand All @@ -17,12 +17,13 @@ class WorkspacePlugin {
static pluginName = 'WorkspacePlugin';
static events = ['sizeChange'];
static apis = ['big', 'small', 'auto', 'one', 'setSize'];
workspaceEl: HTMLElement;
workspaceEl!: HTMLElement;
workspace: null | fabric.Rect;
option: any;
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
this.workspace = null;
this.init({
width: 900,
height: 2000,
Expand Down Expand Up @@ -115,7 +116,7 @@ class WorkspacePlugin {
resizeObserver.observe(this.workspaceEl);
}

setSize(width: number, height: number) {
setSize(width: number | undefined, height: number) {
this._initBackground();
this.option.width = width;
this.option.height = height;
Expand Down
1 change: 1 addition & 0 deletions typings/extends.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare namespace fabric {
export interface Canvas {
contextTop: CanvasRenderingContext2D;
lowerCanvasEl: HTMLElement;
wrapperEl: HTMLElement;
_currentTransform: unknown;
_centerObject: (obj: fabric.Object, center: fabric.Point) => fabric.Canvas;
}
Expand Down

0 comments on commit 2596883

Please sign in to comment.