feat: 补全短剧全量清单并接入 DramaBox 官网登录
This commit is contained in:
+62
-3
@@ -106,6 +106,8 @@ const platformLabel = computed(() => {
|
||||
});
|
||||
const dramaboxLang = ref("th");
|
||||
const dramaboxLangs = ref<{ label: string; value: string }[]>([]);
|
||||
const accountBusy = ref(false);
|
||||
const profileError = ref("");
|
||||
const method = ref<Method>("guest");
|
||||
const email = ref("");
|
||||
const password = ref("");
|
||||
@@ -658,6 +660,50 @@ async function loginHuangdou() {
|
||||
}
|
||||
}
|
||||
|
||||
function errorText(exc: unknown, fallback: string) {
|
||||
if (typeof exc === "string" && exc.trim()) return exc;
|
||||
if (exc instanceof Error && exc.message) return exc.message;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loginDramaboxAccount() {
|
||||
const inside = Boolean(token.value);
|
||||
error.value = "";
|
||||
profileError.value = "";
|
||||
if (inside) accountBusy.value = true;
|
||||
else busy.value = true;
|
||||
try {
|
||||
if (!inTauri()) throw new Error("请在桌面程序里登录");
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
const language = dramaboxLang.value || profile.value?.locale || "th";
|
||||
const user = await invoke<Record<string, unknown>>("dramabox_login", { language });
|
||||
localStorage.setItem(DRAMABOX_LANG_KEY, language);
|
||||
const response = await fetch("/api/dramabox/login/account", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ language, user }),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "登录失败");
|
||||
}
|
||||
token.value = payload.token;
|
||||
profile.value = payload.profile;
|
||||
sessionStorage.setItem(tokenKey(), payload.token);
|
||||
if (!inside) {
|
||||
page.value = "download";
|
||||
startLive();
|
||||
}
|
||||
} catch (exc) {
|
||||
const message = errorText(exc, "登录失败");
|
||||
if (inside) profileError.value = message;
|
||||
else error.value = message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
accountBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loginDramabox() {
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
@@ -999,7 +1045,11 @@ onUnmounted(stopLive);
|
||||
</div>
|
||||
</div>
|
||||
<div class="profile-block">
|
||||
<div class="profile-block-title">账号</div>
|
||||
<div class="profile-block-title">
|
||||
账号
|
||||
<n-button v-if="platform === 'dramabox'" size="tiny" secondary :loading="accountBusy" @click="loginDramaboxAccount">登录</n-button>
|
||||
</div>
|
||||
<n-alert v-if="profileError" class="hint" type="error" :show-icon="false">{{ profileError }}</n-alert>
|
||||
<div v-for="item in accountFields" :key="item.key" class="profile-row">
|
||||
<span class="profile-row-label">{{ item.label }}</span>
|
||||
<span class="profile-row-value">{{ profileText(item.key) }}</span>
|
||||
@@ -1075,6 +1125,7 @@ onUnmounted(stopLive);
|
||||
<n-text v-if="platform === 'rapt' && method === 'adb'" class="hint" depth="3">从已 root 的设备读取当前登录账号。未 root 的设备无法获取登录信息。默认同时读取这台设备的品牌、型号和系统版本,可在右下角设置里修改。</n-text>
|
||||
<n-alert v-if="error" class="hint" type="error" :show-icon="false">{{ error }}</n-alert>
|
||||
<div class="login-actions">
|
||||
<n-button v-if="platform === 'dramabox'" attr-type="button" :loading="busy" @click="loginDramaboxAccount">登录</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ isolated ? "进入" : "登录" }}</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
@@ -1265,7 +1316,15 @@ html { color-scheme: dark; }
|
||||
.profile-stat-value { font-size: 18px; font-weight: 600; line-height: 1.2; }
|
||||
.profile-stat-label { font-size: 12px; color: rgba(255, 255, 255, 0.45); }
|
||||
.profile-block { border-top: 1px solid rgba(255, 255, 255, 0.08); }
|
||||
.profile-block-title { padding: 12px 16px 0; font-size: 13px; color: rgba(255, 255, 255, 0.45); }
|
||||
.profile-block-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 12px 16px 0;
|
||||
font-size: 13px;
|
||||
color: rgba(255, 255, 255, 0.45);
|
||||
}
|
||||
.profile-row { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 8px 16px; }
|
||||
.profile-row-label { width: 72px; flex: none; color: rgba(255, 255, 255, 0.72); }
|
||||
.profile-row-value {
|
||||
@@ -1345,7 +1404,7 @@ html { color-scheme: dark; }
|
||||
padding: 28px 20px;
|
||||
}
|
||||
.card { width: 100%; max-width: 560px; }
|
||||
.login-actions { display: flex; justify-content: center; margin-top: 16px; }
|
||||
.login-actions { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
|
||||
.login-actions .n-button { min-width: 180px; }
|
||||
.settings-button { position: fixed; right: 20px; bottom: 20px; z-index: 5; }
|
||||
.gear-icon { width: 18px; height: 18px; display: block; }
|
||||
|
||||
@@ -36,6 +36,21 @@ function coverOf(image: string) {
|
||||
return `https://apis.raptdrama.com${image.startsWith("/") ? image : `/${image}`}`;
|
||||
}
|
||||
|
||||
const coverStatus = ref<Record<string, "ready" | "failed">>({});
|
||||
|
||||
function coverState(image: string): "empty" | "loading" | "ready" | "failed" {
|
||||
const src = coverOf(image);
|
||||
if (!src) return "empty";
|
||||
const status = coverStatus.value[src];
|
||||
if (status === "ready" || status === "failed") return status;
|
||||
return "loading";
|
||||
}
|
||||
|
||||
function markCover(src: string, ok: boolean) {
|
||||
if (!src || coverStatus.value[src]) return;
|
||||
coverStatus.value = { ...coverStatus.value, [src]: ok ? "ready" : "failed" };
|
||||
}
|
||||
|
||||
async function holdAll() {
|
||||
if (!props.active.length || holding.value) return;
|
||||
holding.value = true;
|
||||
@@ -136,8 +151,16 @@ async function remove(id: string) {
|
||||
<div class="job-scroll">
|
||||
<div v-if="!props.active.length" class="progress-empty">没有正在下载的剧</div>
|
||||
<article v-for="job in props.active" :key="job.id" class="job">
|
||||
<img v-if="coverOf(job.image)" class="job-cover" :src="coverOf(job.image)" alt="" />
|
||||
<div v-else class="job-cover"></div>
|
||||
<span class="job-cover" :class="coverState(job.image)">
|
||||
<span v-if="coverState(job.image) === 'loading'" class="job-cover-spin" aria-hidden="true"></span>
|
||||
<img
|
||||
v-if="coverOf(job.image)"
|
||||
:src="coverOf(job.image)"
|
||||
alt=""
|
||||
@load="markCover(coverOf(job.image), true)"
|
||||
@error="markCover(coverOf(job.image), false)"
|
||||
/>
|
||||
</span>
|
||||
<div class="job-main">
|
||||
<div class="job-line">
|
||||
<n-text strong class="job-title">{{ job.title }}</n-text>
|
||||
@@ -184,8 +207,16 @@ async function remove(id: string) {
|
||||
<div class="job-scroll">
|
||||
<div v-if="!props.done.length" class="progress-empty">还没有完成的下载</div>
|
||||
<article v-for="job in props.done" :key="job.id" class="job">
|
||||
<img v-if="coverOf(job.image)" class="job-cover" :src="coverOf(job.image)" alt="" />
|
||||
<div v-else class="job-cover"></div>
|
||||
<span class="job-cover" :class="coverState(job.image)">
|
||||
<span v-if="coverState(job.image) === 'loading'" class="job-cover-spin" aria-hidden="true"></span>
|
||||
<img
|
||||
v-if="coverOf(job.image)"
|
||||
:src="coverOf(job.image)"
|
||||
alt=""
|
||||
@load="markCover(coverOf(job.image), true)"
|
||||
@error="markCover(coverOf(job.image), false)"
|
||||
/>
|
||||
</span>
|
||||
<div class="job-main">
|
||||
<div class="job-line">
|
||||
<n-text strong class="job-title">{{ job.title }}</n-text>
|
||||
@@ -269,7 +300,30 @@ async function remove(id: string) {
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
.job-cover { width: 48px; height: 64px; object-fit: cover; border-radius: 6px; background: #2a2a2a; flex: none; }
|
||||
.job-cover {
|
||||
position: relative;
|
||||
width: 48px;
|
||||
height: 64px;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
.job-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.job-cover.loading img,
|
||||
.job-cover.failed img { position: absolute; width: 0; height: 0; opacity: 0; }
|
||||
.job-cover-spin {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid rgba(99, 226, 183, 0.28);
|
||||
border-top-color: #63e2b7;
|
||||
animation: job-cover-spin 0.7s linear infinite;
|
||||
}
|
||||
@keyframes job-cover-spin { to { transform: rotate(360deg); } }
|
||||
.job-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
|
||||
.job-line { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
|
||||
.job-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
@@ -42,6 +42,7 @@ const flashSerial = ref(0);
|
||||
const directory = ref("");
|
||||
const starting = ref(false);
|
||||
const footError = ref("");
|
||||
const coverStatus = ref<Record<string, "ready" | "failed">>({});
|
||||
const emit = defineEmits<{ started: []; play: [Drama] }>();
|
||||
const scrollEl = ref<HTMLElement | null>(null);
|
||||
|
||||
@@ -52,6 +53,19 @@ function coverOf(image: string) {
|
||||
return `https://apis.raptdrama.com${image.startsWith("/") ? image : `/${image}`}`;
|
||||
}
|
||||
|
||||
function coverState(image: string): "empty" | "loading" | "ready" | "failed" {
|
||||
const src = coverOf(image);
|
||||
if (!src) return "empty";
|
||||
const status = coverStatus.value[src];
|
||||
if (status === "ready" || status === "failed") return status;
|
||||
return "loading";
|
||||
}
|
||||
|
||||
function markCover(src: string, ok: boolean) {
|
||||
if (!src || coverStatus.value[src]) return;
|
||||
coverStatus.value = { ...coverStatus.value, [src]: ok ? "ready" : "failed" };
|
||||
}
|
||||
|
||||
function isExpanded(key: string) {
|
||||
return expanded.value.includes(key);
|
||||
}
|
||||
@@ -441,10 +455,17 @@ async function startDownload() {
|
||||
:data-card="cardKey(section.key, item.id)"
|
||||
@click="toggleDrama(item.id, !selected.has(dramaKey(item.id)))"
|
||||
>
|
||||
<div class="cover">
|
||||
<img v-if="item.image" :src="coverOf(item.image)" :alt="item.title" />
|
||||
<div class="cover" :class="coverState(item.image)">
|
||||
<span v-if="coverState(item.image) === 'loading'" class="cover-spin" aria-hidden="true"></span>
|
||||
<img
|
||||
v-if="coverOf(item.image)"
|
||||
:src="coverOf(item.image)"
|
||||
:alt="item.title"
|
||||
@load="markCover(coverOf(item.image), true)"
|
||||
@error="markCover(coverOf(item.image), false)"
|
||||
/>
|
||||
<span v-if="item.corner || item.locked || item.limitedFree" class="cover-tag">{{ item.corner || (item.limitedFree ? "限免" : item.payType || "付费") }}</span>
|
||||
<div class="cover-play-layer">
|
||||
<div v-if="coverState(item.image) !== 'loading'" class="cover-play-layer">
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="cover-play" aria-label="播放" @click.stop="emit('play', item)">
|
||||
@@ -551,7 +572,22 @@ async function startDownload() {
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
cursor: pointer;
|
||||
}
|
||||
.cover { position: relative; background: #2a2a2a; }
|
||||
.cover {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
aspect-ratio: 3 / 4;
|
||||
background: transparent;
|
||||
}
|
||||
.cover-spin {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid rgba(99, 226, 183, 0.28);
|
||||
border-top-color: #63e2b7;
|
||||
animation: category-spin 0.7s linear infinite;
|
||||
}
|
||||
.cover-tag {
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
@@ -568,8 +604,9 @@ async function startDownload() {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cover img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
|
||||
.cover:not(:has(img)) { aspect-ratio: 3 / 4; }
|
||||
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
||||
.cover.loading img,
|
||||
.cover.failed img { position: absolute; width: 0; height: 0; opacity: 0; }
|
||||
.cover-play-layer {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
||||
Reference in New Issue
Block a user