|
|
@@ -1,9 +1,9 @@
|
|
|
import { useEffect, useId, useRef, useState, type FormEvent, type KeyboardEvent as ReactKeyboardEvent } from "react";
|
|
|
-import { X } from "lucide-react";
|
|
|
+import { Building2, KeyRound, X } from "lucide-react";
|
|
|
import { OrganizationAccountStatus } from "./OrganizationAccountStatus";
|
|
|
import { FIELD_UNAVAILABLE, reloadOrganizationData, type AccountFields, type OrganizationData, useOrganizationSnapshot } from "../lib/organization-demo";
|
|
|
import * as bos from "../lib/api/bos";
|
|
|
-import { ACCT_STATUS, label } from "../lib/api/labels";
|
|
|
+import { ACCT_STATUS, ACTIVATION_STATUS, label } from "../lib/api/labels";
|
|
|
|
|
|
export type AccountTarget =
|
|
|
| { kind: "operator" | "partner" | "operations-member" | "maintenance-lead" | "maintenance-member"; id: string };
|
|
|
@@ -56,8 +56,7 @@ export function OrganizationAccountDialog({ target, onClose }: { target: Account
|
|
|
const [busy, setBusy] = useState(false);
|
|
|
const [feedback, setFeedback] = useState<{ area: FeedbackArea; message: string; error?: boolean } | null>(null);
|
|
|
const [activation, setActivation] = useState<{ code: string | null; expire: string | null } | null>(null);
|
|
|
- const [confirmStop, setConfirmStop] = useState(false);
|
|
|
- const [confirmUnbind, setConfirmUnbind] = useState(false);
|
|
|
+ const [confirmation, setConfirmation] = useState<"stop" | "unbind" | null>(null);
|
|
|
useEffect(() => {
|
|
|
const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
|
dialogRef.current?.focus();
|
|
|
@@ -92,6 +91,7 @@ export function OrganizationAccountDialog({ target, onClose }: { target: Account
|
|
|
const title = `账号设置 · ${current.label}`;
|
|
|
/** 已激活账号**不支持重置激活码**(U-03/`KLT-A003`)⇒ 不展示重置卡片,⛔ 让用户点了才被后端拦。 */
|
|
|
const activated = current.account.activationStatus === "activated";
|
|
|
+ const stopped = current.account.account === "停用";
|
|
|
const report = (area: FeedbackArea, message: string, error = false) => setFeedback({ area, message, error });
|
|
|
const message = (area: FeedbackArea) => feedback?.area === area && <p className={feedback.error ? "org-access-feedback is-error" : "org-access-feedback"} role={feedback.error ? "alert" : "status"}>{feedback.message}</p>;
|
|
|
const checkPhone = (value: string) => (value && !/^1[3-9]\d{9}$/.test(value) ? "请输入 11 位中国大陆手机号,或留空" : "");
|
|
|
@@ -177,7 +177,7 @@ export function OrganizationAccountDialog({ target, onClose }: { target: Account
|
|
|
// 启停态写 `bos_user_binding.status`,契约只认 `active`/`disabled`(⛔ UI 展示态「正常」≠ 入参 `normal`)。
|
|
|
const res = await bos.accountUpdateStatus({ user_id: userId, status: account.account.account === "停用" ? "active" : "disabled" });
|
|
|
await reloadOrganizationData();
|
|
|
- setConfirmStop(false);
|
|
|
+ setConfirmation(null);
|
|
|
report("status", `后端回状态:${res?.status ? label(ACCT_STATUS, res.status) : FIELD_UNAVAILABLE}。`);
|
|
|
} catch (e) {
|
|
|
report("status", (e as Error)?.message || "账号状态变更失败", true);
|
|
|
@@ -194,7 +194,7 @@ export function OrganizationAccountDialog({ target, onClose }: { target: Account
|
|
|
try {
|
|
|
const res = await bos.accountUnbind({ user_id: userId });
|
|
|
await reloadOrganizationData();
|
|
|
- setConfirmUnbind(false);
|
|
|
+ setConfirmation(null);
|
|
|
report(
|
|
|
"status",
|
|
|
res?.unbound
|
|
|
@@ -222,103 +222,126 @@ export function OrganizationAccountDialog({ target, onClose }: { target: Account
|
|
|
tabIndex={-1}
|
|
|
>
|
|
|
<header>
|
|
|
- <div>
|
|
|
- <h2>账号设置</h2>
|
|
|
- <p>{current.label}</p>
|
|
|
- </div>
|
|
|
+ <h2>账号设置</h2>
|
|
|
<button aria-label="关闭账号设置" className="org-icon-button" onClick={onClose} type="button"><X size={18} /></button>
|
|
|
</header>
|
|
|
<div className="org-dialog-content org-account-settings-body">
|
|
|
- <div className="org-account-summary">
|
|
|
- <div>
|
|
|
- <span>登录账号</span>
|
|
|
- <strong>{opened ? current.account.login : "尚未开通"}</strong>
|
|
|
+ <section className="org-account-identity" aria-label="账号概览">
|
|
|
+ <div className="org-account-identity-heading">
|
|
|
+ <span className="org-account-symbol"><Building2 size={22} aria-hidden="true" /></span>
|
|
|
+ <h3>{current.label}</h3>
|
|
|
</div>
|
|
|
- {(opened || current.account.accountPending || current.account.account !== "未开通") && (
|
|
|
- <OrganizationAccountStatus status={current.account.account} pending={current.account.accountPending} title={current.account.accountPending ? "后端未下发该账号的启停状态" : undefined} />
|
|
|
- )}
|
|
|
- </div>
|
|
|
-
|
|
|
- {!opened ? (
|
|
|
- <form id={provisionFormId} className="org-account-fields" onSubmit={openAccount}>
|
|
|
- <label className="org-field">
|
|
|
- <span>登录名 <em>*</em></span>
|
|
|
- <input autoComplete="off" disabled={!provisionPlan || busy} onChange={(event) => setLogin(event.target.value)} placeholder="输入登录名" value={login} />
|
|
|
- </label>
|
|
|
- <label className="org-field">
|
|
|
- <span>手机号 <small>选填</small></span>
|
|
|
- <input inputMode="tel" maxLength={11} disabled={!provisionPlan || busy} onChange={(event) => setPhone(event.target.value)} placeholder="输入 11 位手机号" value={phone} />
|
|
|
- </label>
|
|
|
- {!provisionPlan && <p className="org-form-error">{memberProvisionNote}</p>}
|
|
|
- </form>
|
|
|
- ) : (
|
|
|
- <div className="org-account-actions">
|
|
|
- {canEditPhone && (
|
|
|
- <section className="org-account-setting-row" aria-labelledby="org-access-phone-title">
|
|
|
- <h3 id="org-access-phone-title">登录手机号</h3>
|
|
|
- <form className="org-account-phone-form" onSubmit={savePhone}>
|
|
|
- <label className="org-field">
|
|
|
- <span className="sr-only">绑定手机号</span>
|
|
|
- <input inputMode="tel" maxLength={11} disabled={busy} onChange={(event) => setPhone(event.target.value)} placeholder="未绑定则只能用登录名" value={phone} />
|
|
|
- </label>
|
|
|
- <button className="org-button org-button-quiet" disabled={busy} type="submit">保存手机号</button>
|
|
|
- </form>
|
|
|
- {message("phone")}
|
|
|
- </section>
|
|
|
+ <dl className="org-account-facts">
|
|
|
+ <div><dt>登录名</dt><dd className="org-account-username">{current.account.login || "尚未开通"}</dd></div>
|
|
|
+ {(opened || current.account.accountPending || current.account.account !== "未开通") && (
|
|
|
+ <div>
|
|
|
+ <dt>登录状态</dt>
|
|
|
+ <dd><OrganizationAccountStatus status={current.account.account} pending={current.account.accountPending} /></dd>
|
|
|
+ </div>
|
|
|
)}
|
|
|
- {!activated && (
|
|
|
- <section className="org-account-setting-row" aria-labelledby="org-access-password-title">
|
|
|
- <h3 id="org-access-password-title">激活码</h3>
|
|
|
- <form onSubmit={resetCode}>
|
|
|
- <button className="org-button org-button-quiet" disabled={!userId || busy} title={userId ? undefined : noUserIdNote} type="submit">重置激活码</button>
|
|
|
- </form>
|
|
|
- {message("password")}
|
|
|
- </section>
|
|
|
+ {opened && (
|
|
|
+ <div>
|
|
|
+ <dt>首次激活</dt>
|
|
|
+ <dd>{current.account.activationStatus ? label(ACTIVATION_STATUS, current.account.activationStatus) : "状态未返回"}</dd>
|
|
|
+ </div>
|
|
|
)}
|
|
|
- <section className="org-account-setting-row" aria-labelledby="org-access-status-title">
|
|
|
- <h3 id="org-access-status-title">登录管理</h3>
|
|
|
- {confirmStop ? (
|
|
|
- <div className="org-access-confirm">
|
|
|
- <strong>确认停用此账号?</strong>
|
|
|
- <p>停用后无法登录,之后可在此重新启用。</p>
|
|
|
+ </dl>
|
|
|
+ </section>
|
|
|
+
|
|
|
+ <div className="org-account-workspace">
|
|
|
+ {message("access")}
|
|
|
+ {activationBlock}
|
|
|
+ {!opened ? (
|
|
|
+ <section className="org-account-provision" aria-labelledby="org-account-provision-title">
|
|
|
+ <h3 id="org-account-provision-title">开通登录账号</h3>
|
|
|
+ <p>设置登录名,账号使用人凭激活码完成首次登录。</p>
|
|
|
+ <form id={provisionFormId} className="org-account-fields" onSubmit={openAccount}>
|
|
|
+ <label className="org-field">
|
|
|
+ <span>登录名 <em>*</em></span>
|
|
|
+ <input autoComplete="off" disabled={!provisionPlan || busy} onChange={(event) => setLogin(event.target.value)} placeholder="输入登录名" value={login} />
|
|
|
+ </label>
|
|
|
+ <label className="org-field">
|
|
|
+ <span>手机号 <small>选填</small></span>
|
|
|
+ <input inputMode="tel" maxLength={11} disabled={!provisionPlan || busy} onChange={(event) => setPhone(event.target.value)} placeholder="输入 11 位手机号" value={phone} />
|
|
|
+ </label>
|
|
|
+ {!provisionPlan && <p className="org-form-error">{memberProvisionNote}</p>}
|
|
|
+ </form>
|
|
|
+ </section>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ {!activated && (
|
|
|
+ <section className="org-account-activation" aria-labelledby="org-access-password-title">
|
|
|
+ <KeyRound size={19} aria-hidden="true" />
|
|
|
<div>
|
|
|
- <button className="org-button org-button-quiet" disabled={busy} onClick={() => setConfirmStop(false)} type="button">取消</button>
|
|
|
- <button className="org-button org-button-danger" disabled={!userId || busy} onClick={() => void toggleAccount()} type="button">确认停用</button>
|
|
|
+ <h3 id="org-access-password-title">首次登录凭据</h3>
|
|
|
+ <p>重置后,请将新激活码交给账号使用人。</p>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- ) : confirmUnbind ? (
|
|
|
- <div className="org-access-confirm">
|
|
|
- <strong>确认解绑此登录账号?</strong>
|
|
|
- <p>解绑后本地绑定与平台授权一并撤销;档案主体仍保留,可再开通新登录名。此操作不可恢复原绑定。</p>
|
|
|
+ <form onSubmit={resetCode}>
|
|
|
+ <button className="org-button org-button-quiet" disabled={!userId || busy} title={userId ? undefined : noUserIdNote} type="submit">重置激活码</button>
|
|
|
+ </form>
|
|
|
+ {message("password")}
|
|
|
+ </section>
|
|
|
+ )}
|
|
|
+ <section className="org-account-access" aria-labelledby="org-access-status-title">
|
|
|
+ <h3 id="org-access-status-title">访问管理</h3>
|
|
|
+ {canEditPhone && (
|
|
|
+ <div className="org-account-setting-row">
|
|
|
+ <div><strong>登录手机号</strong></div>
|
|
|
+ <form className="org-account-phone-form" onSubmit={savePhone}>
|
|
|
+ <label className="org-field">
|
|
|
+ <span className="sr-only">绑定手机号</span>
|
|
|
+ <input inputMode="tel" maxLength={11} disabled={busy} onChange={(event) => setPhone(event.target.value)} placeholder="未绑定则只能用登录名" value={phone} />
|
|
|
+ </label>
|
|
|
+ <button className="org-button org-button-quiet" disabled={busy} type="submit">保存手机号</button>
|
|
|
+ </form>
|
|
|
+ {message("phone")}
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ <div className="org-account-setting-row">
|
|
|
<div>
|
|
|
- <button className="org-button org-button-quiet" disabled={busy} onClick={() => setConfirmUnbind(false)} type="button">取消</button>
|
|
|
- <button className="org-button org-button-danger" disabled={!userId || busy} onClick={() => void unbindAccount()} type="button">确认解绑</button>
|
|
|
+ <strong>登录权限</strong>
|
|
|
+ <p>{stopped ? "恢复该账号的登录权限。" : "暂停登录权限,之后可重新启用。"}</p>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- ) : (
|
|
|
- <div className="org-account-row-buttons">
|
|
|
<button
|
|
|
- className={current.account.account === "停用" ? "org-button org-button-quiet" : "org-button org-button-quiet org-account-danger-action"}
|
|
|
+ className="org-button org-button-quiet"
|
|
|
disabled={!userId || busy}
|
|
|
title={userId ? undefined : noUserIdNote}
|
|
|
- onClick={() => current.account.account === "停用" ? void toggleAccount() : setConfirmStop(true)}
|
|
|
+ aria-expanded={stopped ? undefined : confirmation === "stop"}
|
|
|
+ onClick={() => stopped ? void toggleAccount() : setConfirmation("stop")}
|
|
|
type="button"
|
|
|
- >{current.account.account === "停用" ? "重新启用" : "停用账号"}</button>
|
|
|
+ >{stopped ? "重新启用" : "停用账号"}</button>
|
|
|
+ </div>
|
|
|
+ <div className="org-account-setting-row">
|
|
|
+ <div>
|
|
|
+ <strong>账号绑定</strong>
|
|
|
+ <p>撤销当前登录账号的绑定,保留运营商档案。</p>
|
|
|
+ </div>
|
|
|
<button
|
|
|
className="org-button org-button-quiet org-account-danger-action"
|
|
|
disabled={!userId || busy}
|
|
|
title={userId ? undefined : noUserIdNote}
|
|
|
- onClick={() => setConfirmUnbind(true)}
|
|
|
+ aria-expanded={confirmation === "unbind"}
|
|
|
+ onClick={() => setConfirmation("unbind")}
|
|
|
type="button"
|
|
|
>解绑账号</button>
|
|
|
</div>
|
|
|
- )}
|
|
|
- {message("status")}
|
|
|
- </section>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- {message("access")}
|
|
|
- {activationBlock}
|
|
|
+ {confirmation && (
|
|
|
+ <div className="org-access-confirm">
|
|
|
+ <strong>{confirmation === "stop" ? "确认停用此账号?" : "确认解绑此登录账号?"}</strong>
|
|
|
+ <p>{confirmation === "stop" ? "停用后无法登录,之后可在此重新启用。" : "解绑会撤销当前账号的登录授权。原绑定无法恢复,可为此档案重新开通账号。"}</p>
|
|
|
+ <div>
|
|
|
+ <button className="org-button org-button-quiet" disabled={busy} onClick={() => setConfirmation(null)} type="button">取消</button>
|
|
|
+ <button className="org-button org-button-danger" disabled={!userId || busy} onClick={() => void (confirmation === "stop" ? toggleAccount() : unbindAccount())} type="button">
|
|
|
+ {confirmation === "stop" ? "确认停用" : "确认解绑"}
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ {message("status")}
|
|
|
+ </section>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<footer>
|
|
|
<button className="org-button org-button-quiet" onClick={onClose} type="button">关闭</button>
|