✨ 添加下载功能
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user