This commit is contained in:
728
2023-10-24 13:48:10 +08:00
parent e0dc8d1574
commit dcec576f50
8 changed files with 100 additions and 36 deletions

View File

@ -1,14 +1,12 @@
import type { Soc } from "../eid/typ.ts"
import type { Pas, Psg } from "./pas.ts"
import type { Pre } from "./pre.ts"
import type { Put } from "./put.ts"
import type { Pos, Pre, Put, Psg, Pas } from "./pos.ts"
import { is_aut, is_cdt, is_id, is_idl, is_lim, is_msg, is_nam, is_nbr, is_rec, is_recid, lim_aut, lim_code, lim_msg, lim_msg_id, lim_sec } from "../eid/is.ts"
import { is_adm } from "../ont/adm.ts"
// deno-lint-ignore no-explicit-any
export type Ret<T extends (...args: any) => any> = Awaited<ReturnType<T>>
function is_in(
export function is_in(
sl: Soc["_id"][],
s?: Soc["_id"],
): boolean {
@ -80,3 +78,13 @@ export function is_put(
&& is_idl(p.aut, lim_aut.aut) && is_idl(p.wsl, lim_aut.wsl) && is_idl(p.lit, lim_aut.lit)
}
}
export function is_pos(
pas: Pas,
p: Pos,
): boolean {
if ("psg" in p) return is_psg(p)
else if ("pre" in p) return is_pre(pas, p)
else if ("put" in p) return is_put(pas, p)
return false
}

View File

@ -3,9 +3,9 @@ import { Pas, Psg, pas, psg } from "./pas.ts"
import { Pre, pre } from "./pre.ts"
import { Put, put } from "./put.ts"
export type { Pre } from "./pre.ts"
export type { Put } from "./put.ts"
export type { Psg } from "./pas.ts"
export type { Psg, Pas, PsgRet } from "./pas.ts"
export type { Pre, PreRet } from "./pre.ts"
export type { Put, PutRet } from "./put.ts"
export type Pos = Psg | Pre | Put

View File

@ -1,8 +1,8 @@
import { Usr } from "../../src/eid/typ.ts";
import type { Usr } from "../../src/eid/typ.ts"
import type { QueRet } from "../../src/pra/que.ts"
import { que } from "./fetch.ts"
import { nav } from "./nav.ts"
import { btn_usr, id, idn, sms } from "./section.ts"
import { btn_aut, btn_usr, id, idn, sms } from "./section.ts"
import { article } from "./template.ts"
export async function usr(
@ -10,10 +10,8 @@ export async function usr(
) {
const t = article()
const u = await que<QueRet["usr"]>({ que: "usr", ...q })
if (u) {
t.append(id(u))
if (nav.pas && nav.pas.usr == u._id) t.append(btn_usr(u))
} else t.append(idn(`${usr}`, "无效用户", `#${usr} 是无效用户`))
t.append(id("usr" in q ? `${q.usr}` : q.nam, u))
if (u && nav.pas && nav.pas.usr == u._id) t.append(btn_usr(u), btn_aut(nav.pas))
}
export function psg(

View File

@ -1,5 +1,6 @@
import type { Pos } from "../../src/pra/pos.ts"
import type { Que } from "../../src/pra/que.ts"
import { navpas } from "./nav.ts"
export async function que<T>(
q: Que
@ -14,6 +15,8 @@ export async function que<T>(
export async function pos<T>(
p: Pos,
) {
const r = await fetch(`/p`, { method: "POST", body: JSON.stringify(p) })
return r.json() as T
const res = await fetch(`/p`, { method: "POST", body: JSON.stringify(p) })
const r = await res.json() as T
if (r && !("psg" in p)) await navpas()
return r
}

View File

@ -1,5 +1,5 @@
// deno-lint-ignore-file no-window-prefix
import type { PsgRet, Pas } from "../../src/pra/pas.ts"
import type { PsgRet, Pas } from "../../src/pra/pos.ts"
import { psg, usr } from "./article.ts"
import { pos } from "./fetch.ts"
import { pas } from "./template.ts"

View File

@ -1,14 +1,13 @@
import type { Id } from "../../src/eid/typ.ts"
import type { PsgRet } from "../../src/pra/pas.ts"
import { is_nbr, lim_msg_id } from "../../src/eid/is.ts"
import type { Pos, Put, PsgRet, Pas } from "../../src/pra/pos.ts"
import type { QueRet } from "../../src/pra/que.ts"
import { is_aut, is_id, is_nbr, lim_aut, lim_msg_id } from "../../src/eid/is.ts"
import { utc_dt } from "../../src/ont/utc.ts"
import { pos } from "./fetch.ts"
import { Bind, article, section } from "./template.ts"
import { hash, nav, navpas, utc_rf } from "./nav.ts"
import { QueRet } from "../../src/pra/que.ts"
import { adm, adm1_def, adm2_def } from "../../src/ont/adm.ts"
import { Put } from "../../src/pra/pos.ts"
import { is_put } from "../../src/pra/can.ts"
import { is_in, is_pos, is_put } from "../../src/pra/can.ts"
export function idn(
id: string,
@ -24,15 +23,15 @@ export function idn(
}
export function id(
d: Id,
p: "" | "s" | "a" = "",
id: string,
d: QueRet["usr" | "soc" | "agd"],
): Bind {
if (!d) return idn(id, "无效链接", `#${id} 是无效 id`)
const b = section("id")
b.id.innerText = `${p}${d._id}`
b.id.innerText = id
b.nam.innerText = d.nam
b.idnam.href = `#${p}${d._id}`
b.mta.innerText = `城市:${d.adm1} ${d.adm2}`
+ `\n注册${utc_dt(d.utc, "short")}`
b.idnam.href = `#${id}`
b.mta.innerText = `城市:${d.adm1} ${d.adm2}\n注册${utc_dt(d.utc, "short")}`
b.msg.innerText = d.msg
return b.bind
}
@ -70,6 +69,16 @@ export function sms(
return s.bind
}
export function put_s(
nam: string,
s?: string,
): { bind: Bind, val: () => string } {
const b = section("put_s")
label(b.put, nam)
if (s) b.put.value = s
return { bind: b.bind, val: () => b.put.value }
}
export function put_id(
d: Id,
): { bind: Bind, val: () => Pick<Id, "nam" | "adm1" | "adm2" | "msg"> } {
@ -92,7 +101,7 @@ export function btn_usr(
const b = section("btn_usr")
b.put.addEventListener("click", () => {
const put = put_id(d)
const btn = btn_put(`#${d._id}`, () => ({ put: "usr", usr: d._id, ...put.val() }))
const btn = btn_pos(`#${d._id}`, () => ({ put: "usr", usr: d._id, ...put.val() }))
article(put.bind, btn)
})
b.clr.addEventListener("click", async () => {
@ -104,12 +113,40 @@ export function btn_usr(
return b.bind
}
export function btn_put(
export function btn_aut(
p: Pas,
): Bind {
const b = section("btn_aut")
if (is_aut(p.aut.sup, p.usr)) b.aut.addEventListener("click", () => {
const [aut, wsl, lit] = [
put_s(`管理员:(最多${lim_aut.aut}名)`, p.aut.aut.join(",")),
put_s(`法律援助编辑:(最多${lim_aut.wsl}名)`, p.aut.wsl.join(",")),
put_s(`理论学习编辑:(最多${lim_aut.lit}名)`, p.aut.lit.join(",")),
]
const btn = btn_pos(`#${p.usr}`, () => ({
put: "aut",
aut: aut.val().split(",").map(v => parseInt(v)).filter(is_id),
wsl: wsl.val().split(",").map(v => parseInt(v)).filter(is_id),
lit: lit.val().split(",").map(v => parseInt(v)).filter(is_id),
}))
article(aut.bind, wsl.bind, lit.bind, btn)
}); else b.aut.remove()
if (is_aut(p.aut, p.usr) || is_in(p.sec)) b.usr.addEventListener("click", () => {
const nbr = put_s("激活手机号:")
const btn = btn_pos(`#${p.usr}`, () => ({ pre: "usr", nbr: nbr.val(), adm1: adm1_def, adm2: adm2_def }))
article(nbr.bind, btn)
}); else b.usr.remove()
if (is_aut(p.aut.aut, p.usr)) b.soc.remove()
if (p.sec.length == 0) b.agd.remove()
return b.bind
}
export function btn_pos(
h: string,
put: () => Put | null,
p: () => Pos | null,
del?: Put,
): Bind {
const b = section("btn_put")
const b = section("btn_pos")
if (del) b.del.addEventListener("click", async () => {
if (!is_put(nav.pas!, del) || !confirm("确认删除?")) return
b.del.disabled = b.put.disabled = b.ret.disabled = true
@ -119,8 +156,8 @@ export function btn_put(
}); else b.del.remove()
b.put.addEventListener("click", async () => {
b.del.disabled = b.put.disabled = b.ret.disabled = true
const p = put()
if (p && is_put(nav.pas!, p) && await pos(p)) return setTimeout(() => hash(h), utc_rf)
const d = p()
if (d && is_pos(nav.pas!, d) && await pos(d) != null) return setTimeout(() => hash(h), utc_rf)
alert("无效输入")
b.del.disabled = b.put.disabled = b.ret.disabled = false
})

View File

@ -1,4 +1,4 @@
import type { Pas } from "../../src/pra/pas.ts"
import type { Pas } from "../../src/pra/pos.ts"
const pas_a = document.getElementById("pas")! as HTMLAnchorElement
@ -19,9 +19,11 @@ const template = {
id: { idnam: tag("a"), id: tag("code"), nam: tag("span"), mta: tag("p"), msg: tag("p") },
sms: { nbr: tag("input"), sms: tag("button"), hint: tag("p") },
code: { code: tag("input"), send: tag("button") },
put_s: { put: tag("input") },
put_id: { nam: tag("input"), adm1: tag("select"), adm2: tag("select"), msg: tag("textarea") },
btn_usr: { put: tag("button"), clr: tag("button") },
btn_put: { del: tag("button"), put: tag("button"), ret: tag("button") },
btn_pos: { del: tag("button"), put: tag("button"), ret: tag("button") },
btn_aut: { aut: tag("button"), usr: tag("button"), soc: tag("button"), agd: tag("button") },
}
type Template = typeof template

View File

@ -23,6 +23,13 @@
</section>
</template>
<template id="put_s">
<section class="flex">
<label></label>
<input class="put" />
</section>
</template>
<template id="put_id">
<section class="flex">
<label>名称2-16个中文字符</label>
@ -46,10 +53,19 @@
</section>
</template>
<template id="btn_put">
<template id="btn_pos">
<section class="flex">
<button class="del">删除</button>
<button class="put">确认</button>
<button class="ret">取消</button>
</section>
</template>
<template id="btn_aut">
<section class="flex">
<button class="aut">增删管理员</button>
<button class="usr">添加用户</button>
<button class="soc">添加俱乐部</button>
<button class="agd">添加活动</button>
</section>
</template>