diff --git a/src/hooks/useExport.ts b/src/hooks/useExport.ts index f39e6cb8..c3709ac2 100644 --- a/src/hooks/useExport.ts +++ b/src/hooks/useExport.ts @@ -353,7 +353,7 @@ export default () => { } // 导出PPTX文件 - const exportPPTX = (_slides: Slide[], masterOverwrite: boolean) => { + const exportPPTX = (_slides: Slide[], masterOverwrite: boolean, ignoreMedia: boolean) => { exporting.value = true const pptx = new pptxgen() @@ -743,6 +743,28 @@ export default () => { pptxSlide.addImage(options) } + + else if (!ignoreMedia && (el.type === 'video' || el.type === 'audio')) { + const options: pptxgen.MediaProps = { + x: el.left / INCH_PX_RATIO, + y: el.top / INCH_PX_RATIO, + w: el.width / INCH_PX_RATIO, + h: el.height / INCH_PX_RATIO, + path: el.src, + type: el.type, + } + if (el.type === 'video' && el.poster) options.cover = el.poster + + const extMatch = el.src.match(/\.([a-zA-Z0-9]+)(?:[\?#]|$)/) + if (extMatch && extMatch[1]) options.extn = extMatch[1] + else if (el.ext) options.extn = el.ext + + const videoExts = ['avi', 'mp4', 'm4v', 'mov', 'wmv'] + const audioExts = ['mp3', 'm4a', 'mp4', 'wav', 'wma'] + if (options.extn && [...videoExts, ...audioExts].includes(options.extn)) { + pptxSlide.addMedia(options) + } + } } } diff --git a/src/types/slides.ts b/src/types/slides.ts index b594071b..e4eddc8d 100644 --- a/src/types/slides.ts +++ b/src/types/slides.ts @@ -568,11 +568,14 @@ export interface PPTLatexElement extends PPTBaseElement { * src: 视频地址 * * poster: 预览封面 + * + * ext: 视频后缀,当资源链接缺少后缀时用该字段确认资源类型 */ export interface PPTVideoElement extends PPTBaseElement { type: 'video' src: string poster?: string + ext?: string } /** @@ -589,14 +592,17 @@ export interface PPTVideoElement extends PPTBaseElement { * autoplay: 自动播放 * * src: 音频地址 + * + * ext: 音频后缀,当资源链接缺少后缀时用该字段确认资源类型 */ export interface PPTAudioElement extends PPTBaseElement { type: 'audio' fixedRatio: boolean - color: string, - loop: boolean, - autoplay: boolean, + color: string + loop: boolean + autoplay: boolean src: string + ext?: string } diff --git a/src/views/Editor/ExportDialog/ExportImage.vue b/src/views/Editor/ExportDialog/ExportImage.vue index 86985dd9..31c3414d 100644 --- a/src/views/Editor/ExportDialog/ExportImage.vue +++ b/src/views/Editor/ExportDialog/ExportImage.vue @@ -59,7 +59,7 @@