修复detail打开有时候没有添加衣服成功

This commit is contained in:
X1627315083
2024-01-10 17:20:08 +08:00
parent 838d6e86bd
commit c43c73e270
3 changed files with 30 additions and 18 deletions

View File

@@ -431,7 +431,7 @@ export default defineComponent({
}else{
this.designShowPrview = 1
}
await this.setImgSize()
// await this.setImgSize()
this.generateHighDesignImg = rv.highDesignUrl
this.designDetailShow = true
this.loadingShow = false
@@ -468,11 +468,13 @@ export default defineComponent({
designItemDetail?.others?.forEach((item:any) => {
if(item.type == 'Body'){
body = item
this.frontBack.body = item
}
});
let ratio:any = await this?.setPostition(body?.layersObject?.[0]?.imageUrl)
if( Number.isNaN(ratio)){
if(Number.isNaN(ratio) || ratio == 0){
this.setImgSize()
return
}
let frontIndex = 6
let backIndex = 3
@@ -697,28 +699,30 @@ export default defineComponent({
},
//按比设置单件衣服宽高位置
async setPostition(url:any){
let modal_body:any
let num:any
let img:any = await loadImage(url).then((img:any)=>{
modal_body = document.getElementsByClassName('detail_modal_model')[0]
if(modal_body == undefined){
this.setPostition(url)
}
num = modal_body?.offsetWidth / img.width;
})
// nextTick().then(()=>{
// })
function loadImage(url:any) {
return new Promise((resolve, reject) => {
await nextTick().then(async ()=>{
let modal_body:any= document.getElementsByClassName('detail_modal_model')[0]
let imgWidth:any
await new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
imgWidth = img.width
resolve(img)
};
img.onerror = reject;
img.src = url;
});
}
// await loadImage(url).then((img:any)=>{
// console.log(2);
// // modal_body = document.getElementsByClassName('detail_modal_model')[0]
// if(modal_body == undefined){
// this.setPostition(url)
// }
// console.log( modal_body?.offsetWidth,imgWidth, img.width);
// return num
// })
num = modal_body?.offsetWidth / imgWidth;
})
return num
},
//切换上一张或下一张图的详情