Skip to content

Commit 476e748

Browse files
committed
refactor: 移除文件列表的虚拟滚动功能
1 parent 878f13b commit 476e748

3 files changed

Lines changed: 2 additions & 78 deletions

File tree

src/components/FileList.tsx

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,10 @@ export const FileList: React.FC<FileListProps> = ({
2828
onCopy,
2929
}) => {
3030
const [filteredFiles, setFilteredFiles] = useState<WinFileInfo[]>(files);
31-
const [scrollTop, setScrollTop] = useState(0);
32-
33-
const ROW_HEIGHT = 86;
34-
const CONTAINER_HEIGHT = 520;
35-
const OVERSCAN = 6;
3631

3732
// 当外部 files 变化时更新过滤列表
3833
React.useEffect(() => {
3934
setFilteredFiles(files);
40-
setScrollTop(0);
4135
}, [files]);
4236

4337
/**
@@ -47,50 +41,6 @@ export const FileList: React.FC<FileListProps> = ({
4741
setFilteredFiles(newFilteredFiles);
4842
}, []);
4943

50-
const visibleRange = useMemo(() => {
51-
const start = Math.max(0, Math.floor(scrollTop / ROW_HEIGHT) - OVERSCAN);
52-
const visibleCount = Math.ceil(CONTAINER_HEIGHT / ROW_HEIGHT) + OVERSCAN * 2;
53-
const end = Math.min(filteredFiles.length, start + visibleCount);
54-
return { start, end };
55-
}, [filteredFiles.length, scrollTop]);
56-
57-
const visibleRows = useMemo(() => {
58-
return filteredFiles.slice(visibleRange.start, visibleRange.end).map((info, offset) => {
59-
const index = visibleRange.start + offset;
60-
const top = index * ROW_HEIGHT;
61-
return (
62-
<List.ListItem className="file-list-row file-list-row-virtual" style={{ top }} key={`${info.FileName}-${index}`}>
63-
<div className="file-list-main">
64-
<div className="file-list-title">
65-
{`Windows ${info.SystemCode} ${info.VerCode} (${info.BuildVer})`}
66-
</div>
67-
<div className="file-list-meta">
68-
<span>{info.Language}</span>
69-
<span>{info.Edition}</span>
70-
<span>{info.Architecture}</span>
71-
<span>{formatFileSize(info.Size)}</span>
72-
<span>SHA: {info.Sha256 || info.Sha1 || '-'}</span>
73-
</div>
74-
</div>
75-
<Space className="file-list-actions" size="small">
76-
<Link theme="primary" hover="color" onClick={() => onDownload(info.FilePath)}>
77-
下载
78-
</Link>
79-
<Link theme="primary" hover="color" onClick={() => onCopy(info.FilePath)}>
80-
复制直链
81-
</Link>
82-
</Space>
83-
</List.ListItem>
84-
);
85-
});
86-
}, [filteredFiles, onCopy, onDownload, visibleRange]);
87-
88-
const totalHeight = filteredFiles.length * ROW_HEIGHT;
89-
90-
const handleScroll = useCallback((event: React.UIEvent<HTMLDivElement>) => {
91-
setScrollTop(event.currentTarget.scrollTop);
92-
}, []);
93-
9444
const renderRows = useMemo(() => {
9545
return filteredFiles.map((info, index) => (
9646
<List.ListItem className="file-list-row" key={`${info.FileName}-${index}`}>
@@ -136,15 +86,7 @@ export const FileList: React.FC<FileListProps> = ({
13686
没有找到匹配的文件
13787
</div>
13888
) : (
139-
filteredFiles.length <= 30 ? (
140-
<List className="file-list-wrap">{renderRows}</List>
141-
) : (
142-
<div className="file-list-virtual" style={{ height: CONTAINER_HEIGHT }} onScroll={handleScroll}>
143-
<List className="file-list-virtual-inner" style={{ height: totalHeight }}>
144-
{visibleRows}
145-
</List>
146-
</div>
147-
)
89+
<List className="file-list-wrap">{renderRows}</List>
14890
)}
14991
</div>
15092
);

src/global/main.css

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@ p {
189189
background: #fff;
190190
}
191191

192-
.file-list-row-virtual {
193-
position: absolute;
194-
left: 0;
195-
right: 0;
196-
min-height: 78px;
197-
}
198-
199192
.file-list-main {
200193
min-width: 0;
201194
text-align: left;
@@ -235,17 +228,6 @@ p {
235228
flex-shrink: 0;
236229
}
237230

238-
.file-list-virtual {
239-
overflow: auto;
240-
border: 1px solid var(--app-border);
241-
border-radius: 12px;
242-
background: #fff;
243-
}
244-
245-
.file-list-virtual-inner {
246-
position: relative;
247-
}
248-
249231
.file-card + .file-card {
250232
margin-top: 14px;
251233
}

src/services/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
const config = {
66
apiHost: import.meta.env.DEV
7-
? "http://localhost:3333" // 开发环境
7+
? "http://localhost:3000" // 开发环境
88
: "https://api.hotpe.top", // 生产环境
99
};
1010

0 commit comments

Comments
 (0)