From a9df1c95b1df49d6ddb323d473ec0e70cc210f9c Mon Sep 17 00:00:00 2001 From: 728 Date: Wed, 22 Feb 2023 18:32:48 +0800 Subject: [PATCH] nav #39 --- ismism.ts/ui/bind/article.ts | 59 +++++++----------------------------- ismism.ts/ui/bind/bind.ts | 2 +- ismism.ts/ui/bind/nav.ts | 47 ++++++++++++++++++++++++++++ ismism.ts/ui/bind/section.ts | 3 +- 4 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 ismism.ts/ui/bind/nav.ts diff --git a/ismism.ts/ui/bind/article.ts b/ismism.ts/ui/bind/article.ts index 4ae9aa3..8d2031d 100644 --- a/ismism.ts/ui/bind/article.ts +++ b/ismism.ts/ui/bind/article.ts @@ -1,4 +1,3 @@ -// deno-lint-ignore-file no-window-prefix import type { DocC } from "../../src/db.ts" import type { Id } from "../../src/eid/typ.ts" import { utc_medium } from "../../src/ont/utc.ts" @@ -9,26 +8,15 @@ import { admsel, idnam, ida, idmeta, pro, label, btn, txt, goal } from "./sectio import { bind, main, pas_a, pos, que } from "./template.ts" import { not_aut, not_pro } from "../../src/pra/con.ts" import { is_rol, not_actid, not_nbr } from "../../src/eid/is.ts" +import { hashchange, pas, paschange } from "./nav.ts" -export let hash = "" -let pas: Pas | null = null - -function hashchange( - h: string -): boolean { - if (hash === h || hash === "" && h === "agd") return false - location.href = `#${h}` - return true -} - -function pasact( +export function pasact( ) { if (hashchange("pas")) return - - if (pas) pos("pas", { uid: pas.id.uid }) - pas = null - pas_a.innerText = "用户登录" - pas_a.href = "#pas" + if (pas) { + pos("pas", { uid: pas.id.uid }) + paschange(null) + } main.innerHTML = "" const t = bind("pasact") @@ -71,9 +59,7 @@ function pasact( t.code.readOnly = t.issue.disabled = false return alert("无效验证码") } - pas = p - pas_a.innerText = p.nam - pas_a.href = `#${p.id.uid}` + paschange(p) usr(p.id.uid) }) @@ -85,7 +71,7 @@ export type Usr = Omit, "unam" | "snam"> & { snam: Map, } -async function usr( +export async function usr( uid: Usr["_id"], ) { if (hashchange(`${uid}`)) return @@ -137,7 +123,7 @@ export type Soc = Omit, "unam"> & { unam: Map, } -async function soc( +export async function soc( sid?: Soc["_id"] ) { if (hashchange(`s${sid ?? "oc"}`)) return @@ -199,7 +185,7 @@ export type Agd = Omit, "unam"> & { unam: Map, } -async function agd( +export async function agd( aid?: Agd["_id"] ) { if (hashchange(`a${aid ?? "gd"}`)) return @@ -330,7 +316,7 @@ function putusr( main.append(t.bind) } -function idnull( +export function idnull( id: string, nam: string, ) { @@ -342,26 +328,3 @@ function idnull( main.append(t.bind) } - -window.addEventListener("hashchange", () => { - hash = decodeURI(location.hash).substring(1) - if (hash === "pas") pasact() - else if (/^\d+$/.test(hash)) usr(parseInt(hash)) - else if (hash === "soc") soc() - else if (/^s\d+$/.test(hash)) soc(parseInt(hash.substring(1))) - else if (hash === "" || hash === "agd") agd() - else if (/^a\d+$/.test(hash)) agd(parseInt(hash.substring(1))) - else idnull(hash, "链接") -}) - -export async function load( -) { - console.log("ismism-20230204") - console.log(`\n主义主义开发小组!成员招募中!\n\n发送自我介绍至网站维护邮箱,或微信联系 728 万大可\n \n`) - pas = await pos("pas", {}) - if (pas) { - pas_a.innerText = pas.nam - pas_a.href = `#${pas.id.uid}` - } - window.dispatchEvent(new Event("hashchange")) -} diff --git a/ismism.ts/ui/bind/bind.ts b/ismism.ts/ui/bind/bind.ts index ad1d650..4cfd43b 100644 --- a/ismism.ts/ui/bind/bind.ts +++ b/ismism.ts/ui/bind/bind.ts @@ -1,3 +1,3 @@ -import { load } from "./article.ts" +import { load } from "./nav.ts" load() diff --git a/ismism.ts/ui/bind/nav.ts b/ismism.ts/ui/bind/nav.ts new file mode 100644 index 0000000..779b3a0 --- /dev/null +++ b/ismism.ts/ui/bind/nav.ts @@ -0,0 +1,47 @@ +// deno-lint-ignore-file no-window-prefix +import { Pas } from "../../src/pra/pas.ts" +import { pasact, soc, usr, agd, idnull } from "./article.ts" +import { pas_a, pos } from "./template.ts" + +export let pas: Pas | null = null +export let hash = "" + +export async function paschange( + p?: Pas | null +) { + pas = p === undefined ? await pos("pas", {}) : p + if (pas) { + pas_a.innerText = pas.nam + pas_a.href = `#${pas.id.uid}` + } else { + pas_a.innerText = "用户登录" + pas_a.href = "#pas" + } +} + +export function hashchange( + h: string +): boolean { + if (hash === h || hash === "" && h === "agd") return false + location.href = `#${h}` + return true +} + +window.addEventListener("hashchange", () => { + hash = decodeURI(location.hash).substring(1) + if (hash === "pas") pasact() + else if (/^\d+$/.test(hash)) usr(parseInt(hash)) + else if (hash === "soc") soc() + else if (/^s\d+$/.test(hash)) soc(parseInt(hash.substring(1))) + else if (hash === "" || hash === "agd") agd() + else if (/^a\d+$/.test(hash)) agd(parseInt(hash.substring(1))) + else idnull(hash, "链接") +}) + +export async function load( +) { + console.log("ismism-20230204") + console.log(`\n主义主义开发小组!成员招募中!\n\n发送自我介绍至网站维护邮箱,或微信联系 728 万大可\n \n`) + await paschange() + window.dispatchEvent(new Event("hashchange")) +} diff --git a/ismism.ts/ui/bind/section.ts b/ismism.ts/ui/bind/section.ts index cd80eb4..2a875eb 100644 --- a/ismism.ts/ui/bind/section.ts +++ b/ismism.ts/ui/bind/section.ts @@ -4,9 +4,10 @@ import { utc_medium } from "../../src/ont/utc.ts" import { adm } from "../../src/ont/adm.ts" import { bind, pos, Template, utc_refresh } from "./template.ts" import { is_aut } from "../../src/pra/con.ts" -import { Usr, Soc, Agd, hash } from "./article.ts" +import type { Usr, Soc, Agd } from "./article.ts" import type { DocU } from "../../src/db.ts" import { is_rol } from "../../src/eid/is.ts" +import { hash } from "./nav.ts" export function label( el: HTMLElement,