Skip to content

Commit

Permalink
refactor(lock): 锁定插件重构
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaojob committed Jul 6, 2024
1 parent 5c8a5cd commit 7d78936
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
23 changes: 11 additions & 12 deletions packages/core/plugin/LayerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 秦少卫
* @Date: 2023-06-15 23:23:18
* @LastEditors: 秦少卫
* @LastEditTime: 2024-04-10 17:33:28
* @LastEditTime: 2024-07-06 18:22:46
* @Description: 图层调整插件
*/

Expand All @@ -12,7 +12,7 @@ type IEditor = Editor;

class LayerPlugin implements IPluginTempl {
static pluginName = 'LayerPlugin';
static apis = ['up', 'upTop', 'down', 'downTop'];
static apis = ['up', 'down', 'toFront', 'toBack'];
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}

_getWorkspace() {
Expand All @@ -34,28 +34,27 @@ class LayerPlugin implements IPluginTempl {
}
}

upTop() {
down() {
const actives = this.canvas.getActiveObjects();
if (actives && actives.length === 1) {
const activeObject = this.canvas.getActiveObjects()[0];
activeObject && activeObject.bringToFront();
activeObject && activeObject.sendBackwards();
this.canvas.renderAll();
console.log(this);
this._workspaceSendToBack();
}
}

down() {
toFront() {
const actives = this.canvas.getActiveObjects();
if (actives && actives.length === 1) {
const activeObject = this.canvas.getActiveObjects()[0];
activeObject && activeObject.sendBackwards();
activeObject && activeObject.bringToFront();
this.canvas.renderAll();
this._workspaceSendToBack();
}
}

downTop() {
toBack() {
const actives = this.canvas.getActiveObjects();
if (actives && actives.length === 1) {
const activeObject = this.canvas.getActiveObjects()[0];
Expand All @@ -75,22 +74,22 @@ class LayerPlugin implements IPluginTempl {
subitems: [
{
text: '上一个',
hotkey: 'key',
hotkey: '',
onclick: () => this.up(),
},
{
text: '下一个',
hotkey: 'key',
hotkey: '',
onclick: () => this.down(),
},
{
text: '置顶',
hotkey: 'key',
hotkey: '',
onclick: () => this.upTop(),
},
{
text: '置底',
hotkey: 'key',
hotkey: '',
onclick: () => this.downTop(),
},
],
Expand Down
11 changes: 2 additions & 9 deletions packages/core/plugin/LockPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
/*
* @Author: 秦少卫
* @Date: 2024-07-06 12:10:36
* @LastEditors: 秦少卫
* @LastEditTime: 2024-07-06 12:10:38
* @Description: file content
*/
/*
* @Author: 秦少卫
* @Date: 2024-07-04 14:27:05
* @LastEditors: 秦少卫
* @LastEditTime: 2024-07-04 23:06:33
* @Description: file content
* @LastEditTime: 2024-07-06 17:49:01
* @Description: 锁定文件
*/
import { fabric } from 'fabric';
import type Editor from '../Editor';
Expand Down
6 changes: 3 additions & 3 deletions src/components/layer.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: 2024-05-21 08:59:36
* @LastEditTime: 2024-07-06 17:59:51
* @Description: 图层面板
-->

Expand Down Expand Up @@ -115,13 +115,13 @@ const up = () => {
canvasEditor.up();
};
const upTop = () => {
canvasEditor.upTop();
canvasEditor.toFront();
};
const down = () => {
canvasEditor.down();
};
const downTop = () => {
canvasEditor.downTop();
canvasEditor.toBack();
};

const getList = () => {
Expand Down

0 comments on commit 7d78936

Please sign in to comment.