Commit 16f4ca18 authored by 罗超's avatar 罗超

1、字体上传新增通知后台服务

2、优化图片替换时重新调整大小位置的问题
parent 41aeed2c
......@@ -85,6 +85,7 @@ import { CustomerFonts } from '@/store/font'
import { injectKeyDataSource,injectKeyTemplate } from '@/types/injectKey'
import { VIEWPORT_SIZE, VIEWPORT_VER_SIZE } from '@/configs/canvas'
import { reduceFont } from '@/utils/fonts/convertFont'
import FileService from '@/services/FileService'
const props = defineProps({
visible:{
......@@ -165,6 +166,7 @@ const uploadFontHandler = async (uploadFile:any, uploadFiles:any, fontName:strin
reduceName = `${fontName}_reduce`
reduceUrl = await AliyunUpload.UploadAsync(info.file,"tripfont/"+info.file.name)
}
await FileService.notifyFontUpdateAsync(uploadFile.name)
} catch (error) {
console.log('发生异常',error)
}
......
......@@ -21,7 +21,7 @@ const fetchWithTimeout = (url:string, timeout:number)=>{
}
class FileService {
static downloadLinePdfAsync = async (id: any) => {
let url = `http://localhost:5164/api/pdf/${id}`
let url = `http://fileservice.oytour.com/api/pdf/${id}`
try {
const response = await fetchWithTimeout(url, 60*1000);
// 处理响应
......@@ -102,6 +102,10 @@ class FileService {
let file = new File([blob],fileName)
return file
}
static notifyFontUpdateAsync = async (fileName:string)=>{
await fetch('http://fileservice.oytour.com/api/file/downfont/'+fileName)
}
}
export default FileService
\ No newline at end of file
......@@ -103,7 +103,7 @@ export const useFontStore = defineStore('fonts',{
document.fonts.add(fontFace)
this.loaded.push(item.fontFamily)
let newStyle = document.createElement('style');
const fontFormat = item.fontUrl.toLowerCase().indexOf('.ttf')!=-1?'truetype':(item.fontUrl.toLowerCase().indexOf('.otf')!=-1?'opentype':item.fontUrl.split('.').reverse()[0])
const fontFormat = item.fontUrl.toLowerCase().indexOf('.ttf')!=-1?'truetype':(item.fontUrl.toLowerCase().indexOf('.otf')!=-1?'opentype':`'${item.fontUrl.split('.').reverse()[0]}'`)
newStyle.setAttribute("type", "text/css");
newStyle.appendChild(document.createTextNode("\
@font-face {\
......
......@@ -241,49 +241,24 @@ const setImgs = async () => {
}
const setPropsDatas = (image:any) => {
let width = handleImageElement.value.width
let height = handleImageElement.value.height
let maxWidth = VIEWPORT_SIZE,maxHeight = VIEWPORT_VER_SIZE.Value, viewportRatio = slidesStore.viewportRatio
if(viewportRatio<1){
maxWidth = VIEWPORT_VER_SIZE.Value
maxHeight = VIEWPORT_SIZE.Value
}
if(image.width>maxWidth){
let ratio = maxWidth/img.width
image.width = maxWidth
image.height = img.height*ratio
}
if(image.height>maxHeight){
let ratio = maxHeight/image.height
image.height = maxHeight
image.width = image.width*ratio
}
if(width>height){
let ratio = width/image.width
image.width = Math.ceil(image.width*ratio)
image.height = Math.ceil(image.height*ratio)
}
if(width<height){
let ratio = height/image.height
image.width = Math.ceil(image.width*ratio)
image.height = Math.ceil(image.height*ratio)
}
if(image.height<height){
let ratio = height/image.height
image.width = Math.ceil(image.width*ratio)
image.height = Math.ceil(image.height*ratio)
}
if(image.width<width){
let ratio = width/image.width
image.width = Math.ceil(image.width*ratio)
image.height = Math.ceil(image.height*ratio)
}
if(image.width) {
if(image.width>image.height) propsDatas.value.left -= (image.width - width)/2
if(image.width<image.height) propsDatas.value.top -= (image.height - height)/2
propsDatas.value.width = image.width
propsDatas.value.height = image.height
let width = 0
let height = 0
//按照宽度进行缩放
let ratio = image.width / handleImageElement.value.width
width = handleImageElement.value.width
height = image.height / ratio
if(height<handleImageElement.value.height){
ratio = height / handleImageElement.value.height
height = handleImageElement.value.height
width = width / ratio
propsDatas.value.left = handleImageElement.value.left - (Math.ceil((width - handleImageElement.value.width)/2))
}else{
propsDatas.value.top = handleImageElement.value.top - (Math.ceil((height - handleImageElement.value.height)/2))
}
propsDatas.value.height = height
propsDatas.value.width = width
propsDatas.value.fixedRatio = true
slidesStore.updateElement({ id: handleElementId.value, props:propsDatas.value })
addHistorySnapshot()
......
......@@ -200,11 +200,11 @@ const GetTripFiledData = async () =>{
})
isHideOverflowText = true
} catch (error) {}
let maxWidth = VIEWPORT_SIZE,maxHeight = VIEWPORT_VER_SIZE.Value, viewportRatios = slidesStore.viewportRatio
if(viewportRatio<1){
maxWidth = VIEWPORT_VER_SIZE.Value
maxHeight = VIEWPORT_SIZE.Value
}
// let maxWidth = VIEWPORT_SIZE,maxHeight = VIEWPORT_VER_SIZE.Value, viewportRatios = slidesStore.viewportRatio
// if(viewportRatio<1){
// maxWidth = VIEWPORT_VER_SIZE.Value
// maxHeight = VIEWPORT_SIZE.Value
// }
const travel = dataRes.data.data
const cursors = [] as Array<any>
for (let index = 0; index < slidesData.length; index++) {
......@@ -263,45 +263,27 @@ const GetTripFiledData = async () =>{
//替换
if(y.type=='image'&&value[0]!=''){
try {
let width = y.width
let height = y.height
// let width = y.width
// let height = y.height
let tempSize = await FileService.getImageSizeWithoutDownloading(value[0])
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(width>height){
let ratio = width/tempSize.width
tempSize.width = Math.ceil(tempSize.width*ratio)
tempSize.height = Math.ceil(tempSize.height*ratio)
}
if(width<height){
let ratio = height/tempSize.height
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)
}
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.width){
if(tempSize.width>tempSize.height) y.left -= (tempSize.width - width) / 2
if(tempSize.width<tempSize.height) y.top -= (tempSize.height - height) / 2
y.width = tempSize.width
y.height = tempSize.height
let width = 0
let height = 0
//按照宽度进行缩放
let ratio = tempSize.width / y.width
width = y.width
height = tempSize.height / ratio
if(height<y.height){
ratio = height / y.height
height = y.height
width = width / ratio
y.left -= Math.ceil((width - y.width)/2)
}else{
y.top = Math.ceil((height - y.height)/2)
}
y.height = height
y.width = width
y.fixedRatio = true
} catch (error) {
console.log(error)
......
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