This commit is contained in:
728
2023-06-02 02:24:27 +08:00
parent 8b341389f3
commit 2939b38e74
6 changed files with 46 additions and 18 deletions

View File

@ -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 }
}

View File

@ -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 () => {

View File

@ -565,12 +565,15 @@ type Rd = {
prize: string[],
}
export type Dst = Omit<NonNullable<Q.Dst>, "rd" | "anam"> & {
rd: Rd | null, anam: Map<Id["_id"], Id["nam"]>,
}
export async function dst(
) {
if (navhash("")) return
const d = await que<Q.Dst>("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<Q.Dst>("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 += `<a class="none" href="#a${d.aid}" target="_blank" rel="noopener noreferrer"><img src="${src}"></a>`
t.imgl.innerHTML += `<a class="none" href="#a${d.aid}" target="_blank" rel="noopener noreferrer"><img src="${src}"></a>`
}
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(

View File

@ -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")

View File

@ -208,6 +208,8 @@ const template = {
imgl: {
tid: "imgl" as const,
...section.idnam,
adm1: t("p"),
...section.cover,
imgl: t("section"),
},

View File

@ -562,7 +562,12 @@
<template id="imgl">
<article>
<section>
<a class="idnam"><code class="id" hidden></code> <span class="nam">参赛作品</span></a>
<a class="idnam" href="#dst"><code class="id" hidden></code> <span class="nam">参赛作品</span></a>
</section>
<hr>
<section>
<label>作品分区:</label>
<p class="adm1"></p>
</section>
<hr>
<section class="cover flex">