2024-03-15 16:05:33 +08:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
API,
|
|
|
|
|
|
copy,
|
|
|
|
|
|
showError,
|
|
|
|
|
|
showSuccess,
|
|
|
|
|
|
timestamp2string,
|
2025-06-03 23:56:39 +08:00
|
|
|
|
renderQuota
|
2025-06-04 00:42:06 +08:00
|
|
|
|
} from '../../helpers';
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2025-06-29 02:32:09 +08:00
|
|
|
|
import { Ticket } from 'lucide-react';
|
✨ feat: Add lucide-react icons to all table Tag components
- Add semantic icons to ChannelsTable.js for channel status, response time, and quota display
- Add status and quota icons to TokensTable.js for better visual distinction
- Add status and quota icons to RedemptionsTable.js for redemption code management
- Add role, status, and statistics icons to UsersTable.js for user management
- Import appropriate lucide-react icons for each table component
- Enhance UI consistency and user experience across all table interfaces
Icons added include:
- Status indicators: CheckCircle, XCircle, AlertCircle, HelpCircle
- Performance metrics: Zap, Timer, Clock, AlertTriangle, TestTube
- Financial data: Coins, DollarSign
- User roles: User, Shield, Crown
- Activity tracking: Activity, Users, UserPlus
This improves visual clarity and makes table data more intuitive to understand.
2025-06-08 23:13:45 +08:00
|
|
|
|
|
2025-06-04 00:42:06 +08:00
|
|
|
|
import { ITEMS_PER_PAGE } from '../../constants';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
Button,
|
2025-05-23 16:58:19 +08:00
|
|
|
|
Card,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
Divider,
|
2025-05-23 16:58:19 +08:00
|
|
|
|
Dropdown,
|
2025-06-08 23:42:39 +08:00
|
|
|
|
Empty,
|
2025-06-08 18:41:04 +08:00
|
|
|
|
Form,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
Modal,
|
|
|
|
|
|
Popover,
|
2025-05-23 16:58:19 +08:00
|
|
|
|
Space,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
Table,
|
|
|
|
|
|
Tag,
|
✨ feat: Add lucide-react icons to all table Tag components
- Add semantic icons to ChannelsTable.js for channel status, response time, and quota display
- Add status and quota icons to TokensTable.js for better visual distinction
- Add status and quota icons to RedemptionsTable.js for redemption code management
- Add role, status, and statistics icons to UsersTable.js for user management
- Import appropriate lucide-react icons for each table component
- Enhance UI consistency and user experience across all table interfaces
Icons added include:
- Status indicators: CheckCircle, XCircle, AlertCircle, HelpCircle
- Performance metrics: Zap, Timer, Clock, AlertTriangle, TestTube
- Financial data: Coins, DollarSign
- User roles: User, Shield, Crown
- Activity tracking: Activity, Users, UserPlus
This improves visual clarity and makes table data more intuitive to understand.
2025-06-08 23:13:45 +08:00
|
|
|
|
Typography
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} from '@douyinfe/semi-ui';
|
2025-06-08 23:42:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IllustrationNoResult,
|
|
|
|
|
|
IllustrationNoResultDark
|
|
|
|
|
|
} from '@douyinfe/semi-illustrations';
|
2025-05-23 16:58:19 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IconSearch,
|
2025-06-22 18:10:00 +08:00
|
|
|
|
IconMore,
|
2025-05-23 16:58:19 +08:00
|
|
|
|
} from '@douyinfe/semi-icons';
|
2025-06-04 00:42:06 +08:00
|
|
|
|
import EditRedemption from '../../pages/Redemption/EditRedemption';
|
2024-12-13 19:03:14 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-06-22 18:10:00 +08:00
|
|
|
|
import { useTableCompactMode } from '../../hooks/useTableCompactMode';
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2025-05-23 16:58:19 +08:00
|
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
|
2023-04-26 17:02:26 +08:00
|
|
|
|
function renderTimestamp(timestamp) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return <>{timestamp2string(timestamp)}</>;
|
2023-04-26 17:02:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const RedemptionsTable = () => {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
2025-06-13 20:51:20 +08:00
|
|
|
|
const isExpired = (rec) => {
|
|
|
|
|
|
return rec.status === 1 && rec.expired_time !== 0 && rec.expired_time < Math.floor(Date.now() / 1000);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const renderStatus = (status, record) => {
|
|
|
|
|
|
if (isExpired(record)) {
|
|
|
|
|
|
return (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag color='orange' size='large' shape='circle'>{t('已过期')}</Tag>
|
2025-06-13 20:51:20 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
return (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag color='green' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('未使用')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
return (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag color='red' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('已禁用')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
return (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag color='grey' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('已使用')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
default:
|
|
|
|
|
|
return (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag color='black' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('未知状态')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const columns = [
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('ID'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'id',
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('名称'),
|
2024-03-23 21:24:39 +08:00
|
|
|
|
dataIndex: 'name',
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('状态'),
|
2024-03-15 16:05:33 +08:00
|
|
|
|
dataIndex: 'status',
|
|
|
|
|
|
key: 'status',
|
|
|
|
|
|
render: (text, record, index) => {
|
2025-06-13 20:51:20 +08:00
|
|
|
|
return <div>{renderStatus(text, record)}</div>;
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('额度'),
|
2024-03-15 16:05:33 +08:00
|
|
|
|
dataIndex: 'quota',
|
|
|
|
|
|
render: (text, record, index) => {
|
✨ feat: Add lucide-react icons to all table Tag components
- Add semantic icons to ChannelsTable.js for channel status, response time, and quota display
- Add status and quota icons to TokensTable.js for better visual distinction
- Add status and quota icons to RedemptionsTable.js for redemption code management
- Add role, status, and statistics icons to UsersTable.js for user management
- Import appropriate lucide-react icons for each table component
- Enhance UI consistency and user experience across all table interfaces
Icons added include:
- Status indicators: CheckCircle, XCircle, AlertCircle, HelpCircle
- Performance metrics: Zap, Timer, Clock, AlertTriangle, TestTube
- Financial data: Coins, DollarSign
- User roles: User, Shield, Crown
- Activity tracking: Activity, Users, UserPlus
This improves visual clarity and makes table data more intuitive to understand.
2025-06-08 23:13:45 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Tag size={'large'} color={'grey'} shape='circle'>
|
✨ feat: Add lucide-react icons to all table Tag components
- Add semantic icons to ChannelsTable.js for channel status, response time, and quota display
- Add status and quota icons to TokensTable.js for better visual distinction
- Add status and quota icons to RedemptionsTable.js for redemption code management
- Add role, status, and statistics icons to UsersTable.js for user management
- Import appropriate lucide-react icons for each table component
- Enhance UI consistency and user experience across all table interfaces
Icons added include:
- Status indicators: CheckCircle, XCircle, AlertCircle, HelpCircle
- Performance metrics: Zap, Timer, Clock, AlertTriangle, TestTube
- Financial data: Coins, DollarSign
- User roles: User, Shield, Crown
- Activity tracking: Activity, Users, UserPlus
This improves visual clarity and makes table data more intuitive to understand.
2025-06-08 23:13:45 +08:00
|
|
|
|
{renderQuota(parseInt(text))}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('创建时间'),
|
2024-03-15 16:05:33 +08:00
|
|
|
|
dataIndex: 'created_time',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return <div>{renderTimestamp(text)}</div>;
|
|
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
2025-06-13 20:51:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: t('过期时间'),
|
|
|
|
|
|
dataIndex: 'expired_time',
|
|
|
|
|
|
render: (text) => {
|
|
|
|
|
|
return <div>{text === 0 ? t('永不过期') : renderTimestamp(text)}</div>;
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('兑换人ID'),
|
2024-03-15 16:05:33 +08:00
|
|
|
|
dataIndex: 'used_user_id',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
return <div>{text === 0 ? t('无') : text}</div>;
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
dataIndex: 'operate',
|
2025-06-07 02:45:07 +08:00
|
|
|
|
fixed: 'right',
|
2025-05-23 16:58:19 +08:00
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
// 创建更多操作的下拉菜单项
|
|
|
|
|
|
const moreMenuItems = [
|
|
|
|
|
|
{
|
|
|
|
|
|
node: 'item',
|
|
|
|
|
|
name: t('删除'),
|
|
|
|
|
|
type: 'danger',
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: t('确定是否要删除此兑换码?'),
|
|
|
|
|
|
content: t('此修改将不可逆'),
|
|
|
|
|
|
onOk: () => {
|
|
|
|
|
|
manageRedemption(record.id, 'delete', record).then(() => {
|
|
|
|
|
|
removeRecord(record.key);
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2024-03-23 21:24:39 +08:00
|
|
|
|
});
|
2025-05-23 16:58:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2025-06-13 20:51:20 +08:00
|
|
|
|
if (record.status === 1 && !isExpired(record)) {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
moreMenuItems.push({
|
|
|
|
|
|
node: 'item',
|
|
|
|
|
|
name: t('禁用'),
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
manageRedemption(record.id, 'disable', record);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-06-13 20:51:20 +08:00
|
|
|
|
} else if (!isExpired(record)) {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
moreMenuItems.push({
|
|
|
|
|
|
node: 'item',
|
|
|
|
|
|
name: t('启用'),
|
|
|
|
|
|
type: 'secondary',
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
manageRedemption(record.id, 'enable', record);
|
|
|
|
|
|
},
|
|
|
|
|
|
disabled: record.status === 3,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Popover content={record.key} style={{ padding: 20 }} position='top'>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('查看')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Popover>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
2025-05-23 16:58:19 +08:00
|
|
|
|
type='secondary'
|
|
|
|
|
|
size="small"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onClick={async () => {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
await copyText(record.key);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
{t('复制')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
2025-05-23 16:58:19 +08:00
|
|
|
|
type='tertiary'
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setEditingRedemption(record);
|
|
|
|
|
|
setShowEdit(true);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}}
|
2025-05-23 16:58:19 +08:00
|
|
|
|
disabled={record.status !== 1}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
{t('编辑')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
<Dropdown
|
|
|
|
|
|
trigger='click'
|
|
|
|
|
|
position='bottomRight'
|
|
|
|
|
|
menu={moreMenuItems}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
size="small"
|
2025-06-29 02:32:09 +08:00
|
|
|
|
icon={<IconMore />}
|
2025-05-23 16:58:19 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</Dropdown>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
];
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [redemptions, setRedemptions] = useState([]);
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
const [activePage, setActivePage] = useState(1);
|
|
|
|
|
|
const [searching, setSearching] = useState(false);
|
|
|
|
|
|
const [tokenCount, setTokenCount] = useState(ITEMS_PER_PAGE);
|
|
|
|
|
|
const [selectedKeys, setSelectedKeys] = useState([]);
|
2024-12-31 15:28:25 +08:00
|
|
|
|
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const [editingRedemption, setEditingRedemption] = useState({
|
2024-03-23 21:24:39 +08:00
|
|
|
|
id: undefined,
|
2024-03-15 16:05:33 +08:00
|
|
|
|
});
|
|
|
|
|
|
const [showEdit, setShowEdit] = useState(false);
|
2025-06-22 18:10:00 +08:00
|
|
|
|
const [compactMode, setCompactMode] = useTableCompactMode('redemptions');
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2025-06-08 18:41:04 +08:00
|
|
|
|
const formInitValues = {
|
|
|
|
|
|
searchKeyword: '',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const [formApi, setFormApi] = useState(null);
|
|
|
|
|
|
|
|
|
|
|
|
const getFormValues = () => {
|
|
|
|
|
|
const formValues = formApi ? formApi.getValues() : {};
|
|
|
|
|
|
return {
|
|
|
|
|
|
searchKeyword: formValues.searchKeyword || '',
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const closeEdit = () => {
|
|
|
|
|
|
setShowEdit(false);
|
2025-05-23 16:58:19 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
setEditingRedemption({
|
|
|
|
|
|
id: undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
}, 500);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const setRedemptionFormat = (redeptions) => {
|
|
|
|
|
|
setRedemptions(redeptions);
|
|
|
|
|
|
};
|
2023-11-10 00:46:07 +08:00
|
|
|
|
|
2025-06-27 07:42:04 +08:00
|
|
|
|
const loadRedemptions = async (page = 1, pageSize) => {
|
2025-06-27 07:29:28 +08:00
|
|
|
|
setLoading(true);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const res = await API.get(
|
2025-06-27 07:42:04 +08:00
|
|
|
|
`/api/redemption/?p=${page}&page_size=${pageSize}`,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const newPageData = data.items;
|
2025-06-27 07:42:04 +08:00
|
|
|
|
setActivePage(data.page <= 0 ? 1 : data.page);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setTokenCount(data.total);
|
|
|
|
|
|
setRedemptionFormat(newPageData);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showError(message);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const removeRecord = (key) => {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let newDataSource = [...redemptions];
|
|
|
|
|
|
if (key != null) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
let idx = newDataSource.findIndex((data) => data.key === key);
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
if (idx > -1) {
|
|
|
|
|
|
newDataSource.splice(idx, 1);
|
|
|
|
|
|
setRedemptions(newDataSource);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-11-10 00:10:41 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const copyText = async (text) => {
|
|
|
|
|
|
if (await copy(text)) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showSuccess(t('已复制到剪贴板!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
Modal.error({
|
|
|
|
|
|
title: t('无法复制到剪贴板,请手动复制'),
|
|
|
|
|
|
content: text,
|
|
|
|
|
|
size: 'large'
|
|
|
|
|
|
});
|
2023-11-09 17:08:32 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
useEffect(() => {
|
2025-06-27 07:42:04 +08:00
|
|
|
|
loadRedemptions(1, pageSize)
|
2024-03-15 16:05:33 +08:00
|
|
|
|
.then()
|
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
|
showError(reason);
|
|
|
|
|
|
});
|
2025-05-23 16:58:19 +08:00
|
|
|
|
}, [pageSize]);
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const refresh = async () => {
|
2024-12-31 15:28:25 +08:00
|
|
|
|
await loadRedemptions(activePage - 1, pageSize);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const manageRedemption = async (id, action, record) => {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
setLoading(true);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let data = { id };
|
|
|
|
|
|
let res;
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
case 'delete':
|
|
|
|
|
|
res = await API.delete(`/api/redemption/${id}/`);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'enable':
|
|
|
|
|
|
data.status = 1;
|
|
|
|
|
|
res = await API.put('/api/redemption/?status_only=true', data);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'disable':
|
|
|
|
|
|
data.status = 2;
|
|
|
|
|
|
res = await API.put('/api/redemption/?status_only=true', data);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
|
if (success) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showSuccess(t('操作成功完成!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let redemption = res.data.data;
|
|
|
|
|
|
let newRedemptions = [...redemptions];
|
|
|
|
|
|
if (action === 'delete') {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
record.status = redemption.status;
|
|
|
|
|
|
}
|
|
|
|
|
|
setRedemptions(newRedemptions);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
2025-05-23 16:58:19 +08:00
|
|
|
|
setLoading(false);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2025-06-08 18:41:04 +08:00
|
|
|
|
const searchRedemptions = async (keyword = null, page, pageSize) => {
|
|
|
|
|
|
// 如果没有传递keyword参数,从表单获取值
|
|
|
|
|
|
if (keyword === null) {
|
|
|
|
|
|
const formValues = getFormValues();
|
|
|
|
|
|
keyword = formValues.searchKeyword;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keyword === '') {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
await loadRedemptions(page, pageSize);
|
|
|
|
|
|
return;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
setSearching(true);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const res = await API.get(
|
|
|
|
|
|
`/api/redemption/search?keyword=${keyword}&p=${page}&page_size=${pageSize}`,
|
|
|
|
|
|
);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const newPageData = data.items;
|
|
|
|
|
|
setActivePage(data.page);
|
|
|
|
|
|
setTokenCount(data.total);
|
|
|
|
|
|
setRedemptionFormat(newPageData);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showError(message);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
setSearching(false);
|
|
|
|
|
|
};
|
2023-04-26 17:02:26 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const handlePageChange = (page) => {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setActivePage(page);
|
2025-06-08 18:41:04 +08:00
|
|
|
|
const { searchKeyword } = getFormValues();
|
2024-12-31 15:28:25 +08:00
|
|
|
|
if (searchKeyword === '') {
|
|
|
|
|
|
loadRedemptions(page, pageSize).then();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
searchRedemptions(searchKeyword, page, pageSize).then();
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-12-31 15:28:25 +08:00
|
|
|
|
let pageData = redemptions;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const rowSelection = {
|
2025-05-23 16:58:19 +08:00
|
|
|
|
onSelect: (record, selected) => { },
|
|
|
|
|
|
onSelectAll: (selected, selectedRows) => { },
|
2024-03-15 16:05:33 +08:00
|
|
|
|
onChange: (selectedRowKeys, selectedRows) => {
|
|
|
|
|
|
setSelectedKeys(selectedRows);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-11-09 17:08:32 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const handleRow = (record, index) => {
|
2025-06-13 20:51:20 +08:00
|
|
|
|
if (record.status !== 1 || isExpired(record)) {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
return {
|
|
|
|
|
|
style: {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
background: 'var(--semi-color-disabled-border)',
|
|
|
|
|
|
},
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-12-01 01:30:24 +08:00
|
|
|
|
|
2025-05-23 16:58:19 +08:00
|
|
|
|
const renderHeader = () => (
|
|
|
|
|
|
<div className="flex flex-col w-full">
|
|
|
|
|
|
<div className="mb-2">
|
2025-06-22 18:10:00 +08:00
|
|
|
|
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full">
|
|
|
|
|
|
<div className="flex items-center text-orange-500">
|
|
|
|
|
|
<Ticket size={16} className="mr-2" />
|
|
|
|
|
|
<Text>{t('兑换码可以批量生成和分发,适合用于推广活动或批量充值。')}</Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='secondary'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="w-full md:w-auto"
|
2025-06-22 18:10:00 +08:00
|
|
|
|
onClick={() => setCompactMode(!compactMode)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{compactMode ? t('自适应列表') : t('紧凑列表')}
|
|
|
|
|
|
</Button>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<Divider margin="12px" />
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col md:flex-row justify-between items-center gap-4 w-full">
|
2025-06-13 20:51:20 +08:00
|
|
|
|
<div className="flex flex-col sm:flex-row gap-2 w-full md:w-auto order-2 md:order-1">
|
|
|
|
|
|
<div className="flex gap-2 w-full sm:w-auto">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='primary'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="w-full sm:w-auto"
|
2025-06-13 20:51:20 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setEditingRedemption({
|
|
|
|
|
|
id: undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
setShowEdit(true);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('添加兑换码')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type='warning'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="w-full sm:w-auto"
|
2025-06-13 20:51:20 +08:00
|
|
|
|
onClick={async () => {
|
|
|
|
|
|
if (selectedKeys.length === 0) {
|
|
|
|
|
|
showError(t('请至少选择一个兑换码!'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let keys = '';
|
|
|
|
|
|
for (let i = 0; i < selectedKeys.length; i++) {
|
|
|
|
|
|
keys +=
|
|
|
|
|
|
selectedKeys[i].name + ' ' + selectedKeys[i].key + '\n';
|
|
|
|
|
|
}
|
|
|
|
|
|
await copyText(keys);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('复制所选兑换码到剪贴板')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
<Button
|
2025-06-13 20:51:20 +08:00
|
|
|
|
type='danger'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="w-full sm:w-auto"
|
2025-05-23 16:58:19 +08:00
|
|
|
|
onClick={() => {
|
2025-06-13 20:51:20 +08:00
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: t('确定清除所有失效兑换码?'),
|
|
|
|
|
|
content: t('将删除已使用、已禁用及过期的兑换码,此操作不可撤销。'),
|
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
const res = await API.delete('/api/redemption/invalid');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
showSuccess(t('已删除 {{count}} 条失效兑换码', { count: data }));
|
|
|
|
|
|
await refresh();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
},
|
2025-05-23 16:58:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2025-06-13 20:51:20 +08:00
|
|
|
|
{t('清除失效兑换码')}
|
2025-05-23 16:58:19 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-06-08 18:41:04 +08:00
|
|
|
|
<Form
|
|
|
|
|
|
initValues={formInitValues}
|
|
|
|
|
|
getFormApi={(api) => setFormApi(api)}
|
|
|
|
|
|
onSubmit={() => {
|
|
|
|
|
|
setActivePage(1);
|
|
|
|
|
|
searchRedemptions(null, 1, pageSize);
|
|
|
|
|
|
}}
|
|
|
|
|
|
allowEmpty={true}
|
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
|
layout="horizontal"
|
|
|
|
|
|
trigger="change"
|
|
|
|
|
|
stopValidateWithError={false}
|
|
|
|
|
|
className="w-full md:w-auto order-1 md:order-2"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex flex-col md:flex-row items-center gap-4 w-full md:w-auto">
|
|
|
|
|
|
<div className="relative w-full md:w-64">
|
|
|
|
|
|
<Form.Input
|
|
|
|
|
|
field="searchKeyword"
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('关键字(id或者名称)')}
|
|
|
|
|
|
showClear
|
|
|
|
|
|
pure
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex gap-2 w-full md:w-auto">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
htmlType="submit"
|
2025-06-08 22:01:54 +08:00
|
|
|
|
loading={loading || searching}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="flex-1 md:flex-initial md:w-auto"
|
2025-06-08 18:41:04 +08:00
|
|
|
|
>
|
|
|
|
|
|
{t('查询')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme="light"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
if (formApi) {
|
|
|
|
|
|
formApi.reset();
|
|
|
|
|
|
// 重置后立即查询,使用setTimeout确保表单重置完成
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
setActivePage(1);
|
|
|
|
|
|
loadRedemptions(1, pageSize);
|
|
|
|
|
|
}, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className="flex-1 md:flex-initial md:w-auto"
|
2025-06-08 18:41:04 +08:00
|
|
|
|
>
|
|
|
|
|
|
{t('重置')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
</div>
|
2025-06-08 18:41:04 +08:00
|
|
|
|
</Form>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<EditRedemption
|
|
|
|
|
|
refresh={refresh}
|
|
|
|
|
|
editingRedemption={editingRedemption}
|
|
|
|
|
|
visiable={showEdit}
|
|
|
|
|
|
handleClose={closeEdit}
|
|
|
|
|
|
></EditRedemption>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
|
|
|
|
|
|
<Card
|
2025-06-07 02:45:07 +08:00
|
|
|
|
className="!rounded-2xl"
|
2025-05-23 16:58:19 +08:00
|
|
|
|
title={renderHeader()}
|
2025-06-07 00:53:29 +08:00
|
|
|
|
shadows='always'
|
|
|
|
|
|
bordered={false}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
>
|
2025-06-07 02:51:38 +08:00
|
|
|
|
<Table
|
2025-06-22 18:10:00 +08:00
|
|
|
|
columns={compactMode ? columns.map(({ fixed, ...rest }) => rest) : columns}
|
2025-06-07 02:51:38 +08:00
|
|
|
|
dataSource={pageData}
|
2025-06-22 18:10:00 +08:00
|
|
|
|
scroll={compactMode ? undefined : { x: 'max-content' }}
|
2025-06-07 02:51:38 +08:00
|
|
|
|
pagination={{
|
|
|
|
|
|
currentPage: activePage,
|
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
|
total: tokenCount,
|
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
|
|
|
|
formatPageText: (page) =>
|
|
|
|
|
|
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
|
|
|
|
|
start: page.currentStart,
|
|
|
|
|
|
end: page.currentEnd,
|
|
|
|
|
|
total: tokenCount,
|
|
|
|
|
|
}),
|
|
|
|
|
|
onPageSizeChange: (size) => {
|
|
|
|
|
|
setPageSize(size);
|
|
|
|
|
|
setActivePage(1);
|
2025-06-08 18:41:04 +08:00
|
|
|
|
const { searchKeyword } = getFormValues();
|
2025-06-07 02:51:38 +08:00
|
|
|
|
if (searchKeyword === '') {
|
|
|
|
|
|
loadRedemptions(1, size).then();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
searchRedemptions(searchKeyword, 1, size).then();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onPageChange: handlePageChange,
|
|
|
|
|
|
}}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
rowSelection={rowSelection}
|
|
|
|
|
|
onRow={handleRow}
|
2025-06-08 23:42:39 +08:00
|
|
|
|
empty={
|
|
|
|
|
|
<Empty
|
|
|
|
|
|
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
|
|
|
|
|
|
darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
|
|
|
|
|
|
description={t('搜索无结果')}
|
|
|
|
|
|
style={{ padding: 30 }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
}
|
2025-06-07 02:51:38 +08:00
|
|
|
|
className="rounded-xl overflow-hidden"
|
|
|
|
|
|
size="middle"
|
|
|
|
|
|
></Table>
|
2025-05-23 16:58:19 +08:00
|
|
|
|
</Card>
|
2024-03-15 16:05:33 +08:00
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-04-26 17:02:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default RedemptionsTable;
|