| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /**
- * 客户自助侧页面(第 3 册 6.13 / 6.14)—— 真源=klt-bos。
- *
- * 分账号读写:`POST /sub_account/get_list@v1` + `POST /sub_account/update@v1`;
- * [实] `/sub_account/*` ⛔ 新增与删除路由 ⇒ 只保留「修改真实姓名」;
- * 客户身份展示走 `/customer/get@v1`(**自读**,主体号取自会话),⛔ 下发项标「后端未下发」。
- *
- * ⚠️ 本页此前取的是 `/customer/get_list@v1`——那是**运营侧**名录读口(权限键 `bos.customer.list`),
- * 客户角色本就不该拿到它(2026-11-14「我的套餐/分账号」整页空态的根因)。自读口只要求
- * `bos.customer.view`,且行集由后端按主体收窄,客户看不到别家档案。
- */
- import { useMemo, useState } from "react";
- import { PageIntro } from "../components/PageIntro";
- import { useNavigate, useParams } from "react-router";
- import { FetchError } from "../components/fetchError";
- import { PencilLine } from "lucide-react";
- import { Button } from "../components/ui/button";
- import { Input } from "../components/ui/input";
- import { ListPager } from "../components/ListPager";
- import { OpsNotice, OpsStatus, OpsTableEmpty } from "../components/OperationsKit";
- import { Tri } from "../components/triState";
- import { slicePage, useLocalPage } from "../lib/list-paging";
- import { useDemoIdentity } from "../lib/demo-session";
- import { useProfileOverlay } from "../components/layout/ProfileOverlay";
- import { useLoad } from "../lib/useLoad";
- 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";
- import type { PortalPlanBoardRow, SubAccountRow } from "../lib/api/types";
- import { isSeatPlaceholder, seatDisplayName } from "../lib/customer-subaccounts";
- import "../styles/operations.css";
- const MISSING = "后端未下发";
- /** 金额分 → 「¥1,234.56」;`null` 不可用 ⇒ 显「—」(§4.3 列 3 不许拿订阅价顶替)。 */
- function money(cents: number | null): string {
- if (cents === null || !Number.isFinite(cents)) return "—";
- return `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
- }
- /** 线路出口列:数组逐项一行,空集 ⇒「—」。 */
- function exits(exitsValue: string[] | null) {
- if (!exitsValue || exitsValue.length === 0) return <span className="opacity-60">—</span>;
- return <>{exitsValue.map((e) => <div key={e}>{e}</div>)}</>;
- }
- /**
- * 门户 4「我的套餐」(第 9 册 §4)——真源=`/portal/plan_board@v1`。
- *
- * 两表一次取数、由**服务端**切分与排序(C79):⛔ 前端分两次查询再自行归类,
- * 那会让两次查询之间的状态翻转把同一行摆进两张表。
- * 主体号一律由会话派生(`/portal/plan_board@v1` 硬拒载荷里的 `customer_id`),
- * 所以本页⛔ 传主体号;`useParams().customerNo` 只用来做会话回退比对。
- */
- export function CustomerPlanPage() {
- const { customerNo: customerNoParam = "" } = useParams();
- const identity = useDemoIdentity();
- const customerNo = customerNoParam || identity?.customerNo || "";
- const board = useLoad(() => portalPlanBoard({ view: "board" }), []);
- const data = board.data;
- if (board.error) {
- return <section className="ops-page"><header className="ops-heading"><div><p className="ops-eyebrow"><span /> 企业门户 · 我的套餐</p><h1>我的套餐</h1></div></header>
- <FetchError message={board.error.message} onRetry={board.reload} />
- </section>;
- }
- if (board.loading && !data) {
- return <section className="ops-page"><header className="ops-heading"><div><p className="ops-eyebrow"><span /> 企业门户 · 我的套餐</p><h1>我的套餐</h1></div></header>
- <div className="ops-card ops-plan-card"><div><h2>套餐加载中…</h2><p>正在按会话主体号读取当前套餐与往期套餐。</p></div></div>
- </section>;
- }
- if (!data) {
- return <section className="ops-page"><header className="ops-heading"><div><p className="ops-eyebrow"><span /> 企业门户 · 我的套餐</p><h1>我的套餐</h1></div></header>
- <div className="ops-card ops-plan-card"><div><h2>套餐暂不可读</h2><p>{customerNo ? `会话主体号 ${customerNo}` : "当前会话未带客户主体号"} 未取到套餐数据,请稍后重试或联系运维核实账号权限。</p></div></div>
- </section>;
- }
- const current = data.current_rows;
- const history = data.history_rows;
- const table = (title: string, rows: PortalPlanBoardRow[], empty: string) =>
- <div className="ops-list-shell list-shell-fill">
- <div className="ops-card-title-row"><h2>{title}</h2><span className="ops-muted">共 {rows.length} 条</span></div>
- <div className="ops-table-wrap measured-table-scroll"><table className="ops-table">
- <thead><tr><th>套餐 / 合同</th><th>运营商</th><th>总金额</th><th>方式</th><th>线路出口</th><th>期间</th><th>状态</th></tr></thead>
- <tbody>
- {rows.map((row) => <tr key={row.subscription_id}>
- <td>
- <strong>{row.plan_name}</strong>
- <div className="ops-muted">{row.contract_no ?? "—"}</div>
- {/* 交付现状摘要(第 9 册 §4.3 行内摘要):台账口径,只读;⛔ 不占列、不开详情口 */}
- {row.ip_summary && <div className="ops-muted">在册 {row.ip_summary.live_ip_count} 个 IP · {row.ip_summary.live_account_count} 个在用账号{row.ip_summary.released_ip_count > 0 ? `(已回收 ${row.ip_summary.released_ip_count})` : ""}</div>}
- </td>
- <td>{data.party.operator_name ?? <Tri tone="missing" text={MISSING} title="客户档案未挂运营商:合同签订方一列无值,非取数失败" />}</td>
- <td>{money(row.contract_amount_cents)}</td>
- <td>{row.plan_family ? label(PLAN_FAMILY, row.plan_family) : "—"}</td>
- <td>{exits(row.line_exits)}</td>
- <td>{row.start_date ?? "—"} 至 {row.end_date ?? "—"}</td>
- <td><OpsStatus tone={row.status.key === "active" ? "success" : row.status.key === "pending" ? "warning" : "neutral"}>{row.status.label}</OpsStatus></td>
- </tr>)}
- {!rows.length && <OpsTableEmpty colSpan={7}>{empty}</OpsTableEmpty>}
- </tbody>
- </table></div>
- <p className="ops-muted" role="note">{data.amount_note}</p>
- </div>;
- return <section className="ops-page"><header className="ops-heading"><div><p className="ops-eyebrow"><span /> 企业门户 · 我的套餐</p><h1>{data.party.customer_name || customerNo}</h1><p>所属区域:{data.party.region_path ?? <Tri tone="missing" text={MISSING} />} · 运营商:{data.party.operator_name ?? <Tri tone="missing" text={MISSING} />}</p></div></header>
- {table("当前套餐", current, "当前没有待生效或生效中的套餐。")}
- {table("往期套餐", history, "没有已到期或已终止的套餐。")}
- {data.notes.length > 0 && <ul className="ops-muted" role="note">{data.notes.map((n) => <li key={n}>{n}</li>)}</ul>}
- </section>;
- }
- export function CustomerAccountsPage() {
- const { customerNo: customerNoParam = "" } = useParams();
- const identity = useDemoIdentity();
- 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 state = useLoad(() => subAccountGetList({ customer_id: customerNo, page: 0, page_size: 100 }), [customerNo]);
- const rows: SubAccountRow[] = state.data?.items ?? [];
- const paging = useLocalPage(rows.length);
- const pageRows = slicePage(rows, paging.safePage);
- 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;
- setBusy(true);
- setError("");
- try {
- await subAccountUpdate({ sub_account_id: editing.sub_account_id, display_name: name });
- setEditing(null);
- setNotice("分账号真实姓名已更新(后端回执为准)。");
- state.reload();
- } catch (e) {
- 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>
- <div className="ops-list-shell list-shell-fill">
- {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" 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)
- ? <>{seatDisplayName(row)}{isSeatPlaceholder(row) && <small className="ml-1 text-xs opacity-70">(席位占位·姓名待填)</small>}</>
- : row.status === "not_opened"
- ? <span className="ops-muted" 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>
- <ListPager total={rows.length} page={paging.safePage} pageSize={paging.pageSize} onPageChange={paging.setPage} 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>}
- {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
- </section>;
- }
|