|
@@ -0,0 +1,165 @@
|
|
|
+import {globalStore} from "@/store";
|
|
|
+
|
|
|
+
|
|
|
+export default class EditorUtils {
|
|
|
+
|
|
|
+ public static getEditorRect() {
|
|
|
+ return globalStore().getEditor()?.getBoundingClientRect();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static getEditorMenuPos(eleTop, eleLeft): { top, left } {
|
|
|
+ const editorRect = EditorUtils.getEditorRect();
|
|
|
+ const editorMenuWidthAndHeight = EditorUtils.getEditorMenuWidthAndHeight();
|
|
|
+ console.log('editorMenuWidthAndHeight >> ', editorMenuWidthAndHeight, eleLeft)
|
|
|
+ if (editorRect) {
|
|
|
+ return {
|
|
|
+ top: eleTop - editorRect.top - editorMenuWidthAndHeight?.height ?? 0 - 1,
|
|
|
+ left: eleLeft - editorRect.left - editorMenuWidthAndHeight.width ?? 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {top: 0, left: 0}
|
|
|
+ }
|
|
|
+
|
|
|
+ public static getEditorMenuObj() {
|
|
|
+ return document.querySelector('#yvan-editor-menu')
|
|
|
+ }
|
|
|
+
|
|
|
+ public static getEditorMenuRect() {
|
|
|
+ return EditorUtils.getEditorMenuObj()?.getBoundingClientRect();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static getEditorMenuWidthAndHeight() {
|
|
|
+ const editorMenuRect = EditorUtils.getEditorMenuObj()?.getBoundingClientRect();
|
|
|
+ return {
|
|
|
+ width: editorMenuRect.right - editorMenuRect.left,
|
|
|
+ height: editorMenuRect.bottom - editorMenuRect.top
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static showEditorMenu(elementRect) {
|
|
|
+ globalStore().showEditorMenu({top: elementRect.top, left: elementRect.right})
|
|
|
+ }
|
|
|
+
|
|
|
+ public static hideEditorMenu() {
|
|
|
+ globalStore().hideEditorMenu();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static getEditorMenu() {
|
|
|
+ const currentElement = globalStore().curComponent;
|
|
|
+ if (!currentElement) {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ code: 'paste',
|
|
|
+ icon: 'fa fa-paste',
|
|
|
+ label: '粘贴',
|
|
|
+ status: 'default',
|
|
|
+ event: () => {
|
|
|
+ globalStore().paste(true)
|
|
|
+ globalStore().recordSnapshot()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ if (currentElement?.isLock) {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ code: 'unlock',
|
|
|
+ icon: 'fa fa-unlock',
|
|
|
+ label: '解锁',
|
|
|
+ status: 'default',
|
|
|
+ event: () => {
|
|
|
+ globalStore().unlock({curComponent: currentElement})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ code: 'copy',
|
|
|
+ icon: 'fa fa-copy',
|
|
|
+ label: '复制',
|
|
|
+ status: 'default',
|
|
|
+ event: () => {
|
|
|
+ globalStore().copy()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'cut',
|
|
|
+ icon: 'fa fa-cut',
|
|
|
+ label: '剪切',
|
|
|
+ status: 'default',
|
|
|
+ event: () => {
|
|
|
+ globalStore().cut()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'del',
|
|
|
+ icon: 'fa fa-trash',
|
|
|
+ label: '删除',
|
|
|
+ status: 'danger',
|
|
|
+ event: () => {
|
|
|
+ globalStore().deleteElement({
|
|
|
+ element: globalStore().curComponent,
|
|
|
+ elementIdx: globalStore().curComponentIndex
|
|
|
+ });
|
|
|
+ globalStore().recordSnapshot();
|
|
|
+ EditorUtils.hideEditorMenu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'lock',
|
|
|
+ icon: 'fa fa-lock',
|
|
|
+ label: '锁定',
|
|
|
+ status: 'default',
|
|
|
+ event: () => {
|
|
|
+ globalStore().lock({curComponent: currentElement});
|
|
|
+ EditorUtils.hideEditorMenu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // {
|
|
|
+ // code: 'top',
|
|
|
+ // icon: 'fa fa-angle-double-up',
|
|
|
+ // label: '置顶',
|
|
|
+ // status: 'default',
|
|
|
+ // event: () => {
|
|
|
+ // // this.$store.commit('printTemplateModule/topComponent')
|
|
|
+ // // this.$store.commit('printTemplateModule/recordSnapshot')
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // code: 'bottom',
|
|
|
+ // icon: 'fa fa-angle-double-down',
|
|
|
+ // label: '置底',
|
|
|
+ // status: 'default',
|
|
|
+ // event: () => {
|
|
|
+ // this.$store.commit('printTemplateModule/bottomComponent')
|
|
|
+ // this.$store.commit('printTemplateModule/recordSnapshot')
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // code: 'up',
|
|
|
+ // icon: 'fa fa-arrow-circle-up',
|
|
|
+ // label: '上移',
|
|
|
+ // status: 'default',
|
|
|
+ // event: () => {
|
|
|
+ // // this.$store.commit('printTemplateModule/upComponent')
|
|
|
+ // // this.$store.commit('printTemplateModule/recordSnapshot')
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // code: 'down',
|
|
|
+ // icon: 'fa fa-arrow-circle-down',
|
|
|
+ // label: '下移',
|
|
|
+ // status: 'default',
|
|
|
+ // event: () => {
|
|
|
+ // // this.$store.commit('printTemplateModule/downComponent')
|
|
|
+ // // this.$store.commit('printTemplateModule/recordSnapshot')
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|