添加下载功能

This commit is contained in:
柚子
2025-03-04 04:10:19 +08:00
parent 2e963b65e2
commit aadc137055
10 changed files with 682 additions and 241 deletions

View File

@@ -1,4 +1,4 @@
import { createSignal, createEffect } from 'solid-js';
import { createSignal, createEffect, onCleanup } from 'solid-js';
import { DownloadTask } from '@/types/download';
import { getDownloads, addDownload as addDownloadApi, pauseDownload as pauseDownloadApi, resumeDownload as resumeDownloadApi, cancelDownload as cancelDownloadApi } from '@/lib/api/download';
@@ -15,6 +15,19 @@ createEffect(async () => {
});
export const useDownloadsStore = () => {
// 设置每秒更新一次下载列表的定时器
const intervalId = setInterval(async () => {
try {
const updatedList = await getDownloads();
setDownloads(updatedList);
} catch (error) {
console.error('定时更新下载列表失败:', error);
}
}, 1000); // 1000毫秒 = 1秒
// 组件卸载时清除定时器
onCleanup(() => clearInterval(intervalId));
const activeDownloads = () => downloads().filter(item =>
['downloading', 'paused', 'queued'].includes(item.status)
);