Commit 7ce82819 authored by zhengke's avatar zhengke

替换图片调整

parent 268b4666
......@@ -110,6 +110,8 @@ import { getImageDataURL } from '@/utils/image'
import { useMainStore, useSlidesStore, useScreenStore } from '@/store'
import { injectKeyDataSource } from '@/types/injectKey'
import ConfigService from '@/services/ConfigService'
import { VIEWPORT_SIZE, VIEWPORT_VER_SIZE } from '@/configs/canvas'
import FileService from '@/services/FileService'
import FileInput from '@/components/FileInput.vue'
const showVisible = ref(true)
......@@ -151,6 +153,7 @@ const mainStore = useMainStore()
const { createImageElement } = useCreateElement()
const { addHistorySnapshot } = useHistorySnapshot()
const slidesStore = useSlidesStore()
const { slides, currentSlide, slideIndex, layoutSlides } = storeToRefs(slidesStore)
const { handleElement, handleElementId } = storeToRefs(mainStore)
const handleSizeChange = (val: number) => {
......@@ -171,7 +174,7 @@ const insertImageElement = (files: FileList) => {
})
}
const setImgs = () => {
const setImgs = async () => {
let text = '请选择图片'
let url = imgOnline.value
if(activeName.value=='1') propsDatas.value = { src: imgOnline.value }
......@@ -196,6 +199,37 @@ const setImgs = () => {
close()
}
if(imgType.value==2){
const slidesData = slides.value
for (let index = 0; index < slidesData.length; index++) {
const x = slidesData[index] as any;
for (let j = 0; j < x.elements.length; j++) {
const y = x.elements[j];
if(slideIndex.value==index&&y.id==handleElementId.value){
let maxWidth = VIEWPORT_SIZE,maxHeight = VIEWPORT_VER_SIZE, viewportRatio = slidesStore.viewportRatio
if(viewportRatio<1){
maxWidth = VIEWPORT_VER_SIZE
maxHeight = VIEWPORT_SIZE
}
let tempSize = await FileService.getImageSizeWithoutDownloading(propsDatas.value.src)
if(tempSize.width>maxWidth){
let ratio = maxWidth/tempSize.width
tempSize.width = maxWidth
tempSize.height = tempSize.height*ratio
}
if(tempSize.height>maxHeight){
let ratio = maxHeight/tempSize.height
tempSize.height = maxHeight
tempSize.width = tempSize.width*ratio
}
if(y.left<0)y.left=0
if(y.top<0)y.top=0
y.width = tempSize.width
y.height = tempSize.height
y.src = propsDatas.value.src
y.fixedRatio = true
}
}
}
slidesStore.updateElement({ id: handleElementId.value, props:propsDatas.value })
addHistorySnapshot()
close()
......
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