Commit b3b77c11 by 张立顺

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

2 parents d2e16544 1ec27d5e
Pipeline #346 for b3b77c11 failed in 0 seconds
......@@ -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/...`,与后端一致。
- `.env` 新增 `VITE_API_CONTEXT_PATH=/youjia` 及说明。
- 全程唯一 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)。
......@@ -22,7 +22,14 @@ export const PermButton = forwardRef<HTMLButtonElement, PermButtonProps>(
if (!ok && fallback === 'hide') return null;
const btn = <UButton ref={ref} {...rest} disabled={!ok || rest.disabled} />;
const btn = (
<UButton
ref={ref}
{...rest}
disabled={!ok || rest.disabled}
style={rest.type === 'text' ? { ...rest.style, paddingInline: 0 } : rest.style}
/>
);
if (!ok && fallback === 'disabled' && unauthorizedTip) {
return <UTooltip title={unauthorizedTip}>{btn}</UTooltip>;
......
......@@ -7,10 +7,13 @@
* @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> = {
'192.168.1.178': '192.168.3.197:8788', // 省略协议 → 访问 http 拼 http、访问 https 拼 https
// 'localhost:5173': '192.168.3.197:8788',
// 'x.dev.cn': 'http://192.168.3.197:8788', // 写全协议则不跟随,固定 http
// 例:把某个生产/预发前端域名映射到指定后端(不受本地回退规则影响)
// 'youjia.dev.glsx.com.cn': 'youjia-api.glsx.com.cn',
};
function stripTrailingSlash(url: string): 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://)→ 原样返回;
* - 协议相对(//host)→ 跟随当前页协议;
......@@ -38,8 +61,9 @@ function withProtocol(raw: string): string {
}
/**
* 解析 direct 模式下的后端 origin。
* 仅在浏览器侧调用(config.ts 加载期),Node 侧不会走到此函数。
* 解析 direct 模式下的后端 origin。仅在浏览器侧调用(config.ts 加载期),Node 侧不会走到此函数。
* 优先级:① 映射表 HOST_BACKEND_MAP(显式改写,最高)② 本地/开发地址(localhost、私有网段 IP)→ .env 的 VITE_API_TARGET
* ③ 非本地(正式域名)→ 同源 window.location.origin ④ 兜底 → VITE_API_TARGET
*/
export function resolveBackendOrigin(): string {
const envTarget = stripTrailingSlash(
......@@ -54,10 +78,14 @@ export function resolveBackendOrigin(): string {
const mapped = HOST_BACKEND_MAP[host] ?? HOST_BACKEND_MAP[hostNoPort];
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;
if (origin && origin !== 'null' && !origin.startsWith('file:')) return origin;
// 极端兜底:非浏览器 / origin 不可用
// 极端兜底:非浏览器 / origin 不可用 / env 未配置
return envTarget;
}
......@@ -126,12 +126,21 @@ export function DataTable<T extends object>({
onClick: () => void,
key: string,
isRowAction = false,
style?: CSSProperties,
) => {
const type = action.type ?? (isRowAction ? ('text' as const) : undefined);
const buttonProps = {
danger: action.danger,
disabled: action.disabled,
onClick,
type: action.type ?? (isRowAction ? ('link' as const) : undefined),
type,
style:
isRowAction && type === 'text'
? {
color: action.danger ? 'var(--ant-color-error)' : 'var(--ant-color-primary)',
...style,
}
: style,
};
return action.permission ? (
......@@ -150,21 +159,27 @@ export function DataTable<T extends object>({
key: '__actions',
width: actionColumnWidth,
fixed: actionColumnFixed,
render: (_: unknown, record: T) =>
rowActions
.filter((action) => action.visible?.(record) ?? true)
.map((action, index) => {
const label =
typeof action.label === 'function' ? action.label(record) : action.label;
const danger =
typeof action.danger === 'function' ? action.danger(record) : action.danger;
return renderActionButton(
{ ...action, danger, label },
() => action.onClick(record),
`row-action-${index}`,
true,
);
}),
render: (_: unknown, record: T) => {
const visibleActions = rowActions.filter((action) => action.visible?.(record) ?? true);
const lastPermissionActionIndex = visibleActions.reduce(
(lastIndex, action, index) => (action.permission ? index : lastIndex),
-1,
);
return visibleActions.map((action, index) => {
const label = typeof action.label === 'function' ? action.label(record) : action.label;
const danger =
typeof action.danger === 'function' ? action.danger(record) : action.danger;
return renderActionButton(
{ ...action, danger, label },
() => action.onClick(record),
`row-action-${index}`,
true,
action.permission && index < lastPermissionActionIndex
? { marginRight: 8 }
: undefined,
);
});
},
}
: undefined;
const sourceColumns: DataTableColumnsType<T> = showIndex
......@@ -211,6 +226,10 @@ export function DataTable<T extends object>({
columns={tableColumns}
tableLayout={hasLineLimit ? 'fixed' : undefined}
rowSelection={resolvedSelection}
styles={{
header: { cell: { paddingLeft: 20 } },
body: { cell: { paddingLeft: 20 } },
}}
pagination={
resolvedPagination === false
? false
......
......@@ -129,13 +129,13 @@ export default function AccountManage() {
<UText style={{ color: '#315ce8', fontFamily: 'monospace' }}>{value}</UText>
),
},
{ title: '姓名', dataIndex: 'name', width: 110, line: 1 },
{ title: '姓名', dataIndex: 'name', width: 130, line: 1 },
{ title: '手机号', dataIndex: 'mobile', width: 120 },
{ title: '所属组织', dataIndex: 'orgPath', width: 230, line: 1 },
{
title: '角色',
dataIndex: 'roleNames',
width: 280,
width: 290,
render: (names: string[]) =>
names.length
? names.map((name, index) => (
......@@ -149,7 +149,7 @@ export default function AccountManage() {
))
: '—',
},
{ title: '数据域', dataIndex: 'dataScopeLabel', width: 140 },
{ title: '数据域', dataIndex: 'dataScopeLabel' },
{
title: '状态',
width: 90,
......
......@@ -114,13 +114,13 @@ export default function RoleManage() {
{
title: '角色编码',
dataIndex: 'code',
width: 150,
width: 200,
line: 1,
render: (v) => <UText style={{ color: '#315ce8', fontFamily: 'monospace' }}>{v}</UText>,
},
{ title: '默认数据域', dataIndex: 'scope', width: 130 },
{ title: '默认数据域', dataIndex: 'scope' },
{ title: '账号数', dataIndex: 'userCount', width: 90 },
{ title: '角色描述', dataIndex: 'description', width: 380, line: 1 },
{ title: '角色描述', dataIndex: 'description', width: 400, line: 1 },
{
title: '类型',
dataIndex: 'type',
......
......@@ -27,7 +27,7 @@ export function ConfirmActionBar({ passCount = 12, onBack, onSubmit }: ConfirmAc
icon={<ArrowRightOutlined />}
onClick={onSubmit ?? (() => console.log('下一步:提交审批'))}
>
下一步:提交审批({passCount})
下一步:提交审批
</UButton>
</div>
</div>
......
......@@ -5,6 +5,8 @@ import type { StoreImportFailVO, StoreImportCheckVO } from '@/api/modules/store'
export interface FailDetailCardProps {
checkResult?: StoreImportCheckVO;
/** 上传文件的字节数(兜底:后端可能不返回 fileSize,用 File 对象的 size 字段) */
fileSize?: number;
/** 点击「重新上传」时触发(通常回到 Step 0 并清空文件) */
onReUpload?: () => void;
}
......@@ -13,7 +15,6 @@ const FAIL_COL_LABELS = [
{ key: 'rowIndex' as const, label: '行号', width: 92 },
{ key: 'storeName' as const, label: '门店名称', width: 300 },
{ key: 'merchantNo' as const, label: '门店商户号', width: 160 },
{ key: 'levelLabel' as const, label: '校验层级', width: 130 },
{ key: 'reason' as const, label: '失败原因', width: undefined },
] as const;
......@@ -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 failFileUrl = checkResult?.failFileUrl ?? null;
const failures = (checkResult?.failures ?? []) as StoreImportFailVO[];
......@@ -49,11 +50,13 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
* 底部 L1 / L2 通过校验文字(复用 checkResult 的字段,无则从 failures.length 推断)
*/
const l1 = useMemo(() => {
// 文件大小:优先后端 fileSize,兜底用传入的 File.size(字节)
const rawSize = typeof checkResult?.fileSize === 'number' ? checkResult.fileSize : fileSize;
const size =
typeof checkResult?.fileSize === 'number'
? checkResult.fileSize === 0
typeof rawSize === 'number'
? rawSize === 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 version = checkResult?.templateVersion ? `模板版本${checkResult.templateVersion}` : '';
......@@ -63,7 +66,7 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
: `格式 .xlsx / ${size}${total ? ' / ' + total : ''}${version ? ' / ' + version : ''}`,
];
return parts.filter(Boolean).join(' · ');
}, [checkResult]);
}, [checkResult, fileSize]);
const l2 = useMemo(() => {
const template = checkResult?.templateVersion
......@@ -208,29 +211,6 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
>
{f.merchantNo ?? '-'}
</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) */}
<td
style={{
......
......@@ -6,9 +6,9 @@ import type { USelectProps } from '@uj/ui';
import type { StoreImportCheckVO } from '@/api/modules/store';
export interface ImportInfoValues {
org: string;
scene: string;
categories: string[];
org?: string;
scene?: string;
categories?: string[];
remark?: string;
}
......
......@@ -3,8 +3,8 @@ import type { TableProps } from 'antd';
import type { PolicyConfirmRow } from '../../tools/policyTableData';
const storeInfoHeaderStyle: React.CSSProperties = {
background: '#EEF2FF',
color: '#3730A3',
background: '#EFF4FF',
color: '#2B5CE6',
fontWeight: 600,
fontSize: 13,
};
......@@ -51,7 +51,7 @@ function SceneTag({ text }: { text: string }) {
function CategoryTag({ text }: { text: string }) {
return (
<UTag
color="success"
color="processing"
bordered={false}
title={text}
style={{
......@@ -77,7 +77,27 @@ function FeeValueCell({ value }: { value: string }) {
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 [
// ------------- 第一组:门店信息(4 列) -------------
{
......@@ -90,7 +110,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
key: 'storeName',
width: 200,
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>,
},
{
......@@ -100,7 +123,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 130,
align: 'center',
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>,
},
{
......@@ -110,16 +137,27 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 130,
align: 'center',
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} />,
},
],
},
// ------------- 第二组:商务政策(14 列) -------------
{
title: '商务政策',
align: 'center',
children: [
{
title: '产品分类',
dataIndex: 'productCategory',
key: 'productCategory',
width: 280,
align: 'center',
onHeaderCell: () => ({ style: storeInfoHeaderStyle }),
onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({
style: {
...cellStyle,
......@@ -130,13 +168,6 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
}),
render: (v: string) => <CategoryTag text={v} />,
},
],
},
// ------------- 第二组:商务政策(14 列) -------------
{
title: '商务政策',
align: 'center',
children: [
// 管理层市场费 1
{
title: '管理层市场费1计算模式',
......@@ -203,7 +234,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 170,
align: 'center',
onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({ style: cellStyle }),
onCell: (_r, index) => ({
// 同门店同业务场景合并(与「业务场景」列合并粒度一致)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
},
{
title: '一线阳光计算模式',
......@@ -241,7 +276,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 180,
align: 'center',
onHeaderCell: () => ({ style: bizPolicyHeaderStyle }),
onCell: () => ({ style: cellStyle }),
onCell: (_r, index) => ({
// 同门店同业务场景合并(与「业务场景」列合并粒度一致)
rowSpan: getRowSpan(index ?? 0, (r) => `${r.storeName}|${r.businessScene}`),
style: cellStyle,
}),
},
{
title: '一线阳光2计算模式',
......@@ -285,7 +324,11 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 160,
align: 'center',
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} />,
},
{
......@@ -295,7 +338,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 220,
align: 'center',
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} />,
},
{
......@@ -305,7 +351,10 @@ export function buildPolicyColumns(): TableProps<PolicyConfirmRow>['columns'] {
width: 140,
align: 'center',
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} />,
},
],
......
......@@ -24,7 +24,21 @@ export function PolicyConfirmTable({
ruleCategoryCount,
ruleTotalRows,
}: 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 文字:优先用外部传入的通过行统计,
......@@ -71,17 +85,6 @@ export function PolicyConfirmTable({
return colWidths.reduce((a, b) => a + b, 0) + 40; // 加 40px 冗余
}, [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 时类型不兼容
const tableProps: TableProps<PolicyConfirmRow> = {
rowKey: (r: PolicyConfirmRow) => `${r.storeMerchantNo}-${r.businessScene}-${r.productCategory}`,
......
......@@ -40,7 +40,7 @@ export function SubmitActionBar({
disabled={disabled || loading}
onClick={onSubmit ?? (() => console.log('确认提交并推送审批'))}
>
确认提交并推送审批({totalRows})
确认提交并推送审批
</UButton>
</div>
);
......
import { useState, useCallback, useEffect } from 'react';
import { useState, useCallback, useEffect, useRef } from 'react';
import { App } from 'antd';
import {
InfoCircleFilled,
......@@ -40,6 +40,10 @@ export function UploadCard({
const [uploading, setUploading] = useState(false);
const [downloading, setDownloading] = useState(false);
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 */
const statLineText = (() => {
......@@ -100,18 +104,6 @@ export function UploadCard({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [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(() => {
setFileList([]);
onFileChange?.(null);
......@@ -191,6 +183,38 @@ export function UploadCard({
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 (
<UCard
styles={{ body: { padding: 20 } }}
......@@ -209,7 +233,7 @@ export function UploadCard({
}
>
<div style={{ position: 'relative' }}>
<UUpload.Dragger {...uploadProps}>
<UUpload.Dragger ref={uploadRef} {...uploadProps}>
<div style={{ padding: '30px 0' }}>
<div
style={{
......
......@@ -45,12 +45,13 @@ export default function TemplateImport() {
const handleFileChange = (f: File | null) => {
setSelectedFile(f);
// 移除文件时,同步清空校验结果 + 导入信息里的 3 个回显字段(保留 remark)
// 注意:org/scene 用 undefined 而非 '',否则 antd Select 会把 '' 当成选中值,placeholder 不显示
if (f === null) {
setCheckResult(null);
setImportInfo((prev) => ({
org: prev?.org ?? '',
scene: prev?.scene ?? '',
categories: prev?.categories ?? [],
org: undefined,
scene: undefined,
categories: [],
remark: prev?.remark,
}));
}
......@@ -76,7 +77,9 @@ export default function TemplateImport() {
};
const handleReUpload = () => {
// Step 2 重新上传:不清空文件,回到 Step0 后由 UploadCard.useEffect 监听 trigger 自动重跑上传
// Step 2 重新上传:清空文件 + checkResult,回到 Step0 后由 UploadCard 打开文件选择对话框,
// 用户重新选择文件后走正常 customRequest → runUpload → check 接口链路
setSelectedFile(null);
setCheckResult(null);
setSubmitChecked(true);
setCurrentStep(0);
......@@ -96,14 +99,14 @@ export default function TemplateImport() {
setCheckResult(result);
modal.success({
title: '提交审批成功',
content: `已提交 ${result.passRows ?? 0} 行 / 涉及 ${listingIds.length} 条上架记录,请在「门店审批」中跟踪进度。`,
content: `涉及 ${listingIds.length} 条上架记录,请在「门店审批」中跟踪进度。`,
okText: '前往门店审批',
okButtonProps: { type: 'primary' },
cancelText: '知道了',
// 非阻塞(不强制跳转):「知道了」留在当前页
onOk: () => {
// 跳转门店审批页(对应路由:/store/approve)
window.location.href = '/store/approve';
// 跳转门店审批页(对应路由:/store/approval
window.location.href = '/store/approval';
},
});
} catch (e) {
......@@ -143,7 +146,11 @@ export default function TemplateImport() {
{currentStep === 1 && (
<>
<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} />
</>
)}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!