feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
+197
-116
@@ -16,12 +16,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { writeClipboardText } from '../../helpers/clipboard';
|
||||
import TableEmpty from '../../components/common/table/TableEmpty';
|
||||
import TableToolbar from '../../components/common/table/TableToolbar';
|
||||
import {
|
||||
ConsoleCard,
|
||||
ConsoleSearchBar,
|
||||
} from '../../components/console/ConsolePrimitives';
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ShoppingCart, Search, Copy, Check } from 'lucide-react';
|
||||
import { Search, Copy, Check } from 'lucide-react';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
Input,
|
||||
Tag,
|
||||
Select,
|
||||
@@ -65,12 +72,23 @@ const formatUSDMinor = (value) => {
|
||||
return `$${(Number(value) / 100).toFixed(2)}`;
|
||||
};
|
||||
|
||||
import { Descriptions } from 'antd';
|
||||
import { ConsoleDrawer } from '../../components/console/ConsolePrimitives';
|
||||
import { Button } from '@/components/ui';
|
||||
import {
|
||||
ConsoleFilterField,
|
||||
ConsoleFilterActions,
|
||||
} from '../../components/console/ConsoleModuleFilters';
|
||||
|
||||
const AdminOrder = () => {
|
||||
const { t } = useTranslation();
|
||||
const [detailOrder, setDetailOrder] = useState(null);
|
||||
const [queryVersion, setQueryVersion] = useState(0);
|
||||
const [orders, setOrders] = useState([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(20);
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
const [orderId, setOrderId] = useState(undefined);
|
||||
@@ -89,7 +107,7 @@ const AdminOrder = () => {
|
||||
const fetchOrders = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = { p: page, page_size: 20 };
|
||||
const params = { p: page, page_size: pageSize };
|
||||
if (searchKeyword) params.keyword = searchKeyword;
|
||||
if (appliedOrderId) params.order_id = appliedOrderId;
|
||||
if (appliedUserId) params.user_id = appliedUserId;
|
||||
@@ -107,6 +125,8 @@ const AdminOrder = () => {
|
||||
if (res.data.success) {
|
||||
setOrders(res.data.data?.items || []);
|
||||
setTotal(res.data.data?.total || 0);
|
||||
} else {
|
||||
showError(res.data.message || t('查询失败'));
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err.message);
|
||||
@@ -115,6 +135,7 @@ const AdminOrder = () => {
|
||||
}
|
||||
}, [
|
||||
page,
|
||||
pageSize,
|
||||
searchKeyword,
|
||||
appliedOrderId,
|
||||
appliedUserId,
|
||||
@@ -123,6 +144,7 @@ const AdminOrder = () => {
|
||||
dateRange,
|
||||
appliedMinMoney,
|
||||
appliedMaxMoney,
|
||||
queryVersion,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -149,6 +171,7 @@ const AdminOrder = () => {
|
||||
setAppliedUserId(normalizedUserId);
|
||||
setAppliedMinMoney(minMoney);
|
||||
setAppliedMaxMoney(maxMoney);
|
||||
setQueryVersion((version) => version + 1);
|
||||
};
|
||||
|
||||
const handleStatusFilterChange = (value) => {
|
||||
@@ -175,6 +198,7 @@ const AdminOrder = () => {
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setQueryVersion((version) => version + 1);
|
||||
setPage(1);
|
||||
setKeyword('');
|
||||
setSearchKeyword('');
|
||||
@@ -192,8 +216,7 @@ const AdminOrder = () => {
|
||||
};
|
||||
|
||||
const copyText = (text, id) => {
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
writeClipboardText(text)
|
||||
.then(() => {
|
||||
setCopiedId(id);
|
||||
Toast.success(t('已复制'));
|
||||
@@ -332,124 +355,182 @@ const AdminOrder = () => {
|
||||
width: 150,
|
||||
render: (v) => formatTime(v),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
key: 'operate',
|
||||
fixed: 'right',
|
||||
width: 80,
|
||||
render: (_, record) => (
|
||||
<Button type='link' size='small' onClick={() => setDetailOrder(record)}>
|
||||
{t('详情')}
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='mt-[60px] p-4 sm:p-6'>
|
||||
{/* 筛选区:标题与筛选项同行,紧凑布局 */}
|
||||
<div className='flex flex-wrap items-center gap-2 mb-4'>
|
||||
<div className='flex items-center gap-1.5 mr-2 flex-shrink-0'>
|
||||
<ShoppingCart size={18} className='text-blue-500' />
|
||||
<span className='text-base font-bold text-gray-900 dark:text-white'>
|
||||
{t('订单管理')}
|
||||
</span>
|
||||
<div className='console-content'>
|
||||
<ConsoleDrawer
|
||||
title={t('记录详情')}
|
||||
classNames={{ header: 'console-detail-header' }}
|
||||
open={Boolean(detailOrder)}
|
||||
onClose={() => setDetailOrder(null)}
|
||||
placement='right'
|
||||
maskClosable
|
||||
width={560}
|
||||
footer={
|
||||
<div className='console-model-footer'>
|
||||
<Button onClick={() => setDetailOrder(null)}>{t('关闭')}</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Descriptions
|
||||
bordered
|
||||
column={1}
|
||||
size='small'
|
||||
items={
|
||||
detailOrder
|
||||
? columns
|
||||
.filter((column) => column.key !== 'operate')
|
||||
.map((column, key) => ({
|
||||
key,
|
||||
label: column.title,
|
||||
children:
|
||||
column.dataIndex === 'trade_no'
|
||||
? detailOrder.trade_no
|
||||
: column.render
|
||||
? column.render(
|
||||
detailOrder[column.dataIndex],
|
||||
detailOrder,
|
||||
)
|
||||
: (detailOrder[column.dataIndex] ?? '-'),
|
||||
}))
|
||||
: []
|
||||
}
|
||||
/>
|
||||
</ConsoleDrawer>
|
||||
<ConsoleSearchBar
|
||||
formProps={{
|
||||
layout: 'vertical',
|
||||
onFinish: handleSearch,
|
||||
className: 'console-module-filter-form',
|
||||
}}
|
||||
>
|
||||
<div className='console-module-filter-grid'>
|
||||
<ConsoleFilterField label={t('搜索昵称/订单号')}>
|
||||
<Input
|
||||
prefix={<Search size={14} />}
|
||||
placeholder={t('搜索昵称/订单号')}
|
||||
value={keyword}
|
||||
onChange={setKeyword}
|
||||
onEnterPress={handleSearch}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('订单ID')}>
|
||||
<InputNumber
|
||||
placeholder={t('订单ID')}
|
||||
value={orderId}
|
||||
onChange={setOrderId}
|
||||
min={1}
|
||||
hideButtons
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('用户ID')}>
|
||||
<InputNumber
|
||||
placeholder={t('用户ID')}
|
||||
value={userId}
|
||||
onChange={setUserId}
|
||||
min={1}
|
||||
hideButtons
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('状态')}>
|
||||
<Select
|
||||
placeholder={t('状态')}
|
||||
value={statusFilter || undefined}
|
||||
onChange={handleStatusFilterChange}
|
||||
allowClear
|
||||
optionList={[
|
||||
{ label: t('待支付'), value: 'pending' },
|
||||
{ label: t('已完成'), value: 'success' },
|
||||
{ label: t('已过期'), value: 'expired' },
|
||||
]}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('支付方式')}>
|
||||
<Select
|
||||
placeholder={t('支付方式')}
|
||||
value={paymentMethodFilter || undefined}
|
||||
onChange={handlePaymentMethodChange}
|
||||
allowClear
|
||||
optionList={Object.entries(paymentMethodMap).map(
|
||||
([value, label]) => ({ label, value }),
|
||||
)}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('创建时间')}>
|
||||
<DatePicker
|
||||
type='dateTimeRange'
|
||||
value={dateRange}
|
||||
onChange={handleDateRangeChange}
|
||||
placeholder={[t('开始时间'), t('结束时间')]}
|
||||
density='compact'
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('支付金额')}>
|
||||
<div className='flex items-center gap-1'>
|
||||
<InputNumber
|
||||
placeholder={t('最小金额')}
|
||||
value={minMoney}
|
||||
onChange={handleMinMoneyChange}
|
||||
min={0}
|
||||
precision={2}
|
||||
prefix='¥'
|
||||
/>
|
||||
<span className='text-gray-400'>-</span>
|
||||
<InputNumber
|
||||
placeholder={t('最大金额')}
|
||||
value={maxMoney}
|
||||
onChange={handleMaxMoneyChange}
|
||||
min={0}
|
||||
precision={2}
|
||||
prefix='¥'
|
||||
/>
|
||||
</div>
|
||||
</ConsoleFilterField>
|
||||
</div>
|
||||
<Input
|
||||
prefix={<Search size={14} />}
|
||||
placeholder={t('搜索昵称/订单号')}
|
||||
value={keyword}
|
||||
onChange={setKeyword}
|
||||
onEnterPress={handleSearch}
|
||||
style={{ width: 220 }}
|
||||
<ConsoleFilterActions
|
||||
onReset={handleReset}
|
||||
onSearch={handleSearch}
|
||||
loading={loading}
|
||||
/>
|
||||
<InputNumber
|
||||
placeholder={t('订单ID')}
|
||||
value={orderId}
|
||||
onChange={setOrderId}
|
||||
min={1}
|
||||
style={{ width: 110 }}
|
||||
hideButtons
|
||||
/>
|
||||
<InputNumber
|
||||
placeholder={t('用户ID')}
|
||||
value={userId}
|
||||
onChange={setUserId}
|
||||
min={1}
|
||||
style={{ width: 110 }}
|
||||
hideButtons
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('状态')}
|
||||
value={statusFilter || undefined}
|
||||
onChange={handleStatusFilterChange}
|
||||
style={{ width: 110 }}
|
||||
allowClear
|
||||
optionList={[
|
||||
{ label: t('待支付'), value: 'pending' },
|
||||
{ label: t('已完成'), value: 'success' },
|
||||
{ label: t('已过期'), value: 'expired' },
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('支付方式')}
|
||||
value={paymentMethodFilter || undefined}
|
||||
onChange={handlePaymentMethodChange}
|
||||
style={{ width: 120 }}
|
||||
allowClear
|
||||
optionList={Object.entries(paymentMethodMap).map(
|
||||
([value, label]) => ({ label, value }),
|
||||
)}
|
||||
/>
|
||||
<DatePicker
|
||||
type='dateTimeRange'
|
||||
value={dateRange}
|
||||
onChange={handleDateRangeChange}
|
||||
placeholder={[t('开始时间'), t('结束时间')]}
|
||||
style={{ width: 340 }}
|
||||
density='compact'
|
||||
/>
|
||||
<div className='flex items-center gap-1'>
|
||||
<InputNumber
|
||||
placeholder={t('最小金额')}
|
||||
value={minMoney}
|
||||
onChange={handleMinMoneyChange}
|
||||
min={0}
|
||||
precision={2}
|
||||
style={{ width: 100 }}
|
||||
prefix='¥'
|
||||
/>
|
||||
<span className='text-gray-400'>-</span>
|
||||
<InputNumber
|
||||
placeholder={t('最大金额')}
|
||||
value={maxMoney}
|
||||
onChange={handleMaxMoneyChange}
|
||||
min={0}
|
||||
precision={2}
|
||||
style={{ width: 100 }}
|
||||
prefix='¥'
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
size='default'
|
||||
onClick={handleSearch}
|
||||
>
|
||||
{t('搜索')}
|
||||
</Button>
|
||||
<Button type='tertiary' size='default' onClick={handleReset}>
|
||||
{t('重置')}
|
||||
</Button>
|
||||
</div>
|
||||
</ConsoleSearchBar>
|
||||
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={orders}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
total,
|
||||
pageSize: 20,
|
||||
onPageChange: setPage,
|
||||
showTotal: true,
|
||||
showSizeChanger: false,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
size='small'
|
||||
empty={t('暂无订单数据')}
|
||||
/>
|
||||
<ConsoleCard>
|
||||
<TableToolbar title={t('订单列表')} />
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={orders}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
total,
|
||||
pageSize,
|
||||
onPageChange: setPage,
|
||||
onPageSizeChange: (size) => {
|
||||
setPage(1);
|
||||
setPageSize(size);
|
||||
},
|
||||
showTotal: true,
|
||||
showSizeChanger: false,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
size='middle'
|
||||
empty={<TableEmpty />}
|
||||
/>
|
||||
</ConsoleCard>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user