接入AI生成PPT的功能
This commit is contained in:
parent
d1f3abcc72
commit
8a90da5b64
|
@ -243,6 +243,78 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
|||
})
|
||||
})
|
||||
|
||||
/*创建新的ppt文件*/
|
||||
ipcMain.on('creat-ai-file-default', (e, { name, url, uploadData, cookie }) => {
|
||||
createFolder('tempFile').then(async () => {
|
||||
let path = appTempFilePath + name.replace(/[\\/:*?"<>|]/, '')
|
||||
let {type,item} = await downloadFile(url,name)
|
||||
if (type==="成功") {
|
||||
let fileType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||
let formData = new FormData()
|
||||
for (let key in uploadData) {
|
||||
if (Object.prototype.hasOwnProperty.call(uploadData, key)) {
|
||||
// 检查是否是对象自身的属性
|
||||
formData.append(key, uploadData[key])
|
||||
}
|
||||
}
|
||||
formData.append('fileFlag', '课件')
|
||||
uploadFileByFS({
|
||||
url: uploadUrl,
|
||||
path,
|
||||
name,
|
||||
cookie,
|
||||
fileType,
|
||||
formData,
|
||||
success: (response) => {
|
||||
e.reply('creat-ai-file-default-reply', response.data)
|
||||
console.log('File uploaded successfully:', response.data)
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error uploading file:', err)
|
||||
}
|
||||
})
|
||||
}else {
|
||||
e.reply('creat-ai-file-default-reply', type)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function downloadFile(url,fileName) {
|
||||
return new Promise((resolve, reject)=>{
|
||||
const browserWindow = BrowserWindow.getFocusedWindow()
|
||||
const id = manager.download({
|
||||
window: browserWindow,
|
||||
url: url,
|
||||
saveAsFilename: fileName,
|
||||
directory: appTempFilePath,
|
||||
callbacks: {
|
||||
onDownloadStarted: async ({ id, item, webContents }) => {
|
||||
// Do something with the download id
|
||||
},
|
||||
onDownloadProgress: async ({ id, item, percentCompleted }) => {
|
||||
// console.log(percentCompleted)
|
||||
},
|
||||
onDownloadCompleted: async ({ id, item }) => {
|
||||
console.log('完成')
|
||||
resolve({type:"成功",item})
|
||||
},
|
||||
onDownloadCancelled: async () => {
|
||||
console.log("取消")
|
||||
reject({type:"取消了下载"})
|
||||
},
|
||||
onDownloadInterrupted: async () => {
|
||||
console.log('中断')
|
||||
reject({type:"下载被中断"})
|
||||
},
|
||||
onError: (err, data) => {
|
||||
console.log(err.toString())
|
||||
reject({type:"下载出错",err})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//获取应用文件目录
|
||||
ipcMain.on('get-root-file-path', (e) => {
|
||||
e.reply('get-root-file-path-reply', appRootFilePath)
|
||||
|
|
|
@ -96,3 +96,19 @@ export const creatPPT = (name, uploadData) => {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const creatAIPPT = (name, url, uploadData) => {
|
||||
JSON.parse(JSON.stringify(uploadData))
|
||||
return new Promise((resolve, reject) => {
|
||||
let cookie = localStorage.getItem('Admin-Token')
|
||||
ipcRenderer.send('creat-ai-file-default', {
|
||||
name,
|
||||
url,
|
||||
uploadData: JSON.parse(JSON.stringify(uploadData)),
|
||||
cookie
|
||||
})
|
||||
ipcRenderer.once('creat-ai-file-default-reply', (e, res) => {
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<el-card class="card2" v-if="activeStep == 1">
|
||||
<div class="paragraphs">
|
||||
{{ outputText }}
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-card class="card3" v-if="activeStep == 2">
|
||||
<div class="outline">
|
||||
|
@ -130,6 +130,7 @@
|
|||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { creatAIPPT } from '@/utils/talkFile'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
getBackGround,
|
||||
|
@ -195,6 +196,18 @@ const outlineData = ref({
|
|||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits(['addSuccess'])
|
||||
const props = defineProps({
|
||||
currentNode: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
},
|
||||
uploadData: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
}
|
||||
})
|
||||
|
||||
// 将输入数据或返回数据存入记忆中
|
||||
function updateStagingData(role, newData) {
|
||||
stagingData.value.push({ role: role, content: newData });
|
||||
|
@ -213,7 +226,12 @@ const outlineCreatePPT = () => {
|
|||
percentage.value = response.data.process;
|
||||
if (response.data && response.data.pptUrl && response.data.pptUrl.length > 4) {
|
||||
console.log('PPT',response)
|
||||
//TODO window.location.href = response.data.pptUrl;
|
||||
// window.location.href = response.data.pptUrl;
|
||||
//发消息到主进程,携带名称和URL,将URL下载下来后复制到文件列表并上传到服务
|
||||
// let url = "https://bjcdn.openstorage.cn/xinghuo-privatedata/%2Ftmp/apiTempFiledf28bf990a4c40ffb7477ed4b65392c27232357022409613439/%E3%80%8A%E9%9D%99%E5%A5%B3%E3%80%8B%E6%B7%B1%E5%BA%A6%E8%A7%A3%E8%AF%BB%E4%B8%8E%E7%A0%94%E7%A9%B6.pptx"
|
||||
creatAIPPT(props.currentNode.itemtitle + '.pptx',response.data.pptUrl, props.uploadData).then((res) => {
|
||||
emit('addSuccess',res)
|
||||
})
|
||||
ElMessage.success("生成成功");
|
||||
} else {
|
||||
const sleepTime = 2000;
|
||||
|
@ -602,6 +620,10 @@ const changeCursor = (cursorStyle) => {
|
|||
};
|
||||
|
||||
onMounted(() => {
|
||||
// let url = "https://bjcdn.openstorage.cn/xinghuo-privatedata/%2Ftmp/apiTempFiledf28bf990a4c40ffb7477ed4b65392c27232357022409613439/%E3%80%8A%E9%9D%99%E5%A5%B3%E3%80%8B%E6%B7%B1%E5%BA%A6%E8%A7%A3%E8%AF%BB%E4%B8%8E%E7%A0%94%E7%A9%B6.pptx"
|
||||
// creatAIPPT(props.currentNode.itemtitle + '.pptx',url, props.uploadData).then((res) => {
|
||||
// emit('addSuccess',res)
|
||||
// })
|
||||
connectWebSocket("");
|
||||
getBackground();
|
||||
});
|
||||
|
|
|
@ -7,14 +7,28 @@
|
|||
<i class="iconfont icon-guanbi" @click="close"></i>
|
||||
</div>
|
||||
</template>
|
||||
<AiPpt/>
|
||||
<AiPpt @add-success="addAiPPT" :currentNode="currentNode" :uploadData="uploadData"/>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import AiPpt from './ai-ppt.vue';
|
||||
const model = defineModel()
|
||||
const model = defineModel()
|
||||
const emit = defineEmits(['addSuccess'])
|
||||
const props = defineProps({
|
||||
currentNode: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
},
|
||||
uploadData: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
}
|
||||
})
|
||||
const addAiPPT = (data) => {
|
||||
emit('addSuccess', data)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
@ -30,4 +44,4 @@
|
|||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -138,12 +138,13 @@
|
|||
></reserv>
|
||||
<!-- 上课配置 -->
|
||||
<class-start ref="calssRef" @close="closeChange"/>
|
||||
<PptDialog v-model="pptDialog"/>
|
||||
<PptDialog @add-success="addAiPPT" :currentNode="currentNode" :uploadData="uploadData" v-model="pptDialog"/>
|
||||
</template>
|
||||
<script setup>
|
||||
import { Check,Plus } from '@element-plus/icons-vue'
|
||||
import Reserv from '@/views/prepare/container/reserv.vue'
|
||||
import { ArrowDown } from '@element-plus/icons-vue'
|
||||
import PptDialog from '@/views/prepare/container/ppt-dialog.vue'
|
||||
</script>
|
||||
<script>
|
||||
const Remote = require('@electron/remote')
|
||||
|
@ -156,7 +157,6 @@ import { useToolState } from '@/store/modules/tool'
|
|||
import MoveFile from '@/components/move-file/index.vue'
|
||||
import FileListItem from '@/views/prepare/container/file-list-item.vue'
|
||||
import KjListItem from '@/views/prepare/container/kj-list-item.vue'
|
||||
import PptDialog from './container/ppt-dialog.vue'
|
||||
import { getSmarttalkPage, moveSmarttalk, creatAPT } from '@/api/file'
|
||||
import { toTimeText } from '@/utils/date'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
@ -287,6 +287,10 @@ export default {
|
|||
// }
|
||||
// },
|
||||
methods: {
|
||||
addAiPPT(item) {
|
||||
this.currentFileList.unshift(item.resData)
|
||||
this.pptDialog = false
|
||||
},
|
||||
// 开始上课
|
||||
startClass(item, classObj) {
|
||||
// 关闭状态,打开上课相关功能(已打开,忽略)
|
||||
|
|
Loading…
Reference in New Issue