Przeglądaj źródła

refactor(web): 重排团队成员编辑中的登录账号区域

sy 1 dzień temu
rodzic
commit
3c98eadf69

+ 39 - 60
web-scaffold/src/components/OrganizationAccountInline.tsx

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

+ 39 - 13
web-scaffold/src/styles/organization.css

@@ -391,18 +391,44 @@
 .org-account-secret{display:flex;flex-direction:column;gap:8px;margin-top:17px;padding:15px;border:1px solid var(--primary-border);border-radius:8px;background:var(--primary-soft)}
 .org-account-secret span{font-size:var(--type-support);color:var(--primary)}.org-account-secret strong{font-size:18px;letter-spacing:.04em;word-break:break-all}.org-account-secret small{font-size:var(--type-support);line-height:1.5;color:var(--muted-foreground)}
 /* 档案编辑弹窗内的「登录账号」区(成员/合伙人共用):沿用档案编辑字段风格,概览两格+右侧动作行。 */
-.org-account-inline-facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;margin-bottom:12px}
-.org-account-inline-facts>div{display:flex;flex-direction:column;gap:5px;padding:10px 12px;border:1px solid var(--org-line);border-radius:7px;background:var(--card)}
-.org-account-inline-facts>div>span{font-size:var(--type-support);color:var(--muted-foreground)}
-.org-account-inline-facts>div>strong{display:block;margin:0;font-size:var(--type-body);color:var(--foreground);overflow-wrap:anywhere}
-.org-account-inline .org-helper{margin:8px 0 0}
-.org-account-inline .org-account-notice{margin-top:10px}
-.org-account-inline .org-access-confirm{margin-top:10px}
-.org-account-inline-action{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-top:10px}
-.org-account-inline-action>span{color:var(--muted-foreground);font-size:var(--type-support);line-height:1.5}
-.org-account-inline-action.is-stacked{flex-direction:column;align-items:stretch}
-.org-account-inline-row{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
-.org-account-inline-row>span{color:var(--muted-foreground);font-size:var(--type-support);line-height:1.5}
+.org-account-inline {
+  min-width: 0;
+  overflow: hidden;
+  border: 1px solid var(--border);
+  border-radius: 10px;
+  background: var(--card);
+}
+.org-account-inline-heading {
+  display: grid;
+  grid-template-columns: auto minmax(0, 1fr) auto;
+  align-items: center;
+  gap: 10px;
+  padding: 12px 14px;
+  border-bottom: 1px solid var(--border-subtle);
+  background: var(--surface-subtle);
+}
+.org-account-inline-icon {
+  display: grid;
+  place-items: center;
+  width: 34px;
+  height: 34px;
+  border-radius: 8px;
+  background: var(--primary-soft);
+  color: var(--primary-soft-foreground);
+}
+.org-account-inline-identity h3 { margin: 0; color: var(--text-secondary); font-size: var(--type-support); font-weight: 500; }
+.org-account-inline-identity p { margin: 2px 0 0; color: var(--foreground); font-size: var(--type-body); font-weight: 650; overflow-wrap: anywhere; }
+.org-account-inline-body { display: grid; gap: 10px; padding: 11px 14px; }
+.org-account-inline-actions, .org-account-inline-access {
+  display: flex;
+  align-items: center;
+  flex-wrap: wrap;
+  gap: 8px;
+}
+.org-account-inline-access { margin-inline-start: auto; }
+.org-account-inline-provision { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
+.org-account-inline-provision .org-field { flex: 1 1 180px; margin: 0; }
+.org-account-inline-body > :is(p, .org-account-secret) { margin: 0; }
 .org-account-create{margin-top:20px;padding:18px;border:1px solid var(--primary-border);border-left:4px solid var(--primary);border-radius:9px;background:var(--org-soft)}
 .org-account-create .org-field{margin-bottom:14px}
 .org-account-create .org-field>span:first-child{font-size:var(--type-body);line-height:1.5;color:var(--field-label)}
@@ -485,7 +511,7 @@
 .org-account-setting-row + .org-account-setting-row { border-top: 1px solid var(--border-subtle); }
 .org-account-setting-row strong { color: var(--foreground); font-size: var(--type-body); font-weight: 600; }
 .org-account-settings .org-button,
-.org-account-inline :is(.org-account-inline-action, .org-account-inline-row) > :is(.org-button-scope, .org-button-danger-soft) {
+.org-account-inline-actions .org-button {
   min-height: 34px;
   padding: 5px 11px;
   font-size: var(--type-support);