♻️Refactor: Redemptions Page
This commit is contained in:
@@ -11,17 +11,33 @@ import { ITEMS_PER_PAGE } from '../constants';
|
|||||||
import { renderQuota } from '../helpers/render';
|
import { renderQuota } from '../helpers/render';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
Card,
|
||||||
Divider,
|
Divider,
|
||||||
Form,
|
Dropdown,
|
||||||
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
Popconfirm,
|
|
||||||
Popover,
|
Popover,
|
||||||
|
Space,
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
|
Typography,
|
||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
|
import {
|
||||||
|
IconPlus,
|
||||||
|
IconCopy,
|
||||||
|
IconSearch,
|
||||||
|
IconEyeOpened,
|
||||||
|
IconEdit,
|
||||||
|
IconDelete,
|
||||||
|
IconStop,
|
||||||
|
IconPlay,
|
||||||
|
IconMore,
|
||||||
|
} from '@douyinfe/semi-icons';
|
||||||
import EditRedemption from '../pages/Redemption/EditRedemption';
|
import EditRedemption from '../pages/Redemption/EditRedemption';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
const { Text } = Typography;
|
||||||
|
|
||||||
function renderTimestamp(timestamp) {
|
function renderTimestamp(timestamp) {
|
||||||
return <>{timestamp2string(timestamp)}</>;
|
return <>{timestamp2string(timestamp)}</>;
|
||||||
}
|
}
|
||||||
@@ -33,25 +49,25 @@ const RedemptionsTable = () => {
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
case 1:
|
case 1:
|
||||||
return (
|
return (
|
||||||
<Tag color='green' size='large'>
|
<Tag color='green' size='large' shape='circle'>
|
||||||
{t('未使用')}
|
{t('未使用')}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return (
|
return (
|
||||||
<Tag color='red' size='large'>
|
<Tag color='red' size='large' shape='circle'>
|
||||||
{t('已禁用')}
|
{t('已禁用')}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
case 3:
|
case 3:
|
||||||
return (
|
return (
|
||||||
<Tag color='grey' size='large'>
|
<Tag color='grey' size='large' shape='circle'>
|
||||||
{t('已使用')}
|
{t('已使用')}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<Tag color='black' size='large'>
|
<Tag color='black' size='large' shape='circle'>
|
||||||
{t('未知状态')}
|
{t('未知状态')}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
@@ -99,76 +115,107 @@ const RedemptionsTable = () => {
|
|||||||
{
|
{
|
||||||
title: '',
|
title: '',
|
||||||
dataIndex: 'operate',
|
dataIndex: 'operate',
|
||||||
render: (text, record, index) => (
|
render: (text, record, index) => {
|
||||||
<div>
|
// 创建更多操作的下拉菜单项
|
||||||
<Popover content={record.key} style={{ padding: 20 }} position='top'>
|
const moreMenuItems = [
|
||||||
<Button theme='light' type='tertiary' style={{ marginRight: 1 }}>
|
{
|
||||||
{t('查看')}
|
node: 'item',
|
||||||
</Button>
|
name: t('删除'),
|
||||||
</Popover>
|
icon: <IconDelete />,
|
||||||
<Button
|
type: 'danger',
|
||||||
theme='light'
|
onClick: () => {
|
||||||
type='secondary'
|
Modal.confirm({
|
||||||
style={{ marginRight: 1 }}
|
title: t('确定是否要删除此兑换码?'),
|
||||||
onClick={async (text) => {
|
content: t('此修改将不可逆'),
|
||||||
await copyText(record.key);
|
onOk: () => {
|
||||||
}}
|
manageRedemption(record.id, 'delete', record).then(() => {
|
||||||
>
|
removeRecord(record.key);
|
||||||
{t('复制')}
|
});
|
||||||
</Button>
|
},
|
||||||
<Popconfirm
|
|
||||||
title={t('确定是否要删除此兑换码?')}
|
|
||||||
content={t('此修改将不可逆')}
|
|
||||||
okType={'danger'}
|
|
||||||
position={'left'}
|
|
||||||
onConfirm={() => {
|
|
||||||
manageRedemption(record.id, 'delete', record).then(() => {
|
|
||||||
removeRecord(record.key);
|
|
||||||
});
|
});
|
||||||
}}
|
},
|
||||||
>
|
}
|
||||||
<Button theme='light' type='danger' style={{ marginRight: 1 }}>
|
];
|
||||||
{t('删除')}
|
|
||||||
</Button>
|
// 动态添加启用/禁用按钮
|
||||||
</Popconfirm>
|
if (record.status === 1) {
|
||||||
{record.status === 1 ? (
|
moreMenuItems.push({
|
||||||
<Button
|
node: 'item',
|
||||||
theme='light'
|
name: t('禁用'),
|
||||||
type='warning'
|
icon: <IconStop />,
|
||||||
style={{ marginRight: 1 }}
|
type: 'warning',
|
||||||
onClick={async () => {
|
onClick: () => {
|
||||||
manageRedemption(record.id, 'disable', record);
|
manageRedemption(record.id, 'disable', record);
|
||||||
}}
|
},
|
||||||
>
|
});
|
||||||
{t('禁用')}
|
} else {
|
||||||
</Button>
|
moreMenuItems.push({
|
||||||
) : (
|
node: 'item',
|
||||||
|
name: t('启用'),
|
||||||
|
icon: <IconPlay />,
|
||||||
|
type: 'secondary',
|
||||||
|
onClick: () => {
|
||||||
|
manageRedemption(record.id, 'enable', record);
|
||||||
|
},
|
||||||
|
disabled: record.status === 3,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Space>
|
||||||
|
<Popover content={record.key} style={{ padding: 20 }} position='top'>
|
||||||
|
<Button
|
||||||
|
icon={<IconEyeOpened />}
|
||||||
|
theme='light'
|
||||||
|
type='tertiary'
|
||||||
|
size="small"
|
||||||
|
className="!rounded-full"
|
||||||
|
>
|
||||||
|
{t('查看')}
|
||||||
|
</Button>
|
||||||
|
</Popover>
|
||||||
<Button
|
<Button
|
||||||
|
icon={<IconCopy />}
|
||||||
theme='light'
|
theme='light'
|
||||||
type='secondary'
|
type='secondary'
|
||||||
style={{ marginRight: 1 }}
|
size="small"
|
||||||
|
className="!rounded-full"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
manageRedemption(record.id, 'enable', record);
|
await copyText(record.key);
|
||||||
}}
|
}}
|
||||||
disabled={record.status === 3}
|
|
||||||
>
|
>
|
||||||
{t('启用')}
|
{t('复制')}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
<Button
|
||||||
<Button
|
icon={<IconEdit />}
|
||||||
theme='light'
|
theme='light'
|
||||||
type='tertiary'
|
type='tertiary'
|
||||||
style={{ marginRight: 1 }}
|
size="small"
|
||||||
onClick={() => {
|
className="!rounded-full"
|
||||||
setEditingRedemption(record);
|
onClick={() => {
|
||||||
setShowEdit(true);
|
setEditingRedemption(record);
|
||||||
}}
|
setShowEdit(true);
|
||||||
disabled={record.status !== 1}
|
}}
|
||||||
>
|
disabled={record.status !== 1}
|
||||||
{t('编辑')}
|
>
|
||||||
</Button>
|
{t('编辑')}
|
||||||
</div>
|
</Button>
|
||||||
),
|
<Dropdown
|
||||||
|
trigger='click'
|
||||||
|
position='bottomRight'
|
||||||
|
menu={moreMenuItems}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<IconMore />}
|
||||||
|
theme='light'
|
||||||
|
type='tertiary'
|
||||||
|
size="small"
|
||||||
|
className="!rounded-full"
|
||||||
|
/>
|
||||||
|
</Dropdown>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -187,6 +234,11 @@ const RedemptionsTable = () => {
|
|||||||
|
|
||||||
const closeEdit = () => {
|
const closeEdit = () => {
|
||||||
setShowEdit(false);
|
setShowEdit(false);
|
||||||
|
setTimeout(() => {
|
||||||
|
setEditingRedemption({
|
||||||
|
id: undefined,
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
const setRedemptionFormat = (redeptions) => {
|
const setRedemptionFormat = (redeptions) => {
|
||||||
@@ -225,8 +277,11 @@ const RedemptionsTable = () => {
|
|||||||
if (await copy(text)) {
|
if (await copy(text)) {
|
||||||
showSuccess(t('已复制到剪贴板!'));
|
showSuccess(t('已复制到剪贴板!'));
|
||||||
} else {
|
} else {
|
||||||
// setSearchKeyword(text);
|
Modal.error({
|
||||||
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
|
title: t('无法复制到剪贴板,请手动复制'),
|
||||||
|
content: text,
|
||||||
|
size: 'large'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -245,13 +300,14 @@ const RedemptionsTable = () => {
|
|||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
showError(reason);
|
showError(reason);
|
||||||
});
|
});
|
||||||
}, []);
|
}, [pageSize]);
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
await loadRedemptions(activePage - 1, pageSize);
|
await loadRedemptions(activePage - 1, pageSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
const manageRedemption = async (id, action, record) => {
|
const manageRedemption = async (id, action, record) => {
|
||||||
|
setLoading(true);
|
||||||
let data = { id };
|
let data = { id };
|
||||||
let res;
|
let res;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@@ -272,7 +328,6 @@ const RedemptionsTable = () => {
|
|||||||
showSuccess(t('操作成功完成!'));
|
showSuccess(t('操作成功完成!'));
|
||||||
let redemption = res.data.data;
|
let redemption = res.data.data;
|
||||||
let newRedemptions = [...redemptions];
|
let newRedemptions = [...redemptions];
|
||||||
// let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
|
||||||
if (action === 'delete') {
|
if (action === 'delete') {
|
||||||
} else {
|
} else {
|
||||||
record.status = redemption.status;
|
record.status = redemption.status;
|
||||||
@@ -281,6 +336,7 @@ const RedemptionsTable = () => {
|
|||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchRedemptions = async (keyword, page, pageSize) => {
|
const searchRedemptions = async (keyword, page, pageSize) => {
|
||||||
@@ -333,8 +389,8 @@ const RedemptionsTable = () => {
|
|||||||
|
|
||||||
let pageData = redemptions;
|
let pageData = redemptions;
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
onSelect: (record, selected) => {},
|
onSelect: (record, selected) => { },
|
||||||
onSelectAll: (selected, selectedRows) => {},
|
onSelectAll: (selected, selectedRows) => { },
|
||||||
onChange: (selectedRowKeys, selectedRows) => {
|
onChange: (selectedRowKeys, selectedRows) => {
|
||||||
setSelectedKeys(selectedRows);
|
setSelectedKeys(selectedRows);
|
||||||
},
|
},
|
||||||
@@ -352,6 +408,80 @@ const RedemptionsTable = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderHeader = () => (
|
||||||
|
<div className="flex flex-col w-full">
|
||||||
|
<div className="mb-2">
|
||||||
|
<div className="flex items-center text-orange-500">
|
||||||
|
<IconEyeOpened className="mr-2" />
|
||||||
|
<Text>{t('兑换码可以批量生成和分发,适合用于推广活动或批量充值。')}</Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Divider margin="12px" />
|
||||||
|
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-center gap-4 w-full">
|
||||||
|
<div className="flex gap-2 w-full md:w-auto order-2 md:order-1">
|
||||||
|
<Button
|
||||||
|
theme='light'
|
||||||
|
type='primary'
|
||||||
|
icon={<IconPlus />}
|
||||||
|
className="!rounded-full w-full md:w-auto"
|
||||||
|
onClick={() => {
|
||||||
|
setEditingRedemption({
|
||||||
|
id: undefined,
|
||||||
|
});
|
||||||
|
setShowEdit(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('添加兑换码')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='warning'
|
||||||
|
icon={<IconCopy />}
|
||||||
|
className="!rounded-full w-full md:w-auto"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<div className="flex flex-col md:flex-row items-center gap-4 w-full md:w-auto order-1 md:order-2">
|
||||||
|
<div className="relative w-full md:w-64">
|
||||||
|
<Input
|
||||||
|
prefix={<IconSearch />}
|
||||||
|
placeholder={t('关键字(id或者名称)')}
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={handleKeywordChange}
|
||||||
|
className="!rounded-full"
|
||||||
|
showClear
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
searchRedemptions(searchKeyword, 1, pageSize).then();
|
||||||
|
}}
|
||||||
|
loading={searching}
|
||||||
|
className="!rounded-full w-full md:w-auto"
|
||||||
|
>
|
||||||
|
{t('查询')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<EditRedemption
|
<EditRedemption
|
||||||
@@ -360,88 +490,45 @@ const RedemptionsTable = () => {
|
|||||||
visiable={showEdit}
|
visiable={showEdit}
|
||||||
handleClose={closeEdit}
|
handleClose={closeEdit}
|
||||||
></EditRedemption>
|
></EditRedemption>
|
||||||
<Form
|
|
||||||
onSubmit={() => {
|
|
||||||
searchRedemptions(searchKeyword, activePage, pageSize).then();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Form.Input
|
|
||||||
label={t('搜索关键字')}
|
|
||||||
field='keyword'
|
|
||||||
icon='search'
|
|
||||||
iconPosition='left'
|
|
||||||
placeholder={t('关键字(id或者名称)')}
|
|
||||||
value={searchKeyword}
|
|
||||||
loading={searching}
|
|
||||||
onChange={handleKeywordChange}
|
|
||||||
/>
|
|
||||||
</Form>
|
|
||||||
<Divider style={{ margin: '5px 0 15px 0' }} />
|
|
||||||
<div>
|
|
||||||
<Button
|
|
||||||
theme='light'
|
|
||||||
type='primary'
|
|
||||||
style={{ marginRight: 8 }}
|
|
||||||
onClick={() => {
|
|
||||||
setEditingRedemption({
|
|
||||||
id: undefined,
|
|
||||||
});
|
|
||||||
setShowEdit(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('添加兑换码')}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
label={t('复制所选兑换码')}
|
|
||||||
type='warning'
|
|
||||||
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>
|
|
||||||
|
|
||||||
<Table
|
<Card
|
||||||
style={{ marginTop: 20 }}
|
className="!rounded-2xl overflow-hidden"
|
||||||
columns={columns}
|
title={renderHeader()}
|
||||||
dataSource={pageData}
|
shadows='hover'
|
||||||
pagination={{
|
>
|
||||||
currentPage: activePage,
|
<Table
|
||||||
pageSize: pageSize,
|
columns={columns}
|
||||||
total: tokenCount,
|
dataSource={pageData}
|
||||||
showSizeChanger: true,
|
pagination={{
|
||||||
pageSizeOpts: [10, 20, 50, 100],
|
currentPage: activePage,
|
||||||
formatPageText: (page) =>
|
pageSize: pageSize,
|
||||||
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
total: tokenCount,
|
||||||
start: page.currentStart,
|
showSizeChanger: true,
|
||||||
end: page.currentEnd,
|
pageSizeOptions: [10, 20, 50, 100],
|
||||||
total: tokenCount,
|
formatPageText: (page) =>
|
||||||
}),
|
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
||||||
onPageSizeChange: (size) => {
|
start: page.currentStart,
|
||||||
setPageSize(size);
|
end: page.currentEnd,
|
||||||
setActivePage(1);
|
total: tokenCount,
|
||||||
if (searchKeyword === '') {
|
}),
|
||||||
loadRedemptions(1, size).then();
|
onPageSizeChange: (size) => {
|
||||||
} else {
|
setPageSize(size);
|
||||||
searchRedemptions(searchKeyword, 1, size).then();
|
setActivePage(1);
|
||||||
}
|
if (searchKeyword === '') {
|
||||||
},
|
loadRedemptions(1, size).then();
|
||||||
onPageChange: handlePageChange,
|
} else {
|
||||||
}}
|
searchRedemptions(searchKeyword, 1, size).then();
|
||||||
loading={loading}
|
}
|
||||||
rowSelection={rowSelection}
|
},
|
||||||
onRow={handleRow}
|
onPageChange: handlePageChange,
|
||||||
></Table>
|
}}
|
||||||
|
loading={loading}
|
||||||
|
rowSelection={rowSelection}
|
||||||
|
onRow={handleRow}
|
||||||
|
className="rounded-xl overflow-hidden"
|
||||||
|
size="middle"
|
||||||
|
></Table>
|
||||||
|
</Card>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1432,5 +1432,6 @@
|
|||||||
"30个": "30 items",
|
"30个": "30 items",
|
||||||
"100个": "100 items",
|
"100个": "100 items",
|
||||||
"Midjourney 任务记录": "Midjourney Task Records",
|
"Midjourney 任务记录": "Midjourney Task Records",
|
||||||
"任务记录": "Task Records"
|
"任务记录": "Task Records",
|
||||||
|
"兑换码可以批量生成和分发,适合用于推广活动或批量充值。": "Redemption codes can be batch generated and distributed, suitable for promotion activities or bulk recharge."
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import RedemptionsTable from '../../components/RedemptionsTable';
|
import RedemptionsTable from '../../components/RedemptionsTable';
|
||||||
import { Layout } from '@douyinfe/semi-ui';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
const Redemption = () => {
|
const Redemption = () => {
|
||||||
const { t } = useTranslation();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Layout>
|
<RedemptionsTable />
|
||||||
<Layout.Header>
|
|
||||||
<h3>{t('管理兑换码')}</h3>
|
|
||||||
</Layout.Header>
|
|
||||||
<Layout.Content>
|
|
||||||
<RedemptionsTable />
|
|
||||||
</Layout.Content>
|
|
||||||
</Layout>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import TokensTable from '../../components/TokensTable';
|
import TokensTable from '../../components/TokensTable';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
const Token = () => {
|
const Token = () => {
|
||||||
const { t } = useTranslation();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TokensTable />
|
<TokensTable />
|
||||||
|
|||||||
Reference in New Issue
Block a user