Files
RaptDramaDump/ui/src/App.vue
T

2115 lines
72 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { darkTheme, dateZhCN, zhCN, type GlobalThemeOverrides } from "naive-ui";
import { getCurrentWindow } from "@tauri-apps/api/window";
import VideoListPage from "./views/VideoListPage.vue";
import DownloadProgressPage from "./views/DownloadProgressPage.vue";
import SettingsPanel from "./views/SettingsPanel.vue";
import PlayerPage from "./views/PlayerPage.vue";
type Method = "guest" | "password" | "adb";
type Platform = "rapt" | "huangdou" | "dramabox";
interface Profile {
nickname?: string;
email?: string | null;
id?: string | number;
badge?: string;
vipday?: number;
score?: number;
watched?: number;
rewards?: number;
login_day?: number;
email_bind?: number;
mobile_bind?: number;
google_bind?: number;
apple_bind?: number;
avatarNumUrl?: string;
username?: string;
phone?: string;
group_name?: string;
balance?: string | number;
is_vip?: string | number;
has_login?: string;
host?: string;
country?: string;
language?: string;
native?: string;
locale?: string;
loginType?: string;
}
interface Device {
serial: string;
model: string;
rooted: boolean;
state: string;
}
interface SavedAccount {
email: string;
password: string;
nickname: string;
uid: string;
}
interface HuangdouAccount {
username: string;
password: string;
nickname: string;
}
interface DeviceProfile {
brand: string;
model: string;
os_version: string;
device_type: string;
physical: boolean;
device_id: string;
fingerprint: string;
app_version: string;
app_build: string;
language: string;
}
interface ProxySettings {
mode: "off" | "system" | "custom";
scheme: "http" | "socks5";
host: string;
port: string;
username: string;
password: string;
}
function emptyProxy(): ProxySettings {
return { mode: "off", scheme: "http", host: "", port: "", username: "", password: "" };
}
function normalizeProxy(value: Partial<ProxySettings> | null | undefined): ProxySettings {
const proxy = { ...emptyProxy(), ...(value || {}) };
if (proxy.mode !== "off" && proxy.mode !== "system" && proxy.mode !== "custom") proxy.mode = "off";
if (proxy.scheme !== "http" && proxy.scheme !== "socks5") proxy.scheme = "http";
proxy.host = String(proxy.host || "");
proxy.port = String(proxy.port || "");
proxy.username = String(proxy.username || "");
proxy.password = String(proxy.password || "");
return proxy;
}
const DEVICE_KEY = "rapt-device-settings";
const SESSION_DEVICE_KEY = "rapt-device";
const ACCOUNTS_KEY = "rapt-accounts";
const PLATFORM_KEY = "rapt-platform";
const DRAMABOX_LANG_KEY = "dramabox-language";
const HUANGDOU_HOST_KEY = "huangdou-host";
const HUANGDOU_ACCOUNTS_KEY = "huangdou-accounts";
const HUANGDOU_REMEMBER_KEY = "huangdou-remember";
const DRAMABOX_DEVICE_KEY = "dramabox-device";
const themeOverrides: GlobalThemeOverrides = {
Form: {
labelFontSizeLeftSmall: "14px",
},
};
const platforms: { key: Platform; label: string }[] = [
{ key: "rapt", label: "RaptDrama" },
{ key: "huangdou", label: "黄豆短剧" },
{ key: "dramabox", label: "DramaBox" },
];
const platform = ref<Platform>(readPlatform());
const isolated = computed(() => platform.value === "huangdou" || platform.value === "dramabox");
const apiBase = computed(() => {
if (platform.value === "huangdou") return "/api/huangdou";
if (platform.value === "dramabox") return "/api/dramabox";
return "/api";
});
const platformLabel = computed(() => {
const name = platforms.find((item) => item.key === platform.value)?.label || "VideosDownTools";
if (platform.value === "dramabox" && profile.value?.nickname) return `${name} · ${profile.value.nickname}`;
return name;
});
const dramaboxLang = ref("th");
const huangdouHost = ref(readHuangdouHost());
const huangdouUser = ref("");
const huangdouPassword = ref("");
const huangdouRemember = ref(readHuangdouRemember());
const huangdouAccounts = ref<HuangdouAccount[]>([]);
const huangdouSelected = ref<string | null>(null);
const huangdouFingerprintBusy = ref(false);
const huangdouFingerprintNote = ref("");
const dramaboxLangs = ref<{ label: string; value: string }[]>([]);
const accountBusy = ref(false);
const activeProxyUrl = ref("");
const profileError = ref("");
const signNotice = ref("");
const method = ref<Method>("guest");
const email = ref("");
const password = ref("");
const serial = ref<string | null>(null);
const devices = ref<Device[]>([]);
const devicesBusy = ref(false);
const busy = ref(false);
const error = ref("");
const token = ref("");
const profile = ref<Profile | null>(null);
const dramaboxLoggedIn = computed(() => profile.value?.has_login === "1");
const dramaboxDeviceReady = computed(() => devices.value.some((item) => item.state === "device"));
const credentialFile = ref<HTMLInputElement | null>(null);
const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download");
const playing = ref<{ id: string | number; title: string; image: string } | null>(null);
const progressCount = ref(0);
interface LiveJob {
id: string;
title: string;
image: string;
status: string;
episode_count: number;
done_count: number;
progress: number;
speed: string;
stage: string;
completed_at: string;
error: string;
}
const downloadState = ref<{ active: LiveJob[]; done: LiveJob[]; active_count: number }>({
active: [],
done: [],
active_count: 0,
});
const downloadRef = ref<{
reload: (refresh?: boolean) => void;
busy: boolean;
find: (keyword?: string) => void;
searchHint: string;
clearSearch: () => void;
loadDirectory: () => Promise<void>;
} | null>(null);
const catalogQuery = ref("");
const catalogMaxPages = ref(99);
let catalogPagesTimer: number | null = null;
const mainMenu = computed(() => [
{ label: "视频清单", key: "download" },
{
key: "progress",
label: () =>
h("span", { class: "nav-label" }, [
"下载进度",
progressCount.value
? h("span", { class: "nav-badge" }, String(progressCount.value))
: null,
]),
},
{ label: "系统设置", key: "settings" },
]);
const pageTitle = computed(() => {
if (page.value === "play") return playing.value?.title || "播放";
if (page.value === "progress") return "下载进度";
if (page.value === "profile") return "个人信息";
if (page.value === "settings") return "系统设置";
return "视频清单";
});
const menuValue = computed(() => {
if (page.value === "profile") return null;
if (page.value === "play") return "download";
return page.value;
});
function currentBrowserFingerprint() {
const ua = navigator.userAgent || "";
let browserName = "Chrome";
if (ua.includes("Edg/")) browserName = "Edge";
else if (ua.includes("Firefox/")) browserName = "Firefox";
else if (ua.includes("Safari/") && !ua.includes("Chrome/")) browserName = "Safari";
return {
browserName,
language: navigator.language || "zh-CN",
userAgent: ua,
platform: navigator.platform || "Win32",
};
}
async function sendHuangdouFingerprint() {
try {
await fetch("/api/huangdou/fingerprint", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(currentBrowserFingerprint()),
});
} catch {
// 首次指纹沿用代码里的默认值
}
}
async function rollHuangdouFingerprint() {
huangdouFingerprintNote.value = "";
error.value = "";
huangdouFingerprintBusy.value = true;
try {
const response = await fetch("/api/huangdou/fingerprint/roll", { method: "POST" });
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "更换失败");
}
huangdouFingerprintNote.value = "已更换设备指纹";
} catch (exc) {
error.value = exc instanceof Error ? exc.message : "更换失败";
} finally {
huangdouFingerprintBusy.value = false;
}
}
function readHuangdouRemember() {
try {
return localStorage.getItem(HUANGDOU_REMEMBER_KEY) !== "0";
} catch {
return true;
}
}
function readHuangdouHost() {
try {
const value = localStorage.getItem(HUANGDOU_HOST_KEY) || "";
if (value.trim()) return value.trim();
} catch {
// 沿用默认域名
}
return "https://pmihlvee.cc";
}
function readPlatform(): Platform {
try {
const value = localStorage.getItem(PLATFORM_KEY);
if (value === "huangdou" || value === "rapt" || value === "dramabox") return value;
} catch {
// 沿用默认平台
}
return "rapt";
}
function selectPlatform(key: string) {
if (key !== "rapt" && key !== "huangdou" && key !== "dramabox") return;
platform.value = key;
localStorage.setItem(PLATFORM_KEY, key);
error.value = "";
if (key === "dramabox") {
void loadDramaboxLanguages();
void loadDevices();
}
if (key === "huangdou") void sendHuangdouFingerprint();
}
function tokenKey() {
if (platform.value === "huangdou") return "huangdou-token";
if (platform.value === "dramabox") return "dramabox-token";
return "rapt-token";
}
function readSavedToken() {
try {
return localStorage.getItem(tokenKey()) || "";
} catch {
return "";
}
}
function writeSavedToken(value: string) {
localStorage.setItem(tokenKey(), value);
}
function forgetSavedToken() {
localStorage.removeItem(tokenKey());
}
async function loadDramaboxLanguages() {
try {
const response = await fetch("/api/dramabox/languages");
const payload = await response.json();
const items = Array.isArray(payload.items) ? payload.items : [];
dramaboxLangs.value = items.map((item: { id: string; label: string }) => ({
label: item.label,
value: item.id,
}));
} catch {
dramaboxLangs.value = [];
}
if (!dramaboxLangs.value.length) {
dramaboxLangs.value = [
{ label: "泰国 · 泰语", value: "th" },
{ label: "美国 · 英语", value: "en" },
];
}
try {
const saved = localStorage.getItem(DRAMABOX_LANG_KEY);
if (saved && dramaboxLangs.value.some((item) => item.value === saved)) dramaboxLang.value = saved;
} catch {
// 使用默认地区
}
}
function openPlay(drama: { id: string | number; title: string; image: string }) {
playing.value = drama;
page.value = "play";
}
function closePlay() {
page.value = "download";
playing.value = null;
}
watch(catalogQuery, (value) => {
if (!String(value ?? "").trim()) downloadRef.value?.clearSearch();
});
let liveSocket: WebSocket | null = null;
const builtinDevice = ref<DeviceProfile>({
brand: "Redmi",
model: "23113RKC6C",
os_version: "12",
device_type: "phone",
physical: true,
device_id: "rd_c9f0fa17a39f96aa",
fingerprint: "0a4e4b212cbb0a2434cf804c8e30ab58",
app_version: "1.1.81",
app_build: "139",
language: "en-US",
});
const settings = ref({
adbMode: "device" as "device" | "settings",
custom: { ...builtinDevice.value },
proxy: emptyProxy(),
workers: 6,
directory: "",
defaultDirectory: "",
});
const settingsError = ref("");
const settingsBusy = ref(false);
const settingsOpen = ref(false);
const settingsTab = ref<"device" | "proxy" | "download">("device");
const draft = ref(copySettings(settings.value));
const rememberPassword = ref(true);
const savedAccounts = ref<SavedAccount[]>([]);
const selectedAccount = ref<string | null>(null);
const methods: { id: Method; label: string }[] = [
{ id: "guest", label: "游客" },
{ id: "password", label: "账号密码" },
{ id: "adb", label: "ADB" },
];
const profileSub = computed(() => {
if (!profile.value) return "";
if (platform.value === "huangdou") {
if (profile.value.has_login === "1") {
return profile.value.username || profile.value.phone || profile.value.email || "";
}
return "访客";
}
if (platform.value === "dramabox") return profile.value.native || profile.value.email || "";
return profile.value.email || "未绑定邮箱";
});
const accountFields = computed(() => {
if (platform.value === "huangdou") {
return [
{ key: "username" as const, label: "账号" },
{ key: "id" as const, label: "用户 ID" },
{ key: "group_name" as const, label: "身份" },
{ key: "email" as const, label: "邮箱" },
{ key: "phone" as const, label: "手机" },
];
}
if (platform.value === "dramabox") {
if (profile.value?.has_login === "1") {
return [
{ key: "nickname" as const, label: "昵称" },
{ key: "email" as const, label: "邮箱" },
{ key: "id" as const, label: "用户 ID" },
{ key: "loginType" as const, label: "登录方式" },
{ key: "country" as const, label: "国家" },
{ key: "language" as const, label: "语言" },
];
}
return [
{ key: "country" as const, label: "国家" },
{ key: "language" as const, label: "语言" },
];
}
return [
{ key: "email" as const, label: "邮箱" },
{ key: "id" as const, label: "用户 ID" },
];
});
const statFields = computed(() =>
platform.value === "huangdou"
? [
{ key: "vipday" as const, label: "VIP" },
{ key: "score" as const, label: "余额" },
{ key: "watched" as const, label: "观看" },
]
: platform.value === "dramabox"
? []
: [
{ key: "vipday" as const, label: "VIP" },
{ key: "score" as const, label: "积分" },
{ key: "watched" as const, label: "观看" },
{ key: "rewards" as const, label: "奖励" },
{ key: "login_day" as const, label: "登录" },
],
);
const bindFields: { key: keyof Profile; label: string }[] = [
{ key: "email_bind", label: "邮箱" },
{ key: "mobile_bind", label: "手机" },
{ key: "google_bind", label: "Google" },
{ key: "apple_bind", label: "Apple" },
];
function copySettings<T>(value: T): T {
return JSON.parse(JSON.stringify(value));
}
function loadSettings() {
try {
const data = JSON.parse(localStorage.getItem(DEVICE_KEY) || "");
if (data.adbMode === "device" || data.adbMode === "settings") settings.value.adbMode = data.adbMode;
if (data.mode === "default") {
settings.value.custom = { ...builtinDevice.value };
} else if (data.custom && typeof data.custom === "object") {
settings.value.custom = { ...builtinDevice.value, ...data.custom };
}
if (data.proxy && typeof data.proxy === "object") {
settings.value.proxy = normalizeProxy(data.proxy);
}
} catch {
settings.value.custom = { ...builtinDevice.value };
}
}
async function loadDeviceDefaults() {
const response = await fetch("/api/device/defaults");
if (!response.ok) return;
builtinDevice.value = { ...builtinDevice.value, ...(await response.json()) };
}
function normalizeWorkers(value: unknown) {
const count = Number(value);
if (!Number.isInteger(count) || count < 1) return 6;
return count;
}
function normalizeCatalogPages(value: unknown) {
const count = Number(value);
if (!Number.isInteger(count) || count < 1) return 99;
return Math.min(count, 999);
}
async function loadCatalogSettings() {
if (platform.value !== "dramabox") return;
try {
const response = await fetch("/api/dramabox/catalog/settings");
if (!response.ok) return;
const payload = await response.json();
catalogMaxPages.value = normalizeCatalogPages(payload.max_pages);
} catch {
catalogMaxPages.value = 99;
}
}
async function saveCatalogMaxPages(value: number) {
const pages = normalizeCatalogPages(value);
catalogMaxPages.value = pages;
try {
const response = await fetch("/api/dramabox/catalog/settings", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ max_pages: pages }),
});
if (!response.ok) return;
const payload = await response.json();
catalogMaxPages.value = normalizeCatalogPages(payload.max_pages);
} catch {
// 下次刷新会重新读取
}
}
function onCatalogMaxPages(value: number | null) {
if (value === null) return;
catalogMaxPages.value = normalizeCatalogPages(value);
if (catalogPagesTimer) window.clearTimeout(catalogPagesTimer);
catalogPagesTimer = window.setTimeout(() => {
void saveCatalogMaxPages(catalogMaxPages.value);
}, 400);
}
async function loadDownloadSettings() {
const response = await fetch(`${apiBase.value}/downloads/settings`);
if (!response.ok) return;
const payload = await response.json();
settings.value.workers = normalizeWorkers(payload.workers);
settings.value.directory = typeof payload.directory === "string" ? payload.directory : "";
settings.value.defaultDirectory = typeof payload.default_directory === "string" ? payload.default_directory : "";
}
async function enterSettings() {
settingsError.value = "";
if (isolated.value && settingsTab.value === "device") settingsTab.value = "download";
await loadDownloadSettings();
draft.value = copySettings(settings.value);
}
async function openSettings() {
settingsTab.value = isolated.value ? "download" : "device";
await enterSettings();
settingsOpen.value = true;
}
watch(page, (value) => {
if (value === "settings") void enterSettings();
if (value === "profile" && platform.value === "dramabox") void loadDevices();
});
watch(
() => platform.value === "dramabox" && !!profile.value,
(ready) => {
if (ready) void loadCatalogSettings();
},
{ immediate: true },
);
async function applyProxy(proxy: ProxySettings) {
const response = await fetch("/api/proxy", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(proxy),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "代理设置失败");
}
activeProxyUrl.value = typeof payload.url === "string" ? payload.url : "";
}
// 代理存在后台文件里。页面地址每次启动端口不同,不能只靠浏览器本地存储。
async function loadProxySettings() {
const response = await fetch("/api/proxy");
if (response.ok) {
const payload = await response.json().catch(() => ({}));
const server = normalizeProxy(payload);
if (server.mode !== "off") {
settings.value.proxy = server;
activeProxyUrl.value = typeof payload.url === "string" ? payload.url : "";
return;
}
}
if (settings.value.proxy.mode !== "off") await applyProxy(settings.value.proxy);
}
async function saveSettings() {
settingsError.value = "";
const proxy = draft.value.proxy;
if (proxy.mode === "custom") {
if (!proxy.host.trim()) {
settingsTab.value = "proxy";
settingsError.value = "请填写代理地址";
return;
}
const port = Number(proxy.port);
if (!Number.isInteger(port) || port < 1 || port > 65535) {
settingsTab.value = "proxy";
settingsError.value = "请填写 1 到 65535 的端口";
return;
}
}
const workers = normalizeWorkers(draft.value.workers);
if (workers !== Number(draft.value.workers)) {
settingsTab.value = "download";
settingsError.value = "同时下载数量至少为 1";
return;
}
const directory = draft.value.directory.trim();
settingsBusy.value = true;
try {
await applyProxy(proxy);
settings.value.proxy = copySettings(proxy);
localStorage.setItem(DEVICE_KEY, JSON.stringify({
adbMode: settings.value.adbMode,
custom: settings.value.custom,
proxy: settings.value.proxy,
}));
if (!directory) {
settingsTab.value = "download";
settingsError.value = "请选择下载目录";
return;
}
const response = await fetch(`${apiBase.value}/downloads/settings`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ directory, workers }),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
settingsTab.value = "download";
settingsError.value = typeof payload.detail === "string" ? payload.detail : "下载设置失败";
return;
}
draft.value.directory = payload.directory || directory;
draft.value.workers = normalizeWorkers(payload.workers);
draft.value.defaultDirectory = payload.default_directory || draft.value.defaultDirectory;
settings.value = copySettings(draft.value);
localStorage.setItem(DEVICE_KEY, JSON.stringify({
adbMode: settings.value.adbMode,
custom: settings.value.custom,
proxy: settings.value.proxy,
}));
await downloadRef.value?.loadDirectory();
settingsOpen.value = false;
} catch (exc) {
settingsError.value = exc instanceof Error ? exc.message : "设置保存失败";
} finally {
settingsBusy.value = false;
}
}
async function chooseDownloadDirectory() {
settingsError.value = "";
const response = await fetch(`${apiBase.value}/downloads/choose`, { method: "POST" });
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
settingsError.value = typeof payload.detail === "string" ? payload.detail : "目录选择失败";
return;
}
if (typeof payload.directory === "string" && payload.directory) draft.value.directory = payload.directory;
}
function restoreCurrent() {
settingsError.value = "";
if (settingsTab.value === "device") {
draft.value.custom = { ...builtinDevice.value };
draft.value.adbMode = "device";
return;
}
if (settingsTab.value === "proxy") {
draft.value.proxy = emptyProxy();
return;
}
draft.value.workers = 6;
draft.value.directory = draft.value.defaultDirectory || settings.value.defaultDirectory;
}
function settingsDevice(): DeviceProfile {
return settings.value.custom;
}
function rememberSessionDevice(device: DeviceProfile | undefined) {
if (!device) return;
sessionStorage.setItem(SESSION_DEVICE_KEY, JSON.stringify(device));
}
function sessionDevice(): DeviceProfile | null {
try {
const raw = sessionStorage.getItem(SESSION_DEVICE_KEY);
return raw ? JSON.parse(raw) : settingsDevice();
} catch {
return settingsDevice();
}
}
const deviceOptions = computed(() =>
devices.value.map((item) => ({
label: deviceLabel(item),
value: item.serial,
disabled: item.state !== "device",
})),
);
const accountOptions = computed(() =>
savedAccounts.value.map((item) => ({
label: item.nickname ? `${item.nickname} · ${item.email}` : item.email,
value: item.email,
})),
);
const huangdouAccountOptions = computed(() =>
huangdouAccounts.value.map((item) => ({
label: item.nickname ? `${item.nickname} · ${item.username}` : item.username,
value: item.username,
})),
);
function readList<T>(key: string): T[] {
try {
const data = JSON.parse(localStorage.getItem(key) || "[]");
return Array.isArray(data) ? data : [];
} catch {
return [];
}
}
function writeAccounts() {
localStorage.setItem(ACCOUNTS_KEY, JSON.stringify(savedAccounts.value));
}
function applyAccount(emailValue: string) {
const found = savedAccounts.value.find((item) => item.email === emailValue);
if (!found) return;
selectedAccount.value = found.email;
email.value = found.email;
password.value = found.password;
}
function removeAccount() {
if (!selectedAccount.value) return;
const removing = selectedAccount.value;
savedAccounts.value = savedAccounts.value.filter((item) => item.email !== removing);
writeAccounts();
if (email.value === removing) {
email.value = "";
password.value = "";
}
selectedAccount.value = savedAccounts.value[0]?.email ?? null;
if (selectedAccount.value) applyAccount(selectedAccount.value);
}
function saveAccount(info: Profile) {
const next: SavedAccount = {
email: email.value.trim(),
password: password.value,
nickname: info.nickname || "",
uid: info.id == null ? "" : String(info.id),
};
if (!next.email) return;
savedAccounts.value = [next, ...savedAccounts.value.filter((item) => item.email !== next.email)];
writeAccounts();
selectedAccount.value = next.email;
}
let huangdouAccountsReady = false;
let huangdouAccountTimer = 0;
function writeHuangdouAccounts() {
window.clearTimeout(huangdouAccountTimer);
huangdouAccountTimer = window.setTimeout(() => {
const accounts = huangdouAccounts.value.map((item) => ({
username: item.username,
password: item.password,
nickname: item.nickname || "",
}));
void fetch("/api/huangdou/accounts", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ accounts }),
});
}, 200);
}
function usableHuangdouAccounts(rows: HuangdouAccount[]) {
return rows.filter((item) => Boolean(item?.username) && typeof item.password === "string" && item.password);
}
async function loadHuangdouAccounts() {
const local = usableHuangdouAccounts(readList<HuangdouAccount>(HUANGDOU_ACCOUNTS_KEY));
let remote: HuangdouAccount[] = [];
try {
const response = await fetch("/api/huangdou/accounts");
if (response.ok) {
const payload = await response.json();
remote = usableHuangdouAccounts(Array.isArray(payload.accounts) ? payload.accounts : []);
}
} catch {
remote = [];
}
huangdouAccounts.value = remote.length ? remote : local;
if (!remote.length && local.length) writeHuangdouAccounts();
if (huangdouAccounts.value[0]) applyHuangdouAccount(huangdouAccounts.value[0].username);
}
function applyHuangdouAccount(username: string) {
const found = huangdouAccounts.value.find((item) => item.username === username);
if (!found) return;
huangdouSelected.value = found.username;
huangdouUser.value = found.username;
huangdouPassword.value = found.password;
huangdouRemember.value = true;
}
function removeHuangdouAccount() {
if (!huangdouSelected.value) return;
const removing = huangdouSelected.value;
huangdouAccounts.value = huangdouAccounts.value.filter((item) => item.username !== removing);
writeHuangdouAccounts();
if (huangdouUser.value === removing) {
huangdouUser.value = "";
huangdouPassword.value = "";
}
huangdouSelected.value = huangdouAccounts.value[0]?.username ?? null;
if (huangdouSelected.value) applyHuangdouAccount(huangdouSelected.value);
}
function saveHuangdouAccount(info: Profile) {
const username = huangdouUser.value.trim();
if (!username || !huangdouPassword.value) return;
const next: HuangdouAccount = {
username,
password: huangdouPassword.value,
nickname: info.nickname || info.username || "",
};
huangdouAccounts.value = [next, ...huangdouAccounts.value.filter((item) => item.username !== username)];
writeHuangdouAccounts();
huangdouSelected.value = username;
}
function forgetHuangdouAccount(username: string) {
const name = username.trim();
if (!name) return;
const next = huangdouAccounts.value.filter((item) => item.username !== name);
if (next.length === huangdouAccounts.value.length) return;
huangdouAccounts.value = next;
writeHuangdouAccounts();
if (huangdouSelected.value === name) huangdouSelected.value = next[0]?.username ?? null;
}
function profileText(key: keyof Profile) {
if (key === "loginType") {
const kind = String(profile.value?.loginType || "").trim().toLowerCase();
if (kind === "google") return "Google";
if (kind === "facebook") return "Facebook";
if (kind === "apple") return "Apple";
if (kind === "app") return "设备";
return kind ? String(profile.value?.loginType) : "—";
}
const value = profile.value?.[key];
if (value === undefined || value === null || value === "") return "—";
return String(value);
}
function profileNumber(key: keyof Profile) {
const value = Number(profile.value?.[key] ?? 0);
return Number.isFinite(value) ? String(value) : "0";
}
function profileBound(key: keyof Profile) {
return Number(profile.value?.[key] ?? 0) > 0;
}
function deviceLabel(item: Device) {
const mark =
item.state === "unauthorized" ? "未授权" : item.state === "offline" ? "离线" : item.rooted ? "已 root" : "未 root";
return `${item.model} · ${item.serial} · ${mark}`;
}
function rememberedSerial() {
try {
return localStorage.getItem(DRAMABOX_DEVICE_KEY) || "";
} catch {
return "";
}
}
function applyDeviceList(list: Device[]) {
devices.value = list;
const stillThere = devices.value.some((item) => item.serial === serial.value && item.state === "device");
if (!stillThere) {
const ready = devices.value.filter((item) => item.state === "device");
const remembered = ready.find((item) => item.serial === rememberedSerial());
serial.value = remembered?.serial || (ready.length === 1 ? ready[0].serial : null);
}
}
async function loadDevices() {
error.value = "";
devicesBusy.value = true;
try {
const response = await fetch("/api/adb/devices");
const payload = await response.json();
if (!response.ok) {
throw new Error(payload.detail || "读取设备失败");
}
applyDeviceList(payload.devices || []);
} catch (exc) {
devices.value = [];
serial.value = null;
error.value = exc instanceof Error ? exc.message : "读取设备失败";
} finally {
devicesBusy.value = false;
}
}
async function probeMumu() {
error.value = "";
devicesBusy.value = true;
try {
const response = await fetch("/api/adb/probe-mumu", { method: "POST" });
const payload = await response.json();
if (!response.ok) {
throw new Error(payload.detail || "没有连上 MuMu");
}
applyDeviceList(payload.devices || []);
const ready = devices.value.filter((item) => item.state === "device");
if (!ready.length) {
const ports = Array.isArray(payload.ports) ? payload.ports.join("、") : "";
throw new Error(ports ? `已尝试连接 MuMu 端口 ${ports},但设备还不可用。请在模拟器里允许调试后再探测。` : "没有连上 MuMu");
}
} catch (exc) {
if (!devices.value.length) serial.value = null;
error.value = exc instanceof Error ? exc.message : "没有连上 MuMu";
} finally {
devicesBusy.value = false;
}
}
watch(method, (value) => {
error.value = "";
if (value === "adb") loadDevices();
});
watch(huangdouRemember, (value) => {
try {
localStorage.setItem(HUANGDOU_REMEMBER_KEY, value ? "1" : "0");
} catch {
// 勾选状态只影响本机
}
});
watch(huangdouUser, (value) => {
const found = huangdouAccounts.value.find((item) => item.username === value.trim());
huangdouSelected.value = found ? found.username : null;
});
watch([huangdouRemember, huangdouUser, huangdouPassword], () => {
if (!huangdouAccountsReady) return;
const username = huangdouUser.value.trim();
if (!username) return;
if (huangdouRemember.value && huangdouPassword.value) {
const existing = huangdouAccounts.value.find((item) => item.username === username);
if (
existing &&
existing.password === huangdouPassword.value &&
huangdouAccounts.value[0]?.username === username
) {
huangdouSelected.value = username;
return;
}
huangdouAccounts.value = [
{
username,
password: huangdouPassword.value,
nickname: existing?.nickname || "",
},
...huangdouAccounts.value.filter((item) => item.username !== username),
];
huangdouSelected.value = username;
writeHuangdouAccounts();
return;
}
if (!huangdouRemember.value) {
const next = huangdouAccounts.value.filter((item) => item.username !== username);
if (next.length === huangdouAccounts.value.length) return;
huangdouAccounts.value = next;
if (huangdouSelected.value === username) huangdouSelected.value = next[0]?.username ?? null;
writeHuangdouAccounts();
}
});
async function loginHuangdou(asGuest = false) {
error.value = "";
if (!asGuest && (!huangdouUser.value.trim() || !huangdouPassword.value)) {
error.value = "请填写账号和密码";
return;
}
busy.value = true;
try {
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
huangdouHost.value = host;
localStorage.setItem(HUANGDOU_HOST_KEY, host);
const response = await fetch("/api/huangdou/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
host,
username: asGuest ? "" : huangdouUser.value.trim(),
password: asGuest ? "" : huangdouPassword.value,
}),
});
const payload = await response.json();
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "登录失败");
}
if (!asGuest) {
if (huangdouRemember.value) saveHuangdouAccount(payload.profile || {});
else forgetHuangdouAccount(huangdouUser.value);
}
token.value = payload.token;
profile.value = payload.profile;
takeSign(payload);
writeSavedToken(payload.token);
page.value = "download";
startLive();
} catch (exc) {
error.value = exc instanceof Error ? exc.message : "登录失败";
} finally {
busy.value = false;
}
}
async function loginDramaboxAdb() {
const inside = Boolean(token.value);
error.value = "";
profileError.value = "";
if (inside) accountBusy.value = true;
else busy.value = true;
try {
if (!serial.value) await loadDevices();
if (!serial.value && error.value) throw new Error(error.value);
const ready = devices.value.filter((item) => item.state === "device");
const picked = serial.value || "";
if (!picked) {
throw new Error(
ready.length
? "请选择设备"
: "没有检测到已连接的设备。手机请打开 USB 调试;MuMu 请先点探测。",
);
}
serial.value = picked;
localStorage.setItem(DRAMABOX_DEVICE_KEY, picked);
localStorage.setItem(DRAMABOX_LANG_KEY, dramaboxLang.value);
const response = await fetch("/api/dramabox/login/adb", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ serial: picked, language: dramaboxLang.value }),
});
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;
writeSavedToken(payload.token);
if (!inside) {
page.value = "download";
startLive();
}
} catch (exc) {
const message = exc instanceof Error ? exc.message : "读取登录失败";
if (inside) profileError.value = message;
else error.value = message;
} finally {
busy.value = false;
accountBusy.value = false;
}
}
function exportDramaboxCredential() {
const target = token.value ? profileError : error;
target.value = "";
accountBusy.value = Boolean(token.value);
busy.value = !token.value;
fetch("/api/dramabox/login/credential")
.then(async (response) => {
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "导出失败");
}
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "dramabox-login.json";
link.click();
URL.revokeObjectURL(url);
})
.catch((exc) => {
target.value = exc instanceof Error ? exc.message : "导出失败";
})
.finally(() => {
busy.value = false;
accountBusy.value = false;
});
}
function pickDramaboxCredential() {
credentialFile.value?.click();
}
async function onDramaboxCredential(event: Event) {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
input.value = "";
if (!file) return;
const inside = Boolean(token.value);
error.value = "";
profileError.value = "";
if (inside) accountBusy.value = true;
else busy.value = true;
try {
const text = await file.text();
const document = JSON.parse(text);
const response = await fetch("/api/dramabox/login/credential", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...document, language: dramaboxLang.value }),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(typeof payload.detail === "string" ? payload.detail : "导入失败");
}
token.value = payload.token;
profile.value = payload.profile;
writeSavedToken(payload.token);
if (!inside) {
page.value = "download";
startLive();
}
} catch (exc) {
const message = exc instanceof Error ? exc.message : "导入失败";
if (inside) profileError.value = message;
else error.value = message;
} finally {
busy.value = false;
accountBusy.value = false;
}
}
async function loginDramabox() {
error.value = "";
busy.value = true;
try {
localStorage.setItem(DRAMABOX_LANG_KEY, dramaboxLang.value);
const response = await fetch("/api/dramabox/login/device", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ language: dramaboxLang.value }),
});
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;
writeSavedToken(payload.token);
page.value = "download";
startLive();
} catch (exc) {
error.value = exc instanceof Error ? exc.message : "进入失败";
} finally {
busy.value = false;
}
}
async function login() {
if (platform.value === "huangdou") {
await loginHuangdou(false);
return;
}
if (platform.value === "dramabox") {
await loginDramabox();
return;
}
error.value = "";
busy.value = true;
try {
let path = "/api/login/guest";
let body: unknown = { device: settingsDevice() };
if (method.value === "password") {
path = "/api/login/password";
body = { email: email.value, password: password.value, device: settingsDevice() };
} else if (method.value === "adb") {
if (!serial.value) {
throw new Error("请选择设备");
}
path = "/api/login/adb";
const current = settings.value.custom;
body = {
serial: serial.value,
device_source: settings.value.adbMode,
device:
settings.value.adbMode === "device"
? { fingerprint: current.fingerprint, language: current.language }
: current,
};
}
const response = await fetch(path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
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;
writeSavedToken(payload.token);
rememberSessionDevice(payload.device);
page.value = "download";
startLive();
if (method.value === "password" && rememberPassword.value) saveAccount(payload.profile || {});
} catch (exc) {
error.value = exc instanceof Error ? exc.message : "登录失败";
} finally {
busy.value = false;
}
}
const avatarSrc = computed(() => {
const image = profile.value?.avatarNumUrl || "";
if (!image) return undefined;
if (image.startsWith("http://") || image.startsWith("https://") || image.startsWith("/api/")) return image;
return `https://apis.raptdrama.com${image.startsWith("/") ? image : `/${image}`}`;
});
let liveRetry = 0;
function applyLive(payload: { downloads?: { active: LiveJob[]; done: LiveJob[]; active_count?: number }; profile?: Profile | null }) {
if (payload.downloads) {
downloadState.value = {
active: payload.downloads.active || [],
done: payload.downloads.done || [],
active_count: payload.downloads.active_count || 0,
};
progressCount.value = payload.downloads.active_count || 0;
}
if (payload.profile) profile.value = payload.profile;
}
function takeSign(payload: { sign?: { message?: string } | null }) {
const message = payload.sign?.message?.trim() || "";
if (message) signNotice.value = message;
}
function startLive() {
stopLive();
const protocol = location.protocol === "https:" ? "wss" : "ws";
const socket = new WebSocket(`${protocol}://${location.host}/api/live?platform=${platform.value}`);
liveSocket = socket;
socket.onmessage = (event) => {
applyLive(JSON.parse(event.data));
};
socket.onclose = () => {
if (liveSocket !== socket || !token.value) return;
liveRetry = window.setTimeout(() => startLive(), 1000);
};
}
function stopLive() {
if (liveRetry) window.clearTimeout(liveRetry);
liveRetry = 0;
if (liveSocket) {
liveSocket.onclose = null;
liveSocket.close();
liveSocket = null;
}
progressCount.value = 0;
}
async function logout() {
const current = token.value;
const clearSite = platform.value === "dramabox";
stopLive();
token.value = "";
profile.value = null;
page.value = "download";
if (platform.value === "huangdou" && huangdouAccounts.value.length) {
applyHuangdouAccount(huangdouSelected.value || huangdouAccounts.value[0].username);
}
forgetSavedToken();
sessionStorage.removeItem(SESSION_DEVICE_KEY);
try {
if (current) {
await fetch(isolated.value ? `${apiBase.value}/logout` : "/api/logout", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: current }),
});
}
} catch {
// 本地登录态已经清掉
}
if (clearSite && inTauri()) {
try {
const { invoke } = await import("@tauri-apps/api/core");
await invoke("dramabox_clear_login");
} catch {
// 程序里的登录凭据已经清掉
}
}
}
const closeAsk = ref(false);
const closeCount = ref(0);
let allowClose = false;
const updateOpen = ref(false);
const updateInfo = ref({ latest: "", current: "", notes: "", can_apply: false });
const updateBusy = ref(false);
const updateMessage = ref("");
let updateTimer = 0;
function inTauri() {
return "__TAURI_INTERNALS__" in window;
}
async function watchClose() {
if (!inTauri()) return;
const win = getCurrentWindow();
await win.onCloseRequested((event) => {
if (allowClose) return;
event.preventDefault();
void askClose(win);
});
}
async function askClose(win: ReturnType<typeof getCurrentWindow>) {
try {
const [rapt, huangdou, dramabox] = await Promise.all([
fetch("/api/downloads").then((item) => item.json()).catch(() => ({})),
fetch("/api/huangdou/downloads").then((item) => item.json()).catch(() => ({})),
fetch("/api/dramabox/downloads").then((item) => item.json()).catch(() => ({})),
]);
const count = Number(rapt.active_count || 0) + Number(huangdou.active_count || 0) + Number(dramabox.active_count || 0);
if (count > 0) {
closeCount.value = count;
closeAsk.value = true;
return;
}
} catch {
// 后台不可用时直接关闭
}
allowClose = true;
await win.destroy();
}
async function confirmQuit() {
closeAsk.value = false;
allowClose = true;
if (!inTauri()) return;
await getCurrentWindow().destroy();
}
async function checkForUpdate() {
try {
const response = await fetch("/api/update");
if (!response.ok) return;
const payload = await response.json();
if (!payload.available) return;
updateInfo.value = {
latest: String(payload.latest || ""),
current: String(payload.current || ""),
notes: String(payload.notes || ""),
can_apply: Boolean(payload.can_apply),
};
updateMessage.value = "";
updateOpen.value = true;
} catch {
// 检查失败时不打断使用
}
}
async function confirmUpdate() {
updateBusy.value = true;
updateMessage.value = "正在下载更新";
try {
const response = await fetch("/api/update/apply", { method: "POST" });
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
updateBusy.value = false;
updateMessage.value = typeof payload.detail === "string" ? payload.detail : "更新没有完成,请稍后再试";
return;
}
} catch {
updateBusy.value = false;
updateMessage.value = "更新没有完成,请稍后再试";
return;
}
updateTimer = window.setInterval(async () => {
try {
const response = await fetch("/api/update/status");
const payload = await response.json();
updateMessage.value = String(payload.message || "正在下载更新");
if (payload.state === "failed") {
window.clearInterval(updateTimer);
updateBusy.value = false;
return;
}
if (payload.state === "restarting") {
window.clearInterval(updateTimer);
allowClose = true;
if (inTauri()) await getCurrentWindow().destroy();
}
} catch {
window.clearInterval(updateTimer);
updateBusy.value = false;
updateMessage.value = "更新没有完成,请稍后再试";
}
}, 500);
}
onMounted(async () => {
document.title = "VideosDownTools";
void watchClose();
void checkForUpdate();
await loadDeviceDefaults();
loadSettings();
try {
await loadProxySettings();
} catch {
error.value = "代理还没有生效,请重新打开设置并保存";
}
savedAccounts.value = readList<SavedAccount>(ACCOUNTS_KEY);
if (savedAccounts.value[0]) applyAccount(savedAccounts.value[0].email);
await loadHuangdouAccounts();
huangdouAccountsReady = true;
if (platform.value === "dramabox") {
await loadDramaboxLanguages();
void loadDevices();
}
if (platform.value === "huangdou") void sendHuangdouFingerprint();
let saved = readSavedToken();
if (!saved && isolated.value) {
try {
const resume = await fetch(`${apiBase.value}/resume`, { method: "POST" });
if (resume.ok) {
const payload = await resume.json();
if (typeof payload.token === "string" && payload.token) {
saved = payload.token;
writeSavedToken(saved);
}
}
} catch {
// 没有可恢复的登录
}
}
if (!saved) return;
const response = await fetch(isolated.value ? `${apiBase.value}/me` : "/api/me", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: saved, device: sessionDevice() }),
});
if (!response.ok) {
const payload = await response.json().catch(() => ({}));
if (payload.detail === "登录已失效") forgetSavedToken();
return;
}
const payload = await response.json();
token.value = payload.token;
profile.value = payload.profile;
takeSign(payload);
rememberSessionDevice(payload.device);
page.value = "download";
startLive();
});
onUnmounted(stopLive);
</script>
<template>
<n-config-provider class="app" :theme="darkTheme" :theme-overrides="themeOverrides" :locale="zhCN" :date-locale="dateZhCN">
<n-layout v-if="profile" class="shell" has-sider position="absolute">
<n-layout-sider bordered :width="208" content-style="height: 100%; padding: 0">
<div class="sider">
<div class="platform-mark">{{ platformLabel }}</div>
<n-menu
:value="menuValue"
:options="mainMenu"
@update:value="page = $event"
/>
<div v-if="platform === 'dramabox' && page === 'download'" class="catalog-limit">
<div class="catalog-limit-label">
最大页数
<n-tooltip>
<template #trigger>
<span class="help-dot" tabindex="0">?</span>
</template>
每个分类最多翻这么多页。精选这类推荐流可能一直有新内容,到上限就会停下。改完后点刷新生效。
</n-tooltip>
</div>
<n-input-number
:value="catalogMaxPages"
class="catalog-limit-input"
size="small"
button-placement="both"
:min="1"
:max="999"
:precision="0"
@update:value="onCatalogMaxPages"
/>
</div>
<div class="user-nav" :class="{ active: page === 'profile' }">
<button type="button" class="user-nav-main" @click="page = 'profile'">
<n-avatar round :size="28" :src="avatarSrc" />
<span class="user-nav-name">{{ profile.nickname || "个人信息" }}</span>
</button>
<n-tooltip placement="right">
<template #trigger>
<n-button quaternary circle size="small" aria-label="退出" @click="logout">
<template #icon>
<svg class="logout-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
<path d="M16 17l5-5-5-5" />
<path d="M21 12H9" />
</svg>
</template>
</n-button>
</template>
退出
</n-tooltip>
</div>
</div>
</n-layout-sider>
<n-layout class="main-pane">
<n-layout-header bordered class="bar">
<div class="bar-title">
<n-button v-if="page === 'play'" quaternary size="small" @click="closePlay">返回</n-button>
<n-text strong class="bar-title-text">{{ pageTitle }}</n-text>
<n-text v-if="signNotice" class="sign-note">{{ signNotice }}</n-text>
</div>
<div v-if="page === 'download'" class="bar-search">
<n-input
v-model:value="catalogQuery"
class="catalog-query"
placeholder="搜索名称"
clearable
@keyup.enter="downloadRef?.find(catalogQuery)"
/>
<n-button secondary @click="downloadRef?.find(catalogQuery)">搜索</n-button>
<n-text v-if="downloadRef?.searchHint" class="search-hint" depth="3">{{ downloadRef.searchHint }}</n-text>
</div>
<div class="bar-actions">
<template v-if="page === 'settings'">
<n-button secondary :disabled="settingsBusy" @click="restoreCurrent">还原设置</n-button>
<n-button type="primary" :loading="settingsBusy" @click="saveSettings">保存</n-button>
</template>
<n-button v-if="page === 'download'" secondary :loading="downloadRef?.busy" @click="downloadRef?.reload(true)">刷新</n-button>
</div>
</n-layout-header>
<n-layout-content content-style="height: 100%; padding: 0">
<VideoListPage
v-show="page === 'download'"
ref="downloadRef"
:token="token"
:device="sessionDevice()"
:api-base="apiBase"
:remote-search="isolated"
:show-point-download="platform === 'huangdou'"
@started="page = 'progress'"
@play="openPlay"
/>
<PlayerPage
v-if="page === 'play' && playing"
:token="token"
:device="sessionDevice()"
:drama-id="playing.id"
:api-base="apiBase"
/>
<DownloadProgressPage v-show="page === 'progress'" :api-base="apiBase" :active="downloadState.active" :done="downloadState.done" />
<div v-show="page === 'settings'" class="settings-page">
<n-alert v-if="settingsError" class="hint" type="error" :show-icon="false">{{ settingsError }}</n-alert>
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="isolated" @choose="chooseDownloadDirectory" />
</div>
<div v-show="page === 'profile'" class="profile-page">
<div class="profile-sheet">
<div class="profile-head">
<n-avatar round :size="64" :src="avatarSrc" />
<div class="profile-id">
<div class="profile-name-row">
<span class="profile-name">{{ profile.nickname || "未命名" }}</span>
<n-tag v-if="profile.badge" size="small" :bordered="false" type="success">{{ profile.badge }}</n-tag>
<n-tag v-if="platform === 'huangdou'" size="small" :bordered="false" :type="profile.has_login === '1' ? 'success' : 'default'">{{ profile.has_login === "1" ? "已登录" : "访客" }}</n-tag>
</div>
<span class="profile-sub">{{ profileSub }}</span>
</div>
<n-tooltip placement="bottom">
<template #trigger>
<n-button quaternary circle aria-label="退出" @click="logout">
<template #icon>
<svg class="logout-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
<path d="M16 17l5-5-5-5" />
<path d="M21 12H9" />
</svg>
</template>
</n-button>
</template>
退出
</n-tooltip>
</div>
<div v-if="statFields.length" class="profile-stats" :style="{ gridTemplateColumns: `repeat(${statFields.length}, minmax(0, 1fr))` }">
<div v-for="item in statFields" :key="item.key" class="profile-stat">
<span class="profile-stat-value">{{ profileNumber(item.key) }}</span>
<span class="profile-stat-label">{{ item.label }}</span>
</div>
</div>
<div class="profile-block">
<div class="profile-block-title">
<span>账号</span>
<span v-if="platform === 'dramabox'" class="profile-title-actions">
<n-tag size="small" :bordered="false" :type="dramaboxLoggedIn ? 'success' : 'default'">{{ dramaboxLoggedIn ? "已登录" : "访客" }}</n-tag>
<n-button size="tiny" secondary :loading="accountBusy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
<n-button size="tiny" secondary :loading="accountBusy" :disabled="!dramaboxLoggedIn" @click="exportDramaboxCredential">导出凭据</n-button>
<n-button size="tiny" secondary :loading="accountBusy" @click="pickDramaboxCredential">导入凭据</n-button>
</span>
</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>
</div>
</div>
<div v-if="platform === 'rapt'" class="profile-block">
<div class="profile-block-title">绑定</div>
<div class="profile-binds">
<span v-for="item in bindFields" :key="item.key" class="profile-bind" :class="{ on: profileBound(item.key) }">{{ item.label }}</span>
</div>
</div>
</div>
</div>
</n-layout-content>
</n-layout>
</n-layout>
<n-layout v-else class="shell login-shell" has-sider position="absolute">
<n-layout-sider bordered :width="208" content-style="height: 100%; padding: 0">
<div class="sider">
<n-menu
:value="platform"
:options="platforms.map((item) => ({ label: item.label, key: item.key }))"
@update:value="selectPlatform"
/>
</div>
</n-layout-sider>
<n-layout-content>
<div class="login-center">
<div class="card">
<n-tabs v-if="platform === 'rapt'" v-model:value="method" type="segment" size="small">
<n-tab v-for="item in methods" :key="item.id" :name="item.id">{{ item.label }}</n-tab>
</n-tabs>
<n-form label-placement="left" label-width="96" size="small" :show-feedback="false" @submit.prevent="login">
<template v-if="platform === 'huangdou'">
<n-form-item label="域名">
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" />
</n-form-item>
<n-form-item v-if="huangdouAccounts.length" label="已保存">
<div class="device-line">
<n-select
:value="huangdouSelected"
:options="huangdouAccountOptions"
placeholder="选择已保存的账号"
@update:value="applyHuangdouAccount"
/>
<n-button attr-type="button" :disabled="!huangdouSelected" @click="removeHuangdouAccount">删除</n-button>
</div>
</n-form-item>
<n-form-item label="账号">
<n-input v-model:value="huangdouUser" placeholder="手机号或邮箱" autocomplete="username" />
</n-form-item>
<n-form-item label="密码">
<n-input v-model:value="huangdouPassword" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" />
</n-form-item>
<n-form-item label="记住">
<n-checkbox v-model:checked="huangdouRemember">记住账号密码</n-checkbox>
</n-form-item>
<n-form-item label="指纹">
<n-button attr-type="button" secondary :loading="huangdouFingerprintBusy" @click="rollHuangdouFingerprint">更换新设备指纹</n-button>
</n-form-item>
<n-text v-if="huangdouFingerprintNote" class="hint" depth="3">{{ huangdouFingerprintNote }}</n-text>
</template>
<n-form-item v-if="platform === 'dramabox'" label="地区">
<n-select v-model:value="dramaboxLang" filterable :options="dramaboxLangs" placeholder="选择国家 / 语言" />
</n-form-item>
<n-form-item v-if="platform === 'dramabox'" label="设备">
<div class="device-line">
<n-select v-model:value="serial" :options="deviceOptions" :loading="devicesBusy" placeholder="请选择设备" />
<n-button :loading="devicesBusy" @click="loadDevices">刷新</n-button>
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
</div>
</n-form-item>
<template v-if="platform === 'rapt' && method === 'password'">
<n-form-item v-if="savedAccounts.length" label="已保存">
<div class="device-line">
<n-select
:value="selectedAccount"
:options="accountOptions"
placeholder="选择已保存的账号"
@update:value="applyAccount"
/>
<n-button :disabled="!selectedAccount" @click="removeAccount">删除</n-button>
</div>
</n-form-item>
<n-form-item label="邮箱">
<n-input v-model:value="email" type="text" placeholder="邮箱" autocomplete="username" />
</n-form-item>
<n-form-item label="密码">
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" />
</n-form-item>
<n-form-item label="记住">
<n-checkbox v-model:checked="rememberPassword">记住账号密码</n-checkbox>
</n-form-item>
</template>
<n-form-item v-else-if="platform === 'rapt' && method === 'adb'" label="设备">
<div class="device-line">
<n-select
v-model:value="serial"
:options="deviceOptions"
:loading="devicesBusy"
placeholder="请选择设备"
/>
<n-button :loading="devicesBusy" @click="loadDevices">刷新</n-button>
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
</div>
</n-form-item>
<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" secondary :loading="busy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
<n-button v-if="platform === 'dramabox'" attr-type="button" secondary :loading="busy" @click="pickDramaboxCredential">导入凭据</n-button>
<n-button v-if="platform === 'huangdou'" attr-type="button" secondary :loading="busy" @click="loginHuangdou(true)">访客进入</n-button>
<n-button type="primary" attr-type="submit" :loading="busy">{{ platform === "dramabox" ? "访客进入" : platform === "huangdou" ? "登录" : isolated ? "进入" : "登录" }}</n-button>
</div>
</n-form>
</div>
</div>
</n-layout-content>
</n-layout>
<input ref="credentialFile" class="credential-file" type="file" accept="application/json,.json" @change="onDramaboxCredential" />
<n-tooltip v-if="!profile" placement="left">
<template #trigger>
<n-button class="settings-button" secondary circle aria-label="设置" @click="openSettings">
<template #icon>
<svg class="gear-icon" viewBox="0 0 24 24" aria-hidden="true">
<path
fill="currentColor"
d="M19.14 12.94c.04-.31.06-.63.06-.94s-.02-.63-.06-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.6-.22l-2.39.96a7.2 7.2 0 0 0-1.63-.94l-.36-2.54a.5.5 0 0 0-.5-.42h-3.84a.5.5 0 0 0-.5.42l-.36 2.54c-.58.22-1.12.54-1.63.94l-2.39-.96a.5.5 0 0 0-.6.22L2.71 8.84a.5.5 0 0 0 .12.64l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.22.39.31.6.22l2.39-.96c.51.4 1.05.72 1.63.94l.36 2.54c.05.24.26.42.5.42h3.84c.24 0 .45-.18.5-.42l.36-2.54c.58-.22 1.12-.54 1.63-.94l2.39.96c.22.09.47 0 .6-.22l1.92-3.32a.5.5 0 0 0-.12-.64l-2.03-1.58zM12 15.5A3.5 3.5 0 1 1 12 8a3.5 3.5 0 0 1 0 7.5z"
/>
</svg>
</template>
</n-button>
</template>
设置
</n-tooltip>
<n-modal v-model:show="settingsOpen" preset="card" title="设置" style="width: 640px">
<div class="settings-modal-body">
<n-alert v-if="settingsError" class="hint" type="error" :show-icon="false">{{ settingsError }}</n-alert>
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="isolated" @choose="chooseDownloadDirectory" />
</div>
<template #footer>
<div class="modal-actions">
<n-button :disabled="settingsBusy" @click="restoreCurrent">还原设置</n-button>
<span class="modal-spacer"></span>
<n-button :disabled="settingsBusy" @click="settingsOpen = false">取消</n-button>
<n-button type="primary" :loading="settingsBusy" @click="saveSettings">保存</n-button>
</div>
</template>
</n-modal>
<n-modal v-model:show="updateOpen" preset="card" title="发现新版本" style="width: 440px" :mask-closable="!updateBusy" :closable="!updateBusy">
<p class="update-copy">新版本 {{ updateInfo.latest }},当前是 {{ updateInfo.current }}。</p>
<p v-if="updateInfo.notes" class="update-notes">{{ updateInfo.notes }}</p>
<p v-if="updateInfo.can_apply" class="update-copy">选择更新后会自动下载并重新打开。已下载的视频和登录状态会保留,正在进行的下载会中断。</p>
<p v-else class="update-copy">当前这份程序不能自动更新。</p>
<p v-if="updateMessage" class="update-copy">{{ updateMessage }}</p>
<template #footer>
<div class="modal-actions">
<span class="modal-spacer"></span>
<n-button :disabled="updateBusy" @click="updateOpen = false">稍后</n-button>
<n-button v-if="updateInfo.can_apply" type="primary" :loading="updateBusy" @click="confirmUpdate">立即更新</n-button>
</div>
</template>
</n-modal>
<n-modal
v-model:show="closeAsk"
preset="dialog"
title="关闭程序"
positive-text="确定"
negative-text="取消"
:mask-closable="false"
@positive-click="confirmQuit"
>
还有 {{ closeCount }} 个未完成的下载,关闭后会中断。确定要关闭吗?
</n-modal>
</n-config-provider>
</template>
<style>
html, body, #app { height: 100%; margin: 0; }
html { color-scheme: dark; }
* {
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.22);
border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.36); }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
*::-webkit-scrollbar-corner { background: transparent; }
.app { height: 100%; position: relative; }
.shell .n-layout-scroll-container { overflow-y: auto; }
.shell .main-pane { height: 100%; min-height: 0; }
.shell .main-pane > .n-layout-scroll-container {
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.shell .main-pane > .n-layout-scroll-container > .n-layout-content {
flex: 1;
min-height: 0;
}
.shell .main-pane .n-layout-content > .n-layout-scroll-container {
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
}
.shell .main-pane .n-layout-content > .n-layout-scroll-container > * {
flex: 1 1 auto;
min-height: 0;
}
.sider { height: 100%; min-height: 100%; display: flex; flex-direction: column; box-sizing: border-box; padding: 12px 8px; }
.platform-mark {
padding: 2px 12px 10px;
color: rgba(255, 255, 255, 0.55);
font-size: 13px;
line-height: 1.2;
}
.catalog-limit {
flex: none;
margin: 12px 4px 0;
padding: 10px 8px 4px;
}
.catalog-limit-label {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 8px;
color: rgba(255, 255, 255, 0.72);
font-size: 13px;
}
.catalog-limit-input { width: 100%; }
.catalog-limit-input .n-input__input-el { text-align: center; }
.user-nav {
margin-top: auto;
display: flex;
align-items: center;
gap: 2px;
min-height: 48px;
padding: 4px 2px 4px 10px;
border-radius: 6px;
}
.user-nav.active { background: rgba(99, 226, 183, 0.16); }
.user-nav-main {
flex: 1;
min-width: 0;
height: 36px;
display: flex;
align-items: center;
gap: 10px;
margin: 0;
padding: 0;
border: 0;
background: transparent;
color: inherit;
font: inherit;
cursor: pointer;
text-align: left;
}
.user-nav-name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: 1.2;
}
.user-nav .n-avatar,
.profile-head .n-avatar {
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
}
.user-nav .n-avatar img,
.profile-head .n-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.profile-page { height: 100%; overflow: auto; box-sizing: border-box; padding: 20px; }
.profile-sheet {
max-width: 640px;
margin: 0 auto;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(255, 255, 255, 0.03);
overflow: hidden;
}
.profile-head { display: flex; align-items: center; gap: 16px; padding: 20px 16px 16px; }
.profile-id { flex: 1; min-width: 0; }
.profile-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.profile-name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 18px;
font-weight: 600;
line-height: 1.2;
}
.profile-sub {
display: block;
margin-top: 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: rgba(255, 255, 255, 0.45);
font-size: 13px;
}
.profile-stats {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.profile-stat {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
padding: 14px 4px;
}
.profile-stat + .profile-stat { border-left: 1px solid rgba(255, 255, 255, 0.08); }
.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 {
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-title-actions { display: flex; align-items: center; gap: 8px; }
.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 {
flex: 1;
min-width: 0;
text-align: right;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-binds { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 16px; }
.profile-bind {
min-width: 72px;
height: 28px;
padding: 0 10px;
border-radius: 6px;
display: inline-flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.45);
font-size: 13px;
}
.profile-bind.on { background: rgba(99, 226, 183, 0.16); color: #63e2b7; }
.logout-icon {
width: 18px;
height: 18px;
display: block;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.bar {
position: relative;
display: flex; align-items: center; justify-content: space-between;
height: auto; padding: 12px 20px;
}
.bar-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sign-note { flex: none; color: #63e2b7; font-size: 13px; white-space: nowrap; }
.bar-search {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
gap: 8px;
}
.search-hint { min-width: 2.5em; }
.bar-actions { display: flex; align-items: center; gap: 8px; }
.nav-label { display: inline-flex; align-items: center; gap: 8px; }
.nav-badge {
min-width: 18px;
height: 18px;
padding: 0 5px;
border-radius: 9px;
background: #63e2b7;
color: #101014;
font-size: 12px;
line-height: 18px;
text-align: center;
}
.login-shell,
.login-shell > .n-layout-scroll-container,
.login-shell .n-layout-content,
.login-shell .n-layout-content > .n-layout-scroll-container { height: 100%; }
.login-shell .n-layout-sider,
.login-shell .n-layout-sider > .n-layout-sider-scroll-container { height: 100%; }
.login-center {
height: 100%;
display: flex;
align-items: safe center;
justify-content: center;
box-sizing: border-box;
padding: 28px 20px;
}
.card { width: 100%; max-width: 560px; }
.login-actions { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.login-actions .n-button { min-width: 180px; }
.credential-file { display: none; }
.settings-button { position: fixed; right: 20px; bottom: 20px; z-index: 5; }
.gear-icon { width: 18px; height: 18px; display: block; }
.settings-modal-body { max-height: min(58vh, 520px); overflow: auto; padding-right: 4px; }
.modal-actions { display: flex; align-items: center; gap: 8px; }
.update-copy { margin: 0 0 8px; line-height: 1.5; }
.update-notes { margin: 0 0 8px; white-space: pre-wrap; line-height: 1.5; color: rgba(255, 255, 255, 0.72); }
.modal-spacer { flex: 1; }
.card .n-tabs { margin-bottom: 16px; }
.card .n-form-item { margin-bottom: 16px; }
.card .n-avatar { margin-bottom: 16px; }
.device-line { display: flex; gap: 8px; width: 100%; align-items: center; }
.device-line .n-select,
.device-line .n-input { flex: 1; min-width: 0; }
.hint { display: block; margin: 8px 0; }
.settings-page {
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
box-sizing: border-box;
padding: 8px 20px 20px;
}
.settings-page > .n-tabs { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.settings-page .n-tabs-pane-wrapper { flex: 1; min-height: 0; overflow: auto; }
.settings-form { max-width: 640px; padding-top: 8px; }
.settings-form .n-form-item { margin-bottom: 16px; }
.field-label { display: inline-flex; align-items: center; gap: 6px; }
.worker-input { width: 148px; }
.worker-input .n-input__input-el { text-align: center; }
.help-dot {
width: 16px;
height: 16px;
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.28);
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 11px;
line-height: 1;
color: rgba(255, 255, 255, 0.65);
cursor: help;
}
</style>