2024-09-25 11:07:49 +08:00
|
|
|
<template>
|
2025-06-19 09:21:32 +08:00
|
|
|
<div class="generalCanvas">
|
|
|
|
|
<div class="canvasBox" ref="canvasBox">
|
2025-06-23 09:27:29 +08:00
|
|
|
<editCanvas v-if="canvasLoad" :config="canvasConfig"
|
|
|
|
|
:clothingImageUrl="imgUrl"
|
|
|
|
|
:clothing-image-opts="{
|
|
|
|
|
imageMode:'contains',
|
|
|
|
|
}"
|
|
|
|
|
ref="editCanvas"></editCanvas>
|
2024-09-25 11:07:49 +08:00
|
|
|
</div>
|
2025-06-23 09:27:29 +08:00
|
|
|
<div class="gallery_btn" @click="canvasSave" style="width: min-content;margin: 0 auto;">Save</div>
|
2025-06-19 09:21:32 +08:00
|
|
|
<div class="mark_loading" v-show="isShowMark">
|
|
|
|
|
<a-spin size="large" />
|
2024-09-25 11:07:49 +08:00
|
|
|
</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";
|
2024-09-25 11:07:49 +08:00
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
|
2024-09-25 11:07:49 +08:00
|
|
|
export default defineComponent({
|
|
|
|
|
components: {
|
2025-06-19 09:21:32 +08:00
|
|
|
editCanvas,
|
2024-09-25 11:07:49 +08:00
|
|
|
},
|
2025-06-19 09:21:32 +08:00
|
|
|
props:{
|
|
|
|
|
imgUrl:{
|
|
|
|
|
type:String,
|
|
|
|
|
default:''
|
|
|
|
|
}
|
2024-09-25 11:07:49 +08:00
|
|
|
},
|
2025-06-19 09:21:32 +08:00
|
|
|
emits:['submitBase64Data'],
|
2024-09-25 11:07:49 +08:00
|
|
|
setup(props,{emit}) {
|
2025-06-19 09:21:32 +08:00
|
|
|
const { t } = useI18n();
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const isShowMark = ref(false)
|
|
|
|
|
const component = reactive({
|
2024-09-25 11:07:49 +08:00
|
|
|
})
|
2025-06-19 09:21:32 +08:00
|
|
|
const data = reactive({
|
|
|
|
|
canvasLoad:false,
|
|
|
|
|
canvasConfig:{
|
|
|
|
|
|
2024-10-10 11:32:49 +08:00
|
|
|
},
|
2024-09-25 11:07:49 +08:00
|
|
|
})
|
2025-06-19 09:21:32 +08:00
|
|
|
const dataDom = reactive({
|
|
|
|
|
editCanvas:null,
|
|
|
|
|
canvasBox:null,
|
2024-09-25 11:07:49 +08:00
|
|
|
})
|
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 ()=>{
|
|
|
|
|
|
2024-09-25 11:07:49 +08:00
|
|
|
}
|
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
|
|
|
|
|
}
|
2025-06-23 09:27:29 +08:00
|
|
|
const canvasSave = ()=>{
|
|
|
|
|
dataDom.editCanvas.exportImage({isContainBg:false,isContainFixed:true}).then((rv)=>{
|
|
|
|
|
emit('submitBase64Data',rv)
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-06-19 09:21:32 +08:00
|
|
|
onMounted(() => {
|
|
|
|
|
if(props.imgUrl){
|
|
|
|
|
let img = new Image()
|
|
|
|
|
img.onload = ()=>{
|
2025-06-23 09:27:29 +08:00
|
|
|
let wH = [1,1]
|
|
|
|
|
// if(img.width > img.height){
|
|
|
|
|
// let domHeight = dataDom.canvasBox.offsetWidth
|
|
|
|
|
// let imgWidth = img.width
|
|
|
|
|
// data.canvasConfig.height = domHeight
|
|
|
|
|
// data.canvasConfig.width = imgHeight/domHeight * img.width
|
|
|
|
|
// }else{
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
let domHeight = dataDom.canvasBox.offsetHeight - 200
|
2025-06-19 09:21:32 +08:00
|
|
|
let imgHeight = img.height
|
2025-06-23 09:27:29 +08:00
|
|
|
wH = [1,domHeight/imgHeight]
|
|
|
|
|
console.log(domHeight,img.height,img.width)
|
2025-06-19 09:21:32 +08:00
|
|
|
data.canvasConfig.height = domHeight
|
2025-06-23 09:27:29 +08:00
|
|
|
data.canvasConfig.width = wH[1] * img.width
|
2025-06-19 09:21:32 +08:00
|
|
|
// 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()
|
|
|
|
|
})
|
2024-09-25 11:07:49 +08:00
|
|
|
return {
|
2025-06-19 09:21:32 +08:00
|
|
|
...toRefs(data),
|
|
|
|
|
...toRefs(dataDom),
|
|
|
|
|
isShowMark,
|
|
|
|
|
addImage,
|
|
|
|
|
getData,
|
|
|
|
|
getCanvasData,
|
2025-06-23 09:27:29 +08:00
|
|
|
canvasSave,
|
2024-09-25 11:07:49 +08:00
|
|
|
};
|
|
|
|
|
},
|
2025-06-19 09:21:32 +08:00
|
|
|
data(prop) {
|
2024-09-25 11:07:49 +08:00
|
|
|
return {
|
2025-06-19 09:21:32 +08:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
|
2024-09-25 11:07:49 +08:00
|
|
|
},
|
|
|
|
|
mounted() {},
|
2025-06-19 09:21:32 +08:00
|
|
|
|
2024-09-25 11:07:49 +08:00
|
|
|
methods: {
|
2025-06-19 09:21:32 +08:00
|
|
|
|
|
|
|
|
},
|
2024-09-25 11:07:49 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
2025-06-19 09:21:32 +08:00
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.generalCanvas{
|
|
|
|
|
width: 100%;
|
2024-09-25 11:07:49 +08:00
|
|
|
height: 100%;
|
2025-06-19 09:21:32 +08:00
|
|
|
position: relative;
|
2024-09-25 11:07:49 +08:00
|
|
|
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{
|
2024-09-25 11:07:49 +08:00
|
|
|
flex: 1;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|