|
|
@@ -1,4 +1,5 @@
|
|
|
import { useState } from "react";
|
|
|
+import { KeyRound } from "lucide-react";
|
|
|
import { OrganizationAccountStatus } from "./OrganizationAccountStatus";
|
|
|
import { FIELD_UNAVAILABLE, reloadOrganizationData, type AccountFields } from "../lib/organization-demo";
|
|
|
import * as bos from "../lib/api/bos";
|
|
|
@@ -25,8 +26,7 @@ export function OrganizationAccountInline({ account, provision, mobile, note }:
|
|
|
const [busy, setBusy] = useState(false);
|
|
|
const [feedback, setFeedback] = useState<{ 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);
|
|
|
const [login, setLogin] = useState(account.login ?? "");
|
|
|
const opened = Boolean(account.login);
|
|
|
const userId = account.userId;
|
|
|
@@ -93,7 +93,7 @@ export function OrganizationAccountInline({ account, provision, mobile, note }:
|
|
|
// 启停态写 `bos_user_binding.status`,契约只认 `active`/`disabled`(⛔ UI 展示态「正常」≠ 入参 `normal`)。
|
|
|
const res = await bos.accountUpdateStatus({ user_id: userId, status: stopped ? "active" : "disabled" });
|
|
|
await reloadOrganizationData();
|
|
|
- setConfirmStop(false);
|
|
|
+ setConfirmation(null);
|
|
|
setFeedback({ message: `后端回状态:${res?.status ? label(ACCT_STATUS, res.status) : FIELD_UNAVAILABLE}。` });
|
|
|
} catch (e) {
|
|
|
setFeedback({ message: (e as Error)?.message || "账号状态变更失败", error: true });
|
|
|
@@ -110,7 +110,7 @@ export function OrganizationAccountInline({ account, provision, mobile, note }:
|
|
|
try {
|
|
|
const res = await bos.accountUnbind({ user_id: userId });
|
|
|
await reloadOrganizationData();
|
|
|
- setConfirmUnbind(false);
|
|
|
+ setConfirmation(null);
|
|
|
setFeedback({
|
|
|
message: res?.unbound
|
|
|
? `已解绑登录账号(撤销 ${res.revoked_user_ids?.length ?? 1} 个绑定)。档案仍保留,可重新开通。`
|
|
|
@@ -125,68 +125,47 @@ export function OrganizationAccountInline({ account, provision, mobile, note }:
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
- <fieldset className="org-scope-editor org-account-inline">
|
|
|
- <legend>登录账号</legend>
|
|
|
- <div className="org-account-inline-facts">
|
|
|
- <div><span>登录名</span><strong>{opened ? account.login : "尚未开通"}</strong></div>
|
|
|
- <div>
|
|
|
- <span>账号状态</span>
|
|
|
- <strong><OrganizationAccountStatus status={account.account} pending={account.accountPending} title={account.accountPending ? "后端未下发该账号的启停状态" : undefined} /></strong>
|
|
|
+ <section className="org-account-inline" aria-label="登录账号">
|
|
|
+ <div className="org-account-inline-heading">
|
|
|
+ <span className="org-account-inline-icon" aria-hidden="true"><KeyRound size={17} /></span>
|
|
|
+ <div className="org-account-inline-identity">
|
|
|
+ <h3>登录账号</h3>
|
|
|
+ <p>{opened ? account.login : "尚未开通"}</p>
|
|
|
</div>
|
|
|
+ <OrganizationAccountStatus status={account.account} pending={account.accountPending} title={account.accountPending ? "后端未下发该账号的启停状态" : undefined} />
|
|
|
</div>
|
|
|
- {!opened ? (
|
|
|
- provision ? (
|
|
|
- <div className="org-account-inline-action is-stacked">
|
|
|
- <label className="org-field"><span>登录名 <em>*</em> · 全站唯一,开通后不改</span><input autoComplete="off" disabled={busy} maxLength={64} onChange={(event) => { setLogin(event.target.value); setFeedback(null); }} placeholder="输入后提交开通" value={login} /></label>
|
|
|
- <div className="org-account-inline-row">
|
|
|
- <span>登录账号由后端开通管线生成,凭据以激活码一次性下发。</span>
|
|
|
+ <div className="org-account-inline-body">
|
|
|
+ {!opened ? (
|
|
|
+ provision ? (
|
|
|
+ <div className="org-account-inline-provision">
|
|
|
+ <label className="org-field"><span>登录名 <em>*</em></span><input autoComplete="off" disabled={busy} maxLength={64} onChange={(event) => { setLogin(event.target.value); setFeedback(null); }} placeholder="输入登录名" value={login} /></label>
|
|
|
<button className="org-button" disabled={busy} onClick={() => void provisionAccount()} type="button">{busy ? "处理中…" : "开通账号"}</button>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- ) : <p className="org-helper">账号只随建档/开通流程创建,此处不提供单独开通入口。</p>
|
|
|
- ) : (
|
|
|
- <>
|
|
|
- {!activated && (
|
|
|
- <div className="org-account-inline-action">
|
|
|
- <span>激活码仅在未激活时可重置,明文只返回一次。</span>
|
|
|
- <button className="org-button org-button-scope" disabled={!userId || busy} onClick={() => void resetCode()} title={userId ? undefined : "后端未下发 user_id,无法调用重置接口"} type="button">{busy ? "处理中…" : "重置激活码"}</button>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- {activation && <div className="org-account-secret"><span>本次激活码</span><strong>{activation.code ?? FIELD_UNAVAILABLE}</strong><span>有效期至</span><strong>{activation.expire ?? FIELD_UNAVAILABLE}</strong><small>仅本次返回,关闭后不可再查。</small></div>}
|
|
|
- {confirmStop ? (
|
|
|
- <div className="org-access-confirm">
|
|
|
- <strong>确认停用此账号?</strong>
|
|
|
- <p>停用后无法登录,之后可在此重新启用。</p>
|
|
|
- <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>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- ) : confirmUnbind ? (
|
|
|
- <div className="org-access-confirm">
|
|
|
- <strong>确认解绑此登录账号?</strong>
|
|
|
- <p>解绑后本地绑定与平台授权一并撤销;档案主体仍保留,可再开通新登录名。此操作不可恢复原绑定。</p>
|
|
|
- <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>
|
|
|
+ ) : <p className="org-helper">{note || "账号随成员建档开通。"}</p>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <div className="org-account-inline-actions">
|
|
|
+ {!activated && <button className="org-button org-button-scope" disabled={!userId || busy} onClick={() => void resetCode()} title={userId ? undefined : "未获取到账号标识,无法重置激活码"} type="button">重置激活码</button>}
|
|
|
+ <div className="org-account-inline-access">
|
|
|
+ <button className={stopped ? "org-button org-button-scope" : "org-button org-button-danger-soft"} aria-expanded={stopped ? undefined : confirmation === "stop"} disabled={!userId || busy} onClick={() => stopped ? void toggleAccount() : setConfirmation("stop")} title={userId ? undefined : "未获取到账号标识,无法修改登录权限"} type="button">{stopped ? "重新启用" : "停用账号"}</button>
|
|
|
+ <button className="org-button org-button-danger-soft" aria-expanded={confirmation === "unbind"} disabled={!userId || busy} onClick={() => setConfirmation("unbind")} title={userId ? undefined : "未获取到账号标识,无法解绑"} type="button">解绑账号</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
- ) : (
|
|
|
- <div className="org-account-inline-action is-stacked">
|
|
|
- <div className="org-account-inline-row">
|
|
|
- <span>{stopped ? "重新启用后即可恢复登录。" : "停用后无法登录,可在本处重新启用。"}</span>
|
|
|
- <button className={stopped ? "org-button org-button-scope" : "org-button org-button-danger-soft"} disabled={!userId || busy} onClick={() => stopped ? void toggleAccount() : setConfirmStop(true)} title={userId ? undefined : "后端未下发 user_id,无法调用启停接口"} type="button">{stopped ? "重新启用" : "停用账号"}</button>
|
|
|
+ {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>
|
|
|
- <div className="org-account-inline-row">
|
|
|
- <span>解绑=撤销登录绑定(`account/unbind`),与停用不同。</span>
|
|
|
- <button className="org-button org-button-danger-soft" disabled={!userId || busy} onClick={() => setConfirmUnbind(true)} title={userId ? undefined : "后端未下发 user_id,无法调用解绑接口"} type="button">解绑账号</button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- </>
|
|
|
- )}
|
|
|
- {note && !opened && <p className="org-helper">{note}</p>}
|
|
|
- {feedback && <p className={feedback.error ? "org-form-error" : "org-account-notice"} role={feedback.error ? "alert" : "status"}>{feedback.message}</p>}
|
|
|
- </fieldset>
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ {activation && <div className="org-account-secret"><span>本次激活码</span><strong>{activation.code ?? FIELD_UNAVAILABLE}</strong><span>有效期至</span><strong>{activation.expire ?? FIELD_UNAVAILABLE}</strong><small>仅本次返回,关闭后不可再查。</small></div>}
|
|
|
+ {feedback && <p className={feedback.error ? "org-form-error" : "org-account-notice"} role={feedback.error ? "alert" : "status"}>{feedback.message}</p>}
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
);
|
|
|
}
|