解决ppt生成失败的问题

This commit is contained in:
朱浩 2024-10-17 11:18:35 +08:00
parent 39aa3b157d
commit 670c457a9f
2 changed files with 37 additions and 15 deletions

View File

@ -1,27 +1,49 @@
import axios from "axios"; import axios from "axios";
import { getSignature } from "./index"; import { getSignature } from "./index";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import request from '@/utils/request'
let appId = "01ec9aa3"; let appId = "01ec9aa3";
let secret = "M2QxMDAxMjYyYTEzODMwMGRkZTQ4NmUy"; let secret = "M2QxMDAxMjYyYTEzODMwMGRkZTQ4NmUy";
let timestamp = Math.floor(Date.now() / 1000); let timestamp = Math.floor(Date.now() / 1000);
let signature = getSignature(appId, secret, timestamp); let signature = getSignature(appId, secret, timestamp);
let req = (url, type, data)=>{
let config = {
headers: {
"Content-Type": "application/json",
appId: appId,
timestamp: timestamp,
signature: signature,
},
url: url,
method: type,
}
if (type === "GET") {
config.params = data;
} else {
config.data = data;
}
return request(config)
}
const instance = axios.create({ /*const instance = axios.create({
baseURL: "", // baseURL: import.meta.env.VITE_APP_ENV === "development"?"/parth":import.meta.env.VITE_APP_BASE_API,
baseURL: "/dev-api",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
'Authorization': 'Bearer ' + getToken(),
appId: appId, appId: appId,
timestamp: timestamp, timestamp: timestamp,
signature: signature, signature: signature,
}, },
}); });*/
const createOutline = async (data) => { const createOutline = async (data) => {
console.log("createOutline data:", data); console.log("createOutline data:", data);
try { try {
const response = await instance.post( const response = await req(
"/parth/api/aippt/createOutline", "/api/aippt/createOutline",
"POST",
data data
); );
console.log("createOutline response:", response); console.log("createOutline response:", response);
@ -36,7 +58,7 @@ const createOutline = async (data) => {
}; };
const getBackGround = async () => { const getBackGround = async () => {
try { try {
const response = await instance.get("/parth/api/aippt/themeList"); const response = await req("/api/aippt/themeList", "GET");
return response.data; return response.data;
} catch (error) { } catch (error) {
console.error("请求失败:", error); console.error("请求失败:", error);
@ -45,7 +67,7 @@ const getBackGround = async () => {
}; };
const createPPT = async (data) => { const createPPT = async (data) => {
try { try {
const response = await instance.post("/parth/api/aippt/create", data); const response = await req("/api/aippt/create", "POST", data);
console.log("createOutline response:", response); console.log("createOutline response:", response);
return response.data; return response.data;
@ -56,7 +78,7 @@ const createPPT = async (data) => {
}; };
const createByOutline = async (data) => { const createByOutline = async (data) => {
try { try {
const response = await instance.post("/parth/api/aippt/createByOutline", data); const response = await req("/api/aippt/createByOutline","POST", data);
console.log("createByOutline response:", response); console.log("createByOutline response:", response);
return response.data; return response.data;
@ -67,7 +89,7 @@ const createByOutline = async (data) => {
}; };
const getProgress = async (id) => { const getProgress = async (id) => {
try { try {
const response = await instance.get(`/parth/api/aippt/progress?sid=${id}`); const response = await req(`/api/aippt/progress?sid=${id}`, "GET");
return response.data; return response.data;
} catch (error) { } catch (error) {
console.error("请求失败:", error); console.error("请求失败:", error);
@ -75,4 +97,4 @@ const getProgress = async (id) => {
} }
}; };
export { instance, createOutline, getBackGround, createPPT, getProgress, createByOutline }; export { createOutline, getBackGround, createPPT, getProgress, createByOutline };

View File

@ -178,7 +178,7 @@ const getBackground = () => {
treeData.value = []; treeData.value = [];
getBackGround().then((res) => { getBackGround().then((res) => {
console.log(res); console.log(res);
backGroundList.value = res.data; backGroundList.value = res;
}); });
}; };
@ -222,14 +222,14 @@ const outlineCreatePPT = () => {
activeStep.value = 4 activeStep.value = 4
const checkProgress = () => { const checkProgress = () => {
getProgress(res.data.sid).then((response) => { getProgress(res.sid).then((response) => {
percentage.value = response.data.process; percentage.value = response.process;
if (response.data && response.data.pptUrl && response.data.pptUrl.length > 4) { if (response && response.pptUrl && response.pptUrl.length > 4) {
console.log('PPT',response) console.log('PPT',response)
// window.location.href = response.data.pptUrl; // window.location.href = response.data.pptUrl;
//URLURL //URLURL
// 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" // 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) => { creatAIPPT(props.currentNode.itemtitle + '.pptx',response.pptUrl, props.uploadData).then((res) => {
emit('addSuccess',res) emit('addSuccess',res)
}) })
ElMessage.success("生成成功"); ElMessage.success("生成成功");