feat: 实装AI改写结局功能 - 接入DeepSeek API - AI动态生成新结局名称 - 新增rewrite类型结局样式 - 修复请求超时问题
This commit is contained in:
@@ -137,10 +137,10 @@ export default class StoryManager {
|
||||
ending_name: ending?.name,
|
||||
ending_content: ending?.content,
|
||||
prompt: prompt
|
||||
});
|
||||
}, { timeout: 60000 });
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('AI改写失败:', error);
|
||||
console.error('AI改写失败:', error?.errMsg || error?.message || JSON.stringify(error));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export default class EndingScene extends BaseScene {
|
||||
super(main, params);
|
||||
this.storyId = params.storyId;
|
||||
this.ending = params.ending;
|
||||
console.log('EndingScene 接收到的结局:', JSON.stringify(this.ending));
|
||||
this.showButtons = false;
|
||||
this.fadeIn = 0;
|
||||
this.particles = [];
|
||||
@@ -103,6 +104,11 @@ export default class EndingScene extends BaseScene {
|
||||
gradient.addColorStop(0.5, '#3a3515');
|
||||
gradient.addColorStop(1, '#2d2d1f');
|
||||
break;
|
||||
case 'rewrite':
|
||||
gradient.addColorStop(0, '#1a0a2e');
|
||||
gradient.addColorStop(0.5, '#2d1b4e');
|
||||
gradient.addColorStop(1, '#4a1942');
|
||||
break;
|
||||
default:
|
||||
gradient.addColorStop(0, '#0f0c29');
|
||||
gradient.addColorStop(0.5, '#302b63');
|
||||
@@ -195,6 +201,7 @@ export default class EndingScene extends BaseScene {
|
||||
case 'good': return '✨ 完美结局';
|
||||
case 'bad': return '💔 悲伤结局';
|
||||
case 'hidden': return '🔮 隐藏结局';
|
||||
case 'rewrite': return '🤖 AI改写结局';
|
||||
default: return '📖 普通结局';
|
||||
}
|
||||
}
|
||||
@@ -239,6 +246,7 @@ export default class EndingScene extends BaseScene {
|
||||
case 'good': return `rgba(100, 255, 150, ${alpha})`;
|
||||
case 'bad': return `rgba(255, 100, 100, ${alpha})`;
|
||||
case 'hidden': return `rgba(255, 215, 0, ${alpha})`;
|
||||
case 'rewrite': return `rgba(168, 85, 247, ${alpha})`;
|
||||
default: return `rgba(150, 150, 255, ${alpha})`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,6 +538,21 @@ export default class StoryScene extends BaseScene {
|
||||
if (this.waitingForClick) {
|
||||
this.waitingForClick = false;
|
||||
|
||||
// AI改写内容 - 直接跳转到新结局
|
||||
if (this.aiContent && this.aiContent.is_ending) {
|
||||
console.log('AI改写内容:', JSON.stringify(this.aiContent));
|
||||
this.main.sceneManager.switchScene('ending', {
|
||||
storyId: this.storyId,
|
||||
ending: {
|
||||
name: this.aiContent.ending_name,
|
||||
type: this.aiContent.ending_type,
|
||||
content: this.aiContent.content,
|
||||
score: 100
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是结局
|
||||
if (this.main.storyManager.isEnding()) {
|
||||
this.main.sceneManager.switchScene('ending', {
|
||||
|
||||
@@ -10,20 +10,18 @@ const BASE_URL = 'http://localhost:3000/api';
|
||||
*/
|
||||
export function request(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error('请求超时'));
|
||||
}, 5000);
|
||||
|
||||
const timeoutMs = options.timeout || 30000;
|
||||
|
||||
wx.request({
|
||||
url: BASE_URL + options.url,
|
||||
method: options.method || 'GET',
|
||||
data: options.data || {},
|
||||
timeout: timeoutMs,
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.header
|
||||
},
|
||||
success(res) {
|
||||
clearTimeout(timeout);
|
||||
if (res.data.code === 0) {
|
||||
resolve(res.data.data);
|
||||
} else {
|
||||
@@ -31,7 +29,6 @@ export function request(options) {
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
clearTimeout(timeout);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
@@ -48,8 +45,8 @@ export function get(url, data) {
|
||||
/**
|
||||
* POST请求
|
||||
*/
|
||||
export function post(url, data) {
|
||||
return request({ url, method: 'POST', data });
|
||||
export function post(url, data, options = {}) {
|
||||
return request({ url, method: 'POST', data, ...options });
|
||||
}
|
||||
|
||||
export default { request, get, post };
|
||||
|
||||
Reference in New Issue
Block a user