|
@@ -1,9 +1,12 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, onUnmounted, reactive } from "vue";
|
|
|
-import { Meta2d, Options } from "@meta2d/core";
|
|
|
+import { onMounted, onUnmounted, reactive, ref } from "vue";
|
|
|
+import { HoverType, Meta2d, Options, Pen } from "@meta2d/core";
|
|
|
import ContextMenu from "../components/ContextMenu.vue";
|
|
|
import SvgIcon from "../components/SvgIcon.vue";
|
|
|
import { registerAreaPens } from "./pens/register";
|
|
|
+import { useSelection } from '@/services/selections';
|
|
|
+
|
|
|
+const { select } = useSelection();
|
|
|
|
|
|
const meta2dOptions: Options = {
|
|
|
x: 0,
|
|
@@ -13,24 +16,96 @@ const meta2dOptions: Options = {
|
|
|
background: "#F5F7FA",
|
|
|
shadowBlur: 0,
|
|
|
disableAnchor: true,
|
|
|
+ disableScale: true,
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
new Meta2d("env-area-meta2d", meta2dOptions);
|
|
|
meta2d.lock(0)
|
|
|
+ meta2d.on('active', active);
|
|
|
+ meta2d.on('inactive', inactive);
|
|
|
+ meta2d.on('contextmenu', onContextmenu);
|
|
|
+ meta2d.on('click', canvasClick);
|
|
|
registerAreaPens()
|
|
|
});
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
+ meta2d.off('active', active);
|
|
|
+ meta2d.off('inactive', inactive);
|
|
|
+ meta2d.off('contextmenu', onContextmenu);
|
|
|
+ meta2d.off('click', canvasClick);
|
|
|
meta2d?.destroy();
|
|
|
});
|
|
|
|
|
|
+const inactive = () => {
|
|
|
+ if(fitFlag.value){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ select();
|
|
|
+};
|
|
|
+
|
|
|
+const active = (pens: Pen[]) => {
|
|
|
+ if(fitFlag.value){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ select(pens);
|
|
|
+
|
|
|
+ //格式刷处理
|
|
|
+ if (one.value || always.value) {
|
|
|
+ meta2d.formatPainter();
|
|
|
+ one.value = false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const fitFlag = ref(false);
|
|
|
+const one = ref(false);
|
|
|
+const always = ref(false);
|
|
|
+
|
|
|
const contextmenu = reactive({
|
|
|
visible: false,
|
|
|
type: "",
|
|
|
style: {},
|
|
|
});
|
|
|
|
|
|
+const onContextmenu = ({ e, rect }: { e: any; rect: any }) => {
|
|
|
+ contextmenu.type = '';
|
|
|
+ contextmenu.style = {
|
|
|
+ left: e.clientX + 'px',
|
|
|
+ top: e.clientY + 'px',
|
|
|
+ };
|
|
|
+
|
|
|
+ if (
|
|
|
+ meta2d.store.hoverAnchor &&
|
|
|
+ meta2d.canvas.hoverType === HoverType.LineAnchor
|
|
|
+ ) {
|
|
|
+ contextmenu.type = 'anchor';
|
|
|
+ if (document.body.clientHeight - e.clientY < 128) {
|
|
|
+ contextmenu.style = {
|
|
|
+ left: e.clientX + 'px',
|
|
|
+ bottom: '4px',
|
|
|
+ };
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ contextmenu.type = 'pen';
|
|
|
+ if (document.body.clientHeight - e.clientY < 450) {
|
|
|
+ contextmenu.style = {
|
|
|
+ left: e.clientX + 'px',
|
|
|
+ bottom: '4px',
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (contextmenu.type) {
|
|
|
+ contextmenu.visible = true;
|
|
|
+ } else {
|
|
|
+ contextmenu.visible = false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const canvasClick = () => {
|
|
|
+ contextmenu.visible = false;
|
|
|
+};
|
|
|
+
|
|
|
const changeContextMenuVisible = (e: boolean) => {
|
|
|
contextmenu.visible = e;
|
|
|
};
|
|
@@ -81,6 +156,7 @@ const handleCancel = () => {
|
|
|
v-if="contextmenu.visible"
|
|
|
:type="contextmenu.type"
|
|
|
:style="contextmenu.style"
|
|
|
+ isEnvAreaUsed
|
|
|
@changeVisible="changeContextMenuVisible"
|
|
|
></ContextMenu>
|
|
|
</div>
|