diff --git a/docs/design/README.md b/docs/design/README.md index 0db4c13..e7d9b96 100644 --- a/docs/design/README.md +++ b/docs/design/README.md @@ -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` + `` **百分比列宽**(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)。 diff --git a/src/pages/customers/CustomerManagement.responsiveTable.contract.test.tsx b/src/pages/customers/CustomerManagement.responsiveTable.contract.test.tsx new file mode 100644 index 0000000..45c553b --- /dev/null +++ b/src/pages/customers/CustomerManagement.responsiveTable.contract.test.tsx @@ -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` + `` 百分比列宽 + 单元格 `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(''); + 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('')); + 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('')); + expect(tbody.includes('align-top min-w-0')).toBe(true); + expect(tbody.includes('break-words')).toBe(true); + }); +}); diff --git a/src/pages/customers/CustomerManagement.tsx b/src/pages/customers/CustomerManagement.tsx index f26e6ae..294c89b 100644 --- a/src/pages/customers/CustomerManagement.tsx +++ b/src/pages/customers/CustomerManagement.tsx @@ -131,7 +131,32 @@ type CustomerListColumnId = | 'self_pickup' | 'actions'; +/** + * 列宽百分比(自适应):与 `CUSTOMER_LIST_COLUMNS` 的 id 一一对应,合计 100%。 + * 信息量大的列(客户信息/地址/对公)占比高;金额/状态/开关/操作列窄。 + * 注:操作列给 8%,否则三个按钮换行太挤;`table-fixed` 下百分比之外的空间由浏览器平均分配。 + */ +const COLUMN_WIDTH_PERCENT: Record = { + 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> = [ + /** + * **列宽按百分比自适应**(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 ( -
e.stopPropagation()}> +
e.stopPropagation()}> {canEdit ? ( e.stopPropagation()}> +
e.stopPropagation()}> {
-
- +
+
+ {/* 列宽百分比:全部列都参与自适应,宽屏利用率高、窄屏只换行不横向滚动 */} + + {orderedColumns.map((col) => ( + + ))} + {orderedColumns.map((col) => { @@ -1688,18 +1719,8 @@ export const CustomerManagement: React.FC = () => { ); } return ( -
handleSort(sortFieldForCol!) : undefined} > @@ -1774,9 +1795,9 @@ export const CustomerManagement: React.FC = () => { switch (col.id) { case 'customer_info': return ( - +
-
+
@@ -1805,7 +1826,7 @@ export const CustomerManagement: React.FC = () => { ); case 'contact': return ( -
+
{ ); case 'address': return ( -
+ { case 'delivery_time': { const deadline = parseCustomerDeliveryDeadline(c.delivery_time) || ''; return ( - + { } 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 ( - -
+
+
{ ); case 'sales_budget': return ( -
+ { ); case 'cost_budget': return ( - + { ); case 'rebate': return ( - + { ); case 'settlement_days': return ( - + {c.settlement_days != null ? t('customers.settlement.days', { days: c.settlement_days }) : '—'} @@ -1960,7 +1981,7 @@ export const CustomerManagement: React.FC = () => { ); case 'status': return ( - + @@ -1976,13 +1997,13 @@ export const CustomerManagement: React.FC = () => { */ if (c.source === 'main_system') { return ( - + — + -
+
+