From 2939b38e7404baa5f347f364111ce74323867c5e Mon Sep 17 00:00:00 2001 From: 728 Date: Fri, 2 Jun 2023 02:24:27 +0800 Subject: [PATCH] dst --- ismism.ts/src/pra/doc.ts | 4 +-- ismism.ts/tst/que.test.ts | 2 +- ismism.ts/ui/bind/article.ts | 42 +++++++++++++++++++++++--------- ismism.ts/ui/bind/nav.ts | 7 +++--- ismism.ts/ui/bind/template.ts | 2 ++ ismism.ts/ui/index/template.html | 7 +++++- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/ismism.ts/src/pra/doc.ts b/ismism.ts/src/pra/doc.ts index edc3515..ad23a16 100644 --- a/ismism.ts/src/pra/doc.ts +++ b/ismism.ts/src/pra/doc.ts @@ -129,8 +129,8 @@ export async function dst( if (rd === null || rdaid === null) return null const aid = rdaid.map(r => r._id.aid!) const ndst = await Promise.all(aid.map(a => dst_n({ rd: lim_rd, aid: a }))) - const img = await Promise.all(aid.map(a => agd_r(a, { img: 1 }))) - const dst = aid.map((aid, n) => ({ aid, ndst: ndst[n] ?? 0, img: img[n]?.img.map(m => m.src) ?? [] })).sort((a, b) => b.ndst - a.ndst) + const img = await Promise.all(aid.map(a => agd_r(a, { adm1: 1, img: 1 }))) + const dst = aid.map((aid, n) => ({ adm1: img[n]!.adm1, aid, ndst: ndst[n] ?? 0, img: img[n]?.img.map(m => m.src) ?? [] })).sort((a, b) => b.ndst - a.ndst) const anam = await idnam(coll.agd, aid) return { rd: rd.json, dst, anam } } diff --git a/ismism.ts/tst/que.test.ts b/ismism.ts/tst/que.test.ts index d8cad4d..a1662fe 100644 --- a/ismism.ts/tst/que.test.ts +++ b/ismism.ts/tst/que.test.ts @@ -125,7 +125,7 @@ Deno.test("rec", async () => { Deno.test("dst", async () => { const dst = await que("dst", p({})) as Dst assertEquals({ nam: "nam", c: 32 }, JSON.parse(dst?.rd!)) - assertEquals([{ aid: 1, ndst: 2 }, { aid: 2, ndst: 1 }], dst?.dst) + assertEquals([{ adm1: "四川", aid: 1, ndst: 2, img: [] }, { adm1: "江苏", aid: 2, ndst: 1, img: [] }], dst?.dst) }) Deno.test("md", async () => { diff --git a/ismism.ts/ui/bind/article.ts b/ismism.ts/ui/bind/article.ts index 72eaf5e..370bcf7 100644 --- a/ismism.ts/ui/bind/article.ts +++ b/ismism.ts/ui/bind/article.ts @@ -565,12 +565,15 @@ type Rd = { prize: string[], } +export type Dst = Omit, "rd" | "anam"> & { + rd: Rd | null, anam: Map, +} export async function dst( ) { if (navhash("")) return const d = await que("dst") if (!d) return - const q = { ...d, rd: d.rd ? JSON.parse(d.rd) as Rd : null, anam: new Map(d.anam) } + const q: Dst = { ...d, rd: d.rd ? JSON.parse(d.rd) as Rd : null, anam: new Map(d.anam) } navnid() main.innerHTML = "" @@ -611,27 +614,44 @@ export async function dst( if (nav.pas) t.preuid.disabled = true else t.preuid.remove() + main.append(t.bind) + imgl() +} - const ti = bind("imgl") - for (const d of q.dst) { +export async function imgl( + adm1?: string, +) { + const d = await que("dst") + if (!d) return + const q: Dst = { ...d, rd: d.rd ? JSON.parse(d.rd) as Rd : null, anam: new Map(d.anam) } + + navnid() + if (adm1 !== undefined) main.innerHTML = "" + const t = bind("imgl") + + const an = [...new Set(q.dst.map(d => d.adm1))].map(a => ({ adm1: a, n: q.dst.filter(d => d.adm1 === a).length })).sort((u, v) => v.n - u.n) + idnam(t, `dst${adm1 ?? ""}`, `参赛作品${adm1 ? `(${adm1})` : ""}`) + ida(t.adm1, an.map(an => [`dst${an.adm1}`, `${an.adm1}(${an.n})`])) + + for (const d of adm1 ? q.dst.filter(d => d.adm1 === adm1) : q.dst) { for (const src of d.img) - ti.imgl.innerHTML += `` + t.imgl.innerHTML += `` } - const imgl = ti.imgl.getElementsByTagName("a") + const imgl = t.imgl.getElementsByTagName("a") let n = 0 const img = (d: number) => { imgl[n].classList.add("none") - ti.imgn.innerText = `第 ${n + 1} / ${imgl.length} 张` - const aid = imgl[n].hash.substring(1) - ti.imgnam.innerText = `${aid} ${q.anam.get(parseInt(aid.substring(1)))}` n = ((n + d) % imgl.length + imgl.length) % imgl.length; + t.imgn.innerText = `第 ${n + 1} / ${imgl.length} 张` + const aid = imgl[n].hash.substring(1) + t.imgnam.innerText = `${aid} ${q.anam.get(parseInt(aid.substring(1)))}` imgl[n].classList.remove("none") } - ti.prev.addEventListener("click", () => img(-1)) - ti.next.addEventListener("click", () => img(+1)) + t.prev.addEventListener("click", () => img(-1)) + t.next.addEventListener("click", () => img(+1)) img(0) + main.append(t.bind) - main.append(ti.bind) } export async function aut( diff --git a/ismism.ts/ui/bind/nav.ts b/ismism.ts/ui/bind/nav.ts index a5f8a67..61bab7f 100644 --- a/ismism.ts/ui/bind/nav.ts +++ b/ismism.ts/ui/bind/nav.ts @@ -2,7 +2,7 @@ import type { Pas } from "../../src/pra/pas.ts" import type { NId } from "../../src/pra/que.ts" import { adm } from "../../src/ont/adm.ts" -import { pas, aut, soc, usr, agd, ordl, md, idn, id, dst } from "./article.ts" +import { pas, aut, soc, usr, agd, ordl, md, idn, id, dst, imgl } from "./article.ts" import { adm1, adm2, pas_a, pos, que } from "./template.ts" export const nav: { @@ -98,7 +98,7 @@ export async function navnid( export function navhash( h: string ): boolean { - if (nav.hash === h || nav.hash === "" && h === "dst") return false + if (nav.hash === h) return false location.href = `#${h}` return true } @@ -109,7 +109,8 @@ window.addEventListener("hashchange", () => { if (nav.refresh) clearInterval(nav.refresh) nav.refresh = null if (nav.hash === "pas") pas() - else if (nav.hash === "" || nav.hash === "dst") dst() + else if (nav.hash === "") dst() + else if (nav.hash.startsWith("dst")) imgl(nav.hash.substring(3)) else if (nav.hash === "aut") aut() else if (/^\d+$/.test(nav.hash)) usr(parseInt(nav.hash)) else if (nav.hash === "soc") id("soc") diff --git a/ismism.ts/ui/bind/template.ts b/ismism.ts/ui/bind/template.ts index d655396..f97e521 100644 --- a/ismism.ts/ui/bind/template.ts +++ b/ismism.ts/ui/bind/template.ts @@ -208,6 +208,8 @@ const template = { imgl: { tid: "imgl" as const, + ...section.idnam, + adm1: t("p"), ...section.cover, imgl: t("section"), }, diff --git a/ismism.ts/ui/index/template.html b/ismism.ts/ui/index/template.html index f962d73..376004e 100644 --- a/ismism.ts/ui/index/template.html +++ b/ismism.ts/ui/index/template.html @@ -562,7 +562,12 @@