Commit 6e670faf authored by zhengke's avatar zhengke

初始化 图比例

parent 61574e7b
......@@ -218,6 +218,8 @@ const setImgs = async () => {
close()
}
if(imgType.value==2){
let width = propsDatas.value.width
let height = propsDatas.value.height
let maxWidth = VIEWPORT_SIZE,maxHeight = VIEWPORT_VER_SIZE, viewportRatio = slidesStore.viewportRatio
if(viewportRatio<1){
maxWidth = VIEWPORT_VER_SIZE
......@@ -237,8 +239,18 @@ const setImgs = async () => {
tempSize.height = maxHeight
tempSize.width = tempSize.width*ratio
}
if(handleElement.left<0) propsDatas.value.left=0
if(handleElement.top<0) propsDatas.value.top=0
if(tempSize.width!=width){
let ratio = width/tempSize.width
tempSize.width = Math.ceil(tempSize.width*ratio)
tempSize.height = Math.ceil(tempSize.height*ratio)
}
if(tempSize.height<height){
let ratio = height / tempSize.height
tempSize.width = Math.ceil(tempSize.width*ratio)
tempSize.height = Math.ceil(tempSize.height*ratio)
}
propsDatas.value.left -= (tempSize.width - width) / 2
propsDatas.value.top -= (tempSize.height - height) / 2
propsDatas.value.width = tempSize.width
propsDatas.value.height = tempSize.height
} else{
......@@ -255,11 +267,20 @@ const setImgs = async () => {
img.height = maxHeight
img.width = img.width*ratio
}
if(handleElement.left<0)propsDatas.value.left=0
if(handleElement.top<0)propsDatas.value.top=0
if(img.width!=width){
let ratio = width/img.width
img.width = Math.ceil(img.width*ratio)
img.height = Math.ceil(img.height*ratio)
}
if(img.height<height){
let ratio = height / img.height
img.width = Math.ceil(img.width*ratio)
img.height = Math.ceil(img.height*ratio)
}
propsDatas.value.left -= (img.width - width) / 2
propsDatas.value.top -= (img.height - height) / 2
propsDatas.value.width = img.width
propsDatas.value.height = img.height
}
}
propsDatas.value.fixedRatio = true
......
......@@ -259,6 +259,8 @@ const GetTripFiledData = async () =>{
//替换
if(y.type=='image'&&value[0]!=''){
try {
let width = y.width
let height = y.height
let tempSize = await FileService.getImageSizeWithoutDownloading(value[0])
if(tempSize.width>maxWidth){
let ratio = maxWidth/tempSize.width
......@@ -270,13 +272,27 @@ const GetTripFiledData = async () =>{
tempSize.height = maxHeight
tempSize.width = tempSize.width*ratio
}
if(y.left<0)y.left=0
if(y.top<0)y.top=0
if(tempSize.width!=width){
let ratio = width/tempSize.width
tempSize.width = Math.ceil(tempSize.width*ratio)
tempSize.height = Math.ceil(tempSize.height*ratio)
}
if(tempSize.height<height){
let ratio = height / tempSize.height
tempSize.width = Math.ceil(tempSize.width*ratio)
tempSize.height = Math.ceil(tempSize.height*ratio)
}
y.left -= (tempSize.width - width) / 2
y.top -= (tempSize.height - height) / 2
y.width = tempSize.width
y.height = tempSize.height
} catch (error) { }
y.fixedRatio = true
} catch (error) {
console.log(error)
y.fixedRatio = false
}
y.src = value[0]
y.fixedRatio = true
}
}
y.below = y.TemplateDataSource.index!=null && y.TemplateDataSource.index>=0 ? y.TemplateDataSource.index:-1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment