staff_data/apps/web/src/app/main/staffinfo_write/infoCard.tsx

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-03-26 10:39:24 +08:00
import { Input, Button, Space } from 'antd';
2025-03-26 10:31:29 +08:00
import React, { useState } from 'react';
type InfoCardProps = {
onAdd: (content: string) => void;
}
2025-03-26 10:39:24 +08:00
const InfoCard: React.FC<InfoCardProps> = ({ onAdd }) => {
2025-03-26 10:31:29 +08:00
const [content, setContent] = useState('');
2025-03-26 10:39:24 +08:00
const [addedContents, setAddedContents] = useState<string[]>([]);
2025-03-26 10:31:29 +08:00
const handleAdd = () => {
2025-03-26 10:39:24 +08:00
if (content) {
2025-03-26 10:31:29 +08:00
onAdd(content);
2025-03-26 10:39:24 +08:00
setAddedContents([...addedContents, content]);
2025-03-26 10:31:29 +08:00
setContent('');
}
}
return (
2025-03-26 10:39:24 +08:00
// 增大内边距,避免内容被覆盖
<div style={{ border: '1px solid #d9d9d9', padding: '24px' }}>
2025-03-26 10:31:29 +08:00
<Space>
<Input
2025-03-26 10:39:24 +08:00
placeholder='请输入内容'
value={content}
onChange={(e) => setContent(e.target.value)}
/>
2025-03-26 10:31:29 +08:00
<Button type='primary' onClick={handleAdd}></Button>
</Space>
2025-03-26 10:39:24 +08:00
<div style={{ marginTop: '24px' }}>
{addedContents.map((item, index) => (
<div key={index}>{item}</div>
))}
</div>
</div>
2025-03-26 10:31:29 +08:00
);
}
export default InfoCard;