Merge pull request 'zxl' (#107) from zxl into main

Reviewed-on: #107
This commit is contained in:
zhangxuelin 2024-12-11 09:59:16 +08:00
commit 82b70558c2
4 changed files with 89 additions and 47 deletions

View File

@ -33,32 +33,6 @@ const { theme } = storeToRefs(useSlidesStore())
const { addSlidesFromData } = useAddSlidesOrElements() const { addSlidesFromData } = useAddSlidesOrElements()
const { isEmptySlide } = useSlideHandler() const { isEmptySlide } = useSlideHandler()
export default () => {
const exporting = ref(false)
// 导入pptist文件
const importSpecificFile = (files: FileList, cover = false) => {
const file = files[0]
const reader = new FileReader()
reader.addEventListener('load', () => {
try {
const slides = JSON.parse(decrypt(reader.result as string))
if (cover) {
slidesStore.updateSlideIndex(0)
slidesStore.setSlides(slides)
}
else if (isEmptySlide.value) slidesStore.setSlides(slides)
else addSlidesFromData(slides)
}
catch {
message.error('无法正确读取 / 解析该文件')
}
})
reader.readAsText(file)
}
const parseLineElement = (el: Shape) => { const parseLineElement = (el: Shape) => {
let start: [number, number] = [0, 0] let start: [number, number] = [0, 0]
let end: [number, number] = [0, 0] let end: [number, number] = [0, 0]
@ -101,6 +75,33 @@ export default () => {
return data return data
} }
export default () => {
const exporting = ref(false)
// 导入pptist文件
const importSpecificFile = (files: FileList, cover = false) => {
const file = files[0]
const reader = new FileReader()
reader.addEventListener('load', () => {
try {
const slides = JSON.parse(decrypt(reader.result as string))
if (cover) {
slidesStore.updateSlideIndex(0)
slidesStore.setSlides(slides)
}
else if (isEmptySlide.value) slidesStore.setSlides(slides)
else addSlidesFromData(slides)
}
catch {
message.error('无法正确读取 / 解析该文件')
}
})
reader.readAsText(file)
}
// 导入PPTX文件 // 导入PPTX文件
const importPPTXFile = (files: FileList) => { const importPPTXFile = (files: FileList) => {
@ -493,6 +494,7 @@ export default () => {
importPPTXFile, importPPTXFile,
PPTXFileToJson, PPTXFileToJson,
exporting, exporting,
parseLineElement
} }
} }
@ -664,6 +666,7 @@ export const PPTXFileToJson = (data: File|ArrayBuffer) => {
} }
else if (el.type === 'shape') { else if (el.type === 'shape') {
if (el.shapType === 'line' || /Connector/.test(el.shapType)) { if (el.shapType === 'line' || /Connector/.test(el.shapType)) {
// 从返回对象中解构出 xx 函数并调用
const lineElement = parseLineElement(el) const lineElement = parseLineElement(el)
slide.elements.push(lineElement) slide.elements.push(lineElement)
} }

View File

@ -56,4 +56,5 @@ export class Other {
static baseUrl = "/common/upload" static baseUrl = "/common/upload"
// 测试 // 测试
static uploadFile = data => ApiService.publicHttp(this.baseUrl, data, 'post', null, 'file') static uploadFile = data => ApiService.publicHttp(this.baseUrl, data, 'post', null, 'file')
} }

View File

@ -524,7 +524,7 @@ export default {
if (!!o.src) { // src if (!!o.src) { // src
const isBase64 = /^data:image\/(\w+);base64,/.test(o.src) const isBase64 = /^data:image\/(\w+);base64,/.test(o.src)
const isBlobUrl = /^blob:/.test(o.src) const isBlobUrl = /^blob:/.test(o.src)
console.log('isBase64', o, isBase64) // console.log('isBase64', o, isBase64)
if (isBase64) { if (isBase64) {
const bolb = commUtils.base64ToBlob(o.src) const bolb = commUtils.base64ToBlob(o.src)
const fileName = Date.now() + '.png' const fileName = Date.now() + '.png'
@ -539,11 +539,29 @@ export default {
url &&(o.src = url) url &&(o.src = url)
} }
} else if (isBlobUrl) { // } 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
url &&(o.src = url)
}
}
}
}
}
if (o?.background?.image) await this.toRousrceUrl(o.background.image) 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) o.elements.forEach(async o => {await this.toRousrceUrl(o)})
if(o?.elements){
for (let element of o.elements) {
await this.toRousrceUrl(element);
}
}
}, },
async createAIPPTByFile(file) { async createAIPPTByFile(file) {
this.pgDialog.visible = true this.pgDialog.visible = true
@ -559,6 +577,8 @@ export default {
// //
this.pgDialog.pg.percentage = Math.floor(completed / total * 100) this.pgDialog.pg.percentage = Math.floor(completed / total * 100)
} }
console.log('结束', slides)
return
this.pgDialog.pg.percentage = 0 this.pgDialog.pg.percentage = 0
this.pgDialog.visible = false this.pgDialog.visible = false
listEntpcourse({ listEntpcourse({
@ -595,6 +615,8 @@ export default {
}).then(async (res) => { }).then(async (res) => {
const resSlides = slides.map(({id, ...slide}) => JSON.stringify(slide)) const resSlides = slides.map(({id, ...slide}) => JSON.stringify(slide))
console.log(resSlides)
return
let params = { let params = {
parentid: slideid, parentid: slideid,
entpid: resCourse.entpid, entpid: resCourse.entpid,

View File

@ -330,11 +330,27 @@ const toRousrceUrl = async(o) => {
url &&(o.src = url) url &&(o.src = url)
} }
} else if (isBlobUrl) { // } 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
url &&(o.src = url)
}
} }
} }
if (o?.background?.image) await toRousrceUrl(o.background.image) if (o?.background?.image) await toRousrceUrl(o.background.image)
if (o?.elements) o.elements.forEach(async o => {await toRousrceUrl(o)}) if(o?.elements){
for (let element of o.elements) {
await this.toRousrceUrl(element);
}
}
} }
// ======== zdg end ============ // ======== zdg end ============