Merge pull request 'zdg_dev' (#231) from zdg_dev into main

Reviewed-on: #231
This commit is contained in:
zhengdegang 2025-01-21 14:16:10 +08:00
commit a73a409776
1 changed files with 59 additions and 34 deletions

View File

@ -289,7 +289,8 @@ export default {
{ color: '#5cb87a', percentage: 100 }, // 绿
]
}
}
},
pptMedia: {} // ppt
}
},
computed: {
@ -591,52 +592,76 @@ export default {
this.createAIPPTByFile(file, this.currentNode.itemtitle + '.aippt')
}
},
// || 线
getOnlineFileUrl(data, name){
return new Promise(async (resolve, reject) => {
let file
if (data instanceof Blob) { // blob
const fileName = Date.now() + `.${name||'png'}`
file = commUtils.blobToFile(data, fileName)
} else if (data instanceof File) { // file
file = data
} else { // base64
const blob = commUtils.base64ToBlob(data)
const fileName = Date.now() + `.${name||'png'}`
file = commUtils.blobToFile(blob, fileName)
}
const formData = new FormData()
formData.append('file', file)
const res = await Api_server.Other.uploadFile(formData)
if (res && res.code == 200){
resolve(res?.url)
} else { //
reject(res?.msg||'上传失败')
}
})
},
async toRousrceUrl(o) {
if (!!o.src) { // src
const isBase64 = /^data:image\/(\w+);base64,/.test(o.src)
const isBlobUrl = /^blob:/.test(o.src)
// console.log('isBase64', o, isBase64)
if (isBase64) {
const bolb = commUtils.base64ToBlob(o.src)
const fileName = Date.now() + '.png'
const file = commUtils.blobToFile(bolb, fileName)
// o.src = fileName
// console.log('file', file)
const formData = new FormData()
formData.append('file', file)
const res = await Api_server.Other.uploadFile(formData)
if (res && res.code == 200){
const url = res?.url
url &&(o.src = url)
}
} else if (isBlobUrl) { //
const res = await fetch(o.src)
const blob = await res.blob()
const fileName = o.type=='video'? Date.now() + '.mp4':Date.now() + '.mp3'
const file = commUtils.blobToFile(blob, fileName)
// o.src = fileName
// console.log('file', file)
const formData = new FormData()
formData.append('file', file)
const ress = await Api_server.Other.uploadFile(formData)
if (ress && ress.code == 200){
const url = ress?.url
let onLineUrl = '' // 线
if (!!o.zipPath) onLineUrl = this.pptMedia[o.zipPath] || '' //
if (onLineUrl) o.src = onLineUrl // 线
else { //
if (isBase64) { //
const url = await this.getOnlineFileUrl(o.src)
url && o.zipPath && (this.pptMedia[o.zipPath] = url) //
} else if (isBlobUrl) { //
const res = await fetch(o.src)
const blob = await res.blob()
const url = await this.getOnlineFileUrl(blob, o.type=='video'?'mp4':'mp3')
URL.revokeObjectURL(o.src) //
url &&(o.src = url)
url && o.zipPath && (this.pptMedia[o.zipPath] = url) //
}
}
}
// shape
const isBg = o?.gradient?.type == 'image' && !!o?.gradient?.image
if (isBg) {
const {src, zipPath} = o.gradient.image || {}
let onLineUrl = '' // 线
if (!!zipPath) onLineUrl = this.pptMedia[zipPath] || '' //
if (onLineUrl) o.gradient.image.src = onLineUrl // 线
else { //
const url = await this.getOnlineFileUrl(src)
o.gradient.image.src = url
url && zipPath && (this.pptMedia[zipPath] = url) //
}
}
if (o?.background?.image) await this.toRousrceUrl(o.background.image)
// if (o?.elements) o.elements.forEach(async o => {await this.toRousrceUrl(o)})
if(o?.elements){
for (let element of o.elements) {
await this.toRousrceUrl(element);
}
}
if(o?.elements){
for (let element of o.elements) {
await this.toRousrceUrl(element);
}
}
},
async createAIPPTByFile(file,fileShowName) {
this.pgDialog.visible = true
this.pgDialog.pg.percentage = 0
this.pptMedia = {} //
const resPptJson = await PPTXFileToJson(file).catch(() => {
ElMessageBox.alert('PPT文件转换失败请点击素材右侧...下载文件后打开另存为PPTX文件格式再进行导入')
this.pgDialog.visible = false