独立对抗验证(只读、真跑)结论:本次交付不可接受,必须修。逐条处置:
P0 把仓库**既有**契约测试打红且与新断言互斥:OrderManagementPage.contract.test.ts:206 断言
`showEditCols ? 14 : 11`、:207 断言 `colSpan={5}`,而本次改了列数 ⇒ 该文件 1 failed。
根因是我只跑了自己那几个测试文件,没跑**邻接既有**契约测试。已随列数更新两条断言。
P1 合计行首格 `colSpan={5}` 未随新增勾选列 +1 ⇒ 合计行整体左移一格(计划数量合计落到
「加工方式」列、金额落到售价列)。改 `colSpan={6}`(勾选列 1 + 序号/名称/图片/报告/加工方式 5)。
P2 分类筛选后表头全选态说谎 + 点下载必失败:全选原按**计数**比较、取数用被筛选的 visibleItems。
改为按**集合** `every` 判断;取数改用**全量 items**(被筛掉但已勾选的行也进包)。
P3 超长商品名被 zipStore 二次 sanitize 截断 ⇒ **静默丢扩展名**(实测名 93 字 → 无 `.pdf`)。
改为各段先限量(商品名 40 / 批次号 20),拼接后稳在 80 字内。
P4 无规模上限:zipStore 条目数是 u16(>65535 产出损坏包,实测 exit 80)、偏移 u32(>4GB 同理),
且 STORE 打包在主线程逐字节算 CRC(实测 20MB ≈1.8s、峰值内存≈2×)。加 300 文件 / 200MB 前置拦截。
P5 展示专用字段 `batch_report_files` 未从保存载荷剔除(破坏本仓「仅展示字段保存须剔除」约定)。
与 quality_report_files/inbound_photos 同处剔除。
P6 包内序号实为勾选顺序号(与文档口径不符)⇒ 改用**屏幕行序号** displaySeqByItemId,筛选隐藏行兜底。
P7 en/id 失败提示被判成 info(notify 只认中文正则)⇒ notify 增加显式 type 参数,调用处传 'error'。
新增文案 1 条(待批准):orders.detail.downloadBatchReportsTooMany=所选批次报告过多,请分批下载(三语)。
证据:OrderManagementPage.contract.test.ts **20 通过**(回归已闭合)、
batchReportZip.contract.test.ts **12 通过**(含上表 8 项各自的回归守卫)、
zipStore.batchReports.test.ts 真解压通过、WEB `tsc --noEmit` exit 0、
设计门禁 8 通过/1 红(check-ai-cost 按设计恒红)/1 未执行(本机无 psql)与基线一致。
设计文档新增 §8「对抗验证与修复记录」。
137 lines
4.3 KiB
TypeScript
137 lines
4.3 KiB
TypeScript
/**
|
||
* 轻量级 Toast 通知(替代阻塞式 alert)
|
||
* 可在任意模块(含非组件代码)中直接调用。
|
||
*/
|
||
|
||
type NotifyType = 'success' | 'error' | 'info' | 'warning';
|
||
|
||
const CONTAINER_ID = 'app-toast-container';
|
||
|
||
const TYPE_STYLES: Record<NotifyType, { bg: string; border: string; icon: string }> = {
|
||
success: { bg: '#ecfdf5', border: '#10b981', icon: '✓' },
|
||
error: { bg: '#fef2f2', border: '#ef4444', icon: '✕' },
|
||
warning: { bg: '#fffbeb', border: '#f59e0b', icon: '!' },
|
||
info: { bg: '#eff6ff', border: '#3b82f6', icon: 'ℹ' },
|
||
};
|
||
|
||
function ensureContainer(): HTMLElement {
|
||
let container = document.getElementById(CONTAINER_ID);
|
||
if (!container) {
|
||
container = document.createElement('div');
|
||
container.id = CONTAINER_ID;
|
||
container.setAttribute('aria-live', 'polite');
|
||
container.setAttribute('aria-relevant', 'additions');
|
||
Object.assign(container.style, {
|
||
position: 'fixed',
|
||
top: '16px',
|
||
left: '50%',
|
||
transform: 'translateX(-50%)',
|
||
zIndex: '99999',
|
||
display: 'flex',
|
||
flexDirection: 'column',
|
||
gap: '8px',
|
||
alignItems: 'center',
|
||
pointerEvents: 'none',
|
||
maxWidth: '92vw',
|
||
});
|
||
document.body.appendChild(container);
|
||
}
|
||
return container;
|
||
}
|
||
|
||
function showToast(message: string, type: NotifyType, duration = 3500) {
|
||
const container = ensureContainer();
|
||
const style = TYPE_STYLES[type];
|
||
|
||
const toast = document.createElement('div');
|
||
toast.setAttribute('role', type === 'error' ? 'alert' : 'status');
|
||
toast.setAttribute('aria-atomic', 'true');
|
||
toast.tabIndex = 0;
|
||
Object.assign(toast.style, {
|
||
background: style.bg,
|
||
borderLeft: `4px solid ${style.border}`,
|
||
color: '#1f2937',
|
||
padding: '10px 16px',
|
||
borderRadius: '8px',
|
||
boxShadow: '0 4px 12px rgba(0,0,0,0.15)',
|
||
fontSize: '14px',
|
||
lineHeight: '1.5',
|
||
maxWidth: '480px',
|
||
whiteSpace: 'pre-wrap',
|
||
wordBreak: 'break-word',
|
||
pointerEvents: 'auto',
|
||
cursor: 'pointer',
|
||
opacity: '0',
|
||
transition: 'opacity 0.2s ease, transform 0.2s ease',
|
||
transform: 'translateY(-6px)',
|
||
display: 'flex',
|
||
gap: '8px',
|
||
alignItems: 'flex-start',
|
||
});
|
||
|
||
const iconSpan = document.createElement('span');
|
||
iconSpan.textContent = style.icon;
|
||
Object.assign(iconSpan.style, {
|
||
color: style.border,
|
||
fontWeight: '700',
|
||
flexShrink: '0',
|
||
});
|
||
const textSpan = document.createElement('span');
|
||
textSpan.textContent = message;
|
||
toast.appendChild(iconSpan);
|
||
toast.appendChild(textSpan);
|
||
|
||
const dismiss = () => {
|
||
toast.style.opacity = '0';
|
||
toast.style.transform = 'translateY(-6px)';
|
||
window.setTimeout(() => toast.remove(), 220);
|
||
};
|
||
toast.addEventListener('click', dismiss);
|
||
toast.addEventListener('keydown', (event) => {
|
||
if (event.key === 'Enter' || event.key === 'Escape' || event.key === ' ') {
|
||
event.preventDefault();
|
||
dismiss();
|
||
}
|
||
});
|
||
container.appendChild(toast);
|
||
|
||
requestAnimationFrame(() => {
|
||
toast.style.opacity = '1';
|
||
toast.style.transform = 'translateY(0)';
|
||
});
|
||
|
||
// 长文案适当延长展示时间
|
||
const effectiveDuration = Math.min(10000, Math.max(duration, message.length * 60));
|
||
window.setTimeout(dismiss, effectiveDuration);
|
||
}
|
||
|
||
const SUCCESS_PATTERN = /成功|已完成|已生成|已保存|已更新|已删除|已提交|已创建|已流转|已分配|完成!/;
|
||
const ERROR_PATTERN = /失败|错误|无法|异常|不能|无权|未配置|不存在|请重试/;
|
||
|
||
/**
|
||
* 根据文案自动判断类型展示 Toast(替代 alert 的直接替换入口)。
|
||
*
|
||
* `type` 可选**显式指定**:自动判断靠的是中文关键字正则(`失败|错误|…`),
|
||
* 英文/印尼语文案一律落到 `info`(蓝色)⇒ 明确的错误路径应显式传 `'error'`。
|
||
*/
|
||
export function notify(message: unknown, type?: NotifyType) {
|
||
const text = String(message ?? '');
|
||
if (!text) return;
|
||
if (type) {
|
||
showToast(text, type);
|
||
return;
|
||
}
|
||
if (ERROR_PATTERN.test(text)) {
|
||
showToast(text, 'error');
|
||
} else if (SUCCESS_PATTERN.test(text)) {
|
||
showToast(text, 'success');
|
||
} else {
|
||
showToast(text, 'info');
|
||
}
|
||
}
|
||
|
||
notify.success = (message: string) => showToast(message, 'success');
|
||
notify.error = (message: string) => showToast(message, 'error');
|
||
notify.info = (message: string) => showToast(message, 'info');
|
||
notify.warning = (message: string) => showToast(message, 'warning');
|