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

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

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