Files
aida_front/src/component/modules/generalMiniCanvas.vue

142 lines
3.0 KiB
Vue
Raw Normal View History

<template>
2025-06-19 09:21:32 +08:00
<div class="generalCanvas">
<div class="canvasBox" ref="canvasBox">
<editCanvas v-if="canvasLoad" :config="canvasConfig" :clothingImageUrl="imgUrl" ref="editCanvas"></editCanvas>
</div>
2025-06-19 09:21:32 +08:00
<div class="mark_loading" v-show="isShowMark">
<a-spin size="large" />
</div>
</div>
</template>
<script>
2025-06-19 09:21:32 +08:00
import {defineComponent, toRefs, provide, h, ref, nextTick, onBeforeUnmount, reactive, onMounted,
} from "vue";
import {message} from 'ant-design-vue'
import { Https } from "@/tool/https";
import { useStore } from "vuex";
import { useI18n } from "vue-i18n";
2025-06-19 09:21:32 +08:00
import canvasGeneral from "@/tool/canvasGeneralCopy";
import editCanvas from "@/component/Canvas/CanvasEditor/index.vue";
export default defineComponent({
components: {
2025-06-19 09:21:32 +08:00
editCanvas,
},
2025-06-19 09:21:32 +08:00
props:{
imgUrl:{
type:String,
default:''
}
},
2025-06-19 09:21:32 +08:00
emits:['submitBase64Data'],
setup(props,{emit}) {
2025-06-19 09:21:32 +08:00
const { t } = useI18n();
const store = useStore();
const isShowMark = ref(false)
const component = reactive({
})
2025-06-19 09:21:32 +08:00
const data = reactive({
canvasLoad:false,
canvasConfig:{
2024-10-10 11:32:49 +08:00
},
})
2025-06-19 09:21:32 +08:00
const dataDom = reactive({
editCanvas:null,
canvasBox:null,
})
2025-06-19 09:21:32 +08:00
const openSetData = ()=>{
data.canvasLoad = true
2024-10-14 16:08:24 +08:00
}
2025-06-19 09:21:32 +08:00
const addImage = (value)=>{
console.log(value)
dataDom.editCanvas.addImageToLayer(value.imgUrl)
2024-10-14 16:08:24 +08:00
}
2025-06-19 09:21:32 +08:00
const addBottomImage = (value)=>{
dataDom.editCanvas.changeFixedImage(value)
2024-10-14 16:08:24 +08:00
}
2025-06-19 09:21:32 +08:00
const getData = async ()=>{
}
2025-06-19 09:21:32 +08:00
const getCanvasData = ()=>{
2024-10-14 16:08:24 +08:00
2025-06-19 09:21:32 +08:00
return canvasExport
}
onMounted(() => {
if(props.imgUrl){
let img = new Image()
img.onload = ()=>{
let domHeight = dataDom.canvasBox.offsetHeight
let imgHeight = img.height
data.canvasConfig.height = domHeight
data.canvasConfig.width = imgHeight/domHeight * img.width
// canvasWH.value = height
// // canvasBox.style.width = height+'px'
// let wScale = 1
// let hScale = 1
// if(img.width>img.height){
// hScale = img.height/img.width
// exportWH = img.width
// }else{
// wScale = img.width/img.height
// exportWH = img.height
// }
// ratio = [wScale,hScale]
// canvas = canvasGeneral.canvasInit(canvasBox,{
// width:canvasWH.value * wScale,
// height:canvasWH.value * hScale,
// })
// canvas.selection = false;
// dataDom.editCanvas.addImageToLayer(img)
data.canvasLoad = true
2024-10-14 16:08:24 +08:00
}
2025-06-19 09:21:32 +08:00
img.src = props.imgUrl
2024-10-10 11:32:49 +08:00
}else{
2025-06-19 09:21:32 +08:00
data.canvasLoad = true
2024-10-03 14:16:23 +08:00
}
2025-06-19 09:21:32 +08:00
});
onBeforeUnmount(()=>{
data.canvasLoad = false
// canvasGeneral.canvasClear()
})
return {
2025-06-19 09:21:32 +08:00
...toRefs(data),
...toRefs(dataDom),
isShowMark,
addImage,
getData,
getCanvasData,
};
},
2025-06-19 09:21:32 +08:00
data(prop) {
return {
2025-06-19 09:21:32 +08:00
};
},
computed: {
},
watch: {
},
mounted() {},
2025-06-19 09:21:32 +08:00
methods: {
2025-06-19 09:21:32 +08:00
},
});
</script>
2025-06-19 09:21:32 +08:00
<style lang="less" scoped>
.generalCanvas{
width: 100%;
height: 100%;
2025-06-19 09:21:32 +08:00
position: relative;
display: flex;
2025-06-19 09:21:32 +08:00
flex-direction: column;
2024-10-10 11:32:49 +08:00
overflow: hidden;
2025-06-19 09:21:32 +08:00
padding-top: 4rem;
> .canvasBox{
flex: 1;
position: relative;
}
}
</style>