Commit b8e6dc2a by chenwq

Merge branch 'v1.0.0' of http://192.168.3.233:8090/ujia/uj-store into v1.0.0

2 parents 13b51b33 a2980db1
Pipeline #343 for b8e6dc2a failed in 0 seconds
...@@ -38,3 +38,10 @@ ...@@ -38,3 +38,10 @@
- `src/api/core/http.ts`:拦截器顶部按 `API_CONTEXT_PATH` 给相对路径 url 补前缀(绝对 URL/已带前缀跳过)。proxy 模式实际请求 `/api/youjia/...`(vite 代理 rewrite 仅剥 /api,保留 /youjia → 转发 /youjia/...);direct 模式 `origin/youjia/...`。两种模式的 canonPath 均正确得到 `/youjia/system/...`,与后端一致。 - `src/api/core/http.ts`:拦截器顶部按 `API_CONTEXT_PATH` 给相对路径 url 补前缀(绝对 URL/已带前缀跳过)。proxy 模式实际请求 `/api/youjia/...`(vite 代理 rewrite 仅剥 /api,保留 /youjia → 转发 /youjia/...);direct 模式 `origin/youjia/...`。两种模式的 canonPath 均正确得到 `/youjia/system/...`,与后端一致。
- `.env` 新增 `VITE_API_CONTEXT_PATH=/youjia` 及说明。 - `.env` 新增 `VITE_API_CONTEXT_PATH=/youjia` 及说明。
- 全程唯一 axios 实例(http.ts),无绕过拦截器的 fetch;initSign 拉公钥也统一带上前缀。tsc --noEmit 通过(EXIT=0)。 - 全程唯一 axios 实例(http.ts),无绕过拦截器的 fetch;initSign 拉公钥也统一带上前缀。tsc --noEmit 通过(EXIT=0)。
## backend-resolver 迭代:本地开发回退 + DEV 判断(15:27)
- 问题:原逻辑映射表未命中→默认同源,开发者用 192.168.x.x/localhost 访问前端时打到自己机器上不存在的后端,需每人把自己 IP 写进映射表,不可持续。
- 第一版(15:19):新增 isLocalDevHost(hostNoPort) 判断 localhost/127.0.0.1/私有网段(10.x/172.16-31.x/192.168.x/169.254.x),命中则回退 VITE_API_TARGET;映射表清空开发者 IP 示例。
- 第二版(15:27,用户提议用 DEV 判断):isLocalDevHost 按访问地址、import.meta.env.DEV 按构建模式,维度不同不能简单互替(反例:测试服务器以 IP 部署 build 产物,DEV=false 但 IP 应回退)。最终合并为 (import.meta.env.DEV || isLocalDevHost(hostNoPort)) && envTarget → 回退 envTarget;开发者 pnpm dev 零配置,测试服务器 IP 部署也能兜底。
- 文件:src/api/core/backend-resolver.ts。tsc --noEmit 通过(EXIT=0)。
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
// 浏览器侧:根据「当前访问地址」动态解析后端服务地址。 // 浏览器侧:根据「当前访问地址」动态解析后端服务地址。
// 映射表用于「访问域名 → 不同后端」的显式改写(可选,优先级最高)。
// 开发者无需在此登记自己的 IP —— 本地 / 开发地址(localhost、127.0.0.1、私有网段 IP 如 192.168.x.x)
// 会自动回退到 .env 的 VITE_API_TARGET(默认测试服务器),避免「用自己 IP 访问前端却打到自己机器上
// 根本不存在的后端」导致请求全部失败。只有正式域名(youjia.dev.glsx.com.cn 等)才走同源。
const HOST_BACKEND_MAP: Record<string, string> = { const HOST_BACKEND_MAP: Record<string, string> = {
'192.168.1.237': '192.168.3.197:8788', // 省略协议 → 访问 http 拼 http、访问 https 拼 https // 例:把某个生产/预发前端域名映射到指定后端(不受本地回退规则影响)
// 'localhost:5173': '192.168.3.197:8788', // 'youjia.dev.glsx.com.cn': 'youjia-api.glsx.com.cn',
// 'x.dev.cn': 'http://192.168.3.197:8788', // 写全协议则不跟随,固定 http
}; };
function stripTrailingSlash(url: string): string { function stripTrailingSlash(url: string): string {
...@@ -24,6 +27,26 @@ function currentProtocol(): string { ...@@ -24,6 +27,26 @@ function currentProtocol(): string {
} }
/** /**
* 判断 host(不含端口)是否为「本地 / 开发地址」,需要回退到 .env 默认服务端:
* - localhost / 127.0.0.1 / ::1
* - 私有网段:10.x.x.x、172.16-31.x.x、192.168.x.x、169.254.x.x(链路本地)
* 这些地址下开发者机器上通常没有后端,用同源 IP 访问必然失败。
*/
function isLocalDevHost(hostNoPort: string): boolean {
const h = hostNoPort.toLowerCase();
if (h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '[::1]') return true;
const m = h.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
if (!m) return false;
const a = Number(m[1]);
const b = Number(m[2]);
if (a === 10) return true; // 10.0.0.0/8
if (a === 172 && b >= 16 && b <= 31) return true; // 172.16.0.0/12
if (a === 192 && b === 168) return true; // 192.168.0.0/16
if (a === 169 && b === 254) return true; // 169.254.0.0/16 链路本地
return false;
}
/**
* 给映射值补协议,兼容 http / https: * 给映射值补协议,兼容 http / https:
* - 已含协议(http:// / https://)→ 原样返回; * - 已含协议(http:// / https://)→ 原样返回;
* - 协议相对(//host)→ 跟随当前页协议; * - 协议相对(//host)→ 跟随当前页协议;
...@@ -38,8 +61,9 @@ function withProtocol(raw: string): string { ...@@ -38,8 +61,9 @@ function withProtocol(raw: string): string {
} }
/** /**
* 解析 direct 模式下的后端 origin。 * 解析 direct 模式下的后端 origin。仅在浏览器侧调用(config.ts 加载期),Node 侧不会走到此函数。
* 仅在浏览器侧调用(config.ts 加载期),Node 侧不会走到此函数。 * 优先级:① 映射表 HOST_BACKEND_MAP(显式改写,最高)② 本地/开发地址(localhost、私有网段 IP)→ .env 的 VITE_API_TARGET
* ③ 非本地(正式域名)→ 同源 window.location.origin ④ 兜底 → VITE_API_TARGET
*/ */
export function resolveBackendOrigin(): string { export function resolveBackendOrigin(): string {
const envTarget = stripTrailingSlash( const envTarget = stripTrailingSlash(
...@@ -54,10 +78,14 @@ export function resolveBackendOrigin(): string { ...@@ -54,10 +78,14 @@ export function resolveBackendOrigin(): string {
const mapped = HOST_BACKEND_MAP[host] ?? HOST_BACKEND_MAP[hostNoPort]; const mapped = HOST_BACKEND_MAP[host] ?? HOST_BACKEND_MAP[hostNoPort];
if (mapped) return stripTrailingSlash(withProtocol(mapped)); if (mapped) return stripTrailingSlash(withProtocol(mapped));
// 默认同源:访问地址即后端地址(youjia.dev.glsx.com.cn → 后端 youjia.dev.glsx.com.cn) // 开发模式(DEV,即 pnpm dev)→ 直接用 .env 默认服务端,开发者无需配自己的 IP;
// 非开发模式但用本地/私有 IP 访问(如测试服务器以 IP 部署)→ 同样回退到默认服务端;
// 正式域名(youjia.dev.glsx.com.cn 等)→ 走下方同源逻辑。
if ((import.meta.env.DEV || isLocalDevHost(hostNoPort)) && envTarget) return envTarget;
const origin = window.location.origin; const origin = window.location.origin;
if (origin && origin !== 'null' && !origin.startsWith('file:')) return origin; if (origin && origin !== 'null' && !origin.startsWith('file:')) return origin;
// 极端兜底:非浏览器 / origin 不可用 // 极端兜底:非浏览器 / origin 不可用 / env 未配置
return envTarget; return envTarget;
} }
...@@ -27,7 +27,7 @@ export function ConfirmActionBar({ passCount = 12, onBack, onSubmit }: ConfirmAc ...@@ -27,7 +27,7 @@ export function ConfirmActionBar({ passCount = 12, onBack, onSubmit }: ConfirmAc
icon={<ArrowRightOutlined />} icon={<ArrowRightOutlined />}
onClick={onSubmit ?? (() => console.log('下一步:提交审批'))} onClick={onSubmit ?? (() => console.log('下一步:提交审批'))}
> >
下一步:提交审批({passCount}) 下一步:提交审批
</UButton> </UButton>
</div> </div>
</div> </div>
......
...@@ -5,6 +5,8 @@ import type { StoreImportFailVO, StoreImportCheckVO } from '@/api/modules/store' ...@@ -5,6 +5,8 @@ import type { StoreImportFailVO, StoreImportCheckVO } from '@/api/modules/store'
export interface FailDetailCardProps { export interface FailDetailCardProps {
checkResult?: StoreImportCheckVO; checkResult?: StoreImportCheckVO;
/** 上传文件的字节数(兜底:后端可能不返回 fileSize,用 File 对象的 size 字段) */
fileSize?: number;
/** 点击「重新上传」时触发(通常回到 Step 0 并清空文件) */ /** 点击「重新上传」时触发(通常回到 Step 0 并清空文件) */
onReUpload?: () => void; onReUpload?: () => void;
} }
...@@ -13,7 +15,6 @@ const FAIL_COL_LABELS = [ ...@@ -13,7 +15,6 @@ const FAIL_COL_LABELS = [
{ key: 'rowIndex' as const, label: '行号', width: 92 }, { key: 'rowIndex' as const, label: '行号', width: 92 },
{ key: 'storeName' as const, label: '门店名称', width: 300 }, { key: 'storeName' as const, label: '门店名称', width: 300 },
{ key: 'merchantNo' as const, label: '门店商户号', width: 160 }, { key: 'merchantNo' as const, label: '门店商户号', width: 160 },
{ key: 'levelLabel' as const, label: '校验层级', width: 130 },
{ key: 'reason' as const, label: '失败原因', width: undefined }, { key: 'reason' as const, label: '失败原因', width: undefined },
] as const; ] as const;
...@@ -33,7 +34,7 @@ function triggerDownloadFailFile(url: string) { ...@@ -33,7 +34,7 @@ function triggerDownloadFailFile(url: string) {
} }
} }
export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps) { export function FailDetailCard({ checkResult, fileSize, onReUpload }: FailDetailCardProps) {
const failRows = (checkResult?.failRows ?? 0) as number; const failRows = (checkResult?.failRows ?? 0) as number;
const failFileUrl = checkResult?.failFileUrl ?? null; const failFileUrl = checkResult?.failFileUrl ?? null;
const failures = (checkResult?.failures ?? []) as StoreImportFailVO[]; const failures = (checkResult?.failures ?? []) as StoreImportFailVO[];
...@@ -49,11 +50,13 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps) ...@@ -49,11 +50,13 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
* 底部 L1 / L2 通过校验文字(复用 checkResult 的字段,无则从 failures.length 推断) * 底部 L1 / L2 通过校验文字(复用 checkResult 的字段,无则从 failures.length 推断)
*/ */
const l1 = useMemo(() => { const l1 = useMemo(() => {
// 文件大小:优先后端 fileSize,兜底用传入的 File.size(字节)
const rawSize = typeof checkResult?.fileSize === 'number' ? checkResult.fileSize : fileSize;
const size = const size =
typeof checkResult?.fileSize === 'number' typeof rawSize === 'number'
? checkResult.fileSize === 0 ? rawSize === 0
? '0' ? '0'
: `${Math.max(1, Math.round(checkResult.fileSize / 1024))}KB` : `${Math.max(1, Math.round(rawSize / 1024))}KB`
: ''; : '';
const total = typeof checkResult?.totalRows === 'number' ? `${checkResult.totalRows} 行` : ''; const total = typeof checkResult?.totalRows === 'number' ? `${checkResult.totalRows} 行` : '';
const version = checkResult?.templateVersion ? `模板版本${checkResult.templateVersion}` : ''; const version = checkResult?.templateVersion ? `模板版本${checkResult.templateVersion}` : '';
...@@ -63,7 +66,7 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps) ...@@ -63,7 +66,7 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
: `格式 .xlsx / ${size}${total ? ' / ' + total : ''}${version ? ' / ' + version : ''}`, : `格式 .xlsx / ${size}${total ? ' / ' + total : ''}${version ? ' / ' + version : ''}`,
]; ];
return parts.filter(Boolean).join(' · '); return parts.filter(Boolean).join(' · ');
}, [checkResult]); }, [checkResult, fileSize]);
const l2 = useMemo(() => { const l2 = useMemo(() => {
const template = checkResult?.templateVersion const template = checkResult?.templateVersion
...@@ -208,29 +211,6 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps) ...@@ -208,29 +211,6 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
> >
{f.merchantNo ?? '-'} {f.merchantNo ?? '-'}
</td> </td>
{/* 校验层级(浅黄 Tag,与截图 L4 业务级 一致) */}
<td
style={{
padding: '14px 8px',
borderBottom: '1px solid #F3F4F6',
whiteSpace: 'nowrap',
}}
>
<UTag
color="default"
bordered={false}
style={{
background: '#FEF3C7',
color: '#92400E',
padding: '3px 10px',
borderRadius: 6,
fontSize: 13,
lineHeight: 1.4,
}}
>
{f.levelLabel ?? `L${f.levelCode ?? '?'} 校验级`}
</UTag>
</td>
{/* 失败原因(红 #991B1B) */} {/* 失败原因(红 #991B1B) */}
<td <td
style={{ style={{
......
...@@ -3,8 +3,8 @@ import type { TableProps } from 'antd'; ...@@ -3,8 +3,8 @@ import type { TableProps } from 'antd';
import type { PolicyConfirmRow } from '../../tools/policyTableData'; import type { PolicyConfirmRow } from '../../tools/policyTableData';
const storeInfoHeaderStyle: React.CSSProperties = { const storeInfoHeaderStyle: React.CSSProperties = {
background: '#EEF2FF', background: '#EFF4FF',
color: '#3730A3', color: '#2B5CE6',
fontWeight: 600, fontWeight: 600,
fontSize: 13, fontSize: 13,
}; };
...@@ -51,7 +51,7 @@ function SceneTag({ text }: { text: string }) { ...@@ -51,7 +51,7 @@ function SceneTag({ text }: { text: string }) {
function CategoryTag({ text }: { text: string }) { function CategoryTag({ text }: { text: string }) {
return ( return (
<UTag <UTag
color="success" color="processing"
bordered={false} bordered={false}
title={text} title={text}
style={{ style={{
...@@ -77,7 +77,27 @@ function FeeValueCell({ value }: { value: string }) { ...@@ -77,7 +77,27 @@ function FeeValueCell({ value }: { value: string }) {
return <span style={{ fontWeight: 600, color: '#1F2937' }}>{value}</span>; return <span style={{ fontWeight: 600, color: '#1F2937' }}>{value}</span>;
} }
export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { export function buildPolicyColumns(
rows: PolicyConfirmRow[] = [],
): TableProps<PolicyConfirmRow>['columns'] {
/**
* 计算当前行某列的 rowSpan(同门店 / 同业务场景合并单元格):
* - keyFn:对每行提取分组 key(如门店名、或「门店名|业务场景」复合键)
* - 当前行与上一行 key 相同 → rowSpan = 0(被合并)
* - 否则向下统计连续相同 key 的行数作为 rowSpan
*/
const getRowSpan = (index: number, keyFn: (r: PolicyConfirmRow) => string): number => {
if (index < 0 || index >= rows.length) return 1;
const cur = keyFn(rows[index]);
if (index > 0 && keyFn(rows[index - 1]) === cur) return 0;
let span = 1;
for (let i = index + 1; i < rows.length; i++) {
if (keyFn(rows[i]) === cur) span++;
else break;
}
return span;
};
return [ return [
// ------------- 第一组:门店信息(4 列) ------------- // ------------- 第一组:门店信息(4 列) -------------
{ {
...@@ -90,7 +110,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -90,7 +110,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
key: 'storeName', key: 'storeName',
width: 200, width: 200,
onHeaderCell: () => ({ style: storeInfoHeaderStyle }), onHeaderCell: () => ({ style: storeInfoHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
rowSpan: getRowSpan(index ?? 0, (r) => r.storeName),
style: cellStyle,
}),
render: (v) => <span style={{ color: '#1A202C', fontWeight: 500 }}>{v}</span>, render: (v) => <span style={{ color: '#1A202C', fontWeight: 500 }}>{v}</span>,
}, },
{ {
...@@ -100,7 +123,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -100,7 +123,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 130, width: 130,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: storeInfoHeaderStyle }), onHeaderCell: () => ({ style: storeInfoHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
// 同门店的商户号必然相同,按「门店名 + 商户号」复合键合并
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.storeMerchantNo}`),
style: cellStyle,
}),
render: (v) => <a style={{ color: '#2563EB', fontSize: 12.5 }}>{v}</a>, render: (v) => <a style={{ color: '#2563EB', fontSize: 12.5 }}>{v}</a>,
}, },
{ {
...@@ -110,16 +137,27 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -110,16 +137,27 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 130, width: 130,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: storeInfoHeaderStyle }), onHeaderCell: () => ({ style: storeInfoHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
// 同门店下相同业务场景才合并(不同门店同名场景不合并)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
render: (v: string) => <SceneTag text={v} />, render: (v: string) => <SceneTag text={v} />,
}, },
],
},
// ------------- 第二组:商务政策(14 列) -------------
{
title: '商务政策',
align: 'center',
children: [
{ {
title: '产品分类', title: '产品分类',
dataIndex: 'productCategory', dataIndex: 'productCategory',
key: 'productCategory', key: 'productCategory',
width: 280, width: 280,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: storeInfoHeaderStyle }), onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({ onCell: () => ({
style: { style: {
...cellStyle, ...cellStyle,
...@@ -130,13 +168,6 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -130,13 +168,6 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
}), }),
render: (v: string) => <CategoryTag text={v} />, render: (v: string) => <CategoryTag text={v} />,
}, },
],
},
// ------------- 第二组:商务政策(14 列) -------------
{
title: '商务政策',
align: 'center',
children: [
// 管理层市场费 1 // 管理层市场费 1
{ {
title: '管理层市场费1计算模式', title: '管理层市场费1计算模式',
...@@ -203,7 +234,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -203,7 +234,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 170, width: 170,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: bizPolicyHeaderStyle }), onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
// 同门店同业务场景合并(与「业务场景」列合并粒度一致)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
}, },
{ {
title: '一线阳光计算模式', title: '一线阳光计算模式',
...@@ -241,7 +276,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -241,7 +276,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 180, width: 180,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: bizPolicyHeaderStyle }), onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
// 同门店同业务场景合并(与「业务场景」列合并粒度一致)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
}, },
{ {
title: '一线阳光2计算模式', title: '一线阳光2计算模式',
...@@ -285,7 +324,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -285,7 +324,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 160, width: 160,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: costHeaderStyle }), onHeaderCell: () => ({ style: costHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
// 运营成本按「门店 + 业务场景」维度合并(同一门店下不同业务场景的运营成本不同)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
render: (v) => <MoneyCell value={v as string} />, render: (v) => <MoneyCell value={v as string} />,
}, },
{ {
...@@ -295,7 +338,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -295,7 +338,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 220, width: 220,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: costHeaderStyle }), onHeaderCell: () => ({ style: costHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
render: (v) => <MoneyCell value={v as string} />, render: (v) => <MoneyCell value={v as string} />,
}, },
{ {
...@@ -305,7 +351,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] { ...@@ -305,7 +351,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 140, width: 140,
align: 'center', align: 'center',
onHeaderCell: () => ({ style: costHeaderStyle }), onHeaderCell: () => ({ style: costHeaderStyle }),
onCell: () => ({ style: cellStyle }), onCell: (_r, index) => ({
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
render: (v) => <MoneyCell value={v as string} />, render: (v) => <MoneyCell value={v as string} />,
}, },
], ],
......
...@@ -24,7 +24,21 @@ export function PolicyConfirmTable({ ...@@ -24,7 +24,21 @@ export function PolicyConfirmTable({
ruleCategoryCount, ruleCategoryCount,
ruleTotalRows, ruleTotalRows,
}: PolicyConfirmTableProps) { }: PolicyConfirmTableProps) {
const columns = useMemo(() => buildPolicyColumns() as any[], []); /**
* 数据源优先级:previewRows(接口真实数据) > dataSource > mock 兜底
* 放在 columns 之前,因为 buildPolicyColumns 需要 rows 来计算同门店 / 同场景的合并单元格 rowSpan
*/
const rows: PolicyConfirmRow[] = useMemo(() => {
if (Array.isArray(previewRows) && previewRows.length > 0) {
return convertPreviewRows(previewRows);
}
if (Array.isArray(dataSource) && dataSource.length > 0) {
return dataSource;
}
return mockPolicyRows;
}, [dataSource, previewRows]);
const columns = useMemo(() => buildPolicyColumns(rows) as any[], [rows]);
/** /**
* 动态拼接 footer 文字:优先用外部传入的通过行统计, * 动态拼接 footer 文字:优先用外部传入的通过行统计,
...@@ -71,17 +85,6 @@ export function PolicyConfirmTable({ ...@@ -71,17 +85,6 @@ export function PolicyConfirmTable({
return colWidths.reduce((a, b) => a + b, 0) + 40; // 加 40px 冗余 return colWidths.reduce((a, b) => a + b, 0) + 40; // 加 40px 冗余
}, [columns]); }, [columns]);
const rows: PolicyConfirmRow[] = useMemo(() => {
// 优先级:previewRows(接口真实数据) > dataSource > mock 兜底
if (Array.isArray(previewRows) && previewRows.length > 0) {
return convertPreviewRows(previewRows);
}
if (Array.isArray(dataSource) && dataSource.length > 0) {
return dataSource;
}
return mockPolicyRows;
}, [dataSource, previewRows]);
// 显式标注 TableProps:否则 pagination:false 会被推断成 boolean,赋给 UTable 时类型不兼容 // 显式标注 TableProps:否则 pagination:false 会被推断成 boolean,赋给 UTable 时类型不兼容
const tableProps: TableProps<PolicyConfirmRow> = { const tableProps: TableProps<PolicyConfirmRow> = {
rowKey: (r: PolicyConfirmRow) => `${r.storeMerchantNo}-${r.businessScene}-${r.productCategory}`, rowKey: (r: PolicyConfirmRow) => `${r.storeMerchantNo}-${r.businessScene}-${r.productCategory}`,
......
...@@ -40,7 +40,7 @@ export function SubmitActionBar({ ...@@ -40,7 +40,7 @@ export function SubmitActionBar({
disabled={disabled || loading} disabled={disabled || loading}
onClick={onSubmit ?? (() => console.log('确认提交并推送审批'))} onClick={onSubmit ?? (() => console.log('确认提交并推送审批'))}
> >
确认提交并推送审批({totalRows}) 确认提交并推送审批
</UButton> </UButton>
</div> </div>
); );
......
import { useState, useCallback, useEffect } from 'react'; import { useState, useCallback, useEffect, useRef } from 'react';
import { App } from 'antd'; import { App } from 'antd';
import { import {
InfoCircleFilled, InfoCircleFilled,
...@@ -40,6 +40,10 @@ export function UploadCard({ ...@@ -40,6 +40,10 @@ export function UploadCard({
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const [downloading, setDownloading] = useState(false); const [downloading, setDownloading] = useState(false);
const [fileList, setFileList] = useState<UploadFile[]>([]); const [fileList, setFileList] = useState<UploadFile[]>([]);
// antd Upload 实例,用于编程式打开文件选择框
const uploadRef = useRef<any>(null);
// 记录上一次已处理的 reUploadTrigger,防止 effect 因其它依赖变化而重复触发
const processedTriggerRef = useRef(0);
/** 从 checkResult + 文件名推导要显示的统计文案:共 N 行(X 家门店 × Y 场景 × Z 分类)· 模板版本 vX.X.X */ /** 从 checkResult + 文件名推导要显示的统计文案:共 N 行(X 家门店 × Y 场景 × Z 分类)· 模板版本 vX.X.X */
const statLineText = (() => { const statLineText = (() => {
...@@ -100,18 +104,6 @@ export function UploadCard({ ...@@ -100,18 +104,6 @@ export function UploadCard({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [file]); }, [file]);
/**
* Step 2 → 点击失败明细里的【重新上传】:
* 父组件 handleReUpload = 切 Step0 + 清空 checkResult + reUploadCounter++
* 本 useEffect 监听 reUploadTrigger(>0 表示被触发过)+ 有 file + 非 uploading → 自动 runUpload
*/
useEffect(() => {
if (reUploadTrigger > 0 && file && !uploading) {
void runUpload(file);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reUploadTrigger]);
const clearFileState = useCallback(() => { const clearFileState = useCallback(() => {
setFileList([]); setFileList([]);
onFileChange?.(null); onFileChange?.(null);
...@@ -191,6 +183,38 @@ export function UploadCard({ ...@@ -191,6 +183,38 @@ export function UploadCard({
fileList, fileList,
}; };
/**
* Step 2 → 点击失败明细里的【重新上传】:
* 父组件 handleReUpload = 切 Step0 + 清空 checkResult + reUploadCounter++
* 本 effect 监听 reUploadTrigger 变化,清空已选文件并编程式打开文件选择对话框,
* 让用户重新选择文件(选完文件后走正常 customRequest → runUpload → check 接口链路)。
* 注意:不再自动用原文件调用 check 接口,必须由用户重新选文件。
*/
useEffect(() => {
if (reUploadTrigger <= 0) return;
if (reUploadTrigger === processedTriggerRef.current) return;
processedTriggerRef.current = reUploadTrigger;
// 清空文件状态
setFileList([]);
onFileChange?.(null);
// 等 DOM 更新后再打开文件选择框:兼容 antd Upload ref 可能不暴露 upload() 的情况,
// 优先用 ref.upload(),兜底通过 DOM 查找隐藏的 input[type=file] 触发 click
setTimeout(() => {
const inst = uploadRef.current;
if (inst && typeof inst.upload === 'function') {
inst.upload();
return;
}
const input = document.querySelector<HTMLInputElement>(
'.uj-upload-dragger input[type="file"], .ant-upload input[type="file"]',
);
if (input) {
input.value = '';
input.click();
}
}, 0);
}, [reUploadTrigger, onFileChange]);
return ( return (
<UCard <UCard
styles={{ body: { padding: 20 } }} styles={{ body: { padding: 20 } }}
...@@ -209,7 +233,7 @@ export function UploadCard({ ...@@ -209,7 +233,7 @@ export function UploadCard({
} }
> >
<div style={{ position: 'relative' }}> <div style={{ position: 'relative' }}>
<UUpload.Dragger {...uploadProps}> <UUpload.Dragger ref={uploadRef} {...uploadProps}>
<div style={{ padding: '30px 0' }}> <div style={{ padding: '30px 0' }}>
<div <div
style={{ style={{
......
...@@ -45,12 +45,13 @@ export default function TemplateImport() { ...@@ -45,12 +45,13 @@ export default function TemplateImport() {
const handleFileChange = (f: File | null) => { const handleFileChange = (f: File | null) => {
setSelectedFile(f); setSelectedFile(f);
// 移除文件时,同步清空校验结果 + 导入信息里的 3 个回显字段(保留 remark) // 移除文件时,同步清空校验结果 + 导入信息里的 3 个回显字段(保留 remark)
// 注意:org/scene 用 undefined 而非 '',否则 antd Select 会把 '' 当成选中值,placeholder 不显示
if (f === null) { if (f === null) {
setCheckResult(null); setCheckResult(null);
setImportInfo((prev) => ({ setImportInfo((prev) => ({
org: prev?.org ?? '', org: undefined,
scene: prev?.scene ?? '', scene: undefined,
categories: prev?.categories ?? [], categories: [],
remark: prev?.remark, remark: prev?.remark,
})); }));
} }
...@@ -76,7 +77,9 @@ export default function TemplateImport() { ...@@ -76,7 +77,9 @@ export default function TemplateImport() {
}; };
const handleReUpload = () => { const handleReUpload = () => {
// Step 2 重新上传:不清空文件,回到 Step0 后由 UploadCard.useEffect 监听 trigger 自动重跑上传 // Step 2 重新上传:清空文件 + checkResult,回到 Step0 后由 UploadCard 打开文件选择对话框,
// 用户重新选择文件后走正常 customRequest → runUpload → check 接口链路
setSelectedFile(null);
setCheckResult(null); setCheckResult(null);
setSubmitChecked(true); setSubmitChecked(true);
setCurrentStep(0); setCurrentStep(0);
...@@ -102,8 +105,8 @@ export default function TemplateImport() { ...@@ -102,8 +105,8 @@ export default function TemplateImport() {
cancelText: '知道了', cancelText: '知道了',
// 非阻塞(不强制跳转):「知道了」留在当前页 // 非阻塞(不强制跳转):「知道了」留在当前页
onOk: () => { onOk: () => {
// 跳转门店审批页(对应路由:/store/approve) // 跳转门店审批页(对应路由:/store/approval
window.location.href = '/store/approve'; window.location.href = '/store/approval';
}, },
}); });
} catch (e) { } catch (e) {
...@@ -143,7 +146,11 @@ export default function TemplateImport() { ...@@ -143,7 +146,11 @@ export default function TemplateImport() {
{currentStep === 1 && ( {currentStep === 1 && (
<> <>
<ValidationStats checkResult={checkResult ?? undefined} /> <ValidationStats checkResult={checkResult ?? undefined} />
<FailDetailCard checkResult={checkResult ?? undefined} onReUpload={handleReUpload} /> <FailDetailCard
checkResult={checkResult ?? undefined}
fileSize={selectedFile?.size}
onReUpload={handleReUpload}
/>
<ValidationActionBar nextDisabled={failCount > 0} onBack={goPrev} onNextStep={goNext} /> <ValidationActionBar nextDisabled={failCount > 0} onBack={goPrev} onNextStep={goNext} />
</> </>
)} )}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!