Просмотр исходного кода

style(web): 重设计下属分账号页面与姓名编辑对话框

sy 3 дней назад
Родитель
Сommit
b50cefd19b

+ 112 - 40
web-scaffold/src/pages/CustomerSelfServicePages.tsx

@@ -9,20 +9,21 @@
  * 客户角色本就不该拿到它(2026-11-14「我的套餐/分账号」整页空态的根因)。自读口只要求
  * `bos.customer.view`,且行集由后端按主体收窄,客户看不到别家档案。
  */
-import { useMemo, useState } from "react";
-import { PageIntro } from "../components/PageIntro";
+import { useState, type FormEvent } from "react";
 import { useNavigate, useParams } from "react-router";
 import { FetchError } from "../components/fetchError";
-import { ArrowDownRight, Building2, History, Info, Layers3, MapPin, PencilLine } from "lucide-react";
+import { ArrowDownRight, ArrowRight, Building2, History, Info, KeyRound, Layers3, MapPin, PencilLine, Search, UserRound, UsersRound } from "lucide-react";
 import { Button } from "../components/ui/button";
 import { Input } from "../components/ui/input";
+import { SearchInput } from "../components/ui/search-input";
 import { ListPager } from "../components/ListPager";
-import { OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
+import { OpsDialog, OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
 import { Tri } from "../components/triState";
 import { LIST_PAGE_SIZE, clampPage } from "../lib/list-paging";
 import { useDemoIdentity } from "../lib/demo-session";
 import { useProfileOverlay } from "../components/layout/ProfileOverlay";
 import { useLoad } from "../lib/useLoad";
+import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
 import { ApiError } from "../lib/api/http";
 import { customerGet, portalPlanBoard, subAccountGetList, subAccountUpdate } from "../lib/api/bos";
 import { ACCT_STATUS, PLAN_FAMILY, label } from "../lib/api/labels";
@@ -30,6 +31,8 @@ import type { PortalPlanBoardRow, SubAccountRow } from "../lib/api/types";
 import { isSeatPlaceholder, seatDisplayName } from "../lib/customer-subaccounts";
 import "../styles/operations.css";
 import "../styles/portal-plans.css";
+import "../styles/record-detail.css";
+import "../styles/portal-accounts.css";
 
 const MISSING = "后端未下发";
 
@@ -143,72 +146,141 @@ export function CustomerAccountsPage() {
   const navigate = useNavigate();
   const { openProfile } = useProfileOverlay();
   const customerNo = customerNoParam || identity?.customerNo || "";
-  // 额度与主体名走自读口 `/customer/get@v1`(`sub_account_count`/`customer_name`),⛔ 运营侧名录。
   const detail = useLoad(
     () => (customerNo ? customerGet({ customer_id: customerNo }) : Promise.resolve(null)),
     [customerNo],
   );
-  const customer = detail.data;
+  const [query, setQuery] = useState("");
   const [page, setPage] = useState(0);
   const [pageSize, setPageSize] = useState(LIST_PAGE_SIZE);
   const state = useLoad(
-    () => subAccountGetList({ customer_id: customerNo, page, page_size: pageSize }),
-    [customerNo, page, pageSize],
+    () => subAccountGetList({ customer_id: customerNo, page, page_size: pageSize, keyword: query.trim() || undefined }),
+    [customerNo, page, pageSize, query],
   );
-  const rows: SubAccountRow[] = state.data?.items ?? [];
-  const total = Number(state.data?.total ?? 0);
+  const tableOverflow = useHorizontalOverflow();
+  const customer = detail.data;
+  const rows = state.data?.items ?? [];
+  const total = state.data?.total ?? 0;
   const safePage = clampPage(page, total, pageSize);
-  const pageRows = rows;
+  const ownerName = customer?.customer.customer_name || customerNo || "下属分账号";
+  const regions = customer?.region_mounts.map((mount) => mount.path_name || mount.parent_node_id).join("、");
   const [editing, setEditing] = useState<SubAccountRow | null>(null);
   const [name, setName] = useState("");
   const [notice, setNotice] = useState("");
   const [error, setError] = useState("");
   const [busy, setBusy] = useState(false);
-  const quota = customer?.sub_account_count ?? null;
-  const used = state.data?.total ?? null;
-  const remaining = quota !== null && used !== null ? Math.max(0, quota - used) : null;
-  const ownerName = useMemo(() => customer?.customer.customer_name ?? customerNo, [customer, customerNo]);
 
-  async function save() {
-    if (!editing) return;
+  function search(value: string) {
+    setQuery(value);
+    setPage(0);
+  }
+
+  async function save(event: FormEvent<HTMLFormElement>) {
+    event.preventDefault();
+    if (!editing || busy || !name.trim()) return;
     setBusy(true);
     setError("");
     try {
-      await subAccountUpdate({ sub_account_id: editing.sub_account_id, display_name: name });
+      await subAccountUpdate({ sub_account_id: editing.sub_account_id, display_name: name.trim() });
       setEditing(null);
-      setNotice("分账号真实姓名已更新(后端回执为准)。");
+      setNotice("使用人姓名已更新");
       state.reload();
     } catch (e) {
-      setError((e as ApiError).message || "取数失败");
+      setError((e as ApiError).message || "保存失败,请重试。");
     } finally {
       setBusy(false);
     }
   }
 
-  return <section className="ops-page page-fill"><header className="ops-heading"><div><p className="ops-eyebrow"><span /> 企业门户 · 分账号管理</p><h1>{ownerName}</h1><PageIntro>看看企业的分账号额度还剩多少,并为已开通的账号更新使用人姓名。</PageIntro></div><div><Button variant="outline" onClick={() => navigate("/workspace/plan")}>查看我的套餐</Button><Button onClick={openProfile}>修改登录密码</Button></div></header>
-    <div className="ops-quota-meter ops-card"><span><small>分账号额度</small><strong>{quota ?? <Tri tone="missing" text={MISSING} title={`${MISSING}:/customer/get@v1 未回 sub_account_count`} />} · 已用 {used ?? <Tri tone="missing" text={MISSING} />} · 剩余 {remaining ?? <Tri tone="missing" text={MISSING} />}</strong></span><p>后端不提供分账号新增/删除路由,本页仅支持修改真实姓名。</p></div>
+  return <section className="ops-page portal-accounts-page page-fill page-fill-window">
+    <header className="customer-record-masthead portal-accounts-masthead">
+      <span className="portal-accounts-emblem"><UsersRound size={26} strokeWidth={1.6} aria-hidden="true" /></span>
+      <div>
+        <p className="customer-record-id">下属分账号</p>
+        <h1 className="customer-record-title">{ownerName}</h1>
+        <p className="portal-accounts-intro">查看分账号的使用情况,维护账号与使用人的对应关系。</p>
+      </div>
+      <div className="portal-accounts-actions">
+        <Button variant="outline" onClick={openProfile}><KeyRound size={14} />修改登录密码</Button>
+        <Button variant="ghost" onClick={() => navigate("/workspace/plan")}>查看我的套餐<ArrowRight size={15} /></Button>
+      </div>
+    </header>
+
+    {detail.error && <FetchError message={detail.error.message} onRetry={detail.reload} />}
+    <dl className="customer-record-metrics portal-accounts-metrics" aria-label="分账号概况">
+      <div>
+        <dt><UsersRound size={16} aria-hidden="true" />分账号总数</dt>
+        <dd>{customer ? <><strong>{customer.sub_account_count}</strong><span>个</span></> : <span className="table-placeholder">{detail.loading ? "读取中…" : "暂未获取"}</span>}</dd>
+      </div>
+      <div>
+        <dt><MapPin size={16} aria-hidden="true" />所属区域</dt>
+        <dd className={regions ? "portal-accounts-meta" : "portal-accounts-meta table-placeholder"}>{regions || (detail.loading ? "读取中…" : "未配置")}</dd>
+      </div>
+      <div>
+        <dt><Building2 size={16} aria-hidden="true" />运营商</dt>
+        <dd className={customer?.customer.operator_name ? "portal-accounts-meta" : "portal-accounts-meta table-placeholder"}>{customer?.customer.operator_name || (detail.loading ? "读取中…" : "未配置")}</dd>
+      </div>
+    </dl>
+
     <div className="ops-list-shell list-shell-fill">
+      <div className="ops-toolbar">
+        <label className="ops-search portal-accounts-search">
+          <Search size={17} aria-hidden="true" />
+          <SearchInput aria-label="搜索登录名、使用人或网络侧账号" placeholder="搜索账号或使用人" value={query} onCommit={search} />
+        </label>
+        {query && <Button variant="ghost" size="sm" onClick={() => search("")}>重置筛选</Button>}
+      </div>
       {state.error && <FetchError message={state.error.message} onRetry={state.reload} />}
-      <div className="ops-table-wrap measured-table-scroll"><table className="ops-table"><thead><tr><th>登录名</th><th>真实姓名</th><th>状态</th><th>操作</th></tr></thead><tbody>{pageRows.map((row) => <tr key={row.sub_account_id}>
-        {/* 三态(巡检 P1-D2):未开通/已停用的席位没有登录名属正常态,⛔ 标「后端未下发」。 */}
-        <td><strong>{row.username?.trim()
-          ? row.username
-          : row.status === "not_opened"
-            ? <span className="ops-muted table-placeholder" title="该席位尚未开通,登录名在开通后登记">未开通</span>
-            : row.status === "stopped"
-              ? <span className="ops-muted" title="该席位已停用,登录名随停用不再展示">已停用</span>
-              : <Tri tone="missing" text={MISSING} title="sub_account.username 已下发、值为空" />}</strong></td>
-        <td>{seatDisplayName(row)
-          ? <><span>{seatDisplayName(row)}</span>{isSeatPlaceholder(row) && <small className="ml-1 text-xs opacity-70">(席位占位·姓名待填)</small>}</>
-          : row.status === "not_opened"
-            ? <span className="ops-muted table-placeholder" title="该席位尚未开通,真实姓名开通后由客户填写">未开通(开通后填写)</span>
-            : <Tri tone="missing" text={MISSING} title="sub_account.display_name 已下发、值为空" />}</td>
-        <td><OpsStatus tone={row.status === "active" || row.status === "normal" ? "success" : row.status === "stopped" || row.status === "disabled" ? "neutral" : "warning"}>{label(ACCT_STATUS, row.status) || MISSING}</OpsStatus></td>
-        <td><Button variant="ghost" size="sm" onClick={() => { setEditing(row); setName(row.display_name ?? ""); setError(""); }}><PencilLine size={14} />修改姓名</Button></td>
-      </tr>)}{!rows.length && !state.loading && <OpsTableEmpty colSpan={4}>{state.error ? "分账号取数失败。" : "暂无分账号。"}</OpsTableEmpty>}{!rows.length && state.loading && <OpsTableEmpty colSpan={4}>分账号加载中…</OpsTableEmpty>}</tbody></table></div>
+      <div ref={tableOverflow.ref} tabIndex={0} role="region" aria-label="下属分账号列表" className={`ops-table-wrap measured-table-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}`}>
+        <table className="ops-table ops-table-sticky-action portal-accounts-table">
+          <OpsTableColumns widths={[245, 170, 190, 235, 110, 122]} />
+          <thead><tr>{["登录账号", "使用人", "用途", "网络侧账号", "状态", "操作"].map((column) => <th key={column} scope="col">{column}</th>)}</tr></thead>
+          <tbody>
+            {rows.map((row) => (
+              <tr key={row.sub_account_id}>
+                <td>
+                  <span className={row.username?.trim() ? "table-cell-title portal-accounts-login" : "table-placeholder"} title={row.username || undefined}>
+                    {row.username?.trim() || (row.status === "not_opened" ? "未开通" : row.status === "stopped" ? "已停用" : "未配置")}
+                  </span>
+                </td>
+                <td>
+                  <span className={!seatDisplayName(row) || isSeatPlaceholder(row) ? "table-placeholder" : undefined}>{seatDisplayName(row) || (row.status === "not_opened" ? "未开通" : "未填写")}</span>
+                  {isSeatPlaceholder(row) && <small>姓名待填写</small>}
+                </td>
+                <td title={row.purpose || undefined}>{row.purpose || <span className="table-placeholder">未填写</span>}</td>
+                <td title={row.net_account || undefined}>{row.net_account || <span className="table-placeholder">未配置</span>}</td>
+                <td><OpsStatus tone={row.status === "active" || row.status === "normal" ? "success" : row.status === "stopped" || row.status === "disabled" ? "neutral" : "warning"}>{label(ACCT_STATUS, row.status) || MISSING}</OpsStatus></td>
+                <td><div className="ops-inline-actions">
+                  <button type="button" onClick={() => { setEditing(row); setName(row.display_name ?? ""); setError(""); }}><PencilLine size={14} />修改姓名</button>
+                </div></td>
+              </tr>
+            ))}
+            {!rows.length && <OpsTableEmpty colSpan={6}>{state.loading ? "正在读取分账号…" : state.error ? "分账号读取失败,请重试。" : query ? "没有找到匹配的分账号,请调整搜索条件。" : "暂无下属分账号"}</OpsTableEmpty>}
+          </tbody>
+        </table>
+      </div>
       <ListPager total={total} page={safePage} pageSize={pageSize} onPageChange={setPage} onPageSizeChange={(size) => { setPageSize(size); setPage(0); }} unit="个" />
     </div>
-    {editing && <div className="ops-confirm-backdrop" onMouseDown={() => setEditing(null)}><div className="ops-confirm-card" onMouseDown={(event) => event.stopPropagation()} role="dialog" aria-modal="true"><p className="ops-confirm-kicker">修改真实姓名</p><h2>{editing.username ?? editing.sub_account_id}</h2><label className="ops-field">真实姓名<span><Input value={name} onChange={(e) => setName(e.target.value)} /></span></label>{error && <p className="ops-form-error" role="alert">{error}</p>}<div className="ops-confirm-actions"><Button variant="outline" onClick={() => setEditing(null)}>取消</Button><Button disabled={busy || !name.trim()} onClick={() => void save()}>{busy ? "保存中…" : "保存"}</Button></div></div></div>}
+
+    {editing && <OpsDialog title="修改使用人姓名" onClose={() => { if (!busy) setEditing(null); }} className="portal-account-dialog">
+      <form onSubmit={(event) => void save(event)}>
+        <div className="portal-account-dialog-body">
+          <div className="portal-account-summary">
+            <span className="portal-account-avatar"><UserRound size={19} aria-hidden="true" /></span>
+            <div><span>登录账号</span><p>{editing.username || (editing.status === "not_opened" ? "未开通" : "未配置")}</p></div>
+            <OpsStatus tone={editing.status === "active" || editing.status === "normal" ? "success" : editing.status === "not_opened" ? "warning" : "neutral"}>{label(ACCT_STATUS, editing.status) || MISSING}</OpsStatus>
+          </div>
+          <label className="portal-account-field"><span>使用人姓名 <span className="portal-account-required" aria-hidden="true">*</span></span>
+            <Input value={name} autoFocus required placeholder="请输入使用人的真实姓名" onChange={(event) => setName(event.target.value)} disabled={busy} />
+          </label>
+          {error && <p className="ops-form-error" role="alert">{error}</p>}
+        </div>
+        <footer className="portal-account-dialog-footer">
+          <Button type="button" variant="outline" disabled={busy} onClick={() => setEditing(null)}>取消</Button>
+          <Button type="submit" disabled={busy || !name.trim() || name.trim() === (editing.display_name ?? "").trim()}>{busy ? "保存中…" : "保存修改"}</Button>
+        </footer>
+      </form>
+    </OpsDialog>}
     {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
   </section>;
 }

+ 57 - 0
web-scaffold/src/styles/portal-accounts.css

@@ -0,0 +1,57 @@
+.portal-accounts-page { gap: 16px; }
+.portal-accounts-masthead { margin: 0; }
+.portal-accounts-emblem {
+  display: grid;
+  place-items: center;
+  width: 58px;
+  height: 58px;
+  border-radius: 14px;
+  background: var(--primary);
+  color: var(--primary-foreground);
+}
+.portal-accounts-intro { margin: 0; color: var(--muted-foreground); font-size: var(--type-support); line-height: 1.6; }
+.portal-accounts-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
+.portal-accounts-actions button { font-size: var(--type-support); }
+.portal-accounts-metrics { grid-template-columns: minmax(160px, .65fr) minmax(0, 1.35fr) minmax(0, 1fr); margin: 0; }
+.portal-accounts-metrics > div:first-child { background: var(--primary-soft); }
+.portal-accounts-metrics dd { display: flex; align-items: baseline; gap: 7px; }
+.portal-accounts-metrics dd > span { color: var(--text-secondary); font-size: var(--type-support); }
+.portal-accounts-metrics dd.portal-accounts-meta { margin-top: 9px; font-size: var(--type-support); color: var(--text-secondary); line-height: 1.6; overflow-wrap: anywhere; }
+.portal-accounts-metrics dd.table-placeholder,
+.portal-accounts-metrics dd > span.table-placeholder { color: var(--border-hover); }
+.portal-accounts-table.ops-table { table-layout: fixed; min-width: 900px; border-collapse: separate; border-spacing: 0; }
+.portal-accounts-table thead th { position: sticky; top: 0; z-index: 1; }
+.portal-accounts-table :is(th, td):last-child { text-align: right; }
+.portal-accounts-table td:not(:last-child) { overflow: hidden; text-overflow: ellipsis; }
+.portal-accounts-table .portal-accounts-login { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.portal-accounts-table .ops-inline-actions { justify-content: flex-end; }
+.portal-accounts-table tbody tr:hover td { background: var(--surface-subtle); }
+.portal-account-dialog.ops-dialog { width: min(480px, calc(100vw - 32px)); }
+.portal-account-dialog.ops-dialog > form { padding: 0; }
+.portal-account-dialog.ops-content-dialog > header h2 { font-size: 18px; font-weight: 600; }
+.portal-account-dialog-body { display: grid; gap: 22px; padding: 24px; }
+.portal-account-summary {
+  display: flex;
+  align-items: center;
+  gap: 11px;
+  padding: 14px;
+  border: 1px solid var(--border-subtle);
+  border-radius: var(--radius-control);
+  background: var(--surface-subtle);
+}
+.portal-account-avatar { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 9px; color: var(--primary); background: var(--primary-soft); }
+.portal-account-summary > div { flex: 1; min-width: 0; }
+.portal-account-summary > div > span { color: var(--muted-foreground); font-size: var(--type-meta); }
+.portal-account-summary p { margin: 3px 0 0; color: var(--text-secondary); font-size: var(--type-support); font-weight: 500; overflow-wrap: anywhere; }
+.portal-account-summary > .ops-status { flex: none; }
+.portal-account-field { display: grid; gap: 7px; color: var(--field-label); font-size: var(--type-support); }
+.portal-account-required { color: var(--destructive); }
+.portal-account-dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border); }
+
+@media (max-width: 760px) {
+  .portal-accounts-masthead { grid-template-columns: auto minmax(0, 1fr); gap: 14px; padding: 18px; }
+  .portal-accounts-actions { grid-column: 1 / -1; justify-content: flex-start; }
+  .portal-accounts-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+  .portal-accounts-metrics > div:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
+  .portal-account-dialog-body { padding: 20px; }
+}