fix(客户列表): 列宽改百分比自适应(table-fixed + colgroup)去掉横向滚动条——12 列合计 100%、单元格可换行收缩
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

This commit is contained in:
Ubuntu
2026-10-28 09:13:42 +08:00
parent 2fa6385bb8
commit 04e6d2b5a4
3 changed files with 106 additions and 34 deletions
+2
View File
@@ -157,6 +157,8 @@ AI 提示词清理已停用条目(7 条归档不删、清单过滤 archived、
**独立加工单 P0:多行原料 / 多行成品 / 成品回仓 / 损耗 / 报告继承**:开发者「先领取原料橘子 然后选择加工出来了什么商品 加工出来了多少斤 损耗了多少 加工好的重新落回仓库 需要一个按钮表示是否继承原材料的报告」+「web 与小程序独立加工单界面需要优化」,并确认:原料多行、成品多行(一原料可出多成品)、损耗自动差额可人工覆盖且不允许产出>投入、成品入库成本默认按产出**均分**可人工设置、损耗只留痕不进账本、报告继承**可选**(批次报告/检验报告)、老单只读保留、**Web 先行**。已落地:迁移 `20261074`(`processing_task_materials` / `processing_task_outputs` / `processing_tasks.client_request_no` 幂等键 / `match_source` 允许 `inherit`,名单 119 项),后端 `createStandaloneProcessingTask` 多行原料(老调用兼容、同 SKU 合并、逐行 FIFO 与可用量校验、原子回滚、请求号幂等)+ 新增 `completeStandaloneProcessingTask`(成品新批次回仓 `processing_in`、持有成本 `cost_source=processing_output`、默认均分/可覆盖、损耗留痕、批次报告只复制关联、检验报告复制文件引用)+ 三个路由。**真库实跑证据**:2 行原料→材料成本 440;2 行成品 20/10→产出 30、损耗 20、单价 14.6667;成品批次 `PG-…-1/2` 成本 14.67;两条 `processing_in`;两条持有成本 293.33/146.67;两条 `match_source=inherit`;重复完成被拒、产出>投入被拒、原料不足整单回滚(可用量前后均 96)。**Web 界面改造与小程序同步为下一步**,见 [20261023-独立加工多产出与成品回仓.md](./20261023-独立加工多产出与成品回仓.md)。
**分拣完成被误拦「销售价为 0」(修)**:开发者「销售价都是存在的呀 为什么还会提醒报错」(订单详情 4 行销售价 5/3/5/3,分拣完成却报木瓜、白心火龙果销售价为 0)。真因:退货留下的 `is_returned=true` 历史行 `price` 被清零,而分拣前校验按**整单所有行**扫零价、未排除已退回行;这些行在订单详情中不显示 ⇒ 用户无从排查。修法:零价校验加 `COALESCE(is_returned,false)=false`(在售行仍全覆盖、独立进货单豁免不变;覆盖范围仍按"该分拣单涉及的所有订单")。真库证据(dev BR005 `ORD_API_20261024_BR005_0001`):旧口径命中 **2 行(均是 `is_returned=true` 的木瓜/白心火龙果,price 0)**,新口径命中 **0 行**。证据:契约测试 3 条(**去掉该过滤即变红**)。
**客户列表列宽自适应(修 UI 横向滚动)**:开发者「客户列表的前端布局你修改一下 动态自适应 每列动态自适应宽度 不能出现横向滚动条」。旧实现表头/单元格写死 `min-w-[13rem]`、`min-w-[16rem]`、`w-[7rem] max-w-[7rem]`、`w-[9.25rem]`,12 列 + `px-4` 内距在 1420px 视口下必然溢出 ⇒ 出现横向滚动条。改法:`table-fixed w-full` + `<colgroup>` **百分比列宽**(12 列合计 100%)+ 单元格 `px-2 py-3 align-top min-w-0` / `break-words` / `overflow-x-hidden`(纵向仍可滚)+ 行内控件 `w-full`、头像 `shrink-0`、操作列改纵向排列。证据:`CustomerManagement.responsiveTable.contract.test.tsx` 5 条(列宽合计=100%、无固定宽、容器禁横向滚动;**恢复 `min-w-[13rem]` 即变红**)。
**主系统 5 项配合的我方接入(事件消费/定向拉取/批量接口)**:主系统 2026-10-24 定稿(零表结构变更,只加可选参数 + 新增独立接口)。我方已落地:① `GET /api/supplier/events` 客户端 + `mainSystemEventConsumer`(首次用 `server_time` 起点、持久化 `next_cursor`、翻页到 `has_more=false`、事件 id 去重、`clamped→needs_full_reconcile`);② 备货分页优先 `cursor`(offset 兼容)+ 新增 `fetchActivePreparationsForOrder()`(`view=active&order_code=…` 只拉受影响单);③ `lookupPreparationStatesBatch()`(≤200 分批);④ `voidSupplierBatchReportsBatch()`(≤100,报告推送撤下 ≥2 行时优先批量);⑤ 确认 `binding.changed` 接收端 **自 2026-10-10(3fb230e)起已在生产 `b18eeae` 内**,验签为 `X-Signature` HMAC-SHA256 + 常量时间比较,生产密钥已配。频率:事件 2 分钟(独立锁)、全量 active 拉取降为 30 分钟(`MAIN_SYSTEM_FULL_ACTIVE_PULL_MINUTES`),旧链路全部保留。真库+假 fetch 验证:分类 8 种、翻页/游标持久化、去重、`clamped` 落 `needs_full_reconcile`;期间抓到并修掉"未知事件带 order_code 会触发全量跟随"的放大点。见 [20261024-主系统5项配合我方接入.md](./20261024-主系统5项配合我方接入.md)。
**对账查询护栏 + 每轮预算 + 增量化(含需主系统配合清单)**:开发者「这个你看看怎么优化 需要主系统配合给我说」。本地做了三件事:① `dbQueryGuard.queryWithTimeout()`(`SET statement_timeout` + **finally RESET**,防连接回池毒化业务查询)接入报告推送每日全量兜底(30s)与自愈补录(30s);② `createRoundBudget(90s)` 给退货/删单跟随(60s 定时器 × 每分公司)加**每轮预算**,超出跳过剩余分公司并告警;③ 自愈补录**增量化**(只扫最近 `MAIN_SYSTEM_REPAIR_WINDOW_DAYS`(默认3) 天 + `LIMIT 50`)+ 迁移 `20261077` 补 3 个索引。真机验证:`pg_sleep` 被掐断、RESET 后连接可用、预算语义、窗口化无回归、迁移幂等。**需主系统配合**:M1 备货/退回增量拉取 `updated_since`、M2 备货行批量状态查询、M3 报告批量撤下、M4 `binding.changed` 推送落地、M5 截断时的分页游标。见 [20261024-对账查询护栏与增量化优化.md](./20261024-对账查询护栏与增量化优化.md)。
@@ -0,0 +1,49 @@
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 客户列表**列宽自适应、无横向滚动条**(2026-10-24 开发者:
* 「客户列表的前端布局你修改一下 动态自适应 每列动态自适应宽度 不能出现横向滚动条」)。
*
* 旧实现:表头/单元格写死 `min-w-[13rem]`、`min-w-[16rem]`、`w-[7rem]`,12 列 + px-4 内距 ⇒ 必然超出视口。
* 现口径:`table-fixed w-full` + `<colgroup>` 百分比列宽 + 单元格 `min-w-0`/`break-words`,
* 容器 `overflow-x-hidden`(纵向仍可滚)。
*/
const src = readFileSync(new URL('./CustomerManagement.tsx', import.meta.url), 'utf8');
describe('客户列表:列宽自适应 / 无横向滚动', () => {
it('表格是 table-fixed + w-full(不再 min-w-full 撑出宽度)', () => {
expect(src).toContain('className="w-full table-fixed border-separate border-spacing-0 text-sm"');
expect(src).not.toContain('min-w-full border-separate');
});
it('用 colgroup + 百分比列宽(12 列合计 100%)', () => {
expect(src).toContain('<colgroup>');
expect(src).toContain('COLUMN_WIDTH_PERCENT');
const block = src.slice(src.indexOf('const COLUMN_WIDTH_PERCENT'), src.indexOf('};', src.indexOf('const COLUMN_WIDTH_PERCENT')));
const percents = [...block.matchAll(/'(\d+)%'/g)].map((m) => Number(m[1]));
expect(percents.length).toBe(12);
expect(percents.reduce((a, b) => a + b, 0)).toBe(100);
});
it('容器禁止横向滚动(纵向保留)', () => {
expect(src).toContain('overflow-y-auto overflow-x-hidden');
expect(src).not.toContain('max-h-[min(70vh,720px)] overflow-auto');
});
it('表头/单元格不再有固定或最小宽度(会撑出横向滚动)', () => {
for (const bad of ['min-w-[13rem]', 'min-w-[16rem]', 'w-[7rem] max-w-[7rem]', 'w-[9.25rem]']) {
expect(src.includes(`className={\`px-4 py-4 ${bad}`)).toBe(false);
}
// 注释里可以mention,但真代码的 th 不再带这些类
const thBlock = src.slice(src.indexOf('<thead'), src.indexOf('</thead>'));
expect(thBlock.includes('min-w-[13rem]')).toBe(false);
expect(thBlock.includes('w-[7rem]')).toBe(false);
});
it('单元格内容可换行/收缩(min-w-0 + break-words/align-top)', () => {
const tbody = src.slice(src.indexOf('<tbody'), src.indexOf('</tbody>'));
expect(tbody.includes('align-top min-w-0')).toBe(true);
expect(tbody.includes('break-words')).toBe(true);
});
});
+55 -34
View File
@@ -131,7 +131,32 @@ type CustomerListColumnId =
| 'self_pickup'
| 'actions';
/**
* 列宽百分比(自适应):与 `CUSTOMER_LIST_COLUMNS` 的 id 一一对应,合计 100%。
* 信息量大的列(客户信息/地址/对公)占比高;金额/状态/开关/操作列窄。
* 注:操作列给 8%,否则三个按钮换行太挤;`table-fixed` 下百分比之外的空间由浏览器平均分配。
*/
const COLUMN_WIDTH_PERCENT: Record<string, string> = {
customer_info: '15%',
contact: '7%',
address: '14%',
delivery_time: '7%',
corporate: '13%',
sales_budget: '8%',
cost_budget: '8%',
rebate: '8%',
settlement_days: '4%',
status: '4%',
self_pickup: '4%',
actions: '8%',
};
const CUSTOMER_LIST_COLUMNS: Array<TableColumnDef<CustomerListColumnId>> = [
/**
* **列宽按百分比自适应**(2026-10-24 开发者:「每列动态自适应宽度 不能出现横向滚动条」)。
* 为什么不用 `min-w-[13rem]` 之类:12 列 × 固定最小宽 + px-4 内距 = 一定超出视口 ⇒ 必然横向滚动。
* 百分比 + `table-fixed` + 单元格 `min-w-0`/换行,则窄屏也只在列内换行,不产生横向滚动条。
*/
{ id: 'customer_info', label: 'col.customer_info' },
{ id: 'contact', label: 'col.contact' },
{ id: 'address', label: 'col.address' },
@@ -301,7 +326,7 @@ function CustomerMonthBudgetCell({
};
return (
<div className="flex items-baseline gap-1.5 min-w-[7.25rem]" onClick={(e) => e.stopPropagation()}>
<div className="flex items-baseline gap-1.5 min-w-0 flex-wrap" onClick={(e) => e.stopPropagation()}>
{canEdit ? (
<DecimalTextInput
value={text}
@@ -433,13 +458,13 @@ function CustomerRebateCell({
}
return (
<div className="space-y-1 min-w-[10rem]" onClick={(e) => e.stopPropagation()}>
<div className="space-y-1 min-w-0" onClick={(e) => e.stopPropagation()}>
<select
value={mode}
aria-label={t('customers.rebate.title')}
disabled={saving}
onChange={(e) => onModeChange(e.target.value as CustomerRebateModeDraft)}
className={`${LIST_INPUT_CLASS} w-[7.5rem] disabled:opacity-50`}
className={`${LIST_INPUT_CLASS} w-full disabled:opacity-50`}
>
{REBATE_MODE_OPTIONS.map((option) => (
<option key={option} value={option}>
@@ -1626,7 +1651,7 @@ export const CustomerManagement: React.FC = () => {
</>
}
>
<div className="relative min-w-[16rem] flex-1">
<div className="relative min-w-0 flex-1 basis-64">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400" />
<input
type="text"
@@ -1676,8 +1701,14 @@ export const CustomerManagement: React.FC = () => {
</PageFilterToolbar>
<div className="app-surface app-border rounded-xl border shadow-sm overflow-hidden min-w-0">
<div className="w-full min-w-0 max-h-[min(70vh,720px)] overflow-auto">
<table className="min-w-full border-separate border-spacing-0 text-sm">
<div className="w-full min-w-0 max-h-[min(70vh,720px)] overflow-y-auto overflow-x-hidden">
<table className="w-full table-fixed border-separate border-spacing-0 text-sm">
{/* 列宽百分比:全部列都参与自适应,宽屏利用率高、窄屏只换行不横向滚动 */}
<colgroup>
{orderedColumns.map((col) => (
<col key={col.id} style={{ width: COLUMN_WIDTH_PERCENT[col.id] || 'auto' }} />
))}
</colgroup>
<thead className="app-table-head sticky top-0 z-10">
<tr>
{orderedColumns.map((col) => {
@@ -1688,18 +1719,8 @@ export const CustomerManagement: React.FC = () => {
<th
key={col.id}
{...headerProps}
className={`app-foreground-muted sticky top-0 z-10 border-b app-border bg-slate-50 px-4 py-3 text-left text-xs font-semibold whitespace-nowrap select-none dark:bg-slate-800 ${
className={`app-foreground-muted sticky top-0 z-10 border-b app-border bg-slate-50 px-2 py-2 text-left text-xs font-semibold align-top select-none dark:bg-slate-800 ${
sortable ? 'cursor-pointer' : ''
} ${
col.id === 'customer_info'
? 'min-w-[13rem]'
: col.id === 'contact'
? 'w-[7rem] max-w-[7rem]'
: col.id === 'address'
? 'min-w-[16rem]'
: col.id === 'sales_budget' || col.id === 'cost_budget'
? 'w-[9.25rem] max-w-[9.25rem]'
: ''
}`}
onClick={sortable ? () => handleSort(sortFieldForCol!) : undefined}
>
@@ -1774,9 +1795,9 @@ export const CustomerManagement: React.FC = () => {
switch (col.id) {
case 'customer_info':
return (
<td key={col.id} className="px-4 py-4 min-w-[13rem]">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center">
<div className="w-9 h-9 shrink-0 rounded-lg bg-indigo-100 flex items-center justify-center">
<Building2 className="w-5 h-5 text-indigo-600" />
</div>
<div className="min-w-0 flex-1">
@@ -1805,7 +1826,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'contact':
return (
<td key={col.id} className="px-4 py-4 w-[7rem] max-w-[7rem]">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<div className="space-y-1 min-w-0">
<CustomerInlineTextCell
value={c.contact_name || ''}
@@ -1842,7 +1863,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'address':
return (
<td key={col.id} className="px-4 py-4 min-w-[16rem]">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<CustomerInlineTextCell
value={c.address || ''}
canEdit={canEdit}
@@ -1857,7 +1878,7 @@ export const CustomerManagement: React.FC = () => {
case 'delivery_time': {
const deadline = parseCustomerDeliveryDeadline(c.delivery_time) || '';
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<CustomerInlineTextCell
value={deadline}
canEdit={canEdit}
@@ -1871,7 +1892,7 @@ export const CustomerManagement: React.FC = () => {
}
return c.delivery_time || '—';
}}
className={`${LIST_INPUT_CLASS} w-[7.5rem]`}
className={`${LIST_INPUT_CLASS} w-full`}
onCommit={async (next) => {
const parsed = parseCustomerDeliveryDeadline(next);
await saveInlineCustomerPatch(c, { delivery_time: parsed });
@@ -1882,8 +1903,8 @@ export const CustomerManagement: React.FC = () => {
}
case 'corporate':
return (
<td key={col.id} className="px-4 py-4">
<div className="space-y-1 min-w-[8rem]">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<div className="space-y-1 min-w-0">
<CustomerInlineTextCell
value={c.bank_name || ''}
canEdit={canEdit}
@@ -1914,7 +1935,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'sales_budget':
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<CustomerMonthBudgetCell
monthly={Number(c.sales_budget) || 0}
canEdit={canEdit}
@@ -1924,7 +1945,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'cost_budget':
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<CustomerMonthBudgetCell
monthly={customerCostMonthly(c)}
canEdit={canEdit}
@@ -1934,7 +1955,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'rebate':
return (
<td key={col.id} className="px-4 py-4 align-top">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<CustomerRebateCell
customer={c}
canEdit={canEdit}
@@ -1952,7 +1973,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'settlement_days':
return (
<td key={col.id} className="app-foreground-muted px-4 py-4 text-sm whitespace-nowrap">
<td key={col.id} className="app-foreground-muted px-2 py-3 align-top text-sm break-words">
{c.settlement_days != null
? t('customers.settlement.days', { days: c.settlement_days })
: '—'}
@@ -1960,7 +1981,7 @@ export const CustomerManagement: React.FC = () => {
);
case 'status':
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<span
className={`inline-flex px-2.5 py-1 text-xs font-medium rounded-full ${statusInfo.bgColor} ${statusInfo.color}`}
>
@@ -1976,13 +1997,13 @@ export const CustomerManagement: React.FC = () => {
*/
if (c.source === 'main_system') {
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<span className="app-foreground-muted text-xs">—</span>
</td>
);
}
return (
<td key={col.id} className="px-4 py-4">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<label
className="inline-flex items-center gap-2 text-xs cursor-pointer"
title={t('customers.col.self_pickup')}
@@ -2002,8 +2023,8 @@ export const CustomerManagement: React.FC = () => {
);
case 'actions':
return (
<td key={col.id} className="px-4 py-4">
<div className="flex items-center gap-2 flex-wrap whitespace-nowrap">
<td key={col.id} className="px-2 py-3 align-top min-w-0">
<div className="flex flex-col items-start gap-1 min-w-0">
<button
onClick={() => openRecipientsModal(c)}
className="text-xs font-medium text-emerald-600 hover:text-emerald-800 whitespace-nowrap"