/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import {
EyeOff as ActionEyeOff,
Eye as ActionEye,
Copy as ActionCopy,
BookOpen as ActionBookOpen,
HelpCircle as ActionHelpCircle,
Search as ActionSearch,
Plus as ActionPlus,
} from '@/components/common/icons/ActionIcons';
import { writeClipboardText } from '../../helpers/clipboard';
import TableEmpty from '../../components/common/table/TableEmpty';
import React, { useState, useRef, useEffect, useContext } from 'react';
import Table from '../../components/ui/CenterActionTable';
import {
Alert,
Button,
Card,
Drawer,
Empty,
Input,
Spin,
Switch,
Tag,
Tooltip,
} from 'antd';
import { Modal, Pagination } from '@/components/ui';
import { ShieldCheck } from 'lucide-react';
import Joyride, { STATUS, ACTIONS, EVENTS } from 'react-joyride';
import { useTokensData } from '../../hooks/tokens/useTokensData';
import EditTokenModal from '../../components/table/tokens/modals/EditTokenModal';
import {
API,
showError,
showInfo,
showSuccess,
getModelCategories,
} from '../../helpers';
import { useLocation, useNavigate } from 'react-router-dom';
import PageBackground from '../../components/common/PageBackground';
import UserCenterPageHeader from '../../components/common/UserCenterPageHeader';
import TableColumnSettings from '../../components/common/table/ColumnSettings';
import { CUSTOMER_SERVICE_OPEN_EVENT } from '../../components/customer-service';
import { StatusContext } from '../../context/Status';
import { UserContext } from '../../context/User';
import { isHeaderActionButtonVisible } from '../../helpers/navigationVisibility';
import {
flushCreationEvents,
trackCreationEvent,
} from '../../helpers/creationEvents';
import './key-management.css';
const KEY_MASK = '••••••••••••••••';
// 列宽按设计图 1582px 表格实测比例换算(table-layout: fixed 下按比例铺满)。
const COLUMN_WIDTHS = {
name: 150,
key: 300,
group: 150,
status: 100,
expired_time: 180,
quota: 100,
models: 100,
actions: 130,
};
// 列设置:只控制本页表格列的显示,不持久化、不改请求。
const COLUMN_OPTIONS = [
{ value: 'name', label: '名称' },
{ value: 'key', label: '密钥' },
{ value: 'group', label: '分组' },
{ value: 'status', label: '状态' },
{ value: 'expired_time', label: '过期时间' },
{ value: 'quota', label: '额度' },
{ value: 'models', label: '模型' },
{ value: 'actions', label: '操作' },
];
// 启用/禁用之外的状态在开关旁补充语义标签。
const extraStatusTag = {
3: { label: '已过期', color: 'error' },
4: { label: '已耗尽', color: 'warning' },
};
// Actions and values remain owned by useTokensData and the page.
const KeyTable = ({
tokens,
loading,
visibleColumns,
emptyText,
onCopy,
onEdit,
onToggle,
onDelete,
showKeys,
onToggleShowKey,
onViewModels,
t,
}) => {
const columns = [
{
title: t('名称'),
key: 'name',
dataIndex: 'name',
render: (name) => (
{name || t('未命名密钥')}
),
},
{
title: t('密钥'),
key: 'key',
render: (_, token) => {
const shown = !!showKeys[token.id];
return (