feat: DramaBox 全量走 App 接口,清单可停止并避免卡死
分类按 App 翻页,精选走推荐接口。清单顶部显示进度,停止后不再拉新剧,已拿到的封面继续加载。列表只绘制可见卡片,避免大量剧目占满主线程。
This commit is contained in:
+451
-81
@@ -15,6 +15,24 @@ interface Section {
|
||||
note: string;
|
||||
items: Drama[];
|
||||
loading: boolean;
|
||||
page: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
interface PageEvent {
|
||||
key: string;
|
||||
name: string;
|
||||
note?: string;
|
||||
items?: Drama[];
|
||||
done?: boolean;
|
||||
page?: number;
|
||||
pages?: number;
|
||||
}
|
||||
|
||||
interface CardSlot {
|
||||
id: string;
|
||||
item: Drama;
|
||||
style: { width: string; height: string; transform: string };
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -25,10 +43,12 @@ const props = defineProps<{
|
||||
}>();
|
||||
const apiBase = computed(() => props.apiBase || "/api");
|
||||
|
||||
const sections = ref<Section[]>([]);
|
||||
const sections = shallowRef<Section[]>([]);
|
||||
const expanded = ref<string[]>([]);
|
||||
const selected = ref<Set<string>>(new Set());
|
||||
const selectedInSection = reactive<Record<string, number>>({});
|
||||
const busy = ref(false);
|
||||
const stopped = ref(false);
|
||||
const error = ref("");
|
||||
const query = ref("");
|
||||
const searchHint = ref("");
|
||||
@@ -42,9 +62,29 @@ const flashSerial = ref(0);
|
||||
const directory = ref("");
|
||||
const starting = ref(false);
|
||||
const footError = ref("");
|
||||
const coverStatus = ref<Record<string, "ready" | "failed">>({});
|
||||
const coverStatus = reactive<Record<string, "ready" | "failed">>({});
|
||||
const coverDone = ref(0);
|
||||
const coverTotal = ref(0);
|
||||
const scrollTop = ref(0);
|
||||
const viewHeight = ref(800);
|
||||
const gridWidth = ref(720);
|
||||
const gridTops = ref<Record<string, number>>({});
|
||||
const emit = defineEmits<{ started: []; play: [Drama] }>();
|
||||
const scrollEl = ref<HTMLElement | null>(null);
|
||||
const grids = new Map<string, HTMLElement>();
|
||||
const gridBinders = new Map<string, (el: unknown) => void>();
|
||||
let resizeObserver: ResizeObserver | null = null;
|
||||
let measureFrame = 0;
|
||||
let flushFrame = 0;
|
||||
let pendingPages: PageEvent[] = [];
|
||||
let coverQueue: string[] = [];
|
||||
const coverQueued = new Set<string>();
|
||||
let coverRunning = 0;
|
||||
let coverToken = 0;
|
||||
const COVER_CONCURRENCY = 2;
|
||||
const GRID_GAP = 12;
|
||||
const TITLE_HEIGHT = 52;
|
||||
const MIN_CARD = 148;
|
||||
|
||||
function coverOf(image: string) {
|
||||
if (!image) return "";
|
||||
@@ -56,14 +96,81 @@ function coverOf(image: string) {
|
||||
function coverState(image: string): "empty" | "loading" | "ready" | "failed" {
|
||||
const src = coverOf(image);
|
||||
if (!src) return "empty";
|
||||
const status = coverStatus.value[src];
|
||||
const status = coverStatus[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" };
|
||||
if (!src || coverStatus[src]) return;
|
||||
coverStatus[src] = ok ? "ready" : "failed";
|
||||
}
|
||||
|
||||
function onCoverError(event: Event, image: string) {
|
||||
const target = event.target;
|
||||
if (target instanceof HTMLImageElement && !target.isConnected) return;
|
||||
markCover(coverOf(image), false);
|
||||
}
|
||||
|
||||
function resetCovers() {
|
||||
coverToken += 1;
|
||||
coverQueue = [];
|
||||
coverQueued.clear();
|
||||
coverRunning = 0;
|
||||
coverDone.value = 0;
|
||||
coverTotal.value = 0;
|
||||
for (const key of Object.keys(coverStatus)) delete coverStatus[key];
|
||||
}
|
||||
|
||||
function enqueueCovers(items: Drama[]) {
|
||||
const token = coverToken;
|
||||
let added = 0;
|
||||
for (const item of items) {
|
||||
const src = coverOf(item.image);
|
||||
if (!src || coverStatus[src] || coverQueued.has(src)) continue;
|
||||
coverQueued.add(src);
|
||||
coverQueue.push(src);
|
||||
added += 1;
|
||||
}
|
||||
if (!added) return;
|
||||
coverTotal.value += added;
|
||||
pumpCovers(token);
|
||||
}
|
||||
|
||||
function pumpCovers(token: number) {
|
||||
while (coverRunning < COVER_CONCURRENCY && coverQueue.length) {
|
||||
const src = coverQueue.shift();
|
||||
if (!src) break;
|
||||
coverRunning += 1;
|
||||
void prefetchCover(src).then(
|
||||
(ok) => settleCover(token, src, ok),
|
||||
() => settleCover(token, src, false),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function prefetchCover(src: string) {
|
||||
if (src.startsWith("/api/")) {
|
||||
const response = await fetch(src);
|
||||
if (!response.ok) return false;
|
||||
await response.arrayBuffer();
|
||||
return true;
|
||||
}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = () => resolve();
|
||||
image.onerror = () => reject(new Error("cover"));
|
||||
image.src = src;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function settleCover(token: number, src: string, ok: boolean) {
|
||||
if (token !== coverToken) return;
|
||||
coverRunning = Math.max(0, coverRunning - 1);
|
||||
markCover(src, ok);
|
||||
coverDone.value += 1;
|
||||
pumpCovers(token);
|
||||
}
|
||||
|
||||
function isExpanded(key: string) {
|
||||
@@ -74,10 +181,22 @@ function toggleExpanded(key: string) {
|
||||
expanded.value = isExpanded(key)
|
||||
? expanded.value.filter((item) => item !== key)
|
||||
: [...expanded.value, key];
|
||||
void nextTick(() => measure());
|
||||
}
|
||||
|
||||
function selectedCount(section: Section) {
|
||||
return section.items.filter((item) => selected.value.has(dramaKey(item.id))).length;
|
||||
return selectedInSection[section.key] || 0;
|
||||
}
|
||||
|
||||
function syncSelectedCounts() {
|
||||
const chosen = selected.value;
|
||||
for (const section of sections.value) {
|
||||
let count = 0;
|
||||
for (const item of section.items) {
|
||||
if (chosen.has(dramaKey(item.id))) count += 1;
|
||||
}
|
||||
selectedInSection[section.key] = count;
|
||||
}
|
||||
}
|
||||
|
||||
function allChecked(section: Section) {
|
||||
@@ -99,6 +218,7 @@ function toggleDrama(id: string | number, checked: boolean) {
|
||||
if (checked) next.add(key);
|
||||
else next.delete(key);
|
||||
selected.value = next;
|
||||
syncSelectedCounts();
|
||||
}
|
||||
|
||||
function toggleSection(section: Section, checked: boolean) {
|
||||
@@ -109,45 +229,123 @@ function toggleSection(section: Section, checked: boolean) {
|
||||
else next.delete(key);
|
||||
}
|
||||
selected.value = next;
|
||||
syncSelectedCounts();
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selected.value = new Set();
|
||||
syncSelectedCounts();
|
||||
}
|
||||
|
||||
function pruneSelection() {
|
||||
const ids = new Set(sections.value.flatMap((section) => section.items.map((item) => dramaKey(item.id))));
|
||||
selected.value = new Set([...selected.value].filter((id) => ids.has(id)));
|
||||
syncSelectedCounts();
|
||||
}
|
||||
|
||||
function publishSections() {
|
||||
sections.value = sections.value.slice();
|
||||
}
|
||||
|
||||
function showOutline(list: { key: string; name: string; note?: string; loading?: boolean }[]) {
|
||||
for (const key of Object.keys(selectedInSection)) delete selectedInSection[key];
|
||||
sections.value = list.map((item) => ({
|
||||
key: item.key,
|
||||
name: item.name,
|
||||
note: item.note || "",
|
||||
items: [],
|
||||
loading: item.loading !== false,
|
||||
page: 0,
|
||||
pages: 0,
|
||||
}));
|
||||
}
|
||||
|
||||
function applyPage(event: { key: string; name: string; note?: string; items?: Drama[]; done?: boolean }) {
|
||||
function applyPage(event: PageEvent) {
|
||||
let section = sections.value.find((item) => item.key === event.key);
|
||||
if (!section) {
|
||||
section = { key: event.key, name: event.name, note: event.note || "", items: [], loading: !event.done };
|
||||
section = {
|
||||
key: event.key,
|
||||
name: event.name,
|
||||
note: event.note || "",
|
||||
items: [],
|
||||
loading: !event.done,
|
||||
page: 0,
|
||||
pages: 0,
|
||||
};
|
||||
sections.value.push(section);
|
||||
}
|
||||
if (event.note) section.note = event.note;
|
||||
if (event.items?.length) section.items = section.items.concat(event.items);
|
||||
if (event.page) section.page = event.page;
|
||||
if (event.pages) section.pages = event.pages;
|
||||
if (event.items?.length) {
|
||||
section.items.push(...event.items);
|
||||
enqueueCovers(event.items);
|
||||
}
|
||||
if (event.done) section.loading = false;
|
||||
}
|
||||
|
||||
function scheduleFlush(generation: number) {
|
||||
if (flushFrame) return;
|
||||
flushFrame = requestAnimationFrame(() => {
|
||||
flushFrame = 0;
|
||||
if (generation !== catalogGeneration) {
|
||||
pendingPages = [];
|
||||
return;
|
||||
}
|
||||
const batch = pendingPages.splice(0, 6);
|
||||
const extra: PageEvent[] = [];
|
||||
for (const event of batch) {
|
||||
const items = event.items || [];
|
||||
const chunk = items.slice(0, 180);
|
||||
const rest = items.slice(180);
|
||||
applyPage({ ...event, items: chunk, done: rest.length ? false : event.done });
|
||||
if (rest.length) extra.push({ ...event, items: rest });
|
||||
}
|
||||
if (extra.length) pendingPages.unshift(...extra);
|
||||
publishSections();
|
||||
void nextTick(() => measure());
|
||||
if (pendingPages.length) scheduleFlush(generation);
|
||||
});
|
||||
}
|
||||
|
||||
function queuePage(event: PageEvent, generation: number) {
|
||||
if (generation !== catalogGeneration) return;
|
||||
pendingPages.push(event);
|
||||
scheduleFlush(generation);
|
||||
}
|
||||
|
||||
function waitFrame() {
|
||||
return new Promise<void>((resolve) => {
|
||||
requestAnimationFrame(() => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
function finishSections() {
|
||||
for (const section of sections.value) section.loading = false;
|
||||
publishSections();
|
||||
}
|
||||
|
||||
function stopLoad() {
|
||||
if (!busy.value) return;
|
||||
stopped.value = true;
|
||||
catalogAbort?.abort();
|
||||
finishSections();
|
||||
busy.value = false;
|
||||
}
|
||||
|
||||
async function reload(refresh = false) {
|
||||
catalogAbort?.abort();
|
||||
const current = new AbortController();
|
||||
catalogAbort = current;
|
||||
const generation = ++catalogGeneration;
|
||||
pendingPages = [];
|
||||
stopped.value = false;
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
sections.value = [];
|
||||
grids.clear();
|
||||
gridBinders.clear();
|
||||
resetCovers();
|
||||
try {
|
||||
const response = await fetch(`${apiBase.value}/catalog`, {
|
||||
method: "POST",
|
||||
@@ -155,6 +353,7 @@ async function reload(refresh = false) {
|
||||
body: JSON.stringify({ token: props.token, device: props.device, refresh }),
|
||||
signal: current.signal,
|
||||
});
|
||||
if (generation !== catalogGeneration) return;
|
||||
if (!response.ok || !response.body) {
|
||||
let message = "获取清单失败";
|
||||
try {
|
||||
@@ -168,8 +367,10 @@ async function reload(refresh = false) {
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = "";
|
||||
let queued = 0;
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (generation !== catalogGeneration) return;
|
||||
if (done) break;
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split("\n");
|
||||
@@ -187,15 +388,27 @@ async function reload(refresh = false) {
|
||||
continue;
|
||||
}
|
||||
if (event.type !== "page") continue;
|
||||
applyPage(event);
|
||||
queuePage(event, generation);
|
||||
queued += 1;
|
||||
if (queued >= 6) {
|
||||
queued = 0;
|
||||
await waitFrame();
|
||||
if (generation !== catalogGeneration) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (exc) {
|
||||
if (exc instanceof DOMException && exc.name === "AbortError") return;
|
||||
if (generation !== catalogGeneration) return;
|
||||
error.value = exc instanceof Error ? exc.message : "获取清单失败";
|
||||
for (const section of sections.value) section.loading = false;
|
||||
finishSections();
|
||||
} finally {
|
||||
if (generation !== catalogGeneration) return;
|
||||
let spins = 0;
|
||||
while (generation === catalogGeneration && (pendingPages.length || flushFrame) && spins < 600) {
|
||||
spins += 1;
|
||||
await waitFrame();
|
||||
}
|
||||
if (generation === catalogGeneration) busy.value = false;
|
||||
}
|
||||
}
|
||||
@@ -230,45 +443,103 @@ function finishFlash(key: string, serial: number, event: AnimationEvent) {
|
||||
if (flashKey.value === key && flashSerial.value === serial) flashKey.value = "";
|
||||
}
|
||||
|
||||
function cardInView(node: HTMLElement, scroller: HTMLElement) {
|
||||
const card = node.getBoundingClientRect();
|
||||
const view = scroller.getBoundingClientRect();
|
||||
return card.top >= view.top && card.bottom <= view.bottom;
|
||||
function layoutOf(section: Section) {
|
||||
const width = Math.max(MIN_CARD, gridWidth.value);
|
||||
const cols = Math.max(1, Math.floor((width + GRID_GAP) / (MIN_CARD + GRID_GAP)));
|
||||
const cardWidth = (width - GRID_GAP * (cols - 1)) / cols;
|
||||
const cardHeight = cardWidth * 4 / 3 + TITLE_HEIGHT;
|
||||
const rowHeight = cardHeight + GRID_GAP;
|
||||
const rows = section.items.length ? Math.ceil(section.items.length / cols) : 0;
|
||||
const height = rows ? rows * rowHeight - GRID_GAP : 0;
|
||||
return { cols, cardWidth, cardHeight, rowHeight, height };
|
||||
}
|
||||
|
||||
function scrollCardIntoView(node: HTMLElement) {
|
||||
function visibleSlots(section: Section): CardSlot[] {
|
||||
const box = layoutOf(section);
|
||||
const count = section.items.length;
|
||||
if (!count) return [];
|
||||
const gridTop = gridTops.value[section.key] ?? 0;
|
||||
const top = scrollTop.value;
|
||||
const bottom = top + Math.max(viewHeight.value, 1);
|
||||
let startRow = Math.floor((top - gridTop) / box.rowHeight) - 1;
|
||||
let endRow = Math.ceil((bottom - gridTop) / box.rowHeight) + 1;
|
||||
const rowCount = Math.ceil(count / box.cols);
|
||||
if (endRow < 0 || startRow >= rowCount) return [];
|
||||
startRow = Math.max(0, startRow);
|
||||
endRow = Math.min(rowCount, Math.max(startRow + 1, endRow));
|
||||
const start = startRow * box.cols;
|
||||
const end = Math.min(count, endRow * box.cols);
|
||||
const slots: CardSlot[] = [];
|
||||
for (let index = start; index < end; index += 1) {
|
||||
const item = section.items[index];
|
||||
const col = index % box.cols;
|
||||
const row = Math.floor(index / box.cols);
|
||||
slots.push({
|
||||
id: dramaKey(item.id),
|
||||
item,
|
||||
style: {
|
||||
width: `${box.cardWidth}px`,
|
||||
height: `${box.cardHeight}px`,
|
||||
transform: `translate(${col * (box.cardWidth + GRID_GAP)}px, ${row * box.rowHeight}px)`,
|
||||
},
|
||||
});
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
function bindGrid(key: string, el: unknown) {
|
||||
if (el instanceof HTMLElement) grids.set(key, el);
|
||||
else grids.delete(key);
|
||||
}
|
||||
|
||||
function gridBinder(key: string) {
|
||||
let binder = gridBinders.get(key);
|
||||
if (!binder) {
|
||||
binder = (el: unknown) => bindGrid(key, el);
|
||||
gridBinders.set(key, binder);
|
||||
}
|
||||
return binder;
|
||||
}
|
||||
|
||||
function measure() {
|
||||
const scroller = scrollEl.value;
|
||||
return new Promise<void>((resolve) => {
|
||||
if (!scroller) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
node.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||
let last = scroller.scrollTop;
|
||||
let stable = 0;
|
||||
let moved = false;
|
||||
const started = performance.now();
|
||||
const tick = () => {
|
||||
const current = scroller.scrollTop;
|
||||
if (Math.abs(current - last) >= 0.5) {
|
||||
moved = true;
|
||||
stable = 0;
|
||||
} else {
|
||||
stable += 1;
|
||||
}
|
||||
last = current;
|
||||
const arrived = cardInView(node, scroller);
|
||||
const stopped = moved ? stable >= 4 : stable >= 8;
|
||||
if ((stopped && arrived) || performance.now() - started > 3000) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
requestAnimationFrame(tick);
|
||||
};
|
||||
requestAnimationFrame(tick);
|
||||
if (!scroller) return;
|
||||
const nextTop = scroller.scrollTop;
|
||||
const nextHeight = scroller.clientHeight || viewHeight.value;
|
||||
let nextWidth = 0;
|
||||
const tops: Record<string, number> = {};
|
||||
const scrollRect = scroller.getBoundingClientRect();
|
||||
for (const [key, el] of grids) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
tops[key] = nextTop + rect.top - scrollRect.top;
|
||||
if (el.clientWidth > 0) nextWidth = el.clientWidth;
|
||||
}
|
||||
if (!nextWidth) nextWidth = Math.max(MIN_CARD, scroller.clientWidth - 80);
|
||||
scrollTop.value = nextTop;
|
||||
viewHeight.value = nextHeight;
|
||||
if (nextWidth !== gridWidth.value) gridWidth.value = nextWidth;
|
||||
gridTops.value = tops;
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
if (measureFrame) return;
|
||||
measureFrame = requestAnimationFrame(() => {
|
||||
measureFrame = 0;
|
||||
measure();
|
||||
});
|
||||
}
|
||||
|
||||
function scrollIndexIntoView(sectionKey: string, index: number) {
|
||||
const section = sections.value.find((item) => item.key === sectionKey);
|
||||
const scroller = scrollEl.value;
|
||||
if (!section || !scroller || index < 0) return;
|
||||
const box = layoutOf(section);
|
||||
const row = Math.floor(index / box.cols);
|
||||
const top = (gridTops.value[sectionKey] ?? 0) + row * box.rowHeight;
|
||||
scroller.scrollTop = Math.max(0, top - 72);
|
||||
measure();
|
||||
}
|
||||
|
||||
async function find(keyword = query.value) {
|
||||
const generation = ++revealGeneration;
|
||||
const text = keyword.trim();
|
||||
@@ -303,23 +574,65 @@ async function find(keyword = query.value) {
|
||||
}
|
||||
await nextTick();
|
||||
if (generation !== revealGeneration) return;
|
||||
const node = scrollEl.value?.querySelector(`[data-card="${key}"]`);
|
||||
if (node instanceof HTMLElement) await scrollCardIntoView(node);
|
||||
measure();
|
||||
const section = sections.value.find((item) => item.key === hit.sectionKey);
|
||||
const index = section?.items.findIndex((item) => dramaKey(item.id) === dramaKey(hit.id)) ?? -1;
|
||||
scrollIndexIntoView(hit.sectionKey, index);
|
||||
await nextTick();
|
||||
if (generation !== revealGeneration) return;
|
||||
if (node instanceof HTMLElement && scrollEl.value && !cardInView(node, scrollEl.value)) {
|
||||
node.scrollIntoView({ block: "center", behavior: "auto" });
|
||||
}
|
||||
flashSerial.value += 1;
|
||||
flashKey.value = "";
|
||||
await nextTick();
|
||||
if (generation !== revealGeneration) return;
|
||||
flashKey.value = key;
|
||||
}
|
||||
const loadedCount = computed(() =>
|
||||
sections.value.reduce((sum, section) => sum + (section.key === "search" ? 0 : section.items.length), 0),
|
||||
);
|
||||
const coverPending = computed(() => coverTotal.value > 0 && coverDone.value < coverTotal.value);
|
||||
const showProgress = computed(() => busy.value || stopped.value || coverPending.value);
|
||||
const progress = computed(() => {
|
||||
if (!busy.value && coverPending.value && coverTotal.value) {
|
||||
return Math.min(100, Math.round((coverDone.value / coverTotal.value) * 100));
|
||||
}
|
||||
let got = 0;
|
||||
let total = 0;
|
||||
for (const section of sections.value) {
|
||||
if (!section.pages || section.key === "search") continue;
|
||||
total += section.pages;
|
||||
got += section.loading ? Math.min(section.page, section.pages) : section.pages;
|
||||
}
|
||||
if (!total) return busy.value ? 0 : 100;
|
||||
return Math.min(100, Math.round((got / total) * 100));
|
||||
});
|
||||
const progressText = computed(() => {
|
||||
const count = loadedCount.value;
|
||||
if (busy.value) return `已加载 ${count} 部`;
|
||||
if (stopped.value && coverPending.value) {
|
||||
return `已停止,共 ${count} 部,封面 ${coverDone.value}/${coverTotal.value}`;
|
||||
}
|
||||
if (stopped.value) return `已停止,共 ${count} 部`;
|
||||
if (coverPending.value) return `封面 ${coverDone.value}/${coverTotal.value}`;
|
||||
return "";
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
void reload();
|
||||
void loadDirectory();
|
||||
resizeObserver = new ResizeObserver(() => onScroll());
|
||||
if (scrollEl.value) resizeObserver.observe(scrollEl.value);
|
||||
measure();
|
||||
});
|
||||
defineExpose({ reload, busy, find, searchHint, clearSearch, loadDirectory });
|
||||
onBeforeUnmount(() => {
|
||||
catalogGeneration += 1;
|
||||
coverToken += 1;
|
||||
pendingPages = [];
|
||||
catalogAbort?.abort();
|
||||
resizeObserver?.disconnect();
|
||||
if (measureFrame) cancelAnimationFrame(measureFrame);
|
||||
if (flushFrame) cancelAnimationFrame(flushFrame);
|
||||
});
|
||||
defineExpose({ reload, busy, stopLoad, showProgress, progress, progressText, find, searchHint, clearSearch, loadDirectory });
|
||||
|
||||
async function searchRemote(keyword: string, generation: number) {
|
||||
searchHint.value = "正在搜索";
|
||||
@@ -349,9 +662,15 @@ async function searchRemote(keyword: string, generation: number) {
|
||||
note: items.length ? "" : "没有搜索结果",
|
||||
items,
|
||||
loading: false,
|
||||
page: 0,
|
||||
pages: 0,
|
||||
});
|
||||
}
|
||||
enqueueCovers(items);
|
||||
publishSections();
|
||||
syncSelectedCounts();
|
||||
if (!isExpanded(key)) expanded.value = [...expanded.value, key];
|
||||
void nextTick(() => measure());
|
||||
} catch {
|
||||
if (generation === revealGeneration) searchHint.value = "搜索失败";
|
||||
}
|
||||
@@ -412,8 +731,25 @@ async function startDownload() {
|
||||
|
||||
<template>
|
||||
<div class="download-page">
|
||||
<div v-if="showProgress" class="load-strip">
|
||||
<n-progress
|
||||
class="load-strip-bar"
|
||||
type="line"
|
||||
:percentage="progress"
|
||||
:show-indicator="false"
|
||||
:processing="busy || coverPending"
|
||||
:height="8"
|
||||
/>
|
||||
<n-text class="load-strip-text" depth="3">{{ progressText }}</n-text>
|
||||
<n-tooltip v-if="busy">
|
||||
<template #trigger>
|
||||
<n-button size="small" secondary @click="stopLoad">停止</n-button>
|
||||
</template>
|
||||
停止后不再获取新剧目,已拿到的封面会继续加载
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<div class="download-body">
|
||||
<div ref="scrollEl" class="download-scroll">
|
||||
<div ref="scrollEl" class="download-scroll" @scroll="onScroll">
|
||||
<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">
|
||||
@@ -426,49 +762,56 @@ async function startDownload() {
|
||||
{{ 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>
|
||||
<span v-if="section.loading" class="category-spin" aria-label="正在加载"></span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<n-checkbox
|
||||
:checked="allChecked(section)"
|
||||
:indeterminate="someChecked(section)"
|
||||
:disabled="section.items.length === 0"
|
||||
:disabled="section.loading || section.items.length === 0"
|
||||
@update:checked="toggleSection(section, $event)"
|
||||
>
|
||||
全选
|
||||
{{ section.loading ? "加载中" : allChecked(section) ? "取消全选" : "全选" }}
|
||||
</n-checkbox>
|
||||
</template>
|
||||
{{ allChecked(section) ? "取消全选" : "全选" }}
|
||||
{{ section.loading ? "这一栏还在加载" : 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>
|
||||
<n-text v-else-if="!section.loading && section.items.length === 0" depth="3">暂无剧集</n-text>
|
||||
<div v-else class="drama-grid">
|
||||
<div
|
||||
v-else
|
||||
class="drama-grid"
|
||||
:style="{ height: `${layoutOf(section).height}px` }"
|
||||
:ref="gridBinder(section.key)"
|
||||
>
|
||||
<article
|
||||
v-for="item in section.items"
|
||||
:key="item.id"
|
||||
v-for="slot in visibleSlots(section)"
|
||||
:key="slot.id"
|
||||
class="drama-card"
|
||||
:data-card="cardKey(section.key, item.id)"
|
||||
@click="toggleDrama(item.id, !selected.has(dramaKey(item.id)))"
|
||||
:data-card="cardKey(section.key, slot.item.id)"
|
||||
:style="slot.style"
|
||||
@click="toggleDrama(slot.item.id, !selected.has(dramaKey(slot.item.id)))"
|
||||
>
|
||||
<div class="cover" :class="coverState(item.image)">
|
||||
<span v-if="coverState(item.image) === 'loading'" class="cover-spin" aria-hidden="true"></span>
|
||||
<div class="cover" :class="coverState(slot.item.image)">
|
||||
<span v-if="coverState(slot.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)"
|
||||
v-if="coverOf(slot.item.image)"
|
||||
:src="coverOf(slot.item.image)"
|
||||
:alt="slot.item.title"
|
||||
decoding="async"
|
||||
@load="markCover(coverOf(slot.item.image), true)"
|
||||
@error="onCoverError($event, slot.item.image)"
|
||||
/>
|
||||
<span v-if="item.corner || item.locked || item.limitedFree" class="cover-tag">{{ item.corner || (item.limitedFree ? "限免" : item.payType || "付费") }}</span>
|
||||
<div v-if="coverState(item.image) !== 'loading'" class="cover-play-layer">
|
||||
<span v-if="slot.item.corner || slot.item.locked || slot.item.limitedFree" class="cover-tag">{{ slot.item.corner || (slot.item.limitedFree ? "限免" : slot.item.payType || "付费") }}</span>
|
||||
<div v-if="coverState(slot.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)">
|
||||
<button type="button" class="cover-play" aria-label="播放" @click.stop="emit('play', slot.item)">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M9 7.5v9l8-4.5z" /></svg>
|
||||
</button>
|
||||
</template>
|
||||
@@ -479,17 +822,17 @@ async function startDownload() {
|
||||
<div class="pick" @click.stop>
|
||||
<n-tooltip placement="left">
|
||||
<template #trigger>
|
||||
<n-checkbox :checked="selected.has(dramaKey(item.id))" @update:checked="toggleDrama(item.id, $event)" />
|
||||
<n-checkbox :checked="selected.has(dramaKey(slot.item.id))" @update:checked="toggleDrama(slot.item.id, $event)" />
|
||||
</template>
|
||||
{{ selected.has(dramaKey(item.id)) ? "取消选择" : "选择" }}
|
||||
{{ selected.has(dramaKey(slot.item.id)) ? "取消选择" : "选择" }}
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<div class="drama-title">{{ item.title }}</div>
|
||||
<div class="drama-title">{{ slot.item.title }}</div>
|
||||
<div
|
||||
v-if="flashKey === cardKey(section.key, item.id)"
|
||||
v-if="flashKey === cardKey(section.key, slot.item.id)"
|
||||
:key="flashSerial"
|
||||
class="drama-mask"
|
||||
@animationend="finishFlash(cardKey(section.key, item.id), flashSerial, $event)"
|
||||
@animationend="finishFlash(cardKey(section.key, slot.item.id), flashSerial, $event)"
|
||||
></div>
|
||||
</article>
|
||||
</div>
|
||||
@@ -514,6 +857,18 @@ async function startDownload() {
|
||||
|
||||
<style>
|
||||
.download-page { height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
|
||||
.load-strip {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-height: 44px;
|
||||
padding: 8px 20px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background: #18181c;
|
||||
}
|
||||
.load-strip-bar { width: 180px; flex: none; }
|
||||
.load-strip-text { flex: 1; min-width: 0; }
|
||||
.download-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
|
||||
.download-scroll { flex: 1; min-height: 0; overflow: auto; padding: 0 0 12px; }
|
||||
.download-foot {
|
||||
@@ -561,12 +916,15 @@ async function startDownload() {
|
||||
.chevron.open { transform: rotate(90deg); }
|
||||
.category-body { padding: 8px 20px 12px 60px; }
|
||||
.drama-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
|
||||
gap: 12px;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
.drama-card {
|
||||
position: relative;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
@@ -574,10 +932,11 @@ async function startDownload() {
|
||||
}
|
||||
.cover {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
aspect-ratio: 3 / 4;
|
||||
background: transparent;
|
||||
}
|
||||
.cover-spin {
|
||||
@@ -658,5 +1017,16 @@ async function startDownload() {
|
||||
0%, 100% { opacity: 0; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
.drama-title { padding: 8px; font-size: 13px; line-height: 1.35; }
|
||||
.drama-title {
|
||||
flex: none;
|
||||
height: 52px;
|
||||
box-sizing: border-box;
|
||||
padding: 8px;
|
||||
overflow: hidden;
|
||||
font-size: 13px;
|
||||
line-height: 1.35;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user