Explorar el Código

兼容妙极客

黄琪勇 hace 2 meses
padre
commit
1dfda4beaf
Se han modificado 1 ficheros con 34 adiciones y 2 borrados
  1. 34 2
      src/libs/jsonTool.ts

+ 34 - 2
src/libs/jsonTool.ts

@@ -36,9 +36,11 @@ export function jsonToPpt(jsonData: Record<string, any>) {
   const { width, theme, slides } = jsonData
   slidesStore.updateSlideIndex(0)
   slidesStore.setViewportSize(width || 1920)
-  slidesStore.setViewportRatio(theme.viewportRatio)
+  slidesStore.setViewportRatio(theme.viewportRatio || 0.5625)
+  // 兼容妙极客 这里过滤一下这个数据
+  const newSlides = formatSlides(slides)
   slidesStore.setTheme(theme)
-  slidesStore.setSlides(slides.length ? slides : slidesData)
+  slidesStore.setSlides(newSlides.length ? newSlides : slidesData)
 }
 
 export function getJsonToBlob() {
@@ -55,3 +57,33 @@ export function getJsonToBlob() {
     title
   }
 }
+
+function formatSlides(slides: any[]): any[] {
+  return slides.map(item => {
+    // 背景兼容  当为渐变并且没有渐变数据的时候,判定为妙极客数据兼容
+    if (item.background?.type === "gradient") {
+      if (item.background.gradientType === "linear" && !item.background?.gradient) {
+        item.background.gradient = {
+          colors: [
+            { pos: 0, color: (item.background.gradientColor && item.background.gradientColor[0]) || "rgba(255,255,255,1)" },
+            { pos: 100, color: (item.background.gradientColor && item.background.gradientColor[1]) || "rgba(255,255,255,1)" }
+          ],
+          rotate: item.background.gradientRotate || 0,
+          type: item.background.gradientType
+        }
+      }
+    }
+    ;(item.elements || []).map((el: any) => {
+      // 兼容块
+      if (el.type === "shape") {
+        if (el.gradient?.type == "linear" && !el.gradient?.colors) {
+          el.gradient.colors = [
+            { pos: 0, color: (el.gradient.color && el.gradient.color[0]) || "rgba(255,255,255,1)" },
+            { pos: 100, color: (el.gradient.color && el.gradient.color[1]) || "rgba(255,255,255,1)" }
+          ]
+        }
+      }
+    })
+    return item
+  })
+}