// src/pages/story/components/TimelineItemDrawer.tsx import TimelineImage from '@/components/TimelineImage'; import { Comments } from '@/components/Comments'; import { ReactionBar } from '@/components/Reactions'; import useComments from '@/hooks/useComments'; import useReactions from '@/hooks/useReactions'; import { StoryItem } from '@/pages/story/data'; import { queryStoryItemImages } from '@/pages/story/service'; import { DeleteOutlined, EditOutlined } from '@ant-design/icons'; import { useIntl, useRequest } from '@umijs/max'; import { Button, Divider, Drawer, Popconfirm, Space, Tag, theme } from 'antd'; import React, { useEffect } from 'react'; // 格式化时间数组为易读格式 const formatTimeArray = (time: string | number[] | undefined): string => { if (!time) return ''; // 如果是数组格式 [2025, 12, 23, 8, 55, 39] if (Array.isArray(time)) { const [year, month, day, hour, minute, second] = time; return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}:${String(second).padStart(2, '0')}`; } // 如果已经是字符串格式,直接返回 return String(time); }; interface Props { storyItem: StoryItem; open: boolean; setOpen: React.Dispatch>; handleDelete: () => void; handOption: (item: StoryItem, option: 'add' | 'edit' | 'addSubItem' | 'editSubItem') => void; disableEdit?: boolean; } const TimelineItemDrawer: React.FC = (props) => { const { storyItem, open, setOpen, handleDelete, handOption, disableEdit } = props; const intl = useIntl(); const { token } = theme.useToken(); const { data: imagesList, run } = useRequest( async (itemId) => { return await queryStoryItemImages(itemId); }, { manual: true, }, ); // Initialize comments for this story item const { comments, loading: commentsLoading, createLoading, updateLoading, deleteLoading, addComment, updateComment, deleteComment, } = useComments({ entityType: 'story', entityId: storyItem.instanceId || '', autoFetch: open, autoSubscribe: open, }); // Initialize reactions for this story item const { reactions, userReaction, addReaction, updateReaction, removeReaction, actionLoading: reactionLoading, } = useReactions('story', storyItem.instanceId || '', { autoFetch: open, autoSubscribe: open, }); useEffect(() => { if (open) { run(storyItem.instanceId); } }, [open]); const closeDrawer = () => { setOpen(false); }; // 格式化日期显示 const formatDate = (dateString: string | number[] | undefined) => { if (!dateString) return ''; const formattedTime = formatTimeArray(dateString); const date = new Date(formattedTime); return date.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', }); }; return ( <> {/* 只在打开时渲染抽屉 */}

{storyItem.title}

{storyItem.createName && ( 创建: {storyItem.createName} )} {storyItem.updateName && storyItem.updateName !== storyItem.createName && ( 更新: {storyItem.updateName} )}
{formatTimeArray(storyItem.storyItemTime)} {storyItem.location ? `于${storyItem.location}` : ''}
} footer={ disableEdit &&
{ e?.stopPropagation(); handleDelete(); }} okText={intl.formatMessage({ id: 'story.yes' })} cancelText={intl.formatMessage({ id: 'story.no' })} >
}>

描述

{storyItem.description}

{/* 时刻图库 */} {imagesList && imagesList.length > 0 && (

时刻图库

{imagesList.map((imageInstanceId, index) => (
))}
)} {/* 创建和更新信息 */}

记录信息

创建时间
{formatDate(storyItem.createTime)}
更新时间
{formatDate(storyItem.updateTime)}
创建人
{storyItem.createName || '系统用户'}
更新人
{storyItem.updateName || storyItem.createName || '系统用户'}
{/* Reactions Section */}

互动

{/* Comments Section */}
); }; export default TimelineItemDrawer;