import { Card, Descriptions, Empty, Typography, Button, Modal, Form, Input, message } from 'antd';
import { GlobalOutlined, EditOutlined } from '@ant-design/icons';
import { useState } from 'react';
import { useStore } from '../store';
import { cardStyles } from '../components/CardStyles';
import { projectApi } from '../services/api';
const { Title, Paragraph } = Typography;
const { TextArea } = Input;
export default function WorldSetting() {
const { currentProject, setCurrentProject } = useStore();
const [isEditModalVisible, setIsEditModalVisible] = useState(false);
const [editForm] = Form.useForm();
const [isSaving, setIsSaving] = useState(false);
if (!currentProject) return null;
// 检查是否有世界设定信息
const hasWorldSetting = currentProject.world_time_period ||
currentProject.world_location ||
currentProject.world_atmosphere ||
currentProject.world_rules;
if (!hasWorldSetting) {
return (
{/* 固定头部 */}
世界设定
{/* 可滚动内容区域 */}
世界设定信息在创建项目向导中生成,用于构建小说的世界观背景。
);
}
return (
{/* 固定头部 */}
世界设定
}
onClick={() => {
editForm.setFieldsValue({
world_time_period: currentProject.world_time_period || '',
world_location: currentProject.world_location || '',
world_atmosphere: currentProject.world_atmosphere || '',
world_rules: currentProject.world_rules || '',
});
setIsEditModalVisible(true);
}}
>
编辑世界观
{/* 可滚动内容区域 */}
基础信息
}
>
{currentProject.title}
{currentProject.description && (
{currentProject.description}
)}
{currentProject.theme || '未设定'}
{currentProject.genre || '未设定'}
{currentProject.narrative_perspective || '未设定'}
{currentProject.target_words ? `${currentProject.target_words.toLocaleString()} 字` : '未设定'}
小说世界观
}
>
{currentProject.world_time_period && (
时间设定
{currentProject.world_time_period}
)}
{currentProject.world_location && (
地点设定
{currentProject.world_location}
)}
{currentProject.world_atmosphere && (
氛围设定
{currentProject.world_atmosphere}
)}
{currentProject.world_rules && (
规则设定
{currentProject.world_rules}
)}
{/* 编辑世界观模态框 */}
{
setIsEditModalVisible(false);
editForm.resetFields();
}}
onOk={async () => {
try {
const values = await editForm.validateFields();
setIsSaving(true);
const updatedProject = await projectApi.updateProject(currentProject.id, {
world_time_period: values.world_time_period,
world_location: values.world_location,
world_atmosphere: values.world_atmosphere,
world_rules: values.world_rules,
});
setCurrentProject(updatedProject);
message.success('世界观更新成功');
setIsEditModalVisible(false);
editForm.resetFields();
} catch (error) {
console.error('更新世界观失败:', error);
message.error('更新失败,请重试');
} finally {
setIsSaving(false);
}
}}
confirmLoading={isSaving}
width={800}
okText="保存"
cancelText="取消"
>
);
}