|
@@ -36,9 +36,10 @@ export function PowerPoint() { |
|
@@ -36,9 +36,10 @@ export function PowerPoint() { |
|
36
|
const { msg, pptMessage } = query.state || {}; //获取路由参数
|
36
|
const { msg, pptMessage } = query.state || {}; //获取路由参数
|
|
37
|
|
37
|
|
|
38
|
const localData: LocalData = getLocalData(accessStore.accessCode); //获取限制次数
|
38
|
const localData: LocalData = getLocalData(accessStore.accessCode); //获取限制次数
|
|
|
|
39
|
+ const localDataRef = useRef(localData);
|
|
39
|
const getToken = async () => {
|
40
|
const getToken = async () => {
|
|
40
|
if (!accessStore.accessCode) {
|
41
|
if (!accessStore.accessCode) {
|
|
41
|
- return message.error("请先输入登录秘钥");
|
42
|
+ return navigate(Path.Auth);
|
|
42
|
}
|
43
|
}
|
|
43
|
const res = await fetch("/api/ppt/createApiToken", {
|
44
|
const res = await fetch("/api/ppt/createApiToken", {
|
|
44
|
method: "POST",
|
45
|
method: "POST",
|
|
@@ -55,7 +56,6 @@ export function PowerPoint() { |
|
@@ -55,7 +56,6 @@ export function PowerPoint() { |
|
55
|
}
|
56
|
}
|
|
56
|
return "";
|
57
|
return "";
|
|
57
|
};
|
58
|
};
|
|
58
|
-
|
|
|
|
59
|
useEffect(() => {
|
59
|
useEffect(() => {
|
|
60
|
const initializeDocmee = async () => {
|
60
|
const initializeDocmee = async () => {
|
|
61
|
let token = localStorage.getItem("token");
|
61
|
let token = localStorage.getItem("token");
|
|
@@ -64,13 +64,15 @@ export function PowerPoint() { |
|
@@ -64,13 +64,15 @@ export function PowerPoint() { |
|
64
|
token = await getToken();
|
64
|
token = await getToken();
|
|
65
|
if (!token) {
|
65
|
if (!token) {
|
|
66
|
message.error("无效token请检查登录密码!");
|
66
|
message.error("无效token请检查登录密码!");
|
|
67
|
- return navigate(Path.Settings); // 跳转回聊天页
|
67
|
+ return navigate(Path.Auth);
|
|
68
|
}
|
68
|
}
|
|
69
|
localStorage.setItem("token", token);
|
69
|
localStorage.setItem("token", token);
|
|
70
|
}
|
70
|
}
|
|
|
|
71
|
+
|
|
71
|
if (!containerRef.current) {
|
72
|
if (!containerRef.current) {
|
|
72
|
throw new Error("Container element not found");
|
73
|
throw new Error("Container element not found");
|
|
73
|
}
|
74
|
}
|
|
|
|
75
|
+
|
|
74
|
const docmee = new DocmeeUI({
|
76
|
const docmee = new DocmeeUI({
|
|
75
|
container: containerRef.current,
|
77
|
container: containerRef.current,
|
|
76
|
page: "creator-v2",
|
78
|
page: "creator-v2",
|
|
@@ -83,19 +85,10 @@ export function PowerPoint() { |
|
@@ -83,19 +85,10 @@ export function PowerPoint() { |
|
83
|
subject: "Ai行业未来10年的发展预测",
|
85
|
subject: "Ai行业未来10年的发展预测",
|
|
84
|
},
|
86
|
},
|
|
85
|
});
|
87
|
});
|
|
86
|
- if (msg) {
|
|
|
|
87
|
- docmee.on("mounted", (msg: generateOutline) => {
|
|
|
|
88
|
- if (localData.pptMaxUses == "0") {
|
|
|
|
89
|
- message.error("你的免费次数已用完");
|
|
|
|
90
|
- return false;
|
|
|
|
91
|
- }
|
|
|
|
92
|
- docmee.changeCreatorData({ text: pptMessage }, true);
|
|
|
|
93
|
- });
|
|
|
|
94
|
- }
|
88
|
+
|
|
95
|
docmee.on("beforeGenerate", (msg: generateOutline) => {
|
89
|
docmee.on("beforeGenerate", (msg: generateOutline) => {
|
|
96
|
//生成大纲事件
|
90
|
//生成大纲事件
|
|
97
|
- console.log(localData.pptMaxUses);
|
|
|
|
98
|
- if (localData.pptMaxUses == "0") {
|
91
|
+ if (localDataRef.current.pptMaxUses == "0") {
|
|
99
|
message.error("你的免费次数已用完");
|
92
|
message.error("你的免费次数已用完");
|
|
100
|
return false;
|
93
|
return false;
|
|
101
|
}
|
94
|
}
|
|
@@ -104,6 +97,16 @@ export function PowerPoint() { |
|
@@ -104,6 +97,16 @@ export function PowerPoint() { |
|
104
|
});
|
97
|
});
|
|
105
|
});
|
98
|
});
|
|
106
|
|
99
|
|
|
|
|
100
|
+ docmee.on("mounted", (str: string) => {
|
|
|
|
101
|
+ if (msg) {
|
|
|
|
102
|
+ if (localDataRef.current.pptMaxUses == "0") {
|
|
|
|
103
|
+ message.error("你的免费次数已用完");
|
|
|
|
104
|
+ return false;
|
|
|
|
105
|
+ }
|
|
|
|
106
|
+ docmee.changeCreatorData({ text: pptMessage }, true);
|
|
|
|
107
|
+ }
|
|
|
|
108
|
+ });
|
|
|
|
109
|
+
|
|
107
|
docmee.on("charge", (msg: string) => {
|
110
|
docmee.on("charge", (msg: string) => {
|
|
108
|
//PPT生成后扣费
|
111
|
//PPT生成后扣费
|
|
109
|
// 解析 pptMaxUses 为数字
|
112
|
// 解析 pptMaxUses 为数字
|
|
@@ -121,21 +124,37 @@ export function PowerPoint() { |
|
@@ -121,21 +124,37 @@ export function PowerPoint() { |
|
121
|
|
124
|
|
|
122
|
docmee.on("error", async (msg: generateError) => {
|
125
|
docmee.on("error", async (msg: generateError) => {
|
|
123
|
//请求错误事件
|
126
|
//请求错误事件
|
|
124
|
- console.log(msg);
|
|
|
|
125
|
if (msg.data.code == 98) {
|
127
|
if (msg.data.code == 98) {
|
|
126
|
// message.error('token失效,请重试')
|
128
|
// message.error('token失效,请重试')
|
|
127
|
const token = await getToken();
|
129
|
const token = await getToken();
|
|
|
|
130
|
+ localStorage.setItem("token", token);
|
|
128
|
docmee.updateToken(token);
|
131
|
docmee.updateToken(token);
|
|
|
|
132
|
+ if (msg) {
|
|
|
|
133
|
+ if (localDataRef.current.pptMaxUses == "0") {
|
|
|
|
134
|
+ message.error("你的免费次数已用完");
|
|
|
|
135
|
+ return false;
|
|
|
|
136
|
+ }
|
|
|
|
137
|
+ docmee.changeCreatorData({ text: pptMessage }, true);
|
|
129
|
return;
|
138
|
return;
|
|
130
|
}
|
139
|
}
|
|
|
|
140
|
+ }
|
|
131
|
message.error(
|
141
|
message.error(
|
|
132
|
msg.data.code == 403 ? "请检查登录密码或网络" : msg.data.message,
|
142
|
msg.data.code == 403 ? "请检查登录密码或网络" : msg.data.message,
|
|
133
|
);
|
143
|
);
|
|
134
|
});
|
144
|
});
|
|
135
|
- return () => docmee.destroy();
|
|
|
|
136
|
};
|
145
|
};
|
|
137
|
- initializeDocmee().catch(console.error);
|
|
|
|
138
|
- }, [navigate, isMobileScreen, msg, pptMessage]);
|
146
|
+ initializeDocmee();
|
|
|
|
147
|
+ }, [
|
|
|
|
148
|
+ navigate,
|
|
|
|
149
|
+ isMobileScreen,
|
|
|
|
150
|
+ pptMessage,
|
|
|
|
151
|
+ config.theme,
|
|
|
|
152
|
+ accessStore.accessCode,
|
|
|
|
153
|
+ ]);
|
|
|
|
154
|
+
|
|
|
|
155
|
+ useEffect(() => {
|
|
|
|
156
|
+ localDataRef.current = localData;
|
|
|
|
157
|
+ }, [localData]);
|
|
139
|
|
158
|
|
|
140
|
return (
|
159
|
return (
|
|
141
|
<>
|
160
|
<>
|