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
+178
View File
@@ -0,0 +1,178 @@
<script setup lang="ts">
import Hls from "hls.js";
interface Episode {
cid: number;
idx: number;
title: string;
playable: boolean;
}
const props = defineProps<{
token: string;
device: object | null;
dramaId: number;
}>();
const episodes = ref<Episode[]>([]);
const current = ref<number | null>(null);
const loading = ref(false);
const error = ref("");
const videoRef = ref<HTMLVideoElement | null>(null);
let hls: Hls | null = null;
const currentTitle = computed(() => episodes.value.find((item) => item.cid === current.value)?.title || "");
async function load() {
loading.value = true;
error.value = "";
try {
const response = await fetch("/api/play/episodes", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: props.token, device: props.device, vid: props.dramaId }),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
error.value = typeof payload.detail === "string" ? payload.detail : "没有读到分集";
return;
}
episodes.value = Array.isArray(payload.episodes) ? payload.episodes : [];
const first = episodes.value.find((item) => item.playable);
if (!first) {
error.value = "缓存和当前账号都没有可播放的集";
return;
}
select(first);
} catch (exc) {
error.value = exc instanceof Error ? exc.message : "没有读到分集";
} finally {
loading.value = false;
}
}
function select(episode: Episode) {
if (!episode.playable || episode.cid === current.value) return;
current.value = episode.cid;
error.value = "";
void nextTick(() => attach(episode.cid));
}
function attach(cid: number) {
const video = videoRef.value;
if (!video) return;
stop();
const url = `/api/play/${props.dramaId}/${cid}/index.m3u8`;
if (Hls.isSupported()) {
const player = new Hls();
hls = player;
player.loadSource(url);
player.attachMedia(video);
player.on(Hls.Events.MANIFEST_PARSED, () => {
video.play().catch(() => undefined);
});
player.on(Hls.Events.ERROR, (_event, data) => {
if (data.fatal) error.value = "这一集播放失败";
});
return;
}
video.src = url;
video.play().catch(() => undefined);
}
function stop() {
hls?.destroy();
hls = null;
if (videoRef.value) {
videoRef.value.removeAttribute("src");
videoRef.value.load();
}
}
onMounted(load);
onUnmounted(stop);
</script>
<template>
<div class="play-page">
<div class="play-stage">
<div class="play-video-wrap">
<video ref="videoRef" class="play-video" controls playsinline></video>
<div v-if="loading || error" class="play-status">{{ loading ? "正在读取分集" : error }}</div>
</div>
<div v-if="currentTitle" class="play-now">{{ currentTitle }}</div>
</div>
<aside class="play-side">
<div class="play-side-title">选集</div>
<div class="play-episodes">
<button
v-for="episode in episodes"
:key="episode.cid"
type="button"
class="play-episode"
:class="{ current: episode.cid === current }"
:disabled="!episode.playable"
@click="select(episode)"
>
<span class="play-episode-title">{{ episode.title }}</span>
<span v-if="!episode.playable" class="play-episode-lock">无地址</span>
</button>
<div v-if="!loading && episodes.length === 0" class="play-empty">没有分集</div>
</div>
</aside>
</div>
</template>
<style>
.play-page { height: 100%; min-height: 0; display: flex; overflow: hidden; background: #101014; }
.play-stage { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.play-video-wrap { position: relative; flex: 1; min-height: 0; background: #000; }
.play-video { display: block; width: 100%; height: 100%; background: #000; }
.play-status {
position: absolute;
left: 16px;
right: 16px;
bottom: 56px;
color: rgba(255, 255, 255, 0.8);
text-align: center;
}
.play-now {
flex: none;
padding: 8px 16px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: rgba(255, 255, 255, 0.72);
}
.play-side {
width: 280px;
flex: none;
min-height: 0;
display: flex;
flex-direction: column;
border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.play-side-title { flex: none; padding: 12px 16px 8px; font-weight: 600; }
.play-episodes { flex: 1; min-height: 0; overflow: auto; padding: 0 8px 12px; }
.play-episode {
width: 100%;
display: flex;
align-items: center;
gap: 8px;
min-height: 36px;
margin: 0 0 4px;
padding: 6px 10px;
border: 0;
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
}
.play-episode.current { background: rgba(99, 226, 183, 0.16); }
.play-episode:disabled { color: rgba(255, 255, 255, 0.35); cursor: default; }
.play-episode-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-episode-lock { flex: none; font-size: 12px; }
.play-empty { padding: 8px 10px; color: rgba(255, 255, 255, 0.45); }
</style>