diff --git a/src/assets/iconfont2/demo_index.html b/src/assets/iconfont2/demo_index.html index 4b8dda54..86fd4fdc 100644 --- a/src/assets/iconfont2/demo_index.html +++ b/src/assets/iconfont2/demo_index.html @@ -54,6 +54,12 @@
@@ -82,6 +88,7 @@ import { useI18n } from "vue-i18n"; import { ToolCommand } from "../commands/ToolCommands"; import { OperationType } from "../utils/layerHelper"; + import { loadImageUrlToLayer } from "../utils/imageHelper"; import { TransformCommand } from "../commands/StateCommands"; const props = defineProps({ canvas: { @@ -262,6 +269,21 @@ finalState.flipY = !finalState.flipY; transformObject(obj, initialState, finalState); }; + // 裁剪图片 + const cropImage = inject("cropImage"); + const clickCropImage = async (obj) => { + const base64 = await props.layerManager.getLayerToBase64(obj.layerId); + if(base64) cropImage(base64).then((res) => { + loadImageUrlToLayer({ + imageUrl: res, + layerManager: props.layerManager, + canvas: props.canvas, + toolManager: props.toolManager, + }).then(res=>{ + console.log("========",res); + }); + }); + }; const updateActiveObjects = (arrs, keys) => { arrs.forEach((v) => { diff --git a/src/component/Canvas/CanvasEditor/index.vue b/src/component/Canvas/CanvasEditor/index.vue index 33ccd3f1..31c01762 100644 --- a/src/component/Canvas/CanvasEditor/index.vue +++ b/src/component/Canvas/CanvasEditor/index.vue @@ -23,6 +23,7 @@ import { BrushStore } from "./store/BrushStore"; import cuowuImg from "@/assets/images/homePage/cuowu.svg"; import { Https } from "@/tool/https"; import SelectImages from "@/component/common/SelectImages.vue"; +import CropImage from "./components/CropImage.vue"; import { UrlToFile } from "@/tool/util"; // import { MinimapManager } from "./managers/minimap/MinimapManager"; @@ -907,6 +908,12 @@ const changeCanvas = async (command) => { } }; +const cropImageRef = ref(null); +const cropImage = (url) => { + return cropImageRef.value.open(url) +}; +provide("cropImage", cropImage); // 提供给子组件使用 + // 提供外部ref实例方法 defineExpose({ layers, // 图层数据 @@ -1249,6 +1256,9 @@ defineExpose({ /> + + +