feat: 补全短剧全量清单并接入 DramaBox 官网登录

This commit is contained in:
Nixevol
2026-10-22 02:20:16 +08:00
parent 39774ad9cc
commit 00e78661a7
22 changed files with 894 additions and 194 deletions
+62 -3
View File
@@ -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; }