2025-08-06 18:41:32 +08:00
|
|
|
import TimelineImage from '@/components/TimelineImage';
|
|
|
|
|
import { StoryItem } from '@/pages/story/data';
|
|
|
|
|
import {
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
DownOutlined,
|
|
|
|
|
EditOutlined,
|
|
|
|
|
UpOutlined,
|
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
import { useIntl, useRequest } from '@umijs/max';
|
|
|
|
|
import { Button, Card, message, Popconfirm } from 'antd';
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { queryStoryItemImages, removeStoryItem } from '../../service';
|
2025-08-05 19:02:14 +08:00
|
|
|
import TimelineItemDrawer from '../TimelineItemDrawer';
|
2025-08-06 18:41:32 +08:00
|
|
|
import useStyles from './index.style';
|
2025-08-05 19:02:14 +08:00
|
|
|
|
|
|
|
|
const TimelineItem: React.FC<{
|
|
|
|
|
item: StoryItem;
|
|
|
|
|
handleOption: (item: StoryItem, option: 'add' | 'edit' | 'addSubItem' | 'editSubItem') => void;
|
|
|
|
|
refresh: () => void;
|
|
|
|
|
}> = ({ item, handleOption, refresh }) => {
|
|
|
|
|
const { styles } = useStyles();
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
const [expanded, setExpanded] = useState(false);
|
|
|
|
|
const [showActions, setShowActions] = useState(false);
|
|
|
|
|
const [subItemsExpanded, setSubItemsExpanded] = useState(false);
|
2025-08-06 18:41:32 +08:00
|
|
|
const [openDetail, setOpenDetail] = useState(false);
|
|
|
|
|
const { data: imagesList } = useRequest(async () => {
|
|
|
|
|
return await queryStoryItemImages(item.instanceId);
|
|
|
|
|
});
|
2025-08-05 19:02:14 +08:00
|
|
|
const handleDelete = async () => {
|
|
|
|
|
try {
|
|
|
|
|
if (!item.instanceId) return;
|
|
|
|
|
const response = await removeStoryItem(item.instanceId);
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
message.success(intl.formatMessage({ id: 'story.deleteSuccess' }));
|
|
|
|
|
refresh();
|
|
|
|
|
} else {
|
|
|
|
|
message.error(intl.formatMessage({ id: 'story.deleteFailed' }));
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
message.error(intl.formatMessage({ id: 'story.deleteFailed' }));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const toggleDescription = () => {
|
|
|
|
|
setExpanded(!expanded);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleSubItems = () => {
|
|
|
|
|
setSubItemsExpanded(!subItemsExpanded);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const displayedDescription = expanded
|
|
|
|
|
? item.description
|
2025-08-06 18:41:32 +08:00
|
|
|
: item.description?.substring(0, 100) +
|
|
|
|
|
(item.description && item.description.length > 100 ? '...' : '');
|
2025-08-05 19:02:14 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card
|
|
|
|
|
className={styles.timelineItem}
|
|
|
|
|
title={item.title}
|
|
|
|
|
onMouseEnter={() => setShowActions(true)}
|
|
|
|
|
onMouseLeave={() => setShowActions(false)}
|
|
|
|
|
extra={
|
2025-08-06 18:41:32 +08:00
|
|
|
<div className={styles.actions}>
|
2025-08-05 19:02:14 +08:00
|
|
|
{showActions && (
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
icon={<EditOutlined />}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
2025-08-06 18:41:32 +08:00
|
|
|
handleOption(item, 'edit');
|
2025-08-05 19:02:14 +08:00
|
|
|
}}
|
|
|
|
|
aria-label={intl.formatMessage({ id: 'story.edit' })}
|
|
|
|
|
/>
|
2025-08-06 18:41:32 +08:00
|
|
|
{/*<Button
|
2025-08-05 19:02:14 +08:00
|
|
|
type="text"
|
|
|
|
|
icon={<PlusOutlined />}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
handleOption(item, 'addSubItem');
|
|
|
|
|
}}
|
|
|
|
|
aria-label={intl.formatMessage({ id: 'story.addSubItem' })}
|
2025-08-06 18:41:32 +08:00
|
|
|
/>*/}
|
2025-08-05 19:02:14 +08:00
|
|
|
<Popconfirm
|
|
|
|
|
title={intl.formatMessage({ id: 'story.deleteConfirm' })}
|
|
|
|
|
description={intl.formatMessage({ id: 'story.deleteConfirmDescription' })}
|
|
|
|
|
onConfirm={(e) => {
|
|
|
|
|
e?.stopPropagation();
|
2025-08-06 18:41:32 +08:00
|
|
|
handleDelete();
|
2025-08-05 19:02:14 +08:00
|
|
|
}}
|
|
|
|
|
okText={intl.formatMessage({ id: 'story.yes' })}
|
|
|
|
|
cancelText={intl.formatMessage({ id: 'story.no' })}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
icon={<DeleteOutlined />}
|
|
|
|
|
danger
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
aria-label={intl.formatMessage({ id: 'story.delete' })}
|
|
|
|
|
/>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
// onClick={() => onDetail(item)}
|
|
|
|
|
hoverable
|
|
|
|
|
>
|
|
|
|
|
<div className={styles.content}>
|
2025-08-06 18:41:32 +08:00
|
|
|
<div className={styles.date} onClick={() => setOpenDetail(true)}>
|
2025-08-05 19:02:14 +08:00
|
|
|
{item.storyItemTime} {item.location ? `创建于${item.location}` : ''}
|
|
|
|
|
</div>
|
2025-08-06 18:41:32 +08:00
|
|
|
<div className={styles.description} onClick={() => setOpenDetail(true)}>
|
2025-08-05 19:02:14 +08:00
|
|
|
{displayedDescription}
|
|
|
|
|
{item.description && item.description.length > 100 && (
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
toggleDescription();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{expanded
|
|
|
|
|
? intl.formatMessage({ id: 'story.showLess' })
|
|
|
|
|
: intl.formatMessage({ id: 'story.showMore' })}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{imagesList && imagesList.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px', marginBottom: '20px' }}>
|
|
|
|
|
{imagesList.map((imageInstanceId, index) => (
|
|
|
|
|
<TimelineImage
|
|
|
|
|
key={imageInstanceId + index}
|
|
|
|
|
title={imageInstanceId}
|
|
|
|
|
imageInstanceId={imageInstanceId}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{item.subItems && item.subItems.length > 0 && (
|
|
|
|
|
<div className={styles.subItems}>
|
|
|
|
|
<div
|
|
|
|
|
className={styles.subItemsHeader}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
toggleSubItems();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<span>
|
|
|
|
|
{intl.formatMessage({ id: 'story.subItems' })} ({item.subItems.length})
|
|
|
|
|
</span>
|
|
|
|
|
{subItemsExpanded ? <UpOutlined /> : <DownOutlined />}
|
|
|
|
|
</div>
|
|
|
|
|
{subItemsExpanded && (
|
|
|
|
|
<div className={styles.subItemsList}>
|
|
|
|
|
{item.subItems.map((subItem) => (
|
|
|
|
|
<div key={subItem.id} className={styles.subItem}>
|
|
|
|
|
<div className={styles.subItemDate}>
|
|
|
|
|
{item.storyItemTime} {item.location ? `创建于${item.location}` : ''}
|
|
|
|
|
</div>
|
2025-08-06 18:41:32 +08:00
|
|
|
<div className={styles.subItemContent}>{subItem.description}</div>
|
2025-08-05 19:02:14 +08:00
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-08-06 18:41:32 +08:00
|
|
|
<TimelineItemDrawer storyItem={item} open={openDetail} setOpen={setOpenDetail} />
|
2025-08-05 19:02:14 +08:00
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TimelineItem;
|