阶段七:完成OrderList React feature化与导入刷新边界
This commit is contained in:
1 parent
66ac84b32d
commit
b128ce60db
20 files changed
+1454
-1366
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import React from 'react';
|
||||
import { Search, User as UserIcon } from 'lucide-react';
|
||||
import type { AccountDetail } from '../../../../types';
|
||||
import { orderStatusOptions } from '../state';
|
||||
|
||||
// OrderFilterBarProps 描述订单状态、账号和文本筛选所需的页面状态。
|
||||
export interface OrderFilterBarProps {
|
||||
// filter 是当前订单状态筛选值。
|
||||
filter: string;
|
||||
// onFilterChange 响应订单状态筛选切换。
|
||||
onFilterChange: (value: string) => void;
|
||||
// accountFilter 是当前账号筛选值。
|
||||
accountFilter: string;
|
||||
// onAccountFilterChange 响应账号筛选切换。
|
||||
onAccountFilterChange: (value: string) => void;
|
||||
// accounts 是账号下拉框的数据源。
|
||||
accounts: AccountDetail[];
|
||||
// accountName 将账号 ID 转换为展示名称。
|
||||
accountName: (cookieId: string) => string;
|
||||
// searchText 是搜索框当前输入值。
|
||||
searchText: string;
|
||||
// onSearchChange 响应订单搜索输入。
|
||||
onSearchChange: (value: string) => void;
|
||||
}
|
||||
|
||||
// OrderFilterBar 渲染订单状态、账号和关键词筛选工具栏。
|
||||
export const OrderFilterBar: React.FC<OrderFilterBarProps> = ({
|
||||
filter,
|
||||
onFilterChange,
|
||||
accountFilter,
|
||||
onAccountFilterChange,
|
||||
accounts,
|
||||
accountName,
|
||||
searchText,
|
||||
onSearchChange,
|
||||
}) => {
|
||||
// handleStatusClick 将用户选择的状态传回订单页面。
|
||||
const handleStatusClick = (event: React.MouseEvent<HTMLButtonElement>) => onFilterChange(event.currentTarget.dataset.status || 'all');
|
||||
// handleAccountChange 将用户选择的账号传回订单页面。
|
||||
const handleAccountChange = (event: React.ChangeEvent<HTMLSelectElement>) => onAccountFilterChange(event.target.value);
|
||||
// handleSearchChange 将用户输入传回订单页面。
|
||||
const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => onSearchChange(event.target.value);
|
||||
|
||||
return (
|
||||
<div className="p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted">
|
||||
<div className="flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full">
|
||||
{orderStatusOptions.map(
|
||||
// option 是当前订单状态筛选标签配置。
|
||||
option => (
|
||||
<button
|
||||
key={option.key}
|
||||
data-status={option.key}
|
||||
onClick={handleStatusClick}
|
||||
className={`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${filter === option.key ? 'bg-white text-black shadow-sm' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<div className="flex w-full md:w-auto flex-col sm:flex-row gap-3">
|
||||
<div className="relative">
|
||||
<UserIcon className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none" />
|
||||
<select
|
||||
aria-label="按账号筛选订单"
|
||||
value={accountFilter}
|
||||
onChange={handleAccountChange}
|
||||
className="ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm"
|
||||
>
|
||||
<option value="">全部账号</option>
|
||||
{accounts.map(
|
||||
// account 是当前账号筛选下拉项。
|
||||
account => <option key={account.id} value={account.id}>{accountName(account.id)}</option>,
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="relative group">
|
||||
<Search className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索订单号/商品/买家..."
|
||||
value={searchText}
|
||||
onChange={handleSearchChange}
|
||||
className="ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Upload, X } from 'lucide-react';
|
||||
import { failedOrderImportRows } from '../state';
|
||||
import type { OrderImportState } from '../types';
|
||||
|
||||
// OrderImportModalProps 描述订单导入弹窗所需的状态和事件。
|
||||
export type OrderImportModalProps = OrderImportState;
|
||||
|
||||
// OrderImportModal 渲染订单文件选择、结果展示和重试操作。
|
||||
export const OrderImportModal: React.FC<OrderImportModalProps> = (state) => {
|
||||
// handleFileChange 保存用户选择的订单文件并清理旧错误。
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
state.setImportFile(event.target.files?.[0] || null);
|
||||
};
|
||||
// handleClose 关闭订单导入弹窗。
|
||||
const handleClose = () => state.closeImportModal();
|
||||
// handleSubmit 提交当前订单导入文件。
|
||||
const handleSubmit = () => void state.handleImportOrders();
|
||||
// handleRetry 重试最近一次失败的订单导入。
|
||||
const handleRetry = () => void state.handleRetryImport();
|
||||
|
||||
if (!state.showImportModal) return null;
|
||||
|
||||
return createPortal(
|
||||
<div className="modal-overlay-centered">
|
||||
<div className="modal-container">
|
||||
<div className="modal-header">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<h3 className="text-2xl font-extrabold text-gray-900">插入订单</h3>
|
||||
<button onClick={handleClose} className="p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors">
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="modal-body space-y-5">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-2">选择Excel文件</label>
|
||||
<input type="file" accept=".xlsx,.csv,.tsv,.json" onChange={handleFileChange} className="w-full ios-input px-4 py-3 rounded-xl text-sm" />
|
||||
<p className="text-xs text-gray-500 mt-2">支持 .xlsx、.csv、.tsv、.json 格式</p>
|
||||
</div>
|
||||
{state.importFile && (
|
||||
<div className="p-3 bg-blue-50 rounded-xl">
|
||||
<div className="flex items-center gap-2">
|
||||
<Upload className="w-4 h-4 text-blue-600" />
|
||||
<span className="text-sm font-medium text-blue-900">{state.importFile.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{state.importError && (
|
||||
<div className="rounded-xl bg-red-50 border border-red-100 p-3 text-sm text-red-700 flex items-center justify-between gap-3">
|
||||
<span>{state.importError}</span>
|
||||
<button type="button" onClick={handleRetry} disabled={state.importing || !state.importFile} className="font-bold whitespace-nowrap">重试</button>
|
||||
</div>
|
||||
)}
|
||||
{state.importResult && state.importResult.failed_count > 0 && (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800">
|
||||
导入完成:成功 {state.importResult.success_count} 条,失败 {state.importResult.failed_count} 条
|
||||
</div>
|
||||
<div className="max-h-64 overflow-y-auto rounded-xl border border-gray-100">
|
||||
<table className="w-full text-left text-xs">
|
||||
<thead className="sticky top-0 bg-gray-50 text-gray-500">
|
||||
<tr><th className="px-3 py-2">订单ID</th><th className="px-3 py-2">失败原因</th></tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{failedOrderImportRows(state.importResult).map(
|
||||
// row 是需要展示失败原因的导入结果行。
|
||||
(row, index) => (
|
||||
<tr key={`${row.order_id}-${index}`}>
|
||||
<td className="px-3 py-2 font-mono">{row.order_id}</td>
|
||||
<td className="px-3 py-2 text-red-600">{row.message || '导入失败'}</td>
|
||||
</tr>
|
||||
),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<div className="flex gap-3 w-full">
|
||||
<button onClick={handleClose} className="flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors">取消</button>
|
||||
<button onClick={handleSubmit} disabled={!state.importFile || state.importing} className="flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50">
|
||||
{state.importing ? '正在导入…' : '导入订单'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user