feat: 补齐桌面端下载播放,并将窗口改为夜间主题和应用图标

This commit is contained in:
Nixevol
2026-09-27 06:16:50 +08:00
parent f010426f94
commit 1b33898fff
81 changed files with 2529 additions and 232 deletions
+134 -16
View File
@@ -32,6 +32,10 @@ let searchCursor = 0;
let lastQuery = "";
let revealGeneration = 0;
const flashSerial = ref(0);
const directory = ref("");
const starting = ref(false);
const footError = ref("");
const emit = defineEmits<{ started: []; play: [Drama] }>();
const scrollEl = ref<HTMLElement | null>(null);
function coverOf(image: string) {
@@ -275,8 +279,62 @@ async function find(keyword = query.value) {
if (generation !== revealGeneration) return;
flashKey.value = key;
}
onMounted(reload);
defineExpose({ reload, busy, find, searchHint, clearSearch });
onMounted(() => {
void reload();
void loadDirectory();
});
defineExpose({ reload, busy, find, searchHint, clearSearch, loadDirectory });
async function loadDirectory() {
const response = await fetch("/api/downloads");
if (!response.ok) return;
const payload = await response.json();
directory.value = payload.directory || "";
}
async function chooseDirectory() {
footError.value = "";
const response = await fetch("/api/downloads/pick", { method: "POST" });
if (!response.ok) {
const payload = await response.json().catch(() => ({}));
const detail = typeof payload.detail === "string" ? payload.detail : "";
if (detail) footError.value = detail;
return;
}
const payload = await response.json();
if (payload.directory) directory.value = payload.directory;
}
async function startDownload() {
const seen = new Set<number>();
const items: { id: number; title: string; image: string }[] = [];
for (const section of sections.value) {
for (const item of section.items) {
if (!selected.value.has(item.id) || seen.has(item.id)) continue;
seen.add(item.id);
items.push({ id: item.id, title: item.title, image: item.image });
}
}
if (!items.length) return;
starting.value = true;
footError.value = "";
try {
const response = await fetch("/api/downloads", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: props.token, device: props.device, items }),
});
const payload = await response.json();
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "加入下载失败");
}
emit("started");
} catch (exc) {
footError.value = exc instanceof Error ? exc.message : "加入下载失败";
} finally {
starting.value = false;
}
}
</script>
<template>
@@ -286,22 +344,32 @@ defineExpose({ reload, busy, find, searchHint, clearSearch });
<n-alert v-if="error" class="catalog-error" type="error" :show-icon="false">{{ error }}</n-alert>
<section v-for="section in sections" :key="section.key" class="category">
<div class="category-bar">
<n-button quaternary circle :aria-label="isExpanded(section.key) ? '收起' : '展开'" @click="toggleExpanded(section.key)">
<span class="chevron" :class="{ open: isExpanded(section.key) }">▸</span>
</n-button>
<n-tooltip placement="top">
<template #trigger>
<n-button quaternary circle :aria-label="isExpanded(section.key) ? '收起' : '展开'" @click="toggleExpanded(section.key)">
<span class="chevron" :class="{ open: isExpanded(section.key) }">▸</span>
</n-button>
</template>
{{ isExpanded(section.key) ? "收起" : "展开" }}
</n-tooltip>
<n-text strong>{{ section.name }}</n-text>
<span v-if="section.loading" class="category-spin" aria-hidden="true"></span>
<n-text depth="3">{{ section.items.length }} 部</n-text>
<n-text depth="3">已选 {{ selectedCount(section) }}</n-text>
<span class="bar-gap"></span>
<n-checkbox
:checked="allChecked(section)"
:indeterminate="someChecked(section)"
:disabled="section.items.length === 0"
@update:checked="toggleSection(section, $event)"
>
全选
</n-checkbox>
<n-tooltip placement="top">
<template #trigger>
<n-checkbox
:checked="allChecked(section)"
:indeterminate="someChecked(section)"
:disabled="section.items.length === 0"
@update:checked="toggleSection(section, $event)"
>
全选
</n-checkbox>
</template>
{{ allChecked(section) ? "取消全选" : "全选" }}
</n-tooltip>
</div>
<div v-if="isExpanded(section.key)" class="category-body">
<n-text v-if="section.note" depth="3">{{ section.note }}</n-text>
@@ -316,9 +384,24 @@ defineExpose({ reload, busy, find, searchHint, clearSearch });
>
<div class="cover">
<img v-if="item.image" :src="coverOf(item.image)" :alt="item.title" />
<div class="cover-play-layer">
<n-tooltip placement="top">
<template #trigger>
<button type="button" class="cover-play" aria-label="播放" @click.stop="emit('play', item)">
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M9 7.5v9l8-4.5z" /></svg>
</button>
</template>
播放
</n-tooltip>
</div>
</div>
<div class="pick" @click.stop>
<n-checkbox :checked="selected.has(item.id)" @update:checked="toggleDrama(item.id, $event)" />
<n-tooltip placement="left">
<template #trigger>
<n-checkbox :checked="selected.has(item.id)" @update:checked="toggleDrama(item.id, $event)" />
</template>
{{ selected.has(item.id) ? "取消选择" : "选择" }}
</n-tooltip>
</div>
<div class="drama-title">{{ item.title }}</div>
<div
@@ -335,7 +418,13 @@ defineExpose({ reload, busy, find, searchHint, clearSearch });
</div>
<footer class="download-foot">
<n-text>已选 {{ selected.size }} 部</n-text>
<div class="foot-actions">
<n-text class="foot-dir" depth="3" :title="directory">{{ directory || "未设置下载目录" }}</n-text>
<n-button secondary size="small" @click="chooseDirectory">选择</n-button>
<n-button type="primary" size="small" :disabled="selected.size === 0" :loading="starting" @click="startDownload">下载</n-button>
</div>
</footer>
<n-text v-if="footError" class="foot-error" type="error">{{ footError }}</n-text>
</div>
</template>
@@ -355,12 +444,15 @@ defineExpose({ reload, busy, find, searchHint, clearSearch });
border-top: 1px solid rgba(255, 255, 255, 0.12);
background: #18181c;
}
.foot-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.foot-dir { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-error { display: block; padding: 0 20px 8px; text-align: right; }
.catalog-error { margin: 8px 20px 12px; }
.category { margin-bottom: 8px; }
.category-bar {
position: sticky;
top: 0;
z-index: 1;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
@@ -395,9 +487,35 @@ defineExpose({ reload, busy, find, searchHint, clearSearch });
background: rgba(255, 255, 255, 0.04);
cursor: pointer;
}
.cover { background: #2a2a2a; }
.cover { position: relative; background: #2a2a2a; }
.cover img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.cover:not(:has(img)) { aspect-ratio: 3 / 4; }
.cover-play-layer {
position: absolute;
inset: 0;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
}
.cover-play {
position: relative;
pointer-events: auto;
width: 44px;
height: 44px;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
border: 0;
border-radius: 50%;
background: rgba(0, 0, 0, 0.55);
color: #fff;
cursor: pointer;
}
.cover-play svg { width: 22px; height: 22px; display: block; }
.cover-play:hover { background: rgba(0, 0, 0, 0.72); }
.pick {
position: absolute;
top: 8px;