Explorar el Código

fix(web): 分成管理表格分成规则列对齐运营商管理样式

sy hace 1 día
padre
commit
cd80bc5d93

+ 40 - 0
web-scaffold/src/lib/__tests__/settle-text.test.ts

@@ -0,0 +1,40 @@
+import { describe, expect, it } from "vitest";
+import { SHARE_TERMS_INCOMPLETE, settlePartsFromSnapshot, settleText, settleTextFromSnapshot } from "../settle-text";
+
+/**
+ * 分成取值文案(册 4 settle_text):两行分列的「方式」「取值」两段必须与单行文案同源——
+ * 以空格相接逐字等于 settleText/settleTextFromSnapshot,⛔ 另起一套措辞。
+ */
+describe("settleText · 三模式三文案", () => {
+  it("逐字输出;不成对 ⇒ 配置不完整", () => {
+    expect(settleText("ratio", 20)).toBe("按比例 20%");
+    expect(settleText("amount", 120)).toBe("每月分成 ¥ 120.00");
+    expect(settleText("per_account", 3)).toBe("按每账号 ¥ 3.00/账号");
+    expect(settleText(null, null)).toBe(SHARE_TERMS_INCOMPLETE);
+    expect(settleText("ratio", null)).toBe(SHARE_TERMS_INCOMPLETE);
+    expect(settleText("monthly", 1)).toBe(SHARE_TERMS_INCOMPLETE);
+  });
+});
+
+describe("settlePartsFromSnapshot · 方式/取值两段", () => {
+  it("两段以空格相接=settleTextFromSnapshot 的文案(三模式)", () => {
+    const cases: [string, string | number][] = [["ratio", 0.2], ["amount", "120"], ["per_account", 3.5]];
+    for (const [mode, value] of cases) {
+      const parts = settlePartsFromSnapshot(mode, value);
+      expect(parts).not.toBeNull();
+      expect(`${parts!.mode} ${parts!.value}`).toBe(settleTextFromSnapshot(mode, value));
+    }
+  });
+
+  it("存储刻度 → 展示刻度:比例分数→百分数、金额/每账号两位小数", () => {
+    expect(settlePartsFromSnapshot("ratio", 0.1)).toEqual({ mode: "按比例", value: "10%" });
+    expect(settlePartsFromSnapshot("amount", "120")).toEqual({ mode: "每月分成", value: "¥ 120.00" });
+    expect(settlePartsFromSnapshot("per_account", 3.5)).toEqual({ mode: "按每账号", value: "¥ 3.50/账号" });
+  });
+
+  it("不成对 ⇒ null(⛔ 只出其中一段)", () => {
+    expect(settlePartsFromSnapshot("ratio", null)).toBeNull();
+    expect(settlePartsFromSnapshot(null, 12)).toBeNull();
+    expect(settlePartsFromSnapshot("monthly", 12)).toBeNull();
+  });
+});

+ 31 - 12
web-scaffold/src/lib/settle-text.ts

@@ -4,7 +4,8 @@
  * `mode` 与 `value` 不成对 ⇒ 「配置不完整」(不 panic)。
  * 消费方(⚠️ 静态断言=四处调用同一符号,⛔ 各页自拼):
  *   册 1 档案列表两列与详情、册 1 审计前后值(写文字表述而不是枚举串)、
- *   册 4 分成管理(列表两列+详情弹窗取值摘要)、册 6 批次/账单明细「分成方式与取值」列。
+ *   册 4 分成管理(列表「分成规则」列方式/取值两行+详情弹窗取值摘要)、
+ *   册 6 批次/账单明细「分成方式与取值」列。
  *
  * 入参约定:mode=后端编码(ratio/amount/per_account);value=**展示刻度**
  * (ratio=百分数,20 表示 20%;amount/per_account=元,两位小数)。
@@ -42,14 +43,23 @@ export function coerceSettleNumber(value: string | number | null | undefined): n
   return Number.isFinite(n) ? n : null;
 }
 
+/** 三模式文案拆出的「方式」「取值」两段:以空格相接即 settleText 的文案(两行分列展示用)。 */
+export type SettleParts = { mode: string; value: string };
+
+/** mode 与 value 不成对、或 mode 出值域 ⇒ null(与 settleText 写「配置不完整」同一判定)。 */
+function settleParts(mode: string | null | undefined, value: number | null): SettleParts | null {
+  if (!mode || value == null) return null;
+  if (mode === "ratio") return { mode: "按比例", value: `${Math.round(value * 100) / 100}%` };
+  // 「按金额」档的方式段沿用文案里的「每月分成」(带上周期),⛔ 换成 SHARE_MODE_TEXT 的短标签。
+  if (mode === "amount") return { mode: "每月分成", value: `¥ ${yuanText(value)}` };
+  if (mode === "per_account") return { mode: "按每账号", value: `¥ ${yuanText(value)}/账号` };
+  return null;
+}
+
 /** 三模式三文案逐字输出;mode/value 不成对或 mode 出值域 ⇒ 「配置不完整」。 */
 export function settleText(mode: string | null | undefined, value: string | number | null | undefined): string {
-  const n = coerceSettleNumber(value);
-  if (!mode || n == null) return SHARE_TERMS_INCOMPLETE;
-  if (mode === "ratio") return `按比例 ${Math.round(n * 100) / 100}%`;
-  if (mode === "amount") return `每月分成 ¥ ${yuanText(n)}`;
-  if (mode === "per_account") return `按每账号 ¥ ${yuanText(n)}/账号`;
-  return SHARE_TERMS_INCOMPLETE;
+  const parts = settleParts(mode, coerceSettleNumber(value));
+  return parts ? `${parts.mode} ${parts.value}` : SHARE_TERMS_INCOMPLETE;
 }
 
 /** 档案态口径:两列皆空 ⇒ 「未配分成」;否则按 settleText(不成对 ⇒ 配置不完整)。 */
@@ -59,13 +69,22 @@ export function settleTextOrUnset(mode: string | null | undefined, value: string
 }
 
 /**
- * 冻结快照/档案存储刻度 → settleText 展示刻度的唯一换算口:
- * ratio 存储为分数(0.2 ⇒ 20%);amount/per_account 存储为元(两位小数在 settleText 内处理)。
+ * 冻结快照/档案存储刻度 → 「方式」「取值」两段。存储刻度→展示刻度的唯一换算口:
+ * ratio 存储为分数(0.2 ⇒ 20%);amount/per_account 存储为元(两位小数在 settleParts 内处理)。
  * ⚠️ 后端若调整存储刻度只动本函数;⛔ 各消费页面自行 ×100。
  * 入参兼容十进制字符串(param_summary D-3③)与数值。
+ * 不成对 ⇒ null:调用方整格写「配置不完整」,⛔ 只出其中一段。
  */
-export function settleTextFromSnapshot(mode: string | null | undefined, value: string | number | null | undefined): string {
+export function settlePartsFromSnapshot(mode: string | null | undefined, value: string | number | null | undefined): SettleParts | null {
   const n = coerceSettleNumber(value);
-  if (mode === "ratio" && n != null) return settleText(mode, n * 100);
-  return settleText(mode, n);
+  return settleParts(mode, mode === "ratio" && n != null ? n * 100 : n);
+}
+
+/**
+ * 冻结快照/档案存储刻度 → settleText 展示刻度(换算走 settlePartsFromSnapshot);
+ * 两段以空格相接 ⇒ 与 settleText 同一文案,不成对 ⇒ 「配置不完整」。
+ */
+export function settleTextFromSnapshot(mode: string | null | undefined, value: string | number | null | undefined): string {
+  const parts = settlePartsFromSnapshot(mode, value);
+  return parts ? `${parts.mode} ${parts.value}` : SHARE_TERMS_INCOMPLETE;
 }

+ 19 - 7
web-scaffold/src/pages/SettlementPages.tsx

@@ -16,7 +16,7 @@ import { hasBizCode } from "../lib/api/http";
 import { billingConfigGet, operatorUpdate } from "../lib/api/bos";
 import type { BillingConfigOperatorRow, EffectiveMode, HolderType } from "../lib/api/types";
 import { submitBillingConfigUpdate, useBillingConfig } from "../lib/recon";
-import { SHARE_TERMS_UNSET, settleTextFromSnapshot, shareAmountText } from "../lib/settle-text";
+import { SHARE_TERMS_INCOMPLETE, SHARE_TERMS_UNSET, settlePartsFromSnapshot, settleTextFromSnapshot, shareAmountText } from "../lib/settle-text";
 import { shareSummaryKey, useShareParamSummary, type ShareSummaryState } from "../lib/share-summary";
 import { PARTY_NO_SHARE_ROWS, PARTY_SCOPE_NOTE } from "../lib/copy-views";
 import {
@@ -73,7 +73,7 @@ export function ShareRulePage() {
    * 1500 页宽 ⇒ 侧栏 252 + main 左右内边距 64 + list-shell 边框 2 + scrollbar-gutter 15
    * ⇒ 表格容器 ≈1167px,故 `.ops-table.share-ledger` 的 min-width 定 1100(容器 1107 时可放满,
    * 即 1440 页宽也不出滚动条)。⛔ 再按 tableOverflow 动态摊剩余宽度:那会让列宽随窗口抖动,
-   * 且 1500 下「分成方式与取值」被摊到 319px。
+   * 且 1500 下「分成规则」被摊到 319px。
    */
   const columnWidths = [64, 244, 252, 96, 200, 92, 80, 154];
   const { identity, organization } = useBusinessView(ALL_ORG_COLLECTIONS);
@@ -122,15 +122,27 @@ export function ShareRulePage() {
   const pageRows = slicePage(filtered, paging.safePage);
   const hasFilter = region !== "" || kind !== "全部" || state !== "全部状态" || search !== "";
   function reset() { setRegion(""); setKind("全部"); setState("全部状态"); setSearch(""); paging.resetPage(); }
-  /** 「分成方式与取值」格:!item→读口未覆盖;item_error→取数失败;!configured→档案未配置;命中→settleText。 */
+  /**
+   * 「分成规则」格(样式对齐运营商台账同名列:取值主题色突出+方式小字,共两行):
+   * !item→读口未覆盖;item_error→取数失败;!configured→档案未配置(占位灰字);
+   * 命中→settle-text 单源拆出的方式/取值两段(⛔ 本页自拼)。
+   */
   function termsCell(row: SharePartyRow) {
     if (summary.fail === "wiring") return <Tri tone="missing" text={WORD_NOT_PROVIDED} title="share_param_summary 读口未在 OpenAPI 声明(待 klt-bos 交付)⇒ 两列待接线" />;
     if (summary.fail) return <Tri tone="fail" text={WORD_FETCH_FAILED} title={summary.fail === "s406" ? "KLT-S406:只这两列取数失败,其余照常;不因此整页不渲染" : summary.message} />;
     const item = summary.items.get(shareSummaryKey(PARTY_HOLDER_TYPE[row.type], row.id));
     if (!item) return <Tri tone="missing" text={WORD_NOT_PROVIDED} title="读口应答未覆盖该方" />;
     if (item.item_error) return <Tri tone="fail" text={WORD_FETCH_FAILED} title={item.item_error} />;
-    if (!item.configured) return <small>{SHARE_TERMS_UNSET}</small>;
-    return <strong>{settleTextFromSnapshot(item.share_mode, item.share_value)}</strong>;
+    if (!item.configured) return <span className="table-placeholder">{SHARE_TERMS_UNSET}</span>;
+    const terms = settlePartsFromSnapshot(item.share_mode, item.share_value);
+    if (!terms) return <span className="org-directory-value org-directory-share-value">{SHARE_TERMS_INCOMPLETE}</span>;
+    return <><span className="org-directory-value org-directory-share-value">{terms.value}</span><small>{terms.mode}</small></>;
+  }
+  /** 「分成规则」格悬停出完整文案(格内拆两行,截断时看全貌);未配/失败态不挂(占位与三态自带说明)。 */
+  function termsTitle(row: SharePartyRow): string | undefined {
+    if (summary.fail) return undefined;
+    const item = summary.items.get(shareSummaryKey(PARTY_HOLDER_TYPE[row.type], row.id));
+    return item?.configured && !item.item_error ? settleTextFromSnapshot(item.share_mode, item.share_value) : undefined;
   }
   return <section className="ops-page ops-page--rules page-fill page-fill-window">
     <header className="ops-heading"><div><p className="ops-eyebrow"><span /> REVENUE SHARING / 分成与对账</p><h1>分成管理</h1><PageIntro>核对各方的分成约定,出账有差异时可回查适用规则。</PageIntro></div></header>
@@ -142,12 +154,12 @@ export function ShareRulePage() {
         <FilterSelect icon="status" aria-label="分成状态筛选" value={state} onChange={(event) => { setState(event.target.value); paging.resetPage(); }}><option>全部状态</option><option>已配分成</option><option>未配分成</option></FilterSelect>
         {hasFilter && <Button variant="ghost" size="sm" onClick={reset}>重置筛选</Button>}
       </div>
-      <div ref={tableOverflow.ref} tabIndex={0} role="region" aria-label="分成方台账,可横向滚动查看字段" className={`measured-table-scroll ops-table-wrap share-ledger-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.width >= 640 ? " can-pin-identity" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`}><table className="ops-table share-ledger"><OpsTableColumns widths={columnWidths} /><thead><tr><th>序号</th><th>分成方</th><th>所属区域</th><th>分成方类型</th><th>分成方式与取值</th><th>状态</th><th>分成客户</th><th>操作</th></tr></thead><tbody>{pageRows.map((row, index) => <tr key={row.id}>
+      <div ref={tableOverflow.ref} tabIndex={0} role="region" aria-label="分成方台账,可横向滚动查看字段" className={`measured-table-scroll ops-table-wrap share-ledger-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.width >= 640 ? " can-pin-identity" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`}><table className="ops-table share-ledger"><OpsTableColumns widths={columnWidths} /><thead><tr><th>序号</th><th>分成方</th><th>所属区域</th><th>分成方类型</th><th>分成规则</th><th>状态</th><th>分成客户</th><th>操作</th></tr></thead><tbody>{pageRows.map((row, index) => <tr key={row.id}>
           <td><span className="ops-mono table-number">{String(paging.safePage * paging.pageSize + index + 1).padStart(2, "0")}</span></td>
           <td><strong className="table-cell-title" title={row.displayName}>{row.displayName}</strong><small title={row.note}>{row.note}</small></td>
           <td><span title={row.regionLabel}>{row.regionLabel || "—"}</span></td>
           <td><OpsTag tone={row.type === "合伙人" ? "brand" : row.type === "运营商" ? "info" : "neutral"}>{row.type}</OpsTag></td>
-          <td className="org-maintenance-share">{termsCell(row)}</td>
+          <td title={termsTitle(row)}>{termsCell(row)}</td>
           <td>{rowConfigured(row) ? <OpsStatus tone="success">已配分成</OpsStatus> : <small>未配分成</small>}</td>
           <td><span className="ops-money">{row.customerCount}</span></td>
           <td><button type="button" className="ops-table-action" onClick={() => setDetail(row)} title="契约 14.2:弹窗出四卡+取值摘要(只读),配置分成请点弹窗里的「去档案里配置分成」">分成金额 <ArrowRight size={14} /></button></td>

+ 45 - 0
web-scaffold/src/pages/__tests__/share-amount-dialog.test.tsx

@@ -133,3 +133,48 @@ describe("分成金额弹窗", () => {
     expect(screen.queryByRole("dialog")).toBeNull();
   });
 });
+
+/**
+ * 列表「分成规则」列(样式对齐运营商台账同名列):表头「分成规则」,取值突出+方式小字分两行,
+ * 未配 ⇒ 占位灰字「未配分成」;文案走 settle-text 单源(⛔ 本页自拼)。
+ */
+describe("分成规则列", () => {
+  beforeEach(() => { cleanup(); prime([summaryItem()]); });
+  afterEach(() => cleanup());
+
+  async function renderPage() {
+    const { ShareRulePage } = await import("../SettlementPages");
+    render(<MemoryRouter initialEntries={["/share-rules"]}><ShareRulePage /></MemoryRouter>);
+    const row = (await screen.findByRole("button", { name: /分成金额/ })).closest("tr");
+    if (!row) throw new Error("分成方行未渲染");
+    return within(row).getAllByRole("cell")[4];
+  }
+
+  it("表头写「分成规则」", async () => {
+    await renderPage();
+    expect(screen.getByRole("columnheader", { name: "分成规则" })).toBeTruthy();
+    expect(screen.queryByRole("columnheader", { name: "分成方式与取值" })).toBeNull();
+  });
+
+  it("已配 ⇒ 取值突出、方式小字分两行;悬停出完整文案", async () => {
+    const cell = await renderPage();
+    expect(cell.querySelector(".org-directory-share-value")?.textContent).toBe("10%");
+    expect(cell.querySelector("small")?.textContent).toBe("按比例");
+    expect(cell.getAttribute("title")).toBe("按比例 10%");
+  });
+
+  it("按金额档的方式段带周期(每月分成),⛔ 丢了「每月」", async () => {
+    prime([summaryItem({ share_mode: "amount", share_value: "120" })]);
+    const cell = await renderPage();
+    expect(cell.querySelector(".org-directory-share-value")?.textContent).toBe("¥ 120.00");
+    expect(cell.querySelector("small")?.textContent).toBe("每月分成");
+  });
+
+  it("未配 ⇒ 该格占位灰字「未配分成」,⛔ 出取值行", async () => {
+    prime([summaryItem({ configured: false, share_mode: null, share_value: null })]);
+    const cell = await renderPage();
+    expect(cell.querySelector(".table-placeholder")?.textContent).toBe("未配分成");
+    expect(cell.querySelector(".org-directory-share-value")).toBeNull();
+    expect(cell.getAttribute("title")).toBeNull();
+  });
+});

+ 3 - 3
web-scaffold/src/styles/organization.css

@@ -293,8 +293,8 @@
 .org-maintenance-ledger-table td{vertical-align:middle}
 .org-maintenance-ledger-table td:first-child{min-width:170px}
 .org-maintenance-ledger-table td:last-child{min-width:235px}
-:is(.org-table,.share-ledger) .org-maintenance-share strong{color:var(--primary);font-size:var(--type-body);font-variant-numeric:tabular-nums}
-:is(.org-table,.share-ledger) .org-maintenance-share small{color:var(--text-secondary)}
+.org-table .org-maintenance-share strong{color:var(--primary);font-size:var(--type-body);font-variant-numeric:tabular-nums}
+.org-table .org-maintenance-share small{color:var(--text-secondary)}
 .org-maintenance-ticket-types{max-width:210px;white-space:normal}
 .org-maintenance-scope-cell{max-width:230px;white-space:normal;line-height:1.5}
 .org-table-actions.is-icons .org-maintenance-account-link{display:inline-flex;align-items:center;gap:5px;min-height:30px;padding:4px 8px;border-radius:5px;color:var(--info);font-size:var(--type-support);font-weight:600;text-decoration:none;white-space:nowrap}
@@ -638,7 +638,7 @@ a.org-overview-card{text-decoration:none;color:inherit}
 .org-directory-sort:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }
 :is(.org-operator-ledger,.org-partner-ledger) .org-directory-identity { position: relative; }
 .org-directory-name { display: block; }
-:is(.org-operator-ledger,.org-partner-ledger) .org-directory-value + small,
+:is(.org-operator-ledger,.org-partner-ledger,.share-ledger) .org-directory-value + small,
 :is(.org-operator-ledger,.org-partner-ledger) .org-directory-identity small { margin-top: 3px; font-size: var(--type-meta); }
 .org-directory-value { display: block; overflow: hidden; color: var(--foreground); font-variant-numeric: tabular-nums; text-overflow: ellipsis; }
 .org-directory-share-value { color: var(--primary); font-weight: 550; }