Files
CyyNote/cyynote-frontend/src/pages/home/HomePage.tsx
T
2026-04-30 18:53:50 +08:00

77 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
List,
Avatar,
Button,
ButtonGroup,
Typography,
Tabs,
TabPane,
Toast,
} from '@douyinfe/semi-ui';
import { useNoteStore } from '../../stores/useNoteStore';
import { useUIStore } from '../../stores/useUIStore';
import noteService from '../../services/note.service';
import type { INote } from '../../types';
export default function HomePage() {
const { homeData, setHomeData, setCurrentNote } = useNoteStore();
const setActiveView = useUIStore((s) => s.setActiveView);
const loadNote = (id: number) => {
noteService.get(id).then(
(res) => {
const note = res.data;
setCurrentNote(note.id, note.title, note.context);
setActiveView('note');
},
() => Toast.error('加载笔记失败'),
);
};
const handleTabChange = (key: string) => {
noteService.getHomeData(key, '0').then(
(res) => setHomeData(res.data),
() => Toast.error('加载列表失败'),
);
};
return (
<>
<Tabs type="button" onChange={handleTabChange} defaultActiveKey="1">
<TabPane tab="最近更新" itemKey="1" />
<TabPane tab="最新添加" itemKey="2" />
<TabPane tab="最近浏览" itemKey="3" />
</Tabs>
<div style={{ padding: 5, border: '1px solid var(--semi-color-border)', margin: 5 }}>
<List
dataSource={homeData}
renderItem={(item: INote) => (
<List.Item
header={<Avatar color="blue">NOTE</Avatar>}
main={
<div>
<span style={{ color: 'var(--semi-color-text-0)', fontWeight: 500 }}>
{item.title}
</span>
<Typography.Text
ellipsis={{ showTooltip: true }}
style={{ width: 'calc(100% - 68px)' }}
>
{item.createtime}{item.updatetime}
{item.viewtime}
</Typography.Text>
</div>
}
extra={
<ButtonGroup theme="borderless">
<Button onClick={() => loadNote(item.id)}></Button>
</ButtonGroup>
}
/>
)}
/>
</div>
</>
);
}