feat(*): 对齐兑换码与渠道表格,统一兑换码侧栏窗并固定消费记录首尾列
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { Copy, Plus, Trash2 } from '@/components/common/icons/ActionIcons';
|
||||
import { Button } from '@/components/ui';
|
||||
import { isAdmin } from '../../../helpers';
|
||||
|
||||
const RedemptionsActions = ({
|
||||
selectedKeys,
|
||||
busy,
|
||||
setEditingRedemption,
|
||||
setShowEdit,
|
||||
batchCopyRedemptions,
|
||||
batchDeleteRedemptions,
|
||||
t,
|
||||
}) => {
|
||||
// Add new redemption code
|
||||
const [copying, setCopying] = useState(false);
|
||||
|
||||
const handleCopy = async () => {
|
||||
setCopying(true);
|
||||
try {
|
||||
await batchCopyRedemptions();
|
||||
} finally {
|
||||
setCopying(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddRedemption = () => {
|
||||
setEditingRedemption({
|
||||
id: undefined,
|
||||
@@ -21,14 +32,21 @@ const RedemptionsActions = ({
|
||||
|
||||
return (
|
||||
<div className='console-list-tool-actions'>
|
||||
<Button icon={<Copy size={16} />} onClick={batchCopyRedemptions}>
|
||||
<Button
|
||||
icon={<Copy size={16} aria-hidden />}
|
||||
disabled={busy || selectedKeys.length === 0}
|
||||
loading={copying}
|
||||
onClick={handleCopy}
|
||||
>
|
||||
{t('复制所选兑换码到剪贴板')}
|
||||
</Button>
|
||||
|
||||
{isAdmin() && (
|
||||
<Button
|
||||
type='danger'
|
||||
icon={<Trash2 size={16} />}
|
||||
danger
|
||||
className='redemption-invalid-action'
|
||||
disabled={busy}
|
||||
icon={<Trash2 size={16} aria-hidden />}
|
||||
onClick={batchDeleteRedemptions}
|
||||
>
|
||||
{t('清除失效兑换码')}
|
||||
@@ -37,7 +55,8 @@ const RedemptionsActions = ({
|
||||
{isAdmin() && (
|
||||
<Button
|
||||
type='primary'
|
||||
icon={<Plus size={16} />}
|
||||
className='console-create-action'
|
||||
icon={<Plus size={16} aria-hidden />}
|
||||
onClick={handleAddRedemption}
|
||||
>
|
||||
{t('添加兑换码')}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Tag, Button, Space, Popover, Dropdown } from '@/components/ui';
|
||||
import { IconMore } from '@/components/ui/icons';
|
||||
import {
|
||||
renderQuota,
|
||||
timestamp2string,
|
||||
isAdmin,
|
||||
hoverOrClickTrigger,
|
||||
} from '../../../helpers';
|
||||
import { Button, Tag, Tooltip } from 'antd';
|
||||
import { renderQuota, timestamp2string, isAdmin } from '../../../helpers';
|
||||
import {
|
||||
REDEMPTION_STATUS,
|
||||
REDEMPTION_STATUS_MAP,
|
||||
@@ -27,36 +21,23 @@ export const isExpired = (record) => {
|
||||
/**
|
||||
* Render timestamp
|
||||
*/
|
||||
const renderTimestamp = (timestamp) => {
|
||||
return <>{timestamp2string(timestamp)}</>;
|
||||
};
|
||||
export const formatRedemptionExpiry = (timestamp, t) =>
|
||||
timestamp === 0 ? t('永不过期') : timestamp2string(timestamp);
|
||||
|
||||
/**
|
||||
* Render redemption code status
|
||||
*/
|
||||
const renderStatus = (status, record, t) => {
|
||||
export const renderRedemptionStatus = (status, record, t) => {
|
||||
if (isExpired(record)) {
|
||||
return (
|
||||
<Tag color='orange' shape='circle'>
|
||||
{t('已过期')}
|
||||
</Tag>
|
||||
);
|
||||
return <Tag color='warning'>{t('已过期')}</Tag>;
|
||||
}
|
||||
|
||||
const statusConfig = REDEMPTION_STATUS_MAP[status];
|
||||
if (statusConfig) {
|
||||
return (
|
||||
<Tag color={statusConfig.color} shape='circle'>
|
||||
{t(statusConfig.text)}
|
||||
</Tag>
|
||||
);
|
||||
return <Tag color={statusConfig.color}>{t(statusConfig.text)}</Tag>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Tag color='black' shape='circle'>
|
||||
{t('未知状态')}
|
||||
</Tag>
|
||||
);
|
||||
return <Tag>{t('未知状态')}</Tag>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -68,115 +49,75 @@ export const getRedemptionsColumns = ({
|
||||
copyText,
|
||||
setEditingRedemption,
|
||||
setShowEdit,
|
||||
refresh,
|
||||
redemptions,
|
||||
activePage,
|
||||
showDetails,
|
||||
showDeleteRedemptionModal,
|
||||
}) => {
|
||||
return [
|
||||
{
|
||||
title: t('ID'),
|
||||
dataIndex: 'id',
|
||||
width: 72,
|
||||
},
|
||||
{
|
||||
title: t('名称'),
|
||||
dataIndex: 'name',
|
||||
width: 224,
|
||||
ellipsis: { showTitle: false },
|
||||
render: (name) => (
|
||||
<Tooltip title={name}>
|
||||
<span>{name}</span>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
render: (text, record) => {
|
||||
return <div>{renderStatus(text, record, t)}</div>;
|
||||
},
|
||||
width: 120,
|
||||
render: (status, record) => renderRedemptionStatus(status, record, t),
|
||||
},
|
||||
{
|
||||
title: t('额度'),
|
||||
dataIndex: 'quota',
|
||||
render: (text) => {
|
||||
return (
|
||||
<div>
|
||||
<Tag color='grey' shape='circle'>
|
||||
{renderQuota(parseInt(text))}
|
||||
</Tag>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
width: 128,
|
||||
align: 'right',
|
||||
render: (quota) => renderQuota(parseInt(quota)),
|
||||
},
|
||||
{
|
||||
title: t('创建时间'),
|
||||
dataIndex: 'created_time',
|
||||
render: (text) => {
|
||||
return <div>{renderTimestamp(text)}</div>;
|
||||
},
|
||||
width: 180,
|
||||
render: (timestamp) => timestamp2string(timestamp),
|
||||
},
|
||||
{
|
||||
title: t('过期时间'),
|
||||
dataIndex: 'expired_time',
|
||||
render: (text) => {
|
||||
return <div>{text === 0 ? t('永不过期') : renderTimestamp(text)}</div>;
|
||||
},
|
||||
width: 180,
|
||||
render: (timestamp) => formatRedemptionExpiry(timestamp, t),
|
||||
},
|
||||
{
|
||||
title: t('兑换人ID'),
|
||||
dataIndex: 'used_user_id',
|
||||
render: (text) => {
|
||||
return <div>{text === 0 ? t('无') : text}</div>;
|
||||
},
|
||||
width: 128,
|
||||
render: (id) => (id === 0 ? t('无') : id),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
dataIndex: 'operate',
|
||||
fixed: 'right',
|
||||
width: 205,
|
||||
render: (text, record) => {
|
||||
// Create dropdown menu items for more operations
|
||||
const moreMenuItems = [
|
||||
{
|
||||
node: 'item',
|
||||
name: t('删除'),
|
||||
type: 'danger',
|
||||
onClick: () => {
|
||||
showDeleteRedemptionModal(record);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (record.status === REDEMPTION_STATUS.UNUSED && !isExpired(record)) {
|
||||
moreMenuItems.push({
|
||||
node: 'item',
|
||||
name: t('禁用'),
|
||||
type: 'warning',
|
||||
onClick: () => {
|
||||
manageRedemption(record.id, REDEMPTION_ACTIONS.DISABLE, record);
|
||||
},
|
||||
});
|
||||
} else if (!isExpired(record)) {
|
||||
moreMenuItems.push({
|
||||
node: 'item',
|
||||
name: t('启用'),
|
||||
type: 'secondary',
|
||||
onClick: () => {
|
||||
manageRedemption(record.id, REDEMPTION_ACTIONS.ENABLE, record);
|
||||
},
|
||||
disabled: record.status === REDEMPTION_STATUS.USED,
|
||||
});
|
||||
}
|
||||
const isUnused = record.status === REDEMPTION_STATUS.UNUSED;
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Popover
|
||||
// 触屏必须 click:这是查看兑换码明文的唯一入口
|
||||
trigger={hoverOrClickTrigger()}
|
||||
content={record.key}
|
||||
style={{ padding: 20 }}
|
||||
position='top'
|
||||
>
|
||||
<Button type='tertiary' size='small'>
|
||||
{t('查看')}
|
||||
</Button>
|
||||
</Popover>
|
||||
<div className='console-module-row-actions redemption-row-actions'>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => showDetails(record)}
|
||||
>
|
||||
{t('查看')}
|
||||
</Button>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={async () => {
|
||||
await copyText(record.key);
|
||||
@@ -187,26 +128,45 @@ export const getRedemptionsColumns = ({
|
||||
{isAdmin() && (
|
||||
<>
|
||||
<Button
|
||||
type='tertiary'
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setEditingRedemption(record);
|
||||
setShowEdit(true);
|
||||
}}
|
||||
disabled={record.status !== REDEMPTION_STATUS.UNUSED}
|
||||
disabled={!isUnused}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Dropdown
|
||||
trigger='click'
|
||||
position='bottomRight'
|
||||
menu={moreMenuItems}
|
||||
{!isExpired(record) && (
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
disabled={record.status === REDEMPTION_STATUS.USED}
|
||||
onClick={() =>
|
||||
manageRedemption(
|
||||
record.id,
|
||||
isUnused
|
||||
? REDEMPTION_ACTIONS.DISABLE
|
||||
: REDEMPTION_ACTIONS.ENABLE,
|
||||
record,
|
||||
)
|
||||
}
|
||||
>
|
||||
{isUnused ? t('禁用') : t('启用')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
danger
|
||||
onClick={() => showDeleteRedemptionModal(record)}
|
||||
>
|
||||
<Button type='tertiary' size='small' icon={<IconMore />} />
|
||||
</Dropdown>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import TableEmpty from '../../common/table/TableEmpty';
|
||||
import CardTable from '../../common/ui/CardTable';
|
||||
import { getRedemptionsColumns } from './RedemptionsColumnDefs';
|
||||
import DeleteRedemptionModal from './modals/DeleteRedemptionModal';
|
||||
import RedemptionDetailsModal from './modals/RedemptionDetailsModal';
|
||||
|
||||
const SELECTION_COLUMN_WIDTH = 34;
|
||||
|
||||
const RedemptionsTable = (redemptionsData) => {
|
||||
const {
|
||||
redemptions,
|
||||
loading,
|
||||
searching,
|
||||
activePage,
|
||||
pageSize,
|
||||
tokenCount,
|
||||
compactMode,
|
||||
handlePageChange,
|
||||
rowSelection,
|
||||
handleRow,
|
||||
manageRedemption,
|
||||
copyText,
|
||||
setEditingRedemption,
|
||||
@@ -26,6 +25,7 @@ const RedemptionsTable = (redemptionsData) => {
|
||||
// Modal states
|
||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||
const [deletingRecord, setDeletingRecord] = useState(null);
|
||||
const [detailRecord, setDetailRecord] = useState(null);
|
||||
|
||||
// Handle show delete modal
|
||||
const showDeleteRedemptionModal = (record) => {
|
||||
@@ -40,49 +40,36 @@ const RedemptionsTable = (redemptionsData) => {
|
||||
copyText,
|
||||
setEditingRedemption,
|
||||
setShowEdit,
|
||||
refresh,
|
||||
redemptions,
|
||||
activePage,
|
||||
showDetails: setDetailRecord,
|
||||
showDeleteRedemptionModal,
|
||||
});
|
||||
|
||||
// Handle compact mode by removing fixed positioning
|
||||
const tableColumns = useMemo(() => {
|
||||
return compactMode
|
||||
? columns.map((col) => {
|
||||
if (col.dataIndex === 'operate') {
|
||||
const { fixed, ...rest } = col;
|
||||
return rest;
|
||||
}
|
||||
return col;
|
||||
})
|
||||
: columns;
|
||||
}, [compactMode, columns]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<CardTable
|
||||
columns={tableColumns}
|
||||
columns={columns}
|
||||
minScrollableWidth={SELECTION_COLUMN_WIDTH * 2}
|
||||
dataSource={redemptions}
|
||||
scroll={compactMode ? undefined : { x: 'max-content' }}
|
||||
pagination={{
|
||||
currentPage: activePage,
|
||||
pageSize: pageSize,
|
||||
total: tokenCount,
|
||||
showSizeChanger: true,
|
||||
pageSizeOptions: [10, 20, 50, 100],
|
||||
onPageSizeChange: redemptionsData.handlePageSizeChange,
|
||||
onPageChange: handlePageChange,
|
||||
}}
|
||||
scroll={{ x: 'max-content' }}
|
||||
hidePagination={true}
|
||||
loading={loading}
|
||||
rowSelection={rowSelection}
|
||||
onRow={handleRow}
|
||||
loading={loading || searching}
|
||||
rowSelection={{
|
||||
...rowSelection,
|
||||
fixed: true,
|
||||
columnWidth: SELECTION_COLUMN_WIDTH,
|
||||
}}
|
||||
empty={<TableEmpty />}
|
||||
className='console-list-table overflow-hidden'
|
||||
className='rounded-xl overflow-hidden'
|
||||
size='middle'
|
||||
/>
|
||||
|
||||
<RedemptionDetailsModal
|
||||
record={detailRecord}
|
||||
onClose={() => setDetailRecord(null)}
|
||||
copyText={copyText}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<DeleteRedemptionModal
|
||||
visible={showDeleteModal}
|
||||
onCancel={() => setShowDeleteModal(false)}
|
||||
|
||||
@@ -8,6 +8,8 @@ import EditRedemptionModal from './modals/EditRedemptionModal';
|
||||
import { useRedemptionsData } from '../../../hooks/redemptions/useRedemptionsData';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import { createCardProPagination } from '../../../helpers/utils';
|
||||
import '../../console/module-alignment.css';
|
||||
import './redemptions.css';
|
||||
|
||||
const RedemptionsPage = () => {
|
||||
const redemptionsData = useRedemptionsData();
|
||||
@@ -47,11 +49,12 @@ const RedemptionsPage = () => {
|
||||
<EditRedemptionModal
|
||||
refresh={refresh}
|
||||
editingRedemption={editingRedemption}
|
||||
visiable={showEdit}
|
||||
visible={showEdit}
|
||||
handleClose={closeEdit}
|
||||
/>
|
||||
|
||||
<CardPro
|
||||
tableTitle={t('兑换码列表')}
|
||||
searchArea={
|
||||
<RedemptionsFilters
|
||||
formInitValues={formInitValues}
|
||||
@@ -65,25 +68,27 @@ const RedemptionsPage = () => {
|
||||
/>
|
||||
}
|
||||
type='type1'
|
||||
actionsArea={
|
||||
<div className='console-list-tools'>
|
||||
<RedemptionsDescription
|
||||
compactMode={compactMode}
|
||||
setCompactMode={setCompactMode}
|
||||
t={t}
|
||||
/>
|
||||
<RedemptionsActions
|
||||
selectedKeys={selectedKeys}
|
||||
setEditingRedemption={setEditingRedemption}
|
||||
setShowEdit={setShowEdit}
|
||||
batchCopyRedemptions={batchCopyRedemptions}
|
||||
batchDeleteRedemptions={batchDeleteRedemptions}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
descriptionArea={
|
||||
<RedemptionsDescription
|
||||
compactMode={compactMode}
|
||||
setCompactMode={setCompactMode}
|
||||
t={t}
|
||||
/>
|
||||
}
|
||||
tableActions={
|
||||
<RedemptionsActions
|
||||
selectedKeys={selectedKeys}
|
||||
busy={loading || searching}
|
||||
setEditingRedemption={setEditingRedemption}
|
||||
setShowEdit={setShowEdit}
|
||||
batchCopyRedemptions={batchCopyRedemptions}
|
||||
batchDeleteRedemptions={batchDeleteRedemptions}
|
||||
t={t}
|
||||
/>
|
||||
}
|
||||
paginationArea={createCardProPagination({
|
||||
preservePage: true,
|
||||
showRange: false,
|
||||
currentPage: redemptionsData.activePage,
|
||||
pageSize: redemptionsData.pageSize,
|
||||
total: redemptionsData.tokenCount,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffectEvent } from '../../../../hooks/common/useEffectEvent';
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import React, { useEffect, useId, useRef, useState } from 'react';
|
||||
import { Button, Card, Col, Row, Spin } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
API,
|
||||
@@ -7,324 +7,238 @@ import {
|
||||
showError,
|
||||
showSuccess,
|
||||
renderQuota,
|
||||
} from '../../../../helpers';
|
||||
} from '@/helpers';
|
||||
import { FormQuotaInput } from '../../../common/ui/QuotaInput';
|
||||
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
SideSheet,
|
||||
Space,
|
||||
Spin,
|
||||
Typography,
|
||||
Card,
|
||||
Tag,
|
||||
Form,
|
||||
Avatar,
|
||||
Row,
|
||||
Col,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
IconCreditCard,
|
||||
IconSave,
|
||||
IconClose,
|
||||
IconGift,
|
||||
} from '@/components/ui/icons';
|
||||
import { Form, Modal, SideSheet } from '@/components/ui';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const initialValues = {
|
||||
name: '',
|
||||
quota: 100000,
|
||||
count: 1,
|
||||
expired_time: null,
|
||||
is_gift: false,
|
||||
};
|
||||
|
||||
const EditRedemptionModal = (props) => {
|
||||
const EditRedemptionModal = ({
|
||||
editingRedemption,
|
||||
visible,
|
||||
refresh,
|
||||
handleClose,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const isEdit = props.editingRedemption.id !== undefined;
|
||||
const [loading, setLoading] = useState(isEdit);
|
||||
const { id } = editingRedemption;
|
||||
const isEdit = id !== undefined;
|
||||
const isMobile = useIsMobile();
|
||||
const formApiRef = useRef(null);
|
||||
const formApi = useRef(null);
|
||||
const formId = useId();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loadedId, setLoadedId] = useState(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const pending = useRef(false);
|
||||
const formDisabled = loading || submitting || (isEdit && loadedId !== id);
|
||||
|
||||
const getInitValues = () => ({
|
||||
name: '',
|
||||
quota: 100000,
|
||||
count: 1,
|
||||
expired_time: null,
|
||||
is_gift: false,
|
||||
});
|
||||
useEffect(() => {
|
||||
if (!visible) return;
|
||||
|
||||
const handleCancel = () => {
|
||||
props.handleClose();
|
||||
};
|
||||
formApi.current?.reset();
|
||||
setLoadedId(null);
|
||||
setLoading(isEdit);
|
||||
if (!isEdit) return;
|
||||
|
||||
const loadRedemption = async () => {
|
||||
setLoading(true);
|
||||
let res = await API.get(`/api/redemption/${props.editingRedemption.id}`);
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (data.expired_time === 0) {
|
||||
data.expired_time = null;
|
||||
} else {
|
||||
data.expired_time = new Date(data.expired_time * 1000);
|
||||
}
|
||||
formApiRef.current?.setValues({ ...getInitValues(), ...data });
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
if (formApiRef.current) {
|
||||
if (isEdit) {
|
||||
loadRedemption();
|
||||
} else {
|
||||
formApiRef.current.setValues(getInitValues());
|
||||
let active = true;
|
||||
async function loadRedemption() {
|
||||
try {
|
||||
const { data: result } = await API.get(`/api/redemption/${id}`);
|
||||
if (!active) return;
|
||||
if (result.success) {
|
||||
const { expired_time, ...data } = result.data;
|
||||
formApi.current?.setValues({
|
||||
...initialValues,
|
||||
...data,
|
||||
expired_time:
|
||||
expired_time === 0 ? null : new Date(expired_time * 1000),
|
||||
});
|
||||
setLoadedId(id);
|
||||
} else {
|
||||
showError(result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
if (active && !error.isAxiosError) showError(error.message);
|
||||
} finally {
|
||||
if (active) setLoading(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, props.editingRedemption.id]);
|
||||
void loadRedemption();
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [id, isEdit, visible]);
|
||||
|
||||
const submit = async (values) => {
|
||||
let name = values.name;
|
||||
if (!isEdit && (!name || name === '')) {
|
||||
name = renderQuota(values.quota);
|
||||
}
|
||||
setLoading(true);
|
||||
let localInputs = { ...values };
|
||||
localInputs.count = parseInt(localInputs.count) || 0;
|
||||
localInputs.quota = parseInt(localInputs.quota) || 0;
|
||||
localInputs.name = name;
|
||||
if (!localInputs.expired_time) {
|
||||
localInputs.expired_time = 0;
|
||||
} else {
|
||||
localInputs.expired_time = Math.floor(
|
||||
localInputs.expired_time.getTime() / 1000,
|
||||
);
|
||||
}
|
||||
let res;
|
||||
if (isEdit) {
|
||||
res = await API.put(`/api/redemption/`, {
|
||||
...localInputs,
|
||||
id: parseInt(props.editingRedemption.id),
|
||||
});
|
||||
} else {
|
||||
res = await API.post(`/api/redemption/`, {
|
||||
...localInputs,
|
||||
});
|
||||
}
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (isEdit) {
|
||||
showSuccess(t('兑换码更新成功!'));
|
||||
props.refresh();
|
||||
props.handleClose();
|
||||
if (formDisabled || pending.current) return;
|
||||
pending.current = true;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const payload = {
|
||||
...values,
|
||||
name: !isEdit && !values.name ? renderQuota(values.quota) : values.name,
|
||||
count: parseInt(values.count) || 0,
|
||||
quota: parseInt(values.quota) || 0,
|
||||
expired_time: values.expired_time
|
||||
? Math.floor(values.expired_time.getTime() / 1000)
|
||||
: 0,
|
||||
};
|
||||
const res = isEdit
|
||||
? await API.put('/api/redemption/', { ...payload, id: parseInt(id) })
|
||||
: await API.post('/api/redemption/', payload);
|
||||
const { success, message, data } = res.data;
|
||||
|
||||
if (success) {
|
||||
showSuccess(isEdit ? t('兑换码更新成功!') : t('兑换码创建成功!'));
|
||||
refresh();
|
||||
handleClose();
|
||||
} else {
|
||||
showSuccess(t('兑换码创建成功!'));
|
||||
props.refresh();
|
||||
formApiRef.current?.setValues(getInitValues());
|
||||
props.handleClose();
|
||||
showError(message);
|
||||
}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
if (!isEdit && data) {
|
||||
let text = '';
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
text += data[i] + '\n';
|
||||
|
||||
if (!isEdit && data) {
|
||||
let text = '';
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
text += data[index] + '\n';
|
||||
}
|
||||
Modal.confirm({
|
||||
title: t('兑换码创建成功'),
|
||||
content: (
|
||||
<div>
|
||||
<p>{t('兑换码创建成功,是否下载兑换码?')}</p>
|
||||
<p>{t('兑换码将以文本文件的形式下载,文件名为兑换码的名称。')}</p>
|
||||
</div>
|
||||
),
|
||||
onOk: () => downloadTextAsFile(text, `${payload.name}.txt`),
|
||||
});
|
||||
}
|
||||
Modal.confirm({
|
||||
title: t('兑换码创建成功'),
|
||||
content: (
|
||||
<div>
|
||||
<p>{t('兑换码创建成功,是否下载兑换码?')}</p>
|
||||
<p>{t('兑换码将以文本文件的形式下载,文件名为兑换码的名称。')}</p>
|
||||
</div>
|
||||
),
|
||||
onOk: () => {
|
||||
downloadTextAsFile(text, `${localInputs.name}.txt`);
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (!error.isAxiosError) showError(error.message);
|
||||
} finally {
|
||||
pending.current = false;
|
||||
setSubmitting(false);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SideSheet
|
||||
placement={isEdit ? 'right' : 'left'}
|
||||
title={
|
||||
<Space>
|
||||
{isEdit ? (
|
||||
<Tag color='blue' shape='circle'>
|
||||
{t('更新')}
|
||||
</Tag>
|
||||
) : (
|
||||
<Tag color='green' shape='circle'>
|
||||
{t('新建')}
|
||||
</Tag>
|
||||
)}
|
||||
<Title heading={4} className='m-0'>
|
||||
{isEdit ? t('更新兑换码信息') : t('创建新的兑换码')}
|
||||
</Title>
|
||||
</Space>
|
||||
}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
visible={props.visiable}
|
||||
width={isMobile ? '100%' : 600}
|
||||
footer={
|
||||
<div className='flex justify-end'>
|
||||
<Space>
|
||||
<Button
|
||||
theme='solid'
|
||||
onClick={() => formApiRef.current?.submitForm()}
|
||||
icon={<IconSave />}
|
||||
loading={loading}
|
||||
>
|
||||
{t('提交')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
onClick={handleCancel}
|
||||
icon={<IconClose />}
|
||||
>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
}
|
||||
closeIcon={null}
|
||||
onCancel={() => handleCancel()}
|
||||
const handleCancel = () => {
|
||||
if (!pending.current) handleClose();
|
||||
};
|
||||
const footer = (
|
||||
<div className='console-dialog-actions redemption-form-actions'>
|
||||
<Button disabled={submitting} onClick={handleCancel}>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
type='primary'
|
||||
htmlType='submit'
|
||||
form={formId}
|
||||
disabled={formDisabled}
|
||||
loading={submitting}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={getInitValues()}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
onSubmit={submit}
|
||||
>
|
||||
{({ values }) => (
|
||||
<div className='p-2'>
|
||||
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
|
||||
{/* Header: Basic Info */}
|
||||
<div className='flex items-center mb-2'>
|
||||
<Avatar
|
||||
size='small'
|
||||
color='blue'
|
||||
className='mr-2 shadow-md'
|
||||
>
|
||||
<IconGift size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
{t('基本信息')}
|
||||
</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('设置兑换码的基本信息')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Row gutter={12}>
|
||||
<Col span={24}>
|
||||
<Form.Input
|
||||
field='name'
|
||||
label={t('名称')}
|
||||
placeholder={t('请输入名称')}
|
||||
style={{ width: '100%' }}
|
||||
rules={
|
||||
!isEdit
|
||||
? []
|
||||
: [{ required: true, message: t('请输入名称') }]
|
||||
}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Form.DatePicker
|
||||
field='expired_time'
|
||||
label={t('过期时间')}
|
||||
type='dateTime'
|
||||
placeholder={t('选择过期时间(可选,留空为永久)')}
|
||||
style={{ width: '100%' }}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
<Card className='!rounded-2xl shadow-sm border-0'>
|
||||
{/* Header: Quota Settings */}
|
||||
<div className='flex items-center mb-2'>
|
||||
<Avatar
|
||||
size='small'
|
||||
color='green'
|
||||
className='mr-2 shadow-md'
|
||||
>
|
||||
<IconCreditCard size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
{t('额度设置')}
|
||||
</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('设置兑换码的额度和数量')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Row gutter={12}>
|
||||
<Col span={12}>
|
||||
<FormQuotaInput
|
||||
field='quota'
|
||||
label={t('额度')}
|
||||
style={{ width: '100%' }}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入额度') },
|
||||
{
|
||||
validator: (rule, v) => {
|
||||
const num = parseInt(v, 10);
|
||||
return num > 0
|
||||
? Promise.resolve()
|
||||
: Promise.reject(t('额度必须大于0'));
|
||||
},
|
||||
},
|
||||
]}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
{!isEdit && (
|
||||
<Col span={12}>
|
||||
<Form.InputNumber
|
||||
field='count'
|
||||
label={t('生成数量')}
|
||||
min={1}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入生成数量') },
|
||||
{
|
||||
validator: (rule, v) => {
|
||||
const num = parseInt(v, 10);
|
||||
return num > 0
|
||||
? Promise.resolve()
|
||||
: Promise.reject(t('生成数量必须大于0'));
|
||||
},
|
||||
},
|
||||
]}
|
||||
style={{ width: '100%' }}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
)}
|
||||
</Row>
|
||||
<Form.Switch
|
||||
field='is_gift'
|
||||
label={t('赠送码')}
|
||||
extraText={t(
|
||||
'开启后兑换额度进入用户赠送钱包(运营赠送性质,计入分佣净消耗剔除);关闭则视为充值性质卡密,进入主余额',
|
||||
)}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
{t('提交')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
const form = (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
id={formId}
|
||||
name={formId}
|
||||
ref={formApi}
|
||||
className='redemption-form'
|
||||
initValues={initialValues}
|
||||
disabled={formDisabled}
|
||||
onSubmit={submit}
|
||||
onSubmitFail={() => formApi.current?.scrollToError()}
|
||||
>
|
||||
<Card size='small' title={t('基本信息')}>
|
||||
<Form.Input
|
||||
field='name'
|
||||
label={t('名称')}
|
||||
placeholder={t('请输入名称')}
|
||||
rules={isEdit ? [{ required: true, message: t('请输入名称') }] : []}
|
||||
className={isEdit ? 'redemption-validated-field' : undefined}
|
||||
showClear
|
||||
/>
|
||||
<Form.DatePicker
|
||||
field='expired_time'
|
||||
label={t('过期时间')}
|
||||
type='dateTime'
|
||||
placeholder={t('选择过期时间(可选,留空为永久)')}
|
||||
showClear
|
||||
/>
|
||||
</Card>
|
||||
<Card size='small' title={t('额度设置')}>
|
||||
<Row gutter={16}>
|
||||
<Col xs={24} sm={isEdit ? 24 : 12}>
|
||||
<FormQuotaInput
|
||||
field='quota'
|
||||
label={t('额度')}
|
||||
className='redemption-validated-field'
|
||||
rules={[
|
||||
{ required: true, message: t('请输入额度') },
|
||||
{
|
||||
validator: (rule, value) =>
|
||||
parseInt(value, 10) > 0
|
||||
? Promise.resolve()
|
||||
: Promise.reject(t('额度必须大于0')),
|
||||
},
|
||||
]}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
{!isEdit && (
|
||||
<Col xs={24} sm={12}>
|
||||
<Form.InputNumber
|
||||
field='count'
|
||||
label={t('生成数量')}
|
||||
className='redemption-validated-field'
|
||||
min={1}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入生成数量') },
|
||||
{
|
||||
validator: (rule, value) =>
|
||||
parseInt(value, 10) > 0
|
||||
? Promise.resolve()
|
||||
: Promise.reject(t('生成数量必须大于0')),
|
||||
},
|
||||
]}
|
||||
showClear
|
||||
/>
|
||||
</Col>
|
||||
)}
|
||||
</Form>
|
||||
</Spin>
|
||||
</SideSheet>
|
||||
</>
|
||||
</Row>
|
||||
<Form.Switch
|
||||
field='is_gift'
|
||||
label={t('赠送码')}
|
||||
extraText={t(
|
||||
'开启后兑换额度进入用户赠送钱包(运营赠送性质,计入分佣净消耗剔除);关闭则视为充值性质卡密,进入主余额',
|
||||
)}
|
||||
/>
|
||||
</Card>
|
||||
</Form>
|
||||
</Spin>
|
||||
);
|
||||
|
||||
return (
|
||||
<SideSheet
|
||||
placement='right'
|
||||
forceRender
|
||||
visible={visible}
|
||||
width={isMobile ? '100%' : 560}
|
||||
title={isEdit ? t('编辑兑换码信息') : t('添加兑换码')}
|
||||
footer={footer}
|
||||
onCancel={handleCancel}
|
||||
closable={!submitting}
|
||||
>
|
||||
{form}
|
||||
</SideSheet>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import React from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { Copy } from '@/components/common/icons/ActionIcons';
|
||||
import { Modal } from '@/components/ui';
|
||||
import { renderQuota, timestamp2string } from '@/helpers';
|
||||
import {
|
||||
formatRedemptionExpiry,
|
||||
renderRedemptionStatus,
|
||||
} from '../RedemptionsColumnDefs';
|
||||
|
||||
export default function RedemptionDetailsModal({
|
||||
record,
|
||||
onClose,
|
||||
copyText,
|
||||
t,
|
||||
}) {
|
||||
const fields = record
|
||||
? [
|
||||
[t('ID'), record.id],
|
||||
[t('额度'), renderQuota(parseInt(record.quota))],
|
||||
[t('创建时间'), timestamp2string(record.created_time)],
|
||||
[t('过期时间'), formatRedemptionExpiry(record.expired_time, t)],
|
||||
[t('兑换人ID'), record.used_user_id || t('无')],
|
||||
]
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Modal
|
||||
centered
|
||||
visible={Boolean(record)}
|
||||
title={t('查看详情')}
|
||||
onCancel={onClose}
|
||||
footer={<Button onClick={onClose}>{t('关闭')}</Button>}
|
||||
destroyOnHidden
|
||||
>
|
||||
{record && (
|
||||
<div className='redemption-details'>
|
||||
<div className='redemption-details-heading'>
|
||||
<h3>{record.name}</h3>
|
||||
{renderRedemptionStatus(record.status, record, t)}
|
||||
</div>
|
||||
<div className='redemption-code'>
|
||||
<div className='redemption-code-header'>
|
||||
<span>{t('兑换码')}</span>
|
||||
<Button
|
||||
icon={<Copy size={16} aria-hidden />}
|
||||
size='small'
|
||||
onClick={() => copyText(record.key)}
|
||||
>
|
||||
{t('复制')}
|
||||
</Button>
|
||||
</div>
|
||||
<code>{record.key}</code>
|
||||
</div>
|
||||
<dl className='redemption-details-fields'>
|
||||
{fields.map(([label, value]) => (
|
||||
<div key={label}>
|
||||
<dt>{label}</dt>
|
||||
<dd>{value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
.console-page[data-console-page='redemption']
|
||||
.console-table
|
||||
.ant-table-tbody
|
||||
> .ant-table-row
|
||||
> .ant-table-cell {
|
||||
height: 51px;
|
||||
}
|
||||
|
||||
.redemption-form {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.redemption-form .ant-card-small > .ant-card-head,
|
||||
.redemption-form .ant-card-small > .ant-card-body {
|
||||
padding-inline: 16px;
|
||||
}
|
||||
|
||||
.redemption-form .ant-card-small > .ant-card-body {
|
||||
padding-block: 16px;
|
||||
}
|
||||
|
||||
.redemption-form.console-form .ant-form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.redemption-form.console-form .ant-card-body > .ant-form-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.redemption-form.console-form .ant-form-item-label > label {
|
||||
color: var(--console-text, var(--ui-color-text-0));
|
||||
}
|
||||
|
||||
.redemption-form,
|
||||
.redemption-invalid-action {
|
||||
--redemption-error-text: color-mix(
|
||||
in srgb,
|
||||
var(--ui-color-danger) 65%,
|
||||
var(--console-text, var(--ui-color-text-0))
|
||||
);
|
||||
}
|
||||
|
||||
.redemption-form .ant-form-item .ant-form-item-explain-error,
|
||||
.redemption-form .ant-form-item-label > .ant-form-item-required::before,
|
||||
.console-page .redemption-invalid-action.ant-btn-dangerous:not(:disabled) {
|
||||
color: var(--redemption-error-text);
|
||||
}
|
||||
|
||||
.redemption-form :is(.ant-input-number, .ant-picker) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.redemption-validated-field .ant-form-item-control {
|
||||
min-block-size: 56px;
|
||||
}
|
||||
|
||||
.redemption-form-actions .ant-btn {
|
||||
min-inline-size: 72px;
|
||||
min-block-size: 34px;
|
||||
}
|
||||
|
||||
.redemption-details {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
padding-block: 8px;
|
||||
color: var(--console-text, var(--ui-color-text-0));
|
||||
}
|
||||
|
||||
.redemption-details-heading,
|
||||
.redemption-code-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.redemption-details-heading h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--console-heading, var(--ui-color-text-0));
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.redemption-details-heading .ant-tag {
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
|
||||
.redemption-code {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid var(--console-border, var(--ui-color-border));
|
||||
border-radius: 8px;
|
||||
background: var(--console-fill, var(--ui-color-fill-0));
|
||||
}
|
||||
|
||||
.redemption-code code {
|
||||
overflow-wrap: anywhere;
|
||||
user-select: all;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.redemption-details-fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px 20px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.redemption-details dt,
|
||||
.redemption-code-header > span {
|
||||
color: var(--console-text, var(--ui-color-text-0));
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.redemption-details dd {
|
||||
margin: 4px 0 0;
|
||||
overflow-wrap: anywhere;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.redemption-details-fields {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
.center-action-table .center-action-cell .redemption-row-actions {
|
||||
flex-wrap: nowrap;
|
||||
vertical-align: middle;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.redemption-row-actions .ant-btn {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.center-action-table .center-action-cell .redemption-row-actions {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.redemption-row-actions.console-module-row-actions .ant-btn-link {
|
||||
padding-inline: 2px;
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,11 @@ const applyUsageRecordPresentation = (
|
||||
};
|
||||
switch (column.key) {
|
||||
case COLUMN_KEYS.TIME:
|
||||
return { ...column, render: (text) => renderRecordTime(text) };
|
||||
return {
|
||||
...column,
|
||||
fixed: 'left',
|
||||
render: (text) => renderRecordTime(text),
|
||||
};
|
||||
case COLUMN_KEYS.USERNAME:
|
||||
return {
|
||||
...column,
|
||||
|
||||
@@ -390,16 +390,17 @@ const LogsTable = (logsData) => {
|
||||
);
|
||||
|
||||
const tableColumns = useMemo(() => {
|
||||
const baseColumns = compactMode
|
||||
? visibleColumnsList.map(({ fixed, ...rest }) => rest)
|
||||
: visibleColumnsList;
|
||||
const baseColumns =
|
||||
compactMode && !usageRecordMode
|
||||
? visibleColumnsList.map(({ fixed, ...rest }) => rest)
|
||||
: visibleColumnsList;
|
||||
if (!hasExpandableRows()) return baseColumns;
|
||||
return [
|
||||
...baseColumns,
|
||||
{
|
||||
title: usageRecordMode ? t('操作') : t('计费详情'),
|
||||
key: 'billingDetailAction',
|
||||
fixed: compactMode || usageRecordMode ? undefined : 'right',
|
||||
fixed: usageRecordMode || !compactMode ? 'right' : undefined,
|
||||
width: 120,
|
||||
render: (_, record) => {
|
||||
const canView =
|
||||
@@ -452,7 +453,9 @@ const LogsTable = (logsData) => {
|
||||
dataSource={logs}
|
||||
rowKey='key'
|
||||
loading={loading}
|
||||
scroll={compactMode ? undefined : { x: 'max-content' }}
|
||||
scroll={
|
||||
usageRecordMode || !compactMode ? { x: 'max-content' } : undefined
|
||||
}
|
||||
className={
|
||||
usageRecordMode
|
||||
? 'usage-logs-table usage-record-table'
|
||||
|
||||
Reference in New Issue
Block a user