diff --git a/src/renderer/src/AixPPTist/src/hooks/useImport.ts b/src/renderer/src/AixPPTist/src/hooks/useImport.ts index d0e450f..b990686 100644 --- a/src/renderer/src/AixPPTist/src/hooks/useImport.ts +++ b/src/renderer/src/AixPPTist/src/hooks/useImport.ts @@ -33,6 +33,48 @@ const { theme } = storeToRefs(useSlidesStore()) const { addSlidesFromData } = useAddSlidesOrElements() const { isEmptySlide } = useSlideHandler() +const parseLineElement = (el: Shape) => { + let start: [number, number] = [0, 0] + let end: [number, number] = [0, 0] + + if (!el.isFlipV && !el.isFlipH) { // 右下 + start = [0, 0] + end = [el.width, el.height] + } + else if (el.isFlipV && el.isFlipH) { // 左上 + start = [el.width, el.height] + end = [0, 0] + } + else if (el.isFlipV && !el.isFlipH) { // 右上 + start = [0, el.height] + end = [el.width, 0] + } + else { // 左下 + start = [el.width, 0] + end = [0, el.height] + } + + const data: PPTLineElement = { + type: 'line', + id: nanoid(10), + width: el.borderWidth || 1, + left: el.left, + top: el.top, + start, + end, + style: el.borderType, + color: el.borderColor, + points: ['', /straightConnector/.test(el.shapType) ? 'arrow' : ''] + } + if (/bentConnector/.test(el.shapType)) { + data.broken2 = [ + Math.abs(start[0] - end[0]) / 2, + Math.abs(start[1] - end[1]) / 2, + ] + } + + return data +} export default () => { const exporting = ref(false) @@ -59,48 +101,7 @@ export default () => { reader.readAsText(file) } - const parseLineElement = (el: Shape) => { - let start: [number, number] = [0, 0] - let end: [number, number] = [0, 0] - - if (!el.isFlipV && !el.isFlipH) { // 右下 - start = [0, 0] - end = [el.width, el.height] - } - else if (el.isFlipV && el.isFlipH) { // 左上 - start = [el.width, el.height] - end = [0, 0] - } - else if (el.isFlipV && !el.isFlipH) { // 右上 - start = [0, el.height] - end = [el.width, 0] - } - else { // 左下 - start = [el.width, 0] - end = [0, el.height] - } - - const data: PPTLineElement = { - type: 'line', - id: nanoid(10), - width: el.borderWidth || 1, - left: el.left, - top: el.top, - start, - end, - style: el.borderType, - color: el.borderColor, - points: ['', /straightConnector/.test(el.shapType) ? 'arrow' : ''] - } - if (/bentConnector/.test(el.shapType)) { - data.broken2 = [ - Math.abs(start[0] - end[0]) / 2, - Math.abs(start[1] - end[1]) / 2, - ] - } - - return data - } + // 导入PPTX文件 const importPPTXFile = (files: FileList) => { @@ -493,6 +494,7 @@ export default () => { importPPTXFile, PPTXFileToJson, exporting, + parseLineElement } } @@ -664,6 +666,7 @@ export const PPTXFileToJson = (data: File|ArrayBuffer) => { } else if (el.type === 'shape') { if (el.shapType === 'line' || /Connector/.test(el.shapType)) { + // 从返回对象中解构出 xx 函数并调用 const lineElement = parseLineElement(el) slide.elements.push(lineElement) } diff --git a/src/renderer/src/api/apiService.js b/src/renderer/src/api/apiService.js index 99deb41..b9ec985 100644 --- a/src/renderer/src/api/apiService.js +++ b/src/renderer/src/api/apiService.js @@ -56,4 +56,5 @@ export class Other { static baseUrl = "/common/upload" // 测试 static uploadFile = data => ApiService.publicHttp(this.baseUrl, data, 'post', null, 'file') + } \ No newline at end of file diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index 39eb0a2..c647c74 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -550,7 +550,7 @@ export default { if (!!o.src) { // 如果有src就转换 const isBase64 = /^data:image\/(\w+);base64,/.test(o.src) const isBlobUrl = /^blob:/.test(o.src) - console.log('isBase64', o, isBase64) + // console.log('isBase64', o, isBase64) if (isBase64) { const bolb = commUtils.base64ToBlob(o.src) const fileName = Date.now() + '.png' @@ -565,11 +565,29 @@ export default { 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 + url &&(o.src = 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) 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) { this.pgDialog.visible = true @@ -585,6 +603,8 @@ export default { // 设置进度条 this.pgDialog.pg.percentage = Math.floor(completed / total * 100) } + console.log('结束', slides) + return this.pgDialog.pg.percentage = 0 this.pgDialog.visible = false listEntpcourse({ @@ -621,6 +641,8 @@ export default { }).then(async (res) => { const resSlides = slides.map(({id, ...slide}) => JSON.stringify(slide)) + console.log(resSlides) + return let params = { parentid: slideid, entpid: resCourse.entpid, diff --git a/src/renderer/src/views/teachingDesign/container/right.vue b/src/renderer/src/views/teachingDesign/container/right.vue index 19f7fd2..24af068 100644 --- a/src/renderer/src/views/teachingDesign/container/right.vue +++ b/src/renderer/src/views/teachingDesign/container/right.vue @@ -330,11 +330,27 @@ const toRousrceUrl = async(o) => { 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 + url &&(o.src = url) + } } } 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 ============