|
11 | 11 | </div> |
12 | 12 |
|
13 | 13 | <!-- 列表内容 --> |
14 | | - <n-virtual-list |
15 | | - :item-size="90" |
16 | | - :items="dataStore.downloadingSongs" |
17 | | - class="virtual-list" |
18 | | - item-resizable |
19 | | - > |
20 | | - <template #default="{ item, index }"> |
21 | | - <div :key="item.song.id" class="download-item"> |
22 | | - <!-- 序号 --> |
23 | | - <div class="num"> |
24 | | - <n-text depth="3">{{ index + 1 }}</n-text> |
25 | | - </div> |
26 | | - <!-- 标题 (封面 + 信息) --> |
27 | | - <div class="title"> |
28 | | - <s-image :src="item.song.coverSize?.s || item.song.cover" class="cover" /> |
29 | | - <div class="info"> |
30 | | - <div class="name"> |
31 | | - <n-text class="name-text" ellipsis>{{ item.song.name }}</n-text> |
32 | | - </div> |
33 | | - <div class="artists text-hidden"> |
34 | | - <n-text depth="3"> |
35 | | - {{ |
36 | | - Array.isArray(item.song.artists) |
37 | | - ? item.song.artists.map((a) => a.name).join(" / ") |
38 | | - : item.song.artists |
39 | | - }} |
40 | | - </n-text> |
41 | | - </div> |
| 14 | + <n-scrollbar class="virtual-list"> |
| 15 | + <div |
| 16 | + v-for="(item, index) in sortedDownloadingSongs" |
| 17 | + :key="item.song.id" |
| 18 | + class="download-item" |
| 19 | + > |
| 20 | + <!-- 序号 --> |
| 21 | + <div class="num"> |
| 22 | + <n-text depth="3">{{ index + 1 }}</n-text> |
| 23 | + </div> |
| 24 | + <!-- 标题 (封面 + 信息) --> |
| 25 | + <div class="title"> |
| 26 | + <s-image :src="item.song.coverSize?.s || item.song.cover" class="cover" /> |
| 27 | + <div class="info"> |
| 28 | + <div class="name"> |
| 29 | + <n-text class="name-text" ellipsis>{{ item.song.name }}</n-text> |
| 30 | + </div> |
| 31 | + <div class="artists text-hidden"> |
| 32 | + <n-text depth="3"> |
| 33 | + {{ |
| 34 | + Array.isArray(item.song.artists) |
| 35 | + ? item.song.artists.map((a) => a.name).join(" / ") |
| 36 | + : item.song.artists |
| 37 | + }} |
| 38 | + </n-text> |
42 | 39 | </div> |
43 | 40 | </div> |
44 | | - <!-- 状态 --> |
45 | | - <div class="status"> |
46 | | - <n-flex v-if="item.status === 'downloading'" vertical :size="6" style="width: 100%"> |
47 | | - <n-flex justify="space-between"> |
48 | | - <n-text depth="3" style="font-size: 12px">{{ item.progress }}%</n-text> |
49 | | - <n-text depth="3" style="font-size: 12px"> |
50 | | - {{ item.transferred }} / {{ item.totalSize }} |
51 | | - </n-text> |
52 | | - </n-flex> |
53 | | - <n-progress |
54 | | - type="line" |
55 | | - :percentage="item.progress" |
56 | | - :show-indicator="false" |
57 | | - processing |
58 | | - status="success" |
59 | | - style="height: 4px" |
60 | | - /> |
| 41 | + </div> |
| 42 | + <!-- 状态 --> |
| 43 | + <div class="status"> |
| 44 | + <n-flex v-if="item.status === 'downloading'" vertical :size="6" style="width: 100%"> |
| 45 | + <n-flex justify="space-between"> |
| 46 | + <n-text depth="3" style="font-size: 12px">{{ item.progress }}%</n-text> |
| 47 | + <n-text depth="3" style="font-size: 12px"> |
| 48 | + {{ item.transferred }} / {{ item.totalSize }} |
| 49 | + </n-text> |
61 | 50 | </n-flex> |
62 | | - <n-flex v-else vertical :size="6" style="width: 100%"> |
63 | | - <n-text type="error" style="font-size: 12px">下载失败</n-text> |
64 | | - <n-progress |
65 | | - type="line" |
66 | | - :percentage="0" |
67 | | - :show-indicator="false" |
68 | | - status="error" |
69 | | - style="height: 4px" |
| 51 | + <div class="custom-progress"> |
| 52 | + <div class="bar" :style="{ width: item.progress + '%' }" /> |
| 53 | + <div |
| 54 | + class="light" |
| 55 | + v-if="item.status === 'downloading'" |
| 56 | + :style="{ left: item.progress + '%' }" |
70 | 57 | /> |
71 | | - </n-flex> |
72 | | - </div> |
73 | | - <!-- 操作 --> |
74 | | - <div class="actions"> |
75 | | - <n-button |
76 | | - type="primary" |
77 | | - secondary |
78 | | - strong |
79 | | - style="margin-right: 12px" |
80 | | - @click="DownloadManager.retryDownload(item.song.id)" |
81 | | - > |
82 | | - <template #icon> |
83 | | - <SvgIcon name="Refresh" /> |
84 | | - </template> |
85 | | - </n-button> |
86 | | - <n-button |
87 | | - type="error" |
88 | | - secondary |
89 | | - strong |
90 | | - @click="DownloadManager.removeDownload(item.song.id)" |
91 | | - > |
92 | | - <template #icon> |
93 | | - <SvgIcon name="Close" /> |
94 | | - </template> |
95 | | - </n-button> |
96 | | - </div> |
| 58 | + </div> |
| 59 | + </n-flex> |
| 60 | + <n-flex v-else-if="item.status === 'waiting'" vertical :size="6" style="width: 100%"> |
| 61 | + <n-text depth="3" style="font-size: 12px">等待下载...</n-text> |
| 62 | + <n-progress |
| 63 | + type="line" |
| 64 | + :percentage="0" |
| 65 | + :show-indicator="false" |
| 66 | + style="height: 4px" |
| 67 | + /> |
| 68 | + </n-flex> |
| 69 | + <n-flex v-else vertical :size="6" style="width: 100%"> |
| 70 | + <n-text type="error" style="font-size: 12px">下载失败</n-text> |
| 71 | + <n-progress |
| 72 | + type="line" |
| 73 | + :percentage="0" |
| 74 | + :show-indicator="false" |
| 75 | + status="error" |
| 76 | + style="height: 4px" |
| 77 | + /> |
| 78 | + </n-flex> |
| 79 | + </div> |
| 80 | + <!-- 操作 --> |
| 81 | + <div class="actions"> |
| 82 | + <n-button |
| 83 | + type="primary" |
| 84 | + secondary |
| 85 | + strong |
| 86 | + style="margin-right: 12px" |
| 87 | + @click="DownloadManager.retryDownload(item.song.id)" |
| 88 | + > |
| 89 | + <template #icon> |
| 90 | + <SvgIcon name="Refresh" /> |
| 91 | + </template> |
| 92 | + </n-button> |
| 93 | + <n-button |
| 94 | + type="error" |
| 95 | + secondary |
| 96 | + strong |
| 97 | + @click="DownloadManager.removeDownload(item.song.id)" |
| 98 | + > |
| 99 | + <template #icon> |
| 100 | + <SvgIcon name="Close" /> |
| 101 | + </template> |
| 102 | + </n-button> |
97 | 103 | </div> |
98 | | - </template> |
99 | | - </n-virtual-list> |
| 104 | + </div> |
| 105 | + </n-scrollbar> |
100 | 106 | </div> |
101 | 107 | <n-empty v-else description="暂无正在下载的任务" class="empty" /> |
102 | 108 | </Transition> |
103 | 109 | </div> |
104 | 110 | </template> |
105 | 111 |
|
106 | 112 | <script setup lang="ts"> |
| 113 | +import { computed } from "vue"; |
107 | 114 | import { useDataStore } from "@/stores"; |
108 | 115 | import DownloadManager from "@/utils/downloadManager"; |
109 | 116 |
|
110 | 117 | const dataStore = useDataStore(); |
| 118 | +
|
| 119 | +const sortedDownloadingSongs = computed(() => { |
| 120 | + return [...dataStore.downloadingSongs].sort((a, b) => { |
| 121 | + // 优先级: 下载中 (1) > 等待中 (2) > 失败 (3) |
| 122 | + const getPriority = (status: string) => { |
| 123 | + if (status === "downloading") return 1; |
| 124 | + if (status === "waiting") return 2; |
| 125 | + return 3; |
| 126 | + }; |
| 127 | + return getPriority(a.status) - getPriority(b.status); |
| 128 | + }); |
| 129 | +}); |
111 | 130 | </script> |
112 | 131 |
|
113 | 132 | <style lang="scss" scoped> |
@@ -237,6 +256,39 @@ const dataStore = useDataStore(); |
237 | 256 | min-width: 120px; |
238 | 257 | } |
239 | 258 | } |
| 259 | + .custom-progress { |
| 260 | + position: relative; |
| 261 | + width: 100%; |
| 262 | + height: 6px; |
| 263 | + margin-top: 4px; |
| 264 | + background-color: var(--surface-variant-hex); |
| 265 | + border-radius: 3px; |
| 266 | + overflow: hidden; |
| 267 | +
|
| 268 | + .bar { |
| 269 | + height: 100%; |
| 270 | + border-radius: 3px; |
| 271 | + background: rgb(var(--primary)); |
| 272 | + background: linear-gradient( |
| 273 | + 90deg, |
| 274 | + rgba(var(--primary), 0.7) 0%, |
| 275 | + rgba(var(--primary), 1) 100% |
| 276 | + ); |
| 277 | + transition: width 0.3s ease-out; |
| 278 | + } |
| 279 | +
|
| 280 | + .light { |
| 281 | + position: absolute; |
| 282 | + top: 0; |
| 283 | + bottom: 0; |
| 284 | + width: 15px; |
| 285 | + transform: skewX(-20deg) translateX(-50%); |
| 286 | + background: rgba(255, 255, 255, 0.4); |
| 287 | + filter: blur(2px); |
| 288 | + transition: left 0.3s ease-out; |
| 289 | + pointer-events: none; |
| 290 | + } |
| 291 | + } |
240 | 292 | } |
241 | 293 | } |
242 | 294 |
|
|
0 commit comments