feat: 结局AI改写支持pathHistory回放和完成通知

This commit is contained in:
wangwuww111
2026-03-10 14:19:13 +08:00
parent aa23db8a89
commit 2b941cc4e0
5 changed files with 119 additions and 29 deletions

View File

@@ -1080,6 +1080,9 @@ export default class EndingScene extends BaseScene {
showCancel: false,
confirmText: '知道了'
});
// 启动专门的草稿检查每5秒检查一次持续2分钟
this.startDraftPolling(result.draftId);
} else {
wx.showToast({ title: '提交失败,请重试', icon: 'none' });
}
@@ -1130,6 +1133,9 @@ export default class EndingScene extends BaseScene {
showCancel: false,
confirmText: '知道了'
});
// 启动专门的草稿检查每5秒检查一次持续2分钟
this.startDraftPolling(result.draftId);
} else {
wx.showToast({ title: '提交失败,请重试', icon: 'none' });
}
@@ -1189,4 +1195,69 @@ export default class EndingScene extends BaseScene {
this.isCollected = !this.isCollected;
this.main.userManager.collectStory(this.storyId, this.isCollected);
}
// 启动草稿完成轮询每5秒检查一次持续2分钟
startDraftPolling(draftId) {
// 清除之前的轮询
if (this.draftPollTimer) {
clearInterval(this.draftPollTimer);
}
let pollCount = 0;
const maxPolls = 24; // 2分钟 / 5秒 = 24次
console.log('[EndingScene] 启动草稿轮询, draftId:', draftId);
this.draftPollTimer = setInterval(async () => {
pollCount++;
if (pollCount > maxPolls) {
console.log('[EndingScene] 轮询超时,停止检查');
clearInterval(this.draftPollTimer);
this.draftPollTimer = null;
return;
}
try {
const userId = this.main.userManager.userId;
if (!userId) return;
const result = await this.main.storyManager.checkNewDrafts(userId);
if (result && result.hasNew && result.count > 0) {
console.log('[EndingScene] 检测到新草稿:', result.count);
// 停止轮询
clearInterval(this.draftPollTimer);
this.draftPollTimer = null;
// 标记为已读
await this.main.storyManager.markAllDraftsRead(userId);
// 弹窗通知
wx.showModal({
title: 'AI改写完成',
content: `您有 ${result.count} 个新的AI改写已完成是否前往查看`,
confirmText: '查看',
cancelText: '稍后',
success: (res) => {
if (res.confirm) {
this.main.sceneManager.switchScene('profile', { tab: 1 });
}
}
});
}
} catch (e) {
console.warn('[EndingScene] 草稿检查失败:', e);
}
}, 5000); // 每5秒检查一次
}
// 场景销毁时清理轮询
destroy() {
if (this.draftPollTimer) {
clearInterval(this.draftPollTimer);
this.draftPollTimer = null;
}
}
}