|
@@ -1,4 +1,4 @@
|
|
|
-import { ref } from 'vue'
|
|
|
+import { ref, nextTick } from 'vue'
|
|
|
import { storeToRefs } from 'pinia'
|
|
|
import { parse, type Shape, type Element, type ChartItem, type BaseElement } from 'pptxtojson'
|
|
|
import { nanoid } from 'nanoid'
|
|
@@ -70,31 +70,113 @@ export default () => {
|
|
|
// 直接读取JSON功能,暴露到window.readJSON
|
|
|
const readJSON = (jsonData: string | any, cover = false) => {
|
|
|
try {
|
|
|
- let slides
|
|
|
+ console.log('readJSON 开始执行:', { jsonData, cover })
|
|
|
+
|
|
|
+ let parsedData
|
|
|
if (typeof jsonData === 'string') {
|
|
|
- const parsed = JSON.parse(jsonData)
|
|
|
- slides = parsed.slides || parsed
|
|
|
+ parsedData = JSON.parse(jsonData)
|
|
|
+ console.log('解析字符串后的数据:', parsedData)
|
|
|
}
|
|
|
else {
|
|
|
- slides = jsonData.slides || jsonData
|
|
|
+ parsedData = jsonData
|
|
|
}
|
|
|
|
|
|
+ // 提取所有可能的数据
|
|
|
+ const slides = parsedData.slides || parsedData
|
|
|
+ const title = parsedData.title
|
|
|
+ const theme = parsedData.theme
|
|
|
+ const width = parsedData.width
|
|
|
+ const height = parsedData.height
|
|
|
+ const viewportRatio = parsedData.viewportRatio || (height && width ? height / width : undefined)
|
|
|
+
|
|
|
+ console.log('提取的数据:', { slides: slides.length, title, theme, width, height, viewportRatio })
|
|
|
+
|
|
|
+ // 更新幻灯片数据
|
|
|
if (cover) {
|
|
|
+ console.log('覆盖模式:更新幻灯片数据')
|
|
|
slidesStore.updateSlideIndex(0)
|
|
|
slidesStore.setSlides(slides)
|
|
|
addHistorySnapshot()
|
|
|
}
|
|
|
else if (isEmptySlide.value) {
|
|
|
+ console.log('空幻灯片模式:更新幻灯片数据')
|
|
|
slidesStore.setSlides(slides)
|
|
|
addHistorySnapshot()
|
|
|
}
|
|
|
else {
|
|
|
+ console.log('添加模式:添加幻灯片数据')
|
|
|
addSlidesFromData(slides)
|
|
|
}
|
|
|
|
|
|
- return { success: true, slides }
|
|
|
+ // 同步更新其他相关内容
|
|
|
+ if (title !== undefined) {
|
|
|
+ console.log('正在更新标题:', title)
|
|
|
+ slidesStore.setTitle(title)
|
|
|
+ console.log('标题更新完成')
|
|
|
+ }
|
|
|
+
|
|
|
+ if (theme !== undefined) {
|
|
|
+ console.log('正在更新主题:', theme)
|
|
|
+ slidesStore.setTheme(theme)
|
|
|
+ console.log('主题更新完成')
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新视口尺寸(如果提供了的话)
|
|
|
+ if (width !== undefined && height !== undefined) {
|
|
|
+ console.log('正在触发视口尺寸更新事件:', { width, height, viewportRatio })
|
|
|
+
|
|
|
+ // 同时也要更新slidesStore中的相关数据
|
|
|
+ if (slidesStore.setViewportSize) {
|
|
|
+ console.log('正在更新store中的视口尺寸')
|
|
|
+ slidesStore.setViewportSize(width)
|
|
|
+ if (slidesStore.setViewportRatio && viewportRatio !== undefined) {
|
|
|
+ slidesStore.setViewportRatio(viewportRatio)
|
|
|
+ console.log('视口比例已更新:', viewportRatio)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ window.dispatchEvent(new CustomEvent('viewportSizeUpdated', {
|
|
|
+ detail: { width, height, viewportRatio }
|
|
|
+ }))
|
|
|
+ console.log('视口尺寸更新事件已触发')
|
|
|
+ }
|
|
|
+
|
|
|
+ // 导入成功后,触发画布尺寸更新
|
|
|
+ // 使用 nextTick 确保DOM更新完成后再触发
|
|
|
+ console.log('开始触发画布尺寸更新事件...')
|
|
|
+ nextTick(() => {
|
|
|
+ console.log('DOM更新完成,触发 slidesDataUpdated 事件')
|
|
|
+ // 触发自定义事件,通知需要更新画布尺寸的组件
|
|
|
+ window.dispatchEvent(new CustomEvent('slidesDataUpdated', {
|
|
|
+ detail: {
|
|
|
+ slides,
|
|
|
+ cover,
|
|
|
+ title,
|
|
|
+ theme,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ viewportRatio,
|
|
|
+ timestamp: Date.now()
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ console.log('slidesDataUpdated 事件已触发')
|
|
|
+
|
|
|
+ // 检查并调整幻灯片索引,确保在有效范围内
|
|
|
+ const newSlideCount = slides.length
|
|
|
+ const currentIndex = slidesStore.slideIndex
|
|
|
+ if (currentIndex >= newSlideCount) {
|
|
|
+ console.log('调整幻灯片索引:', currentIndex, '->', Math.max(0, newSlideCount - 1))
|
|
|
+ slidesStore.updateSlideIndex(Math.max(0, newSlideCount - 1))
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('画布尺寸更新事件处理完成')
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log('readJSON 执行成功')
|
|
|
+ return { success: true, slides, title, theme, width, height, viewportRatio }
|
|
|
}
|
|
|
catch (error) {
|
|
|
+ console.error('readJSON 执行失败:', error)
|
|
|
const errorMsg = '无法正确读取 / 解析该JSON数据'
|
|
|
message.error(errorMsg)
|
|
|
return { success: false, error: errorMsg, details: error }
|