zdg_dev #230
|
@ -1,6 +1,8 @@
|
|||
import { ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { parse, type Shape, type Element, type ChartItem } from 'pptxtojson'
|
||||
// import { parse, type Shape, type Element, type ChartItem } from 'pptxtojson'
|
||||
// import { parse, utils, fill as fillUtil } from '@/plugins/pptTojson'
|
||||
import { parse, fill as fillUtil, type Shape, type Element, type ChartItem } from '@/plugins/pptTojson'
|
||||
import { nanoid } from 'nanoid'
|
||||
import { useSlidesStore } from '../store'
|
||||
import { decrypt } from '../utils/crypto'
|
||||
|
@ -9,6 +11,7 @@ import useAddSlidesOrElements from '../hooks/useAddSlidesOrElements'
|
|||
import useSlideHandler from '../hooks/useSlideHandler'
|
||||
import message from '../utils/message'
|
||||
import { getSvgPathRange } from '../utils/svgPathParser'
|
||||
import { calculatePathDimensions } from '@/utils/ppt/svgUtils'
|
||||
import type {
|
||||
Slide,
|
||||
TableCellStyle,
|
||||
|
@ -75,57 +78,18 @@ const parseLineElement = (el: Shape) => {
|
|||
|
||||
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)
|
||||
// PPT json二次加工处理
|
||||
const parsePptJsonSlides = (slides: Slide[]|any, zip) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const shapeList: ShapePoolItem[] = []
|
||||
for (const item of SHAPE_LIST) {
|
||||
shapeList.push(...item.children)
|
||||
}
|
||||
catch {
|
||||
message.error('无法正确读取 / 解析该文件')
|
||||
}
|
||||
})
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 导入PPTX文件
|
||||
const importPPTXFile = (files: FileList) => {
|
||||
const file = files[0]
|
||||
if (!file) return
|
||||
|
||||
exporting.value = true
|
||||
|
||||
const shapeList: ShapePoolItem[] = []
|
||||
for (const item of SHAPE_LIST) {
|
||||
shapeList.push(...item.children)
|
||||
}
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = async e => {
|
||||
const json = await parse(e.target!.result as ArrayBuffer)
|
||||
|
||||
const ratio = 96 / 72
|
||||
const width = json.size.width
|
||||
|
||||
slidesStore.setViewportSize(width * ratio)
|
||||
|
||||
const slides: Slide[] = []
|
||||
for (const item of json.slides) {
|
||||
const newSlides: Slide[] = []
|
||||
for (const item of slides) {
|
||||
const { type, value } = item.fill
|
||||
let background: SlideBackground
|
||||
if (type === 'image') {
|
||||
|
@ -156,20 +120,20 @@ export default () => {
|
|||
color: value,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const slide: Slide = {
|
||||
id: nanoid(10),
|
||||
elements: [],
|
||||
background,
|
||||
}
|
||||
|
||||
const parseElements = (elements: Element[]) => {
|
||||
|
||||
const parseElements = async (elements: Element[]) => {
|
||||
for (const el of elements) {
|
||||
const originWidth = el.width || 1
|
||||
const originHeight = el.height || 1
|
||||
const originLeft = el.left
|
||||
const originTop = el.top
|
||||
|
||||
|
||||
el.width = el.width * ratio
|
||||
el.height = el.height * ratio
|
||||
el.left = el.left * ratio
|
||||
|
@ -219,6 +183,7 @@ export default () => {
|
|||
rotate: el.rotate,
|
||||
flipH: el.isFlipH,
|
||||
flipV: el.isFlipV,
|
||||
zipPath: el.zipPath,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'audio') {
|
||||
|
@ -235,6 +200,7 @@ export default () => {
|
|||
color: theme.value.themeColor,
|
||||
loop: false,
|
||||
autoplay: false,
|
||||
zipPath: el.zipPath,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'video') {
|
||||
|
@ -248,6 +214,7 @@ export default () => {
|
|||
top: el.top,
|
||||
rotate: 0,
|
||||
autoplay: false,
|
||||
zipPath: el.zipPath,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'shape') {
|
||||
|
@ -257,7 +224,7 @@ export default () => {
|
|||
}
|
||||
else {
|
||||
const shape = shapeList.find(item => item.pptxShapeType === el.shapType)
|
||||
|
||||
|
||||
const vAlignMap: { [key: string]: ShapeTextAlign } = {
|
||||
'mid': 'middle',
|
||||
'down': 'bottom',
|
||||
|
@ -325,7 +292,35 @@ export default () => {
|
|||
element.viewBox = [maxX || originWidth, maxY || originHeight]
|
||||
}
|
||||
}
|
||||
|
||||
// auth: zdg
|
||||
if (el.fill) {
|
||||
const { type, ...opt } = el.fill
|
||||
if (type === 'gradient') { // 线性渐变色
|
||||
element.gradient = {
|
||||
type: 'linear',
|
||||
colors: opt.colors.map(item => ({
|
||||
...item,
|
||||
pos: parseInt(item.pos),
|
||||
})),
|
||||
rotate: opt.rot,
|
||||
}
|
||||
} else if (type == 'image') { // 背景图填充
|
||||
const pathPos = calculatePathDimensions(element.path)
|
||||
const url = opt.picBase64 || (!!zip ? await fillUtil.getPicFillBase64(opt.zipPath, zip) : '')
|
||||
element.gradient = {
|
||||
type: 'image',
|
||||
image: {
|
||||
src: url,
|
||||
width: opt.w||el.width,
|
||||
height: opt.h||el.height,
|
||||
path_W: Math.round(pathPos.width), // 获取path 的宽高
|
||||
path_h: Math.round(pathPos.height), // 获取path 的宽高
|
||||
...opt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (element.path) slide.elements.push(element)
|
||||
}
|
||||
}
|
||||
|
@ -342,17 +337,17 @@ export default () => {
|
|||
const rowCells: TableCell[] = []
|
||||
for (let j = 0; j < col; j++) {
|
||||
const cellData = el.data[i][j]
|
||||
|
||||
|
||||
let textDiv: HTMLDivElement | null = document.createElement('div')
|
||||
textDiv.innerHTML = cellData.text
|
||||
const p = textDiv.querySelector('p')
|
||||
const align = p?.style.textAlign || 'left'
|
||||
|
||||
|
||||
const span = textDiv.querySelector('span')
|
||||
const fontsize = span?.style.fontSize ? (parseInt(span?.style.fontSize) * ratio).toFixed(1) + 'px' : ''
|
||||
const fontname = span?.style.fontFamily || ''
|
||||
const color = span?.style.color || cellData.fontColor
|
||||
|
||||
|
||||
rowCells.push({
|
||||
id: nanoid(10),
|
||||
colspan: cellData.colSpan || 1,
|
||||
|
@ -409,11 +404,11 @@ export default () => {
|
|||
legends = data.map(item => item.key)
|
||||
series = data.map(item => item.values.map(v => v.y))
|
||||
}
|
||||
|
||||
|
||||
const options: ChartOptions = {}
|
||||
|
||||
let chartType: ChartType = 'bar'
|
||||
|
||||
|
||||
switch (el.chartType) {
|
||||
case 'barChart':
|
||||
case 'bar3DChart':
|
||||
|
@ -468,18 +463,91 @@ export default () => {
|
|||
})
|
||||
}
|
||||
else if (el.type === 'group' || el.type === 'diagram') {
|
||||
const elements = el.elements.map(_el => ({
|
||||
..._el,
|
||||
left: _el.left + originLeft,
|
||||
top: _el.top + originTop,
|
||||
}))
|
||||
parseElements(elements)
|
||||
const elements = el.elements.map(_el => {
|
||||
const isGroup = el.type === 'group' // 子级是否为分组
|
||||
const isFlipH = !!(_el.isFlipH ^ el.isFlipH) // 水平翻转(分组有值进行异或运算)
|
||||
const isFlipV = !!(_el.isFlipV ^ el.isFlipV) // 垂直翻转(分组有值进行异或运算)
|
||||
const isPleft = el.isFlipH_def // 是否父级翻转-改变子元素坐标left
|
||||
const isPtop = el.isFlipV_def // 是否父级翻转-改变子元素坐标top
|
||||
const left = originLeft + (isPleft ? originWidth - _el.left - _el.width : _el.left)
|
||||
const top = originTop + (isPtop ? originHeight - _el.top - _el.height : _el.top)
|
||||
return {
|
||||
..._el,
|
||||
left,
|
||||
top,
|
||||
isFlipH,
|
||||
isFlipV,
|
||||
isFlipH_def: _el.isFlipH, // 保留默认
|
||||
isFlipV_def: _el.isFlipV, // 保留默认
|
||||
}
|
||||
})
|
||||
await parseElements(elements)
|
||||
}
|
||||
}
|
||||
}
|
||||
parseElements(item.elements)
|
||||
slides.push(slide)
|
||||
// 设置默认翻转默认属性
|
||||
item.elements.forEach(o => { o.isFlipH_def = o.isFlipH; o.isFlipV_def = o.isFlipV })
|
||||
item.bgElements.forEach(o => { o.isFlipH_def = o.isFlipH; o.isFlipV_def = o.isFlipV })
|
||||
item.bgElements.length && await parseElements(item.bgElements) // 加载当前幻灯片对应的母版
|
||||
item.elements.length && await parseElements(item.elements) // 加载当前幻灯片
|
||||
newSlides.push(slide)
|
||||
}
|
||||
resolve(newSlides)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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文件
|
||||
const importPPTXFile = (files: FileList) => {
|
||||
const file = files[0]
|
||||
if (!file) return
|
||||
|
||||
exporting.value = true
|
||||
|
||||
const shapeList: ShapePoolItem[] = []
|
||||
for (const item of SHAPE_LIST) {
|
||||
shapeList.push(...item.children)
|
||||
}
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = async e => {
|
||||
const json = await parse(e.target!.result as ArrayBuffer)
|
||||
|
||||
const ratio = 96 / 72
|
||||
const width = json.size.width
|
||||
slidesStore.setViewportSize(width * ratio)
|
||||
// json数据二次加工
|
||||
const slides = await parsePptJsonSlides(json.slides, json.zip)
|
||||
slidesStore.updateSlideIndex(0)
|
||||
slidesStore.setSlides(slides)
|
||||
exporting.value = false
|
||||
|
@ -539,365 +607,7 @@ export const PPTXFileToJson = (data: File|ArrayBuffer) => {
|
|||
resData.def = json // 保留原始数据
|
||||
resData.width = width * ratio
|
||||
resData.ratio = slidesStore.viewportRatio
|
||||
|
||||
const slides: Slide[] = []
|
||||
for (const item of json.slides) {
|
||||
const { type, value } = item.fill
|
||||
let background: SlideBackground
|
||||
if (type === 'image') {
|
||||
background = {
|
||||
type: 'image',
|
||||
image: {
|
||||
src: value.picBase64,
|
||||
size: 'cover',
|
||||
},
|
||||
}
|
||||
}
|
||||
else if (type === 'gradient') {
|
||||
background = {
|
||||
type: 'gradient',
|
||||
gradient: {
|
||||
type: 'linear',
|
||||
colors: value.colors.map(item => ({
|
||||
...item,
|
||||
pos: parseInt(item.pos),
|
||||
})),
|
||||
rotate: value.rot,
|
||||
},
|
||||
}
|
||||
}
|
||||
else {
|
||||
background = {
|
||||
type: 'solid',
|
||||
color: value,
|
||||
}
|
||||
}
|
||||
|
||||
const slide: Slide = {
|
||||
id: nanoid(10),
|
||||
elements: [],
|
||||
background,
|
||||
}
|
||||
|
||||
const parseElements = (elements: Element[]) => {
|
||||
for (const el of elements) {
|
||||
const originWidth = el.width || 1
|
||||
const originHeight = el.height || 1
|
||||
const originLeft = el.left
|
||||
const originTop = el.top
|
||||
|
||||
el.width = el.width * ratio
|
||||
el.height = el.height * ratio
|
||||
el.left = el.left * ratio
|
||||
el.top = el.top * ratio
|
||||
|
||||
if (el.type === 'text') {
|
||||
const textEl: PPTTextElement = {
|
||||
type: 'text',
|
||||
id: nanoid(10),
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
rotate: el.rotate,
|
||||
defaultFontName: theme.value.fontName,
|
||||
defaultColor: theme.value.fontColor,
|
||||
content: convertFontSizePtToPx(el.content, ratio),
|
||||
lineHeight: 1,
|
||||
outline: {
|
||||
color: el.borderColor,
|
||||
width: el.borderWidth,
|
||||
style: el.borderType,
|
||||
},
|
||||
fill: el.fillColor,
|
||||
vertical: el.isVertical,
|
||||
}
|
||||
if (el.shadow) {
|
||||
textEl.shadow = {
|
||||
h: el.shadow.h * ratio,
|
||||
v: el.shadow.v * ratio,
|
||||
blur: el.shadow.blur * ratio,
|
||||
color: el.shadow.color,
|
||||
}
|
||||
}
|
||||
slide.elements.push(textEl)
|
||||
}
|
||||
else if (el.type === 'image') {
|
||||
slide.elements.push({
|
||||
type: 'image',
|
||||
id: nanoid(10),
|
||||
src: el.src,
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
fixedRatio: true,
|
||||
rotate: el.rotate,
|
||||
flipH: el.isFlipH,
|
||||
flipV: el.isFlipV,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'audio') {
|
||||
slide.elements.push({
|
||||
type: 'audio',
|
||||
id: nanoid(10),
|
||||
src: el.blob,
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
rotate: 0,
|
||||
fixedRatio: false,
|
||||
color: theme.value.themeColor,
|
||||
loop: false,
|
||||
autoplay: false,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'video') {
|
||||
slide.elements.push({
|
||||
type: 'video',
|
||||
id: nanoid(10),
|
||||
src: (el.blob || el.src)!,
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
rotate: 0,
|
||||
autoplay: false,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'shape') {
|
||||
if (el.shapType === 'line' || /Connector/.test(el.shapType)) {
|
||||
// 从返回对象中解构出 xx 函数并调用
|
||||
const lineElement = parseLineElement(el)
|
||||
slide.elements.push(lineElement)
|
||||
}
|
||||
else {
|
||||
const shape = shapeList.find(item => item.pptxShapeType === el.shapType)
|
||||
|
||||
const vAlignMap: { [key: string]: ShapeTextAlign } = {
|
||||
'mid': 'middle',
|
||||
'down': 'bottom',
|
||||
'up': 'top',
|
||||
}
|
||||
|
||||
const element: PPTShapeElement = {
|
||||
type: 'shape',
|
||||
id: nanoid(10),
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
viewBox: [200, 200],
|
||||
path: 'M 0 0 L 200 0 L 200 200 L 0 200 Z',
|
||||
fill: el.fillColor || 'none',
|
||||
fixedRatio: false,
|
||||
rotate: el.rotate,
|
||||
outline: {
|
||||
color: el.borderColor,
|
||||
width: el.borderWidth,
|
||||
style: el.borderType,
|
||||
},
|
||||
text: {
|
||||
content: convertFontSizePtToPx(el.content, ratio),
|
||||
defaultFontName: theme.value.fontName,
|
||||
defaultColor: theme.value.fontColor,
|
||||
align: vAlignMap[el.vAlign] || 'middle',
|
||||
},
|
||||
flipH: el.isFlipH,
|
||||
flipV: el.isFlipV,
|
||||
}
|
||||
if (el.shadow) {
|
||||
element.shadow = {
|
||||
h: el.shadow.h * ratio,
|
||||
v: el.shadow.v * ratio,
|
||||
blur: el.shadow.blur * ratio,
|
||||
color: el.shadow.color,
|
||||
}
|
||||
}
|
||||
|
||||
if (shape) {
|
||||
element.path = shape.path
|
||||
element.viewBox = shape.viewBox
|
||||
|
||||
if (shape.pathFormula) {
|
||||
element.pathFormula = shape.pathFormula
|
||||
element.viewBox = [el.width, el.height]
|
||||
|
||||
const pathFormula = SHAPE_PATH_FORMULAS[shape.pathFormula]
|
||||
if ('editable' in pathFormula && pathFormula.editable) {
|
||||
element.path = pathFormula.formula(el.width, el.height, pathFormula.defaultValue)
|
||||
element.keypoints = pathFormula.defaultValue
|
||||
}
|
||||
else element.path = pathFormula.formula(el.width, el.height)
|
||||
}
|
||||
}
|
||||
if (el.shapType === 'custom') {
|
||||
if (el.path!.indexOf('NaN') !== -1) element.path = ''
|
||||
else {
|
||||
element.special = true
|
||||
element.path = el.path!
|
||||
|
||||
const { maxX, maxY } = getSvgPathRange(element.path)
|
||||
element.viewBox = [maxX || originWidth, maxY || originHeight]
|
||||
}
|
||||
}
|
||||
|
||||
if (element.path) slide.elements.push(element)
|
||||
}
|
||||
}
|
||||
else if (el.type === 'table') {
|
||||
const row = el.data.length
|
||||
const col = el.data[0].length
|
||||
|
||||
const style: TableCellStyle = {
|
||||
fontname: theme.value.fontName,
|
||||
color: theme.value.fontColor,
|
||||
}
|
||||
const data: TableCell[][] = []
|
||||
for (let i = 0; i < row; i++) {
|
||||
const rowCells: TableCell[] = []
|
||||
for (let j = 0; j < col; j++) {
|
||||
const cellData = el.data[i][j]
|
||||
|
||||
let textDiv: HTMLDivElement | null = document.createElement('div')
|
||||
textDiv.innerHTML = cellData.text
|
||||
const p = textDiv.querySelector('p')
|
||||
const align = p?.style.textAlign || 'left'
|
||||
|
||||
const span = textDiv.querySelector('span')
|
||||
const fontsize = span?.style.fontSize ? (parseInt(span?.style.fontSize) * ratio).toFixed(1) + 'px' : ''
|
||||
const fontname = span?.style.fontFamily || ''
|
||||
const color = span?.style.color || cellData.fontColor
|
||||
|
||||
rowCells.push({
|
||||
id: nanoid(10),
|
||||
colspan: cellData.colSpan || 1,
|
||||
rowspan: cellData.rowSpan || 1,
|
||||
text: textDiv.innerText,
|
||||
style: {
|
||||
...style,
|
||||
align: ['left', 'right', 'center'].includes(align) ? (align as 'left' | 'right' | 'center') : 'left',
|
||||
fontsize,
|
||||
fontname,
|
||||
color,
|
||||
bold: cellData.fontBold,
|
||||
backcolor: cellData.fillColor,
|
||||
},
|
||||
})
|
||||
textDiv = null
|
||||
}
|
||||
data.push(rowCells)
|
||||
}
|
||||
|
||||
const colWidths: number[] = new Array(col).fill(1 / col)
|
||||
|
||||
slide.elements.push({
|
||||
type: 'table',
|
||||
id: nanoid(10),
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
colWidths,
|
||||
rotate: 0,
|
||||
data,
|
||||
outline: {
|
||||
width: el.borderWidth || 2,
|
||||
style: el.borderType,
|
||||
color: el.borderColor || '#eeece1',
|
||||
},
|
||||
cellMinHeight: 36,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'chart') {
|
||||
let labels: string[]
|
||||
let legends: string[]
|
||||
let series: number[][]
|
||||
|
||||
if (el.chartType === 'scatterChart' || el.chartType === 'bubbleChart') {
|
||||
labels = el.data[0].map((item, index) => `坐标${index + 1}`)
|
||||
legends = ['X', 'Y']
|
||||
series = el.data
|
||||
}
|
||||
else {
|
||||
const data = el.data as ChartItem[]
|
||||
labels = Object.values(data[0].xlabels)
|
||||
legends = data.map(item => item.key)
|
||||
series = data.map(item => item.values.map(v => v.y))
|
||||
}
|
||||
|
||||
const options: ChartOptions = {}
|
||||
|
||||
let chartType: ChartType = 'bar'
|
||||
|
||||
switch (el.chartType) {
|
||||
case 'barChart':
|
||||
case 'bar3DChart':
|
||||
chartType = 'bar'
|
||||
if (el.barDir === 'bar') chartType = 'column'
|
||||
if (el.grouping === 'stacked' || el.grouping === 'percentStacked') options.stack = true
|
||||
break
|
||||
case 'lineChart':
|
||||
case 'line3DChart':
|
||||
if (el.grouping === 'stacked' || el.grouping === 'percentStacked') options.stack = true
|
||||
chartType = 'line'
|
||||
break
|
||||
case 'areaChart':
|
||||
case 'area3DChart':
|
||||
if (el.grouping === 'stacked' || el.grouping === 'percentStacked') options.stack = true
|
||||
chartType = 'area'
|
||||
break
|
||||
case 'scatterChart':
|
||||
case 'bubbleChart':
|
||||
chartType = 'scatter'
|
||||
break
|
||||
case 'pieChart':
|
||||
case 'pie3DChart':
|
||||
chartType = 'pie'
|
||||
break
|
||||
case 'radarChart':
|
||||
chartType = 'radar'
|
||||
break
|
||||
case 'doughnutChart':
|
||||
chartType = 'ring'
|
||||
break
|
||||
default:
|
||||
}
|
||||
|
||||
slide.elements.push({
|
||||
type: 'chart',
|
||||
id: nanoid(10),
|
||||
chartType: chartType,
|
||||
width: el.width,
|
||||
height: el.height,
|
||||
left: el.left,
|
||||
top: el.top,
|
||||
rotate: 0,
|
||||
themeColors: [theme.value.themeColor],
|
||||
textColor: theme.value.fontColor,
|
||||
data: {
|
||||
labels,
|
||||
legends,
|
||||
series,
|
||||
},
|
||||
options,
|
||||
})
|
||||
}
|
||||
else if (el.type === 'group' || el.type === 'diagram') {
|
||||
const elements = el.elements.map(_el => ({
|
||||
..._el,
|
||||
left: _el.left + originLeft,
|
||||
top: _el.top + originTop,
|
||||
}))
|
||||
parseElements(elements)
|
||||
}
|
||||
}
|
||||
}
|
||||
parseElements(item.elements)
|
||||
slides.push(slide)
|
||||
}
|
||||
resData.slides = slides
|
||||
resData.slides = await parsePptJsonSlides(json.slides, json.zip)
|
||||
resolve(resData)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ export const enum ElementTypes {
|
|||
*
|
||||
* rotate: 渐变角度(线性渐变)
|
||||
*/
|
||||
export type GradientType = 'linear' | 'radial'
|
||||
export type GradientType = 'linear' | 'radial' | 'image'
|
||||
export type GradientColor = {
|
||||
pos: number
|
||||
color: string
|
||||
|
|
|
@ -46,11 +46,12 @@
|
|||
:options="[
|
||||
{ label: '线性渐变', value: 'linear' },
|
||||
{ label: '径向渐变', value: 'radial' },
|
||||
{ label: '背景图', value: 'image' },
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<template v-if="fillType === 'gradient'">
|
||||
<template v-if="fillType === 'gradient' && gradient.type !== 'image'">
|
||||
<div class="row">
|
||||
<GradientBar
|
||||
:value="gradient.colors"
|
||||
|
@ -206,6 +207,13 @@ const updateFillType = (type: 'gradient' | 'fill') => {
|
|||
const updateGradient = (gradientProps: Partial<Gradient>) => {
|
||||
if (!gradient.value) return
|
||||
const _gradient = { ...gradient.value, ...gradientProps }
|
||||
if (!_gradient.colors) {
|
||||
_gradient.colors = [
|
||||
{ pos: 0, color: '#fff' },
|
||||
{ pos: 100, color: '#fff' },
|
||||
]
|
||||
_gradient.rotate = 0
|
||||
}
|
||||
updateElement({ gradient: _gradient })
|
||||
}
|
||||
const updateGradientColors = (color: string) => {
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
:type="elementInfo.gradient.type"
|
||||
:colors="elementInfo.gradient.colors"
|
||||
:rotate="elementInfo.gradient.rotate"
|
||||
:image="elementInfo.gradient.image"
|
||||
:info="elementInfo"
|
||||
/>
|
||||
</defs>
|
||||
<g
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
<template>
|
||||
<!-- auth:zdg 增加图片 -->
|
||||
<pattern
|
||||
v-if="type === 'image'"
|
||||
:id="id"
|
||||
:x="image?.stretch?.l || 0"
|
||||
:y="image?.stretch?.t || 0"
|
||||
:width="image?.path_W||'100%'"
|
||||
:height="image?.path_h||'100%'"
|
||||
:style="image.rotWithShape==0?'transform:rotate('+(-info.rotate)+'deg)' : ''"
|
||||
patternUnits="userSpaceOnUse">
|
||||
<image
|
||||
:width="image?.path_W||200"
|
||||
:height="image?.path_h||200"
|
||||
:href="image.src"
|
||||
:opacity="image.opacity"
|
||||
preserveAspectRatio="none"
|
||||
/>
|
||||
</pattern>
|
||||
<!-- auth:zdg 默认 线性渐变 -->
|
||||
<linearGradient
|
||||
v-if="type === 'linear'"
|
||||
v-else-if="type === 'linear'"
|
||||
:id="id"
|
||||
x1="0%"
|
||||
y1="0%"
|
||||
|
@ -10,20 +29,35 @@
|
|||
>
|
||||
<stop v-for="(item, index) in colors" :key="index" :offset="`${item.pos}%`" :stop-color="item.color" />
|
||||
</linearGradient>
|
||||
|
||||
<!-- auth:zdg 默认 径向渐变 -->
|
||||
<radialGradient :id="id" v-else>
|
||||
<stop v-for="(item, index) in colors" :key="index" :offset="`${item.pos}%`" :stop-color="item.color" />
|
||||
</radialGradient>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { GradientColor, GradientType } from '../../../../types/slides'
|
||||
|
||||
withDefaults(defineProps<{
|
||||
import type { GradientColor, GradientType, PPTShapeElement } from '../../../../types/slides'
|
||||
interface ImageSvg {
|
||||
src: string,
|
||||
width: number,
|
||||
height: number,
|
||||
zipPath: string,
|
||||
opacity: number,
|
||||
rotWithShape: string,
|
||||
stretch?: {
|
||||
l?: number,
|
||||
t?: number,
|
||||
r?: number,
|
||||
b?: number
|
||||
}
|
||||
}
|
||||
const data = withDefaults(defineProps<{
|
||||
id: string
|
||||
type: GradientType
|
||||
colors: GradientColor[]
|
||||
rotate?: number
|
||||
colors?: GradientColor[]
|
||||
rotate?: number,
|
||||
image?: ImageSvg,
|
||||
info?: PPTShapeElement
|
||||
}>(), {
|
||||
rotate: 0,
|
||||
})
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
:type="elementInfo.gradient.type"
|
||||
:colors="elementInfo.gradient.colors"
|
||||
:rotate="elementInfo.gradient.rotate"
|
||||
:image="elementInfo.gradient.image"
|
||||
:info="elementInfo"
|
||||
/>
|
||||
</defs>
|
||||
<g
|
||||
|
|
|
@ -0,0 +1,358 @@
|
|||
// import type { number } from "echarts"
|
||||
|
||||
export interface Shadow {
|
||||
h: number
|
||||
v: number
|
||||
blur: number
|
||||
color: string
|
||||
}
|
||||
|
||||
export interface Shape {
|
||||
type: 'shape'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
borderColor: string
|
||||
borderWidth: number
|
||||
borderType: 'solid' | 'dashed' | 'dotted'
|
||||
borderStrokeDasharray: string
|
||||
shadow?: Shadow
|
||||
fillColor: string
|
||||
content: string
|
||||
isFlipV: boolean
|
||||
isFlipH: boolean
|
||||
rotate: number
|
||||
shapType: string
|
||||
vAlign: string
|
||||
path?: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Text {
|
||||
type: 'text'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
borderColor: string
|
||||
borderWidth: number
|
||||
borderType: 'solid' | 'dashed' | 'dotted'
|
||||
borderStrokeDasharray: string
|
||||
shadow?: Shadow
|
||||
fillColor: string
|
||||
isFlipV: boolean
|
||||
isFlipH: boolean
|
||||
isVertical: boolean
|
||||
rotate: number
|
||||
content: string
|
||||
vAlign: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
type: 'image'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
src: string
|
||||
rotate: number
|
||||
isFlipH: boolean
|
||||
isFlipV: boolean
|
||||
}
|
||||
|
||||
export interface TableCell {
|
||||
text: string
|
||||
rowSpan?: number
|
||||
colSpan?: number
|
||||
vMerge?: number
|
||||
hMerge?: number
|
||||
fillColor?: string
|
||||
fontColor?: string
|
||||
fontBold?: boolean
|
||||
}
|
||||
export interface Table {
|
||||
type: 'table'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
data: TableCell[][]
|
||||
borderColor: string
|
||||
borderWidth: number
|
||||
borderType: 'solid' | 'dashed' | 'dotted'
|
||||
}
|
||||
|
||||
export type ChartType = 'lineChart' |
|
||||
'line3DChart' |
|
||||
'barChart' |
|
||||
'bar3DChart' |
|
||||
'pieChart' |
|
||||
'pie3DChart' |
|
||||
'doughnutChart' |
|
||||
'areaChart' |
|
||||
'area3DChart' |
|
||||
'scatterChart' |
|
||||
'bubbleChart' |
|
||||
'radarChart' |
|
||||
'surfaceChart' |
|
||||
'surface3DChart' |
|
||||
'stockChart'
|
||||
|
||||
export interface ChartValue {
|
||||
x: string
|
||||
y: number
|
||||
}
|
||||
export interface ChartXLabel {
|
||||
[key: string]: string
|
||||
}
|
||||
export interface ChartItem {
|
||||
key: string
|
||||
values: ChartValue[]
|
||||
xlabels: ChartXLabel
|
||||
}
|
||||
export type ScatterChartData = [number[], number[]]
|
||||
export interface CommonChart {
|
||||
type: 'chart'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
data: ChartItem[]
|
||||
chartType: Exclude<ChartType, 'scatterChart' | 'bubbleChart'>
|
||||
barDir?: 'bar' | 'col'
|
||||
marker?: boolean
|
||||
holeSize?: string
|
||||
grouping?: string
|
||||
style?: string
|
||||
}
|
||||
export interface ScatterChart {
|
||||
type: 'chart'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
data: ScatterChartData,
|
||||
chartType: 'scatterChart' | 'bubbleChart'
|
||||
}
|
||||
export type Chart = CommonChart | ScatterChart
|
||||
|
||||
export interface Video {
|
||||
type: 'video'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
blob?: string
|
||||
src?: string
|
||||
}
|
||||
|
||||
export interface Audio {
|
||||
type: 'audio'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
blob: string
|
||||
}
|
||||
|
||||
export interface Diagram {
|
||||
type: 'diagram'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
elements: (Shape | Text)[]
|
||||
}
|
||||
|
||||
export interface Math {
|
||||
type: 'math'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
latex: string
|
||||
}
|
||||
|
||||
export type BaseElement = Shape | Text | Image | Table | Chart | Video | Audio | Diagram | Math
|
||||
|
||||
export interface Group {
|
||||
type: 'group'
|
||||
left: number
|
||||
top: number
|
||||
width: number
|
||||
height: number
|
||||
rotate: number
|
||||
elements: BaseElement[]
|
||||
}
|
||||
export type Element = BaseElement | Group
|
||||
|
||||
export interface SlideColorFill {
|
||||
type: 'color'
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface SlideImageFill {
|
||||
type: 'image'
|
||||
value: {
|
||||
picBase64: string
|
||||
opacity: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlideGradientFill {
|
||||
type: 'gradient'
|
||||
value: {
|
||||
rot: number
|
||||
colors: {
|
||||
pos: string
|
||||
color: string
|
||||
}[]
|
||||
}
|
||||
}
|
||||
|
||||
export type SlideFill = SlideColorFill | SlideImageFill | SlideGradientFill
|
||||
|
||||
export interface Slide {
|
||||
fill: SlideFill
|
||||
elements: Element[]
|
||||
note: string
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
slideFactor?: number
|
||||
fontsizeFactor?: number
|
||||
}
|
||||
|
||||
export const parse: (file: ArrayBuffer, options?: Options) => Promise<{
|
||||
slides: Slide[]
|
||||
size: {
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
}>
|
||||
|
||||
/** zdg: 新内容 */
|
||||
export const align = {
|
||||
getHorizontalAlign?: (t,e,r,n) => string
|
||||
getVerticalAlign?: (t,e,r,n) => string
|
||||
}
|
||||
export const border = {
|
||||
getBorder?: (t,e,r) => string
|
||||
}
|
||||
export const chart = {
|
||||
getChartInfo?: (t) => string
|
||||
}
|
||||
export const color = {
|
||||
applyHueMod?: (t) => string
|
||||
applyLumMod?: (t) => string
|
||||
applyLumOff?: (t) => string
|
||||
applySatMod?: (t) => string
|
||||
applyShade?: (t) => string
|
||||
applyTint?: (t) => string
|
||||
getColorName2Hex?: (t) => string
|
||||
hslToRgb?: (t) => string
|
||||
hueToRgb?: (t) => string
|
||||
}
|
||||
export const fontStyle = {
|
||||
getFontBold?: (t) => string
|
||||
getFontColor?: (t) => string
|
||||
getFontDecoration?: (t) => string
|
||||
getFontDecorationLine?: (t) => string
|
||||
getFontItalic?: (t) => string
|
||||
getFontShadow?: (t) => string
|
||||
getFontSize?: (t) => string
|
||||
getFontSpace?: (t) => string
|
||||
getFontSubscript?: (t) => string
|
||||
getFontType?: (t) => string
|
||||
}
|
||||
export const fill = {
|
||||
getBgGradientFill?: (bgPr, phClr, slideMasterContent, warpObj) => string|object|null
|
||||
getBgPicFill?: (bgPr, sorce, warpObj) => object|null
|
||||
getFillType?: (node) => string
|
||||
getPicFill?: (type, node, warpObj) => string|null|undefined
|
||||
getPicFillBase64?: (zipPath, zipObj) => string|null|undefined
|
||||
getShapeFill?: (node, isSvgMode, warpObj) => object|null
|
||||
getShapeFillBg?: (node, source, warpObj) => object<{zipPath:string,opacity:number}>|null
|
||||
getSlideBackgroundFill?: (warpObj) => object<{type: string, value: string}>
|
||||
getSolidFill?: (solidFill, clrMap, phClr, warpObj) => string
|
||||
}
|
||||
export const math = {
|
||||
findOMath?: (t) => string
|
||||
latexFormart?: (t) => string
|
||||
parseAccent?: (t) => string
|
||||
parseBar?: (t) => string
|
||||
parseBox?: (t) => string
|
||||
parseDelimiter?: (t) => string
|
||||
parseEqArr?: (t) => string
|
||||
parseFraction?: (t) => string
|
||||
parseFunction?: (t) => string
|
||||
parseGroupChr?: (t) => string
|
||||
parseLimit?: (t) => string
|
||||
parseMatrix?: (t) => string
|
||||
parseNary?: (t) => string
|
||||
parseOMath?: (t) => string
|
||||
parseRadical?: (t) => string
|
||||
parseSubscript?: (t) => string
|
||||
parseSuperscript?: (t) => string
|
||||
}
|
||||
export const position = {
|
||||
getPosition?: (t) => string
|
||||
getPt?: (t) => string
|
||||
getSize?: (t) => string
|
||||
}
|
||||
export const readXmlFile = {
|
||||
readXmlFile?: (t) => string
|
||||
simplifyLostLess?: (t) => string
|
||||
}
|
||||
export const schemeColor = {
|
||||
getSchemeColorFromTheme?: (t) => string
|
||||
}
|
||||
export const shadow = {
|
||||
getShadow?: (t) => string
|
||||
}
|
||||
export const shape = {
|
||||
getCustomShapePath?: (t) => string
|
||||
shapeArc?: (t) => string
|
||||
}
|
||||
export const table = {
|
||||
getTableBorders?: (t) => string
|
||||
getTableCellParams?: (t) => string
|
||||
getTableRowParams?: (t) => string
|
||||
}
|
||||
export const text = {
|
||||
genSpanElement?: (t) => string
|
||||
genTextBody?: (t) => string
|
||||
getListType?: (t) => string
|
||||
}
|
||||
export const utils = {
|
||||
angleToDegrees?: (t) => string
|
||||
base64ArrayBuffer?: (t) => string
|
||||
eachElement?: (t) => string
|
||||
escapeHtml?: (t) => string
|
||||
extractFileExtension?: (t) => string
|
||||
getMimeType?: (t) => string
|
||||
getTextByPathList?: (t) => string
|
||||
isVideoLink?: (t) => string
|
||||
toHex?: (t) => string
|
||||
}
|
||||
|
||||
export const genChart: (node, warpObj) => object
|
||||
export const genDiagram: (node, warpObj) => object
|
||||
export const genShape: (node, slideLayoutSpNode, slideMasterSpNode, name, type, warpObj) => object
|
||||
export const genTable: (node, warpObj) => object
|
||||
export const getContentTypes: (zip) => object
|
||||
export const getNote: (noteContent) => string
|
||||
export const getSlideInfo: (zip) => object
|
||||
export const getSlideLayoutEl: (warpObj, isPh) => Array
|
||||
export const indexNodes: (content) => object
|
||||
export const loadTheme: (zip) => object|null
|
||||
export const processCxnSpNode: (node, warpObj) => object
|
||||
export const processGraphicFrameNode: (node, warpObj, source) => string
|
||||
export const processGroupSpNode: (node, warpObj, source) => object|null
|
||||
export const processMathNode: (t) => string
|
||||
export const processNodesInSlide: (t) => string
|
||||
export const processPicNode: (t) => string
|
||||
export const processSingleSlide: (t) => string
|
||||
export const processSpNode: (t) => string
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,138 @@
|
|||
/**
|
||||
* svg 相关工具类
|
||||
* @module svgUtils
|
||||
* import { svgUtils } from '@/utils/svgUtils'
|
||||
* @author: zdg
|
||||
*/
|
||||
|
||||
// zdg: 计算路径的边界
|
||||
export const calculatePathDimensions = (d) => {
|
||||
let minX = Infinity;
|
||||
let maxX = -Infinity;
|
||||
let minY = Infinity;
|
||||
let maxY = -Infinity;
|
||||
let currentX = 0;
|
||||
let currentY = 0;
|
||||
const commandRegex = /([A-Za-z])([^A-Za-z]+)/g;
|
||||
let match;
|
||||
while ((match = commandRegex.exec(d))!== null) {
|
||||
const type = match[1];
|
||||
const params = match[2].trim().split(/\s+|,/).map(Number);
|
||||
switch (type) {
|
||||
case 'M': // 移动到
|
||||
currentX = params[0];
|
||||
currentY = params[1];
|
||||
break;
|
||||
case 'L': // 直线到
|
||||
currentX = params[0];
|
||||
currentY = params[1];
|
||||
break;
|
||||
case 'H': // 水平直线
|
||||
currentX = params[0];
|
||||
break;
|
||||
case 'V': // 垂直直线
|
||||
currentY = params[0];
|
||||
break;
|
||||
case 'C': // 三次贝塞尔曲线
|
||||
for (let i = 0; i < params.length; i += 6) {
|
||||
const control1X = params[i];
|
||||
const control1Y = params[i + 1];
|
||||
const control2X = params[i + 2];
|
||||
const control2Y = params[i + 3];
|
||||
const endX = params[i + 4];
|
||||
const endY = params[i + 5];
|
||||
// 更新边界
|
||||
if (control1X < minX) minX = control1X;
|
||||
if (control1X > maxX) maxX = control1X;
|
||||
if (control1Y < minY) minY = control1Y;
|
||||
if (control1Y > maxY) maxY = control1Y;
|
||||
if (control2X < minX) minX = control2X;
|
||||
if (control2X > maxX) maxX = control2X;
|
||||
if (control2Y < minY) minY = control2Y;
|
||||
if (control2Y > maxY) maxY = control2Y;
|
||||
if (endX < minX) minX = endX;
|
||||
if (endX > maxX) maxX = endX;
|
||||
if (endY < minY) minY = endY;
|
||||
if (endY > maxY) maxY = endY;
|
||||
currentX = endX;
|
||||
currentY = endY;
|
||||
}
|
||||
break;
|
||||
case 'S': // 光滑三次贝塞尔曲线
|
||||
for (let i = 0; i < params.length; i += 4) {
|
||||
const controlX = params[i];
|
||||
const controlY = params[i + 1];
|
||||
const endX = params[i + 2];
|
||||
const endY = params[i + 3];
|
||||
// 更新边界
|
||||
if (controlX < minX) minX = controlX;
|
||||
if (controlX > maxX) maxX = controlX;
|
||||
if (controlY < minY) minY = controlY;
|
||||
if (controlY > maxY) maxY = controlY;
|
||||
if (endX < minX) minX = endX;
|
||||
if (endX > maxX) maxX = endX;
|
||||
if (endY < minY) minY = endY;
|
||||
if (endY > maxY) maxY = endY;
|
||||
currentX = endX;
|
||||
currentY = endY;
|
||||
}
|
||||
break;
|
||||
case 'Q': // 二次贝塞尔曲线
|
||||
for (let i = 0; i < params.length; i += 4) {
|
||||
const controlX = params[i];
|
||||
const controlY = params[i + 1];
|
||||
const endX = params[i + 2];
|
||||
const endY = params[i + 3];
|
||||
// 更新边界
|
||||
if (controlX < minX) minX = controlX;
|
||||
if (controlX > maxX) maxX = controlX;
|
||||
if (controlY < minY) minY = controlY;
|
||||
if (controlY > maxY) maxY = controlY;
|
||||
if (endX < minX) minX = endX;
|
||||
if (endX > maxX) maxX = endX;
|
||||
if (endY < minY) minY = endY;
|
||||
if (endY > maxY) maxY = endY;
|
||||
currentX = endX;
|
||||
currentY = endY;
|
||||
}
|
||||
break;
|
||||
case 'T': // 光滑二次贝塞尔曲线
|
||||
for (let i = 0; i < params.length; i += 2) {
|
||||
const endX = params[i];
|
||||
const endY = params[i + 1];
|
||||
// 更新边界
|
||||
if (endX < minX) minX = endX;
|
||||
if (endX > maxX) maxX = endX;
|
||||
if (endY < minY) minY = endY;
|
||||
if (endY > maxY) maxY = endY;
|
||||
currentX = endX;
|
||||
currentY = endY;
|
||||
}
|
||||
break;
|
||||
case 'A': // 椭圆弧
|
||||
const endX = params[5];
|
||||
const endY = params[6];
|
||||
// 更新边界
|
||||
if (endX < minX) minX = endX;
|
||||
if (endX > maxX) maxX = endX;
|
||||
if (endY < minY) minY = endY;
|
||||
if (endY > maxY) maxY = endY;
|
||||
currentX = endX;
|
||||
currentY = endY;
|
||||
break;
|
||||
case 'Z': // 闭合路径
|
||||
// 闭合路径不影响边界,这里不需要额外操作
|
||||
break;
|
||||
default:
|
||||
console.error(`Unknown command: ${type}`);
|
||||
break;
|
||||
}
|
||||
if (currentX < minX) minX = currentX;
|
||||
if (currentX > maxX) maxX = currentX;
|
||||
if (currentY < minY) minY = currentY;
|
||||
if (currentY > maxY) maxY = currentY;
|
||||
}
|
||||
const width = maxX - minX;
|
||||
const height = maxY - minY;
|
||||
return { width, height };
|
||||
}
|
|
@ -304,6 +304,8 @@ const pgDialog = ref({ // 弹窗-进度条
|
|||
|
||||
const fileInput = ref(null)
|
||||
|
||||
let pptMedia = {} // ppt媒体数据
|
||||
|
||||
const openFilePicker = () =>{
|
||||
fileInput.value.click();
|
||||
}
|
||||
|
@ -319,6 +321,7 @@ const handleFileChange = ()=> {
|
|||
const createAIPPTByFile = async (file)=> {
|
||||
pgDialog.value.visible = true
|
||||
pgDialog.value.pg.percentage = 0
|
||||
pptMedia = {} // 清空媒体数据
|
||||
const resPptJson = await PPTXFileToJson(file).catch(() => {
|
||||
ElMessageBox.alert('PPT文件转换失败!请点击素材右侧...下载文件后打开另存为PPTX文件格式再进行导入!')
|
||||
pgDialog.value.visible = false
|
||||
|
@ -394,42 +397,66 @@ const createAIPPTByFile = async (file)=> {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 将图片|音频|视频 转换为线上地址
|
||||
const getOnlineFileUrl = (data, name) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let file
|
||||
if (data instanceof Blob) { // blob类型判断
|
||||
const fileName = Date.now() + `.${name||'png'}`
|
||||
file = commUtils.blobToFile(data, fileName)
|
||||
} else if (data instanceof File) { // file类型判断
|
||||
file = data
|
||||
} else { // 其他类型 base64
|
||||
const blob = commUtils.base64ToBlob(data)
|
||||
const fileName = Date.now() + `.${name||'png'}`
|
||||
file = commUtils.blobToFile(blob, fileName)
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const res = await Api_server.Other.uploadFile(formData)
|
||||
if (res && res.code == 200){
|
||||
resolve(res?.url)
|
||||
} else { // 失败
|
||||
reject(res?.msg||'上传失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
const toRousrceUrl = async (o) => {
|
||||
if (!!o.src) { // 如果有src就转换
|
||||
const isBase64 = /^data:image\/(\w+);base64,/.test(o.src)
|
||||
const isBlobUrl = /^blob:/.test(o.src)
|
||||
// console.log('isBase64', o, isBase64)
|
||||
if (isBase64) {
|
||||
const bolb = commUtils.base64ToBlob(o.src)
|
||||
const fileName = Date.now() + '.png'
|
||||
const file = commUtils.blobToFile(bolb, fileName)
|
||||
// o.src = fileName
|
||||
// console.log('file', file)
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const res = await Api_server.Other.uploadFile(formData)
|
||||
if (res && res.code == 200){
|
||||
const url = res?.url
|
||||
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
|
||||
let onLineUrl = '' // 线上地址
|
||||
if (!!o.zipPath) onLineUrl = pptMedia[o.zipPath] || '' // 是否已上传过
|
||||
if (onLineUrl) o.src = onLineUrl // 已存在线上地址直接赋值
|
||||
else { // 不存在重新上传
|
||||
if (isBase64) { // 相同资源处理
|
||||
const url = await getOnlineFileUrl(o.src)
|
||||
url && o.zipPath && (pptMedia[o.zipPath] = url) // 缓存
|
||||
} else if (isBlobUrl) { // 视频和音频
|
||||
const res = await fetch(o.src)
|
||||
const blob = await res.blob()
|
||||
const url = await getOnlineFileUrl(blob, o.type=='video'?'mp4':'mp3')
|
||||
URL.revokeObjectURL(o.src) // 释放内存
|
||||
url &&(o.src = url)
|
||||
url && o.zipPath && (pptMedia[o.zipPath] = url) // 缓存
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理元素为shape 可能存在背景图等
|
||||
const isBg = o?.gradient?.type == 'image' && !!o?.gradient?.image
|
||||
if (isBg) {
|
||||
const {src, zipPath} = o.gradient.image || {}
|
||||
let onLineUrl = '' // 线上地址
|
||||
if (!!zipPath) onLineUrl = pptMedia[zipPath] || '' // 是否已上传过
|
||||
if (onLineUrl) o.gradient.image.src = onLineUrl // 已存在线上地址直接赋值
|
||||
else { // 重新上传
|
||||
const url = await getOnlineFileUrl(src)
|
||||
o.gradient.image.src = url
|
||||
url && zipPath && (pptMedia[zipPath] = url) // 缓存
|
||||
}
|
||||
}
|
||||
|
||||
if (o?.background?.image) await toRousrceUrl(o.background.image)
|
||||
if(o?.elements){
|
||||
for (let element of o.elements) {
|
||||
|
|
Loading…
Reference in New Issue