4343
4444 <!-- 过滤标签 -->
4545 <div class =" filter-tabs" >
46- <a-radio-group v-model =" activeFilter" type =" button" >
47- <a-radio value =" all" >全部 ({{ totalTasks }})</a-radio >
48- <a-radio value =" downloading" >下载中 ({{ downloadingTasks }})</a-radio >
49- <a-radio value =" completed" >已完成 ({{ completedTasks }})</a-radio >
50- <a-radio value =" failed" >失败 ({{ failedTasks }})</a-radio >
51- <a-radio value =" pending" >等待中 ({{ pendingTasks }})</a-radio >
52- </a-radio-group >
46+ <div class =" filter-left" >
47+ <a-radio-group v-model =" activeFilter" type =" button" >
48+ <a-radio value =" all" >全部 ({{ totalTasks }})</a-radio >
49+ <a-radio value =" downloading" >下载中 ({{ downloadingTasks }})</a-radio >
50+ <a-radio value =" completed" >已完成 ({{ completedTasks }})</a-radio >
51+ <a-radio value =" failed" >失败 ({{ failedTasks }})</a-radio >
52+ <a-radio value =" pending" >等待中 ({{ pendingTasks }})</a-radio >
53+ </a-radio-group >
54+ </div >
55+
56+ <!-- 储存空间统计 -->
57+ <div class =" storage-stats" v-if =" downloadStore.tasks.length > 0" >
58+ <div class =" storage-info" >
59+ <div class =" storage-header" >
60+ <icon-download class =" storage-icon" />
61+ <span class =" storage-title" >本地储存空间</span >
62+ <a-tag
63+ :color =" storageStats.isOverLimit ? 'red' : storageStats.isNearLimit ? 'orange' : 'green'"
64+ size =" small"
65+ >
66+ {{ Math.round(storageStats.usagePercentage) }}%
67+ </a-tag >
68+ </div >
69+ <div class =" storage-progress" >
70+ <a-progress
71+ :percent =" storageStats.usagePercentage"
72+ :color =" storageStats.isOverLimit ? '#f53f3f' : storageStats.isNearLimit ? '#ff7d00' : '#00b42a'"
73+ :show-text =" false"
74+ size =" small"
75+ />
76+ </div >
77+ <div class =" storage-details" >
78+ <span class =" storage-used" >已用: {{ storageStats.formattedUsed }}</span >
79+ <span class =" storage-available" >可用: {{ storageStats.formattedAvailable }}</span >
80+ <span class =" storage-total" >总计: {{ storageStats.formattedTotal }}</span >
81+ </div >
82+ </div >
83+ </div >
5384 </div >
5485
5586 <!-- 下载任务列表 -->
92123
93124<script setup>
94125import { ref , computed , onMounted , onUnmounted } from ' vue'
126+ import { useRouter } from ' vue-router'
95127import { Message } from ' @arco-design/web-vue'
96128import {
97129 IconDownload ,
@@ -102,6 +134,7 @@ import DownloadTaskItem from './DownloadTaskItem.vue'
102134import AddDownloadTaskDialog from ' ./AddDownloadTaskDialog.vue'
103135import ChapterDetailsDialog from ' ./ChapterDetailsDialog.vue'
104136import { useDownloadStore } from ' @/stores/downloadStore'
137+ import downloadService from ' @/services/downloadService'
105138
106139// Props
107140const props = defineProps ({
@@ -114,14 +147,16 @@ const props = defineProps({
114147// Emits
115148const emit = defineEmits ([' close' ])
116149
117- // 下载状态管理
150+ // 路由和状态管理
151+ const router = useRouter ()
118152const downloadStore = useDownloadStore ()
119153
120154// 响应式数据
121155const activeFilter = ref (' all' )
122156const showAddTaskDialog = ref (false )
123157const showChapterDialog = ref (false )
124158const selectedTask = ref (null )
159+ const storageStats = ref ({}) // 储存空间统计
125160
126161// 计算属性
127162const totalTasks = computed (() => downloadStore .tasks .length )
@@ -146,37 +181,48 @@ const currentSelectedTask = computed(() => {
146181
147182// 方法
148183const handleClose = () => {
149- emit (' close' )
184+ // 使用Vue Router导航,返回上一页或首页
185+ if (window .history .length > 1 ) {
186+ router .go (- 1 )
187+ } else {
188+ router .push (' /' )
189+ }
150190}
151191
152192const handleAddTask = (taskData ) => {
153193 downloadStore .addTask (taskData)
194+ updateStorageStats () // 更新储存统计
154195 showAddTaskDialog .value = false
155196 Message .success (' 下载任务已添加' )
156197}
157198
158199const handleRetryTask = (taskId ) => {
159200 downloadStore .retryTask (taskId)
201+ updateStorageStats () // 更新储存统计
160202 Message .info (' 正在重试下载任务' )
161203}
162204
163205const handlePauseTask = (taskId ) => {
164206 downloadStore .pauseTask (taskId)
207+ updateStorageStats () // 更新储存统计
165208 Message .info (' 下载任务已暂停' )
166209}
167210
168211const handleResumeTask = (taskId ) => {
169212 downloadStore .resumeTask (taskId)
213+ updateStorageStats () // 更新储存统计
170214 Message .info (' 下载任务已恢复' )
171215}
172216
173217const handleCancelTask = (taskId ) => {
174218 downloadStore .cancelTask (taskId)
219+ updateStorageStats () // 更新储存统计
175220 Message .info (' 下载任务已取消' )
176221}
177222
178223const handleDeleteTask = (taskId ) => {
179224 downloadStore .deleteTask (taskId)
225+ updateStorageStats () // 更新储存统计
180226 Message .success (' 下载任务已删除' )
181227}
182228
@@ -196,12 +242,19 @@ const handleRetryChapter = (taskId, chapterIndex) => {
196242
197243const clearCompleted = () => {
198244 downloadStore .clearCompleted ()
245+ updateStorageStats () // 更新储存统计
199246 Message .success (' 已清理完成的下载任务' )
200247}
201248
249+ // 更新储存空间统计
250+ const updateStorageStats = () => {
251+ storageStats .value = downloadService .getStorageStats ()
252+ }
253+
202254// 生命周期
203255onMounted (() => {
204256 downloadStore .loadTasks ()
257+ updateStorageStats () // 初始化储存统计
205258})
206259
207260onUnmounted (() => {
@@ -258,10 +311,68 @@ onUnmounted(() => {
258311}
259312
260313.filter-tabs {
314+ display : flex ;
315+ justify-content : space-between ;
316+ align-items : center ;
261317 padding : 16px 24px ;
262318 border-bottom : 1px solid var (--color-border-2 );
263319}
264320
321+ .filter-left {
322+ flex : 1 ;
323+ }
324+
325+ .storage-stats {
326+ min-width : 200px ;
327+ }
328+
329+ .storage-info {
330+ display : flex ;
331+ flex-direction : column ;
332+ gap : 8px ;
333+ }
334+
335+ .storage-header {
336+ display : flex ;
337+ align-items : center ;
338+ gap : 8px ;
339+ }
340+
341+ .storage-icon {
342+ font-size : 14px ;
343+ color : var (--color-text-2 );
344+ }
345+
346+ .storage-title {
347+ font-size : 12px ;
348+ color : var (--color-text-2 );
349+ font-weight : 500 ;
350+ }
351+
352+ .storage-progress {
353+ width : 100% ;
354+ }
355+
356+ .storage-details {
357+ display : flex ;
358+ justify-content : space-between ;
359+ font-size : 11px ;
360+ color : var (--color-text-3 );
361+ }
362+
363+ .storage-used {
364+ color : var (--color-text-1 );
365+ font-weight : 500 ;
366+ }
367+
368+ .storage-available {
369+ color : var (--color-text-2 );
370+ }
371+
372+ .storage-total {
373+ color : var (--color-text-2 );
374+ }
375+
265376.download-list {
266377 flex : 1 ;
267378 overflow-y : auto ;
0 commit comments