Files
aida_front/src/component/Canvas/index.vue

84 lines
1.9 KiB
Vue
Raw Normal View History

2024-11-22 09:20:25 +08:00
<template>
2025-06-09 10:25:54 +08:00
<div class="red-green-mode-example">
<!-- 画布编辑器 - 永久启用红绿图模式 -->
<div class="canvas-wrapper">
<div class="canvas-wrapper-btns">
<div @click="getJSON">获取JSON</div>
<div @click="loadJSON">读取JSON</div>
</div>
<CanvasEditor
ref="canvasEditor"
:enabledRedGreenMode="false"
:clothingImageUrl="imageUrls.baseImage"
:redGreenImageUrl="imageUrls.maskImage"
/>
</div>
</div>
2024-11-22 09:20:25 +08:00
</template>
2025-06-09 10:25:54 +08:00
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import CanvasEditor from "./CanvasEditor/index.vue";
2024-11-22 09:20:25 +08:00
2025-06-09 10:25:54 +08:00
// 画布编辑器引用
const canvasEditor = ref(null);
2025-04-16 10:43:54 +08:00
2025-06-09 10:25:54 +08:00
// 图像URL配置
const imageUrls = {
baseImage: "@/assets/redGreenPic/clothing_base_image.png",
maskImage: "@/assets/redGreenPic/clothing_mask_image.png",
};
const getJSON = () => {
if (canvasEditor.value) {
const json = canvasEditor.value.getJSON();
console.log("获取的JSON数据", json);
localStorage.setItem("redGreenModeJSON", json);
}
};
2024-11-22 09:20:25 +08:00
2025-06-09 10:25:54 +08:00
const loadJSON = () => {
if (canvasEditor.value) {
const currentJSON = localStorage.getItem("redGreenModeJSON");
canvasEditor.value.loadJSON(currentJSON);
console.log("加载的JSON数据", currentJSON);
}
};
2025-04-09 14:09:19 +08:00
2025-06-09 10:25:54 +08:00
// 组件挂载时绑定键盘事件
onMounted(() => {});
2025-04-01 15:25:15 +08:00
2025-06-09 10:25:54 +08:00
// 组件卸载时移除键盘事件
onUnmounted(() => {});
2024-11-22 09:20:25 +08:00
</script>
2025-06-09 10:25:54 +08:00
<style scoped lang="less">
.red-green-mode-example {
width: 100%;
// height: 100vh;
2024-11-22 09:20:25 +08:00
height: 100%;
2025-06-09 10:25:54 +08:00
display: flex;
flex-direction: column;
}
.canvas-wrapper {
flex: 1;
position: relative;
}
.canvas-wrapper-btns {
position: fixed;
top: 0;
right: 150px;
z-index: 1000;
display: flex;
gap: 20px;
& > div {
cursor: pointer;
padding: 10px 20px;
background-color: #f0f0f0;
border-radius: 5px;
transition: background-color 0.3s;
}
2024-11-22 09:20:25 +08:00
}
2025-06-09 10:25:54 +08:00
</style>