Merge pull request 'zxl' (#107) from zxl into main

Reviewed-on: #107
This commit is contained in:
zhangxuelin 2024-12-11 09:59:16 +08:00
commit 82b70558c2
4 changed files with 89 additions and 47 deletions

View File

@ -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)
}

View File

@ -56,4 +56,5 @@ export class Other {
static baseUrl = "/common/upload"
// 测试
static uploadFile = data => ApiService.publicHttp(this.baseUrl, data, 'post', null, 'file')
}

View File

@ -524,7 +524,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'
@ -539,11 +539,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
@ -559,6 +577,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({
@ -595,6 +615,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,

View File

@ -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 ============