-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathDownloadTaskItem.vue
More file actions
433 lines (387 loc) · 10.4 KB
/
DownloadTaskItem.vue
File metadata and controls
433 lines (387 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<template>
<div class="download-task-item" :class="taskStatusClass">
<!-- 任务基本信息 -->
<div class="task-info">
<div class="task-header">
<div class="task-title">
<h3>{{ task.novelTitle }}</h3>
<div class="task-meta">
<span class="source-info">{{ task.sourceName }}</span>
<span class="chapter-count">共 {{ task.totalChapters }} 章</span>
<span class="create-time">{{ formatTime(task.createTime) }}</span>
</div>
</div>
<div class="task-status">
<a-tag :color="statusColor">{{ statusText }}</a-tag>
</div>
</div>
<!-- 下载进度 -->
<div class="task-progress" v-if="task.status !== 'pending'">
<div class="progress-info">
<span class="progress-text">
{{ task.completedChapters || 0 }} / {{ task.totalChapters }} 章
<span v-if="task.status === 'downloading'" class="download-speed">
({{ downloadSpeed }})
</span>
</span>
<span class="progress-percent">{{ progressPercent }}%</span>
</div>
<a-progress
:percent="progressPercent"
:status="progressStatus"
:show-text="false"
size="small"
/>
</div>
<!-- 错误信息 -->
<div v-if="task.status === 'failed' && task.errorMessage" class="error-message">
<icon-exclamation-circle-fill />
{{ task.errorMessage }}
</div>
<!-- 任务详情 -->
<div class="task-details" v-if="showDetails">
<div class="detail-row">
<span class="label">下载路径:</span>
<span class="value">{{ task.downloadPath || '默认路径' }}</span>
</div>
<div class="detail-row">
<span class="label">文件大小:</span>
<span class="value">{{ getFileSizeDisplay() }}</span>
</div>
<div class="detail-row">
<span class="label">开始时间:</span>
<span class="value">{{ getStartTimeDisplay() }}</span>
</div>
<div class="detail-row" v-if="task.completeTime">
<span class="label">完成时间:</span>
<span class="value">{{ formatTime(task.completeTime) }}</span>
</div>
</div>
</div>
<!-- 操作按钮 -->
<div class="task-actions">
<a-button-group v-if="task.status === 'downloading'">
<a-button size="small" @click="$emit('pause', task.id)">
<template #icon>
<icon-pause />
</template>
暂停
</a-button>
<a-button size="small" @click="$emit('cancel', task.id)">
<template #icon>
<icon-stop />
</template>
取消
</a-button>
</a-button-group>
<a-button-group v-else-if="task.status === 'paused'">
<a-button size="small" type="primary" @click="$emit('resume', task.id)">
<template #icon>
<icon-play-arrow />
</template>
继续
</a-button>
<a-button size="small" @click="$emit('cancel', task.id)">
<template #icon>
<icon-stop />
</template>
取消
</a-button>
</a-button-group>
<a-button-group v-else-if="task.status === 'failed'">
<a-button size="small" type="primary" @click="$emit('retry', task.id)">
<template #icon>
<icon-refresh />
</template>
重试
</a-button>
<a-button size="small" @click="$emit('delete', task.id)">
<template #icon>
<icon-delete />
</template>
删除
</a-button>
</a-button-group>
<a-button-group v-else-if="task.status === 'completed'">
<a-dropdown @select="handleExportSelect">
<a-button size="small" type="primary">
<template #icon>
<icon-download />
</template>
导出
<icon-down />
</a-button>
<template #content>
<a-doption value="download">
<template #icon>
<icon-download />
</template>
下载TXT文件
</a-doption>
<a-doption value="gallery">
<template #icon>
<icon-book />
</template>
导出到书画柜
</a-doption>
</template>
</a-dropdown>
<a-button size="small" @click="$emit('delete', task.id)">
<template #icon>
<icon-delete />
</template>
删除
</a-button>
</a-button-group>
<a-button-group v-else-if="task.status === 'pending'">
<a-button size="small" @click="$emit('delete', task.id)">
<template #icon>
<icon-delete />
</template>
删除
</a-button>
</a-button-group>
<!-- 通用操作 -->
<a-button size="small" @click="$emit('view-chapters', task)">
<template #icon>
<icon-list />
</template>
章节详情
</a-button>
<a-button size="small" @click="toggleDetails">
<template #icon>
<icon-down v-if="!showDetails" />
<icon-up v-else />
</template>
{{ showDetails ? '收起' : '详情' }}
</a-button>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import {
IconPause,
IconPlayArrow,
IconStop,
IconRefresh,
IconDelete,
IconDownload,
IconList,
IconDown,
IconUp,
IconExclamationCircleFill,
IconBook
} from '@arco-design/web-vue/es/icon'
// Props
const props = defineProps({
task: {
type: Object,
required: true
}
})
// Emits
const emit = defineEmits([
'retry',
'pause',
'resume',
'cancel',
'delete',
'export',
'view-chapters'
])
// 响应式数据
const showDetails = ref(false)
// 计算属性
const taskStatusClass = computed(() => {
return `task-${props.task.status}`
})
const statusColor = computed(() => {
const colors = {
pending: 'gray',
downloading: 'blue',
paused: 'orange',
completed: 'green',
failed: 'red',
cancelled: 'gray'
}
return colors[props.task.status] || 'gray'
})
const statusText = computed(() => {
const texts = {
pending: '等待中',
downloading: '下载中',
paused: '已暂停',
completed: '已完成',
failed: '下载失败',
cancelled: '已取消'
}
return texts[props.task.status] || '未知状态'
})
const progressPercent = computed(() => {
if (!props.task.totalChapters || props.task.totalChapters === 0) return 0
const completed = props.task.completedChapters || 0
return Math.round((completed / props.task.totalChapters) * 100)
})
const progressStatus = computed(() => {
if (props.task.status === 'failed') return 'danger'
if (props.task.status === 'completed') return 'success'
return 'normal'
})
const downloadSpeed = computed(() => {
if (!props.task.downloadSpeed) return '0 章/分钟'
return `${props.task.downloadSpeed} 章/分钟`
})
// 方法
const toggleDetails = () => {
showDetails.value = !showDetails.value
}
// 处理导出选择
const handleExportSelect = (value) => {
if (value === 'download') {
emit('export', props.task.id, { exportToGallery: false })
} else if (value === 'gallery') {
emit('export', props.task.id, { exportToGallery: true })
}
}
const formatTime = (timestamp) => {
if (!timestamp) return '-'
return new Date(timestamp).toLocaleString('zh-CN')
}
const formatFileSize = (bytes) => {
if (!bytes) return '0 B'
const sizes = ['B', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(1024))
return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i]
}
const getFileSizeDisplay = () => {
if (props.task.totalSize > 0) {
return formatFileSize(props.task.totalSize)
} else if (props.task.status === 'pending') {
return '等待计算'
} else if (props.task.status === 'downloading') {
const downloadedSize = props.task.downloadedSize || 0
if (downloadedSize > 0) {
return `${formatFileSize(downloadedSize)} (下载中)`
}
return '计算中...'
} else {
return '未知'
}
}
const getStartTimeDisplay = () => {
if (props.task.startTime) {
return formatTime(props.task.startTime)
} else if (props.task.status === 'pending') {
return '未开始'
} else if (props.task.status === 'downloading') {
return '正在启动...'
} else {
return '-'
}
}
</script>
<style scoped>
.download-task-item {
border: 1px solid var(--color-border-2);
border-radius: 8px;
padding: 16px;
margin-bottom: 12px;
background: var(--color-bg-2);
transition: all 0.2s ease;
}
.download-task-item:hover {
border-color: var(--color-border-3);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.task-downloading {
border-color: var(--color-primary-light-4);
background: var(--color-primary-light-1);
}
.task-completed {
border-color: var(--color-success-light-4);
background: var(--color-success-light-1);
}
.task-failed {
border-color: var(--color-danger-light-4);
background: var(--color-danger-light-1);
}
.task-info {
margin-bottom: 16px;
}
.task-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 12px;
}
.task-title h3 {
margin: 0 0 4px 0;
font-size: 16px;
font-weight: 600;
color: var(--color-text-1);
}
.task-meta {
display: flex;
gap: 12px;
font-size: 12px;
color: var(--color-text-3);
}
.task-progress {
margin-bottom: 12px;
}
.progress-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 4px;
font-size: 12px;
color: var(--color-text-2);
}
.download-speed {
color: var(--color-primary-6);
}
.progress-percent {
font-weight: 600;
}
.error-message {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 12px;
background: var(--color-danger-light-1);
border: 1px solid var(--color-danger-light-4);
border-radius: 4px;
font-size: 12px;
color: var(--color-danger-6);
margin-bottom: 12px;
}
.task-details {
padding: 12px;
background: var(--color-bg-1);
border-radius: 4px;
margin-bottom: 12px;
}
.detail-row {
display: flex;
margin-bottom: 6px;
font-size: 12px;
}
.detail-row:last-child {
margin-bottom: 0;
}
.label {
width: 80px;
color: var(--color-text-3);
flex-shrink: 0;
}
.value {
color: var(--color-text-2);
flex: 1;
}
.task-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
</style>