...
|
...
|
@@ -12,32 +12,15 @@ import { CreatorType, DocmeeUI } from "@docmee/sdk-ui"; |
|
|
import { getClientConfig } from "@/app/config/client";
|
|
|
import { useAppConfig, useAccessStore } from "@/app/store";
|
|
|
import type { generateError, generateOutline } from "@/app/types/docmee";
|
|
|
import type { LocalData } from "@/app/types/zuotang";
|
|
|
import { useLocalStorage } from "../bgRemoval";
|
|
|
import axios from "axios";
|
|
|
|
|
|
import ReturnIcon from "@/app/icons/return.svg";
|
|
|
import MinIcon from "@/app/icons/min.svg";
|
|
|
import MaxIcon from "@/app/icons/max.svg";
|
|
|
import { message } from "antd";
|
|
|
|
|
|
// 错误消息映射
|
|
|
const errorMap: { [key: number]: string } = {
|
|
|
[-1]: "操作失败",
|
|
|
[88]: "功能受限(积分已用完 或 非VIP)",
|
|
|
[98]: "认证失败(检查token是否过期)",
|
|
|
[99]: "登录过期",
|
|
|
[1001]: "数据不存在",
|
|
|
[1002]: "数据访问异常",
|
|
|
[1003]: "无权限访问",
|
|
|
[1006]: "内容涉及敏感信息",
|
|
|
[1009]: "AI服务异常",
|
|
|
[1010]: "你的次数已用完",
|
|
|
[1012]: "请求太频繁,限流",
|
|
|
};
|
|
|
|
|
|
// 获取错误消息的函数
|
|
|
const getErrorMessage = (errorCode: number): string => {
|
|
|
return errorMap[errorCode] || `未知错误(错误码:${errorCode})`;
|
|
|
};
|
|
|
|
|
|
export function PowerPoint() {
|
|
|
const accessStore = useAccessStore();
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
...
|
...
|
@@ -48,20 +31,23 @@ export function PowerPoint() { |
|
|
const showMaxIcon = !isMobileScreen && !clientConfig?.isApp;
|
|
|
const config = useAppConfig();
|
|
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
|
const { updateLocalUsage, getLocalData } = useLocalStorage();
|
|
|
const query = useLocation(); //获取路由参数
|
|
|
const { msg, pptMessage } = query.state || {}; //获取路由参数
|
|
|
|
|
|
const query = useLocation();
|
|
|
const { msg, pptMessage } = query.state || {};
|
|
|
|
|
|
const localData: LocalData = getLocalData(accessStore.accessCode); //获取限制次数
|
|
|
const getToken = async () => {
|
|
|
if (!accessStore.accessCode) {
|
|
|
return message.error("请先输入登录秘钥");
|
|
|
}
|
|
|
const res = await fetch("/api/ppt/createApiToken", {
|
|
|
method: "POST",
|
|
|
body: JSON.stringify(accessStore.accessCode),
|
|
|
body: JSON.stringify({
|
|
|
accessCode: accessStore.accessCode,
|
|
|
max_use: localData.pptMaxUses,
|
|
|
}),
|
|
|
});
|
|
|
const data = await res.json();
|
|
|
console.log(data);
|
|
|
if (data.status == 200) {
|
|
|
return data.data.data.token;
|
|
|
} else {
|
...
|
...
|
@@ -89,7 +75,7 @@ export function PowerPoint() { |
|
|
container: containerRef.current,
|
|
|
page: "creator-v2",
|
|
|
token: token,
|
|
|
mode: "light",
|
|
|
mode: config.theme as "dark" | "light",
|
|
|
lang: "zh",
|
|
|
isMobile: isMobileScreen,
|
|
|
creatorData: {
|
...
|
...
|
@@ -99,19 +85,52 @@ export function PowerPoint() { |
|
|
});
|
|
|
if (msg) {
|
|
|
docmee.on("mounted", (msg: generateOutline) => {
|
|
|
if (localData.pptMaxUses == "0") {
|
|
|
message.error("你的免费次数已用完");
|
|
|
return false;
|
|
|
}
|
|
|
docmee.changeCreatorData({ text: pptMessage }, true);
|
|
|
});
|
|
|
}
|
|
|
docmee.on("beforeGenerate", (msg: generateOutline) => {
|
|
|
//生成大纲事件
|
|
|
console.log(localData.pptMaxUses);
|
|
|
if (localData.pptMaxUses == "0") {
|
|
|
message.error("你的免费次数已用完");
|
|
|
return false;
|
|
|
}
|
|
|
axios.post("https://docmee.cn/api/ppt/v2/generateContent", msg, {
|
|
|
headers: { token: token },
|
|
|
});
|
|
|
});
|
|
|
docmee.on("error", (msg: generateError) => {
|
|
|
|
|
|
docmee.on("charge", (msg: string) => {
|
|
|
//PPT生成后扣费
|
|
|
// 解析 pptMaxUses 为数字
|
|
|
let max_use = parseInt(localData.pptMaxUses, 10);
|
|
|
// 校验解析结果是否为有效数字
|
|
|
if (isNaN(max_use)) {
|
|
|
max_use = 0; // 如果解析失败,设置默认值为 0
|
|
|
}
|
|
|
max_use = max_use - 1;
|
|
|
if (max_use < 0) {
|
|
|
max_use = 0;
|
|
|
}
|
|
|
updateLocalUsage(accessStore.accessCode, undefined, max_use);
|
|
|
});
|
|
|
|
|
|
docmee.on("error", async (msg: generateError) => {
|
|
|
//请求错误事件
|
|
|
console.log(msg);
|
|
|
if (msg.data.code == 98) {
|
|
|
// message.error('token失效,请重试')
|
|
|
const token = await getToken();
|
|
|
docmee.updateToken(token);
|
|
|
return;
|
|
|
}
|
|
|
message.error(msg.data.message);
|
|
|
message.error(
|
|
|
msg.data.code == 403 ? "请检查登录密码或网络" : msg.data.message,
|
|
|
);
|
|
|
});
|
|
|
return () => docmee.destroy();
|
|
|
};
|
...
|
...
|
|