From 3c52735ad6bdc725b1794c031254a14334c0807f Mon Sep 17 00:00:00 2001 From: zhanjunhao <642307404@qq.com> Date: Wed, 25 Nov 2026 16:17:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(console/usage-record):=20=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E5=85=91=E6=8D=A2=E7=A0=81=E4=B8=8E=E6=B8=A0=E9=81=93=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=85=91=E6=8D=A2=E7=A0=81?= =?UTF-8?q?=E4=BE=A7=E6=A0=8F=E7=AA=97=E5=B9=B6=E5=9B=BA=E5=AE=9A=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E8=AE=B0=E5=BD=95=E9=A6=96=E5=B0=BE=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/CHANGELOG.md | 32 ++ docs/ui/CONSOLE_SPEC.md | 4 +- docs/ui/USER_CENTER_SPEC.md | 4 +- src/components/console/module-alignment.css | 12 + .../table/redemptions/RedemptionsActions.jsx | 33 +- .../redemptions/RedemptionsColumnDefs.jsx | 172 +++--- .../table/redemptions/RedemptionsTable.jsx | 61 +-- src/components/table/redemptions/index.jsx | 39 +- .../modals/EditRedemptionModal.jsx | 512 ++++++++---------- .../modals/RedemptionDetailsModal.jsx | 67 +++ .../table/redemptions/redemptions.css | 148 +++++ .../table/usage-logs/UsageLogsColumnDefs.jsx | 6 +- .../table/usage-logs/UsageLogsTable.jsx | 13 +- src/constants/redemption.constants.js | 6 +- src/hooks/redemptions/useRedemptionsData.jsx | 47 +- src/i18n/locales/en.json | 3 + src/i18n/locales/fr.json | 3 + src/i18n/locales/ja.json | 3 + src/i18n/locales/ko.json | 3 + src/i18n/locales/ru.json | 3 + src/i18n/locales/th.json | 3 + src/i18n/locales/vi.json | 3 + src/i18n/locales/zh-TW.json | 3 + src/i18n/locales/zh.json | 3 + 24 files changed, 674 insertions(+), 509 deletions(-) create mode 100644 src/components/table/redemptions/modals/RedemptionDetailsModal.jsx create mode 100644 src/components/table/redemptions/redemptions.css diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index efcb8f00..8aea4634 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,38 @@ ## 2026-11-25 +### 优化 · 消费记录固定首尾列 + +- **范围**:用户中心 `/user-center/usage-record` 的消费记录调用明细。 +- **变更**:时间列固定在左侧,操作列显示时固定在右侧。 +- **影响**:横向滚动中间字段时,仍可读取时间并打开账单详情。 +- **回滚**:还原消费记录时间列和操作列的固定配置。 +- **关联**:`src/components/table/usage-logs/`、`docs/ui/USER_CENTER_SPEC.md`。 + +### 优化 · 兑换码编辑侧栏窗 + +- **范围**:控制台 `/console/redemption` 编辑入口。 +- **变更**:编辑兑换码信息与添加兑换码共用右侧侧栏窗。 +- **影响**:两种表单使用相同的宽度、关闭方式和页脚,编辑继续回填当前记录。 +- **回滚**:还原兑换码编辑表单的独立弹窗。 +- **关联**:`src/components/table/redemptions/modals/EditRedemptionModal.jsx`、`docs/ui/CONSOLE_SPEC.md`。 + +### 优化 · 兑换码列表行内操作 + +- **范围**:控制台 `/console/redemption` 表格操作列。 +- **变更**:「查看详情」入口简化为「查看」,启用、禁用和删除从更多菜单移至行内,按钮单行排列并随操作列固定在右侧。 +- **影响**:桌面与窄屏均可直接使用行操作,启停权限和删除确认沿用原规则。 +- **回滚**:还原兑换码操作列按钮、宽度和换行样式。 +- **关联**:`src/components/table/redemptions/`、`docs/ui/CONSOLE_SPEC.md`。 + +### 优化 · 兑换码列表与表单 + +- **范围**:控制台 `/console/redemption` 与 `/console/channel` 的表头。 +- **变更**:沿用渠道列表的表格与行内操作样式,提升两页表头文字对比度,固定兑换码操作列,新增同页详情弹窗,统一添加侧栏窗与编辑弹窗的表单及页脚。 +- **影响**:可在详情弹窗查看与复制原码,批量复制随选中态启用,清除失效操作保留二次确认。 +- **回滚**:还原兑换码列表、表单、详情弹窗和对应样式与文案。 +- **关联**:`src/components/table/redemptions/`、`docs/ui/CONSOLE_SPEC.md`。 + ### 修复 · 控制台数据看板持续加载 - **范围**:控制台 `/console/analytics` 运营看板、创作作品详情抽屉及公共 API 的只读请求。 diff --git a/docs/ui/CONSOLE_SPEC.md b/docs/ui/CONSOLE_SPEC.md index da65f564..6d6b4c3b 100644 --- a/docs/ui/CONSOLE_SPEC.md +++ b/docs/ui/CONSOLE_SPEC.md @@ -1,6 +1,6 @@ # 控制台 UI 规范(/console/\*) -> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-18 · 版本:v2.4 +> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-25 · 版本:v2.7 管理控制台 `/console/*` 的规范:统一页头、控制台原语与差异样式。 @@ -58,6 +58,8 @@ - 提示栏:控制台内的 `Banner` / `Alert` 统一走 `ConsoleAlert`,内边距 12px 16px、正文 14 / 22px、图标 16px,颜色取对应语义 token。 - 系统设置(`page.key === 'setting'`):表单统一纵向布局、8px 标签间距、24px 栅格、控件等宽,校验信息预留高度;弹窗页脚按钮高 34px、间距 8px、右对齐。规则限定在 `.settings-page` / `.settings-form-dialog`。 - 控制台上下文中 `CompactModeToggle` 不渲染,表格密度状态保留;其他模块仍可使用紧凑模式。 +- 兑换码列表沿用渠道列表的行内链接按钮、右侧固定操作列和底部分页。「查看、复制、编辑、禁用/启用、删除」在同一行直接显示,保留既有权限和状态限制,删除仍需确认。窄屏横向滚动时操作列不换行。批量复制在选中兑换码后可用,清除失效兑换码由独立的危险操作确认承载。 +- 添加兑换码与编辑兑换码信息共用右侧侧栏窗、表单样式及页脚。查看详情使用弹窗,优先展示兑换码和状态,再列出额度、时间与兑换人信息。 - 平台 Skill 中心的分类标签区域与搜索工具栏同宽、左对齐,不保留独立的最大宽度和自动居中;窄屏按原间距自然换行。 - 平台 Skill 详情的审核工作台仅由抽屉正文纵向滚动,技能原文不设置独立滚动区;审核操作进入抽屉固定页脚,按钮右对齐、间距 8px,仅在审核页签展示。 - 官网文章抽屉允许点击遮罩关闭,X、取消、遮罩共用同一未保存内容确认流程。 diff --git a/docs/ui/USER_CENTER_SPEC.md b/docs/ui/USER_CENTER_SPEC.md index 33fe2c6c..4ed1b70d 100644 --- a/docs/ui/USER_CENTER_SPEC.md +++ b/docs/ui/USER_CENTER_SPEC.md @@ -1,6 +1,6 @@ # 用户中心 UI 规范(/user-center/\*) -> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-18 · 版本:v2.4 +> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-25 · 版本:v2.5 个人登录后用户中心页面的规范,只记录与公共规范不同的部分;密钥管理、服务监控见各自规范。 @@ -78,7 +78,7 @@ - 页签:纯文字页签(公共列表页签样式),与下方 20px,URL `?tab=` 同步并懒挂载。 - 筛选卡:5 列栅格,时间范围跨 2 列;背景使用 `--surface-card` 纯色(浅色为白色、深色为主题卡片色);操作“重置 / 搜索”右下。 - 列表卡:标题 15px / 600,导出、列设置位于卡头右侧;表头字重 400(公共标准为 500,待收敛)。 -- 消费记录调用明细为固定列宽宽表,时间分两行(日期 11px、时间 15px / 600),操作列文字“查看”,固定在右侧;横向滚动条保留 Ant Design 官方固定列表格行为,固定列兼容规则遵循公共规范第 5.2 节。 +- 消费记录调用明细为固定列宽宽表,横向滚动时“时间”列固定在左侧,“操作”列显示时固定在右侧,中间列可滚动。时间分两行(日期 11px、时间 15px / 600),固定列兼容规则遵循公共规范第 5.2 节。 - 消费记录“用时 / 首字”列宽 190px,总用时、首字耗时与流式状态分别用 antd 默认带描边 `Tag` 展示,保留主题算法生成的浅底 / 文字 / 边框。总用时对 `use_time` 取整数秒,`<101s` 用 `green`、`101–299s` 用 `gold`、`≥300s` 用 `magenta`;首字耗时取 `other.frt / 1000`,先保留一位小数再判色,`<3s` 用 `cyan`、`3–<10s` 用 `orange`、`≥10s` 用 `red`。流式显示三枚标签(状态为蓝色“流”),非流式仅显示总用时与中性“非流”;零值正常展示,缺失、非数值或负耗时显示中性破折号。 - 绘图与视频:三张统计卡(高 70px、间距 15px)+ 任务记录表。 - Webhook 示例为 `
` +“复制”链接,复制提示沿用原文案。
diff --git a/src/components/console/module-alignment.css b/src/components/console/module-alignment.css
index b3acabe6..884da4c4 100644
--- a/src/components/console/module-alignment.css
+++ b/src/components/console/module-alignment.css
@@ -59,6 +59,7 @@
 
 .console-page:is(
     [data-console-page='channel'],
+    [data-console-page='redemption'],
     [data-console-page='models'],
     [data-console-page='user'],
     [data-console-page='organizations'],
@@ -73,6 +74,17 @@
   font-weight: 400;
 }
 
+.console-page:is(
+    [data-console-page='channel'],
+    [data-console-page='redemption']
+  )
+  .console-table.ant-table-wrapper
+  .ant-table-thead
+  > tr
+  > th {
+  color: var(--console-text);
+}
+
 .console-model-drawer .ant-drawer-title > .ant-space {
   align-items: center;
 }
diff --git a/src/components/table/redemptions/RedemptionsActions.jsx b/src/components/table/redemptions/RedemptionsActions.jsx
index 43818cc6..cd2a2e48 100644
--- a/src/components/table/redemptions/RedemptionsActions.jsx
+++ b/src/components/table/redemptions/RedemptionsActions.jsx
@@ -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 (
     
- {isAdmin() && ( - +
+ - + manageRedemption( + record.id, + isUnused + ? REDEMPTION_ACTIONS.DISABLE + : REDEMPTION_ACTIONS.ENABLE, + record, + ) + } + > + {isUnused ? t('禁用') : t('启用')} + + )} + )} - +
); }, }, diff --git a/src/components/table/redemptions/RedemptionsTable.jsx b/src/components/table/redemptions/RedemptionsTable.jsx index 6253a732..f0c5dd4e 100644 --- a/src/components/table/redemptions/RedemptionsTable.jsx +++ b/src/components/table/redemptions/RedemptionsTable.jsx @@ -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 ( <> } - className='console-list-table overflow-hidden' + className='rounded-xl overflow-hidden' size='middle' /> + setDetailRecord(null)} + copyText={copyText} + t={t} + /> + setShowDeleteModal(false)} diff --git a/src/components/table/redemptions/index.jsx b/src/components/table/redemptions/index.jsx index e76c203f..702e853d 100644 --- a/src/components/table/redemptions/index.jsx +++ b/src/components/table/redemptions/index.jsx @@ -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 = () => { { /> } type='type1' - actionsArea={ -
- - -
+ descriptionArea={ + + } + tableActions={ + } paginationArea={createCardProPagination({ preservePage: true, + showRange: false, currentPage: redemptionsData.activePage, pageSize: redemptionsData.pageSize, total: redemptionsData.tokenCount, diff --git a/src/components/table/redemptions/modals/EditRedemptionModal.jsx b/src/components/table/redemptions/modals/EditRedemptionModal.jsx index c4d4cfe2..2c0928f7 100644 --- a/src/components/table/redemptions/modals/EditRedemptionModal.jsx +++ b/src/components/table/redemptions/modals/EditRedemptionModal.jsx @@ -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: ( +
+

{t('兑换码创建成功,是否下载兑换码?')}

+

{t('兑换码将以文本文件的形式下载,文件名为兑换码的名称。')}

+
+ ), + onOk: () => downloadTextAsFile(text, `${payload.name}.txt`), + }); } - Modal.confirm({ - title: t('兑换码创建成功'), - content: ( -
-

{t('兑换码创建成功,是否下载兑换码?')}

-

{t('兑换码将以文本文件的形式下载,文件名为兑换码的名称。')}

-
- ), - onOk: () => { - downloadTextAsFile(text, `${localInputs.name}.txt`); - }, - }); + } catch (error) { + if (!error.isAxiosError) showError(error.message); + } finally { + pending.current = false; + setSubmitting(false); } - setLoading(false); }; - return ( - <> - - {isEdit ? ( - - {t('更新')} - - ) : ( - - {t('新建')} - - )} - - {isEdit ? t('更新兑换码信息') : t('创建新的兑换码')} - - - } - bodyStyle={{ padding: '0' }} - visible={props.visiable} - width={isMobile ? '100%' : 600} - footer={ -
- - - - -
- } - closeIcon={null} - onCancel={() => handleCancel()} + const handleCancel = () => { + if (!pending.current) handleClose(); + }; + const footer = ( +
+ + +
+ ); + const form = ( + + formApi.current?.scrollToError()} + > + + + + + + + + + parseInt(value, 10) > 0 + ? Promise.resolve() + : Promise.reject(t('额度必须大于0')), + }, + ]} + showClear + /> + + {!isEdit && ( + + + parseInt(value, 10) > 0 + ? Promise.resolve() + : Promise.reject(t('生成数量必须大于0')), + }, + ]} + showClear + /> + )} - - -
- + + + + + + ); + + return ( + + {form} + ); }; diff --git a/src/components/table/redemptions/modals/RedemptionDetailsModal.jsx b/src/components/table/redemptions/modals/RedemptionDetailsModal.jsx new file mode 100644 index 00000000..1b780d01 --- /dev/null +++ b/src/components/table/redemptions/modals/RedemptionDetailsModal.jsx @@ -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 ( + {t('关闭')}} + destroyOnHidden + > + {record && ( +
+
+

{record.name}

+ {renderRedemptionStatus(record.status, record, t)} +
+
+
+ {t('兑换码')} + +
+ {record.key} +
+
+ {fields.map(([label, value]) => ( +
+
{label}
+
{value}
+
+ ))} +
+
+ )} +
+ ); +} diff --git a/src/components/table/redemptions/redemptions.css b/src/components/table/redemptions/redemptions.css new file mode 100644 index 00000000..116af21d --- /dev/null +++ b/src/components/table/redemptions/redemptions.css @@ -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; + } +} diff --git a/src/components/table/usage-logs/UsageLogsColumnDefs.jsx b/src/components/table/usage-logs/UsageLogsColumnDefs.jsx index 4632acaa..2fac2d61 100644 --- a/src/components/table/usage-logs/UsageLogsColumnDefs.jsx +++ b/src/components/table/usage-logs/UsageLogsColumnDefs.jsx @@ -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, diff --git a/src/components/table/usage-logs/UsageLogsTable.jsx b/src/components/table/usage-logs/UsageLogsTable.jsx index 05f0378a..c47b00d8 100644 --- a/src/components/table/usage-logs/UsageLogsTable.jsx +++ b/src/components/table/usage-logs/UsageLogsTable.jsx @@ -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' diff --git a/src/constants/redemption.constants.js b/src/constants/redemption.constants.js index 036d2af6..365a3d5c 100644 --- a/src/constants/redemption.constants.js +++ b/src/constants/redemption.constants.js @@ -7,15 +7,15 @@ export const REDEMPTION_STATUS = { // Redemption code status display mapping export const REDEMPTION_STATUS_MAP = { [REDEMPTION_STATUS.UNUSED]: { - color: 'green', + color: 'success', text: '未使用', }, [REDEMPTION_STATUS.DISABLED]: { - color: 'red', + color: 'error', text: '已禁用', }, [REDEMPTION_STATUS.USED]: { - color: 'grey', + color: 'default', text: '已使用', }, }; diff --git a/src/hooks/redemptions/useRedemptionsData.jsx b/src/hooks/redemptions/useRedemptionsData.jsx index 67dd3153..185c3d62 100644 --- a/src/hooks/redemptions/useRedemptionsData.jsx +++ b/src/hooks/redemptions/useRedemptionsData.jsx @@ -7,6 +7,7 @@ import { REDEMPTION_STATUS, } from '../../constants/redemption.constants'; import { Modal } from '@/components/ui'; +import { confirmTableAction } from '@/components/common/table/confirmTableAction'; import { useTranslation } from 'react-i18next'; import { useTableCompactMode } from '../common/useTableCompactMode'; @@ -185,28 +186,6 @@ export const useRedemptionsData = () => { }, }; - // Row style handling - using isExpired function - const handleRow = (record, index) => { - // Local isExpired function - const isExpired = (rec) => { - return ( - rec.status === REDEMPTION_STATUS.UNUSED && - rec.expired_time !== 0 && - rec.expired_time < Math.floor(Date.now() / 1000) - ); - }; - - if (record.status !== REDEMPTION_STATUS.UNUSED || isExpired(record)) { - return { - style: { - background: 'var(--ui-color-disabled-border)', - }, - }; - } else { - return {}; - } - }; - // Copy text const copyText = async (text) => { if (await copy(text)) { @@ -235,21 +214,28 @@ export const useRedemptionsData = () => { }; // Batch delete redemption codes (clear invalid) - const batchDeleteRedemptions = async () => { - Modal.confirm({ + const batchDeleteRedemptions = () => { + confirmTableAction({ title: t('确定清除所有失效兑换码?'), content: t('将删除已使用、已禁用及过期的兑换码,此操作不可撤销。'), + focusable: { autoFocusButton: 'cancel' }, onOk: async () => { setLoading(true); - const res = await API.delete('/api/redemption/invalid'); - const { success, message, data } = res.data; - if (success) { + try { + const res = await API.delete('/api/redemption/invalid'); + const { success, message, data } = res.data; + if (!success) { + showError(message); + return false; + } showSuccess(t('已删除 {{count}} 条失效兑换码', { count: data })); await refresh(); - } else { - showError(message); + } catch (error) { + if (!error.isAxiosError) showError(error.message); + return false; + } finally { + setLoading(false); } - setLoading(false); }, }); }; @@ -324,7 +310,6 @@ export const useRedemptionsData = () => { handlePageChange, handlePageSizeChange, rowSelection, - handleRow, closeEdit, getFormValues, diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index bfdbab8d..0b20c21b 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -1560,6 +1560,9 @@ "兑换": "Redeem", "兑换成功!": "Redemption successful!", "兑换额度": "Redeem", + "兑换码": "Redemption code", + "兑换码列表": "Redemption codes", + "编辑兑换码信息": "Edit redemption code", "兑换码充值": "Redemption code recharge", "兑换码创建成功": "Redemption Code Created", "兑换码创建成功,是否下载兑换码?": "Redemption code created successfully. Do you want to download it?", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index ee20af7c..d41fae7f 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -1512,6 +1512,9 @@ "兑换": "échange", "兑换成功!": "Échange réussi !", "兑换额度": "Utiliser", + "兑换码": "Code d’échange", + "兑换码列表": "Codes d’échange", + "编辑兑换码信息": "Modifier les informations du code d’échange", "兑换码充值": "Recharge par code d'échange", "兑换码创建成功": "Code d'échange créé", "兑换码创建成功,是否下载兑换码?": "Code d'échange créé avec succès. Voulez-vous le télécharger ?", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index d08a25fe..6e0a0e88 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -1560,6 +1560,9 @@ "兑换": "引き換え", "兑换成功!": "引き換えに成功しました", "兑换额度": "引き換え", + "兑换码": "引き換えコード", + "兑换码列表": "引き換えコード一覧", + "编辑兑换码信息": "引き換えコード情報を編集", "兑换码充值": "引き換えコードによるチャージ", "兑换码创建成功": "引き換えコードの作成に成功しました", "兑换码创建成功,是否下载兑换码?": "引き換えコードの作成に成功しました。ダウンロードしますか?", diff --git a/src/i18n/locales/ko.json b/src/i18n/locales/ko.json index ec30c00f..8852c7ba 100644 --- a/src/i18n/locales/ko.json +++ b/src/i18n/locales/ko.json @@ -1560,6 +1560,9 @@ "兑换": "교환", "兑换成功!": "교환되었습니다!", "兑换额度": "할당량 교환", + "兑换码": "교환 코드", + "兑换码列表": "교환 코드 목록", + "编辑兑换码信息": "교환 코드 정보 편집", "兑换码充值": "교환 코드 충전", "兑换码创建成功": "교환 코드가 생성되었습니다", "兑换码创建成功,是否下载兑换码?": "교환 코드가 생성되었습니다. 내려받으시겠습니까?", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 887995b2..fbedb8af 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -1532,6 +1532,9 @@ "兑换": "Обмен валюты", "兑换成功!": "Обмен успешен!", "兑换额度": "Обменять квоту", + "兑换码": "Код активации", + "兑换码列表": "Список кодов активации", + "编辑兑换码信息": "Редактировать данные кода активации", "兑换码充值": "Пополнение кодом купона", "兑换码创建成功": "Код купона успешно создан", "兑换码创建成功,是否下载兑换码?": "Код купона успешно создан, скачать код купона?", diff --git a/src/i18n/locales/th.json b/src/i18n/locales/th.json index ab605229..d23b8873 100644 --- a/src/i18n/locales/th.json +++ b/src/i18n/locales/th.json @@ -1560,6 +1560,9 @@ "兑换": "แลก", "兑换成功!": "แลกสำเร็จ!", "兑换额度": "แลก", + "兑换码": "รหัสแลก", + "兑换码列表": "รายการรหัสแลก", + "编辑兑换码信息": "แก้ไขข้อมูลรหัสแลก", "兑换码充值": "เติมเงินด้วยรหัสแลก", "兑换码创建成功": "สร้างรหัสแลกแล้ว", "兑换码创建成功,是否下载兑换码?": "สร้างรหัสแลกสำเร็จ ต้องการดาวน์โหลดหรือไม่?", diff --git a/src/i18n/locales/vi.json b/src/i18n/locales/vi.json index 54dd28e4..a43b1461 100644 --- a/src/i18n/locales/vi.json +++ b/src/i18n/locales/vi.json @@ -1560,6 +1560,9 @@ "兑换": "Đổi", "兑换成功!": "Đổi thành công!", "兑换额度": "Đổi", + "兑换码": "Mã đổi thưởng", + "兑换码列表": "Danh sách mã đổi thưởng", + "编辑兑换码信息": "Chỉnh sửa thông tin mã đổi thưởng", "兑换码充值": "Nạp tiền bằng mã đổi thưởng", "兑换码创建成功": "Đã tạo mã đổi thưởng", "兑换码创建成功,是否下载兑换码?": "Tạo mã đổi thưởng thành công. Bạn có muốn tải xuống không?", diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index 862fcc2d..fec388ec 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -1560,6 +1560,9 @@ "兑换": "兌換", "兑换成功!": "兌換成功!", "兑换额度": "兌換額度", + "兑换码": "兌換碼", + "兑换码列表": "兌換碼清單", + "编辑兑换码信息": "編輯兌換碼資訊", "兑换码充值": "兌換碼儲值", "兑换码创建成功": "兌換碼建立成功", "兑换码创建成功,是否下载兑换码?": "兌換碼建立成功,是否下載兌換碼?", diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index a552f911..3f0dc11e 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -1532,6 +1532,9 @@ "兑换": "兑换", "兑换成功!": "兑换成功!", "兑换额度": "兑换额度", + "兑换码": "兑换码", + "兑换码列表": "兑换码列表", + "编辑兑换码信息": "编辑兑换码信息", "兑换码充值": "兑换码充值", "兑换码创建成功": "兑换码创建成功", "兑换码创建成功,是否下载兑换码?": "兑换码创建成功,是否下载兑换码?",