用户生成资源容量管控
This commit is contained in:
@@ -13,6 +13,7 @@ import type {
|
||||
VideoPromptSchemaConfigOut, VideoPromptSchemaConfigSavePayload,
|
||||
VideoPromptSchemaPreviewPayload, VideoPromptSchemaPreviewOut, VideoPromptSchemaExportOut,
|
||||
AdminCreditRecordListResponse, AdminCreditRecordQueryParams,
|
||||
ResourceCapacityConfigOut, ResourceCapacityConfigPayload, AdminUserResourceCapacityOut,
|
||||
} from '../types';
|
||||
|
||||
// ── Auth ──────────────────────────────────────────────────
|
||||
@@ -149,6 +150,34 @@ export async function updateSystemConfig(id: string, value: string): Promise<voi
|
||||
await api.put(`/admin/system-configs/${id}`, { value });
|
||||
}
|
||||
|
||||
export async function getGlobalResourceCapacity(): Promise<ResourceCapacityConfigOut> {
|
||||
return api.get('/admin/resource-capacity/global');
|
||||
}
|
||||
|
||||
export async function saveGlobalResourceCapacity(payload: ResourceCapacityConfigPayload): Promise<ResourceCapacityConfigOut> {
|
||||
return api.put('/admin/resource-capacity/global', {
|
||||
enabled: payload.enabled,
|
||||
limit_value: payload.limitValue ?? null,
|
||||
limit_unit: payload.limitUnit ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUserResourceCapacity(userId: string): Promise<AdminUserResourceCapacityOut> {
|
||||
return api.get(`/admin/users/${userId}/resource-capacity`);
|
||||
}
|
||||
|
||||
export async function saveUserResourceCapacity(userId: string, payload: ResourceCapacityConfigPayload): Promise<AdminUserResourceCapacityOut> {
|
||||
return api.put(`/admin/users/${userId}/resource-capacity`, {
|
||||
enabled: payload.enabled,
|
||||
limit_value: payload.limitValue ?? null,
|
||||
limit_unit: payload.limitUnit ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteUserResourceCapacity(userId: string): Promise<AdminUserResourceCapacityOut> {
|
||||
return api.delete(`/admin/users/${userId}/resource-capacity`);
|
||||
}
|
||||
|
||||
export async function uploadPdf(file: File, configKey: string): Promise<{ url: string }> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button, Card, Form, Input, message, Space, Switch, Typography, Upload,
|
||||
Button, Card, Form, Input, InputNumber, message, Select, Space, Switch, Typography, Upload,
|
||||
} from 'antd';
|
||||
import {
|
||||
SettingOutlined, SaveOutlined, UploadOutlined, FilePdfOutlined, EyeOutlined,
|
||||
SettingOutlined, SaveOutlined, UploadOutlined, FilePdfOutlined, EyeOutlined, DatabaseOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { getSystemConfigs, updateSystemConfig, uploadPdf, uploadLogo } from '../api';
|
||||
import type { SystemConfig } from '../types';
|
||||
import {
|
||||
getGlobalResourceCapacity,
|
||||
getSystemConfigs,
|
||||
saveGlobalResourceCapacity,
|
||||
updateSystemConfig,
|
||||
uploadLogo,
|
||||
uploadPdf,
|
||||
} from '../api';
|
||||
import type { ResourceCapacityUnit, SystemConfig } from '../types';
|
||||
|
||||
const capacityUnitOptions: { value: ResourceCapacityUnit; label: string }[] = [
|
||||
{ value: 'MB', label: 'MB(1024 × 1024 字节)' },
|
||||
{ value: 'GB', label: 'GB(1024 × 1024 × 1024 字节)' },
|
||||
{ value: 'TB', label: 'TB(1024 × 1024 × 1024 × 1024 字节)' },
|
||||
];
|
||||
|
||||
const AdminSettings: React.FC = () => {
|
||||
const [configs, setConfigs] = useState<SystemConfig[]>([]);
|
||||
@@ -14,7 +27,6 @@ const AdminSettings: React.FC = () => {
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [uploading, setUploading] = useState('');
|
||||
const [form] = Form.useForm();
|
||||
const [logoPreview, setLogoPreview] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
@@ -22,12 +34,23 @@ const AdminSettings: React.FC = () => {
|
||||
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
const data = await getSystemConfigs();
|
||||
setConfigs(data);
|
||||
const formValues: Record<string, string> = {};
|
||||
data.forEach(c => { formValues[c.key] = c.value; });
|
||||
form.setFieldsValue(formValues);
|
||||
setLoading(false);
|
||||
try {
|
||||
const [data, capacity] = await Promise.all([
|
||||
getSystemConfigs(),
|
||||
getGlobalResourceCapacity(),
|
||||
]);
|
||||
setConfigs(data);
|
||||
const formValues: Record<string, any> = {};
|
||||
data.forEach(c => { formValues[c.key] = c.value; });
|
||||
formValues.resource_capacity_enabled = capacity.enabled;
|
||||
formValues.resource_capacity_limit_value = capacity.limitValue || '1.000';
|
||||
formValues.resource_capacity_limit_unit = capacity.limitUnit || 'GB';
|
||||
form.setFieldsValue(formValues);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '加载配置失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
@@ -36,17 +59,21 @@ const AdminSettings: React.FC = () => {
|
||||
setSaving(true);
|
||||
for (const config of configs) {
|
||||
const newVal = values[config.key];
|
||||
if (newVal !== undefined && newVal !== config.value) {
|
||||
await updateSystemConfig(config.id, newVal ?? '');
|
||||
if (newVal !== undefined && String(newVal) !== config.value) {
|
||||
await updateSystemConfig(config.id, String(newVal ?? ''));
|
||||
}
|
||||
}
|
||||
await saveGlobalResourceCapacity({
|
||||
enabled: !!values.resource_capacity_enabled,
|
||||
limitValue: String(values.resource_capacity_limit_value ?? '1.000'),
|
||||
limitUnit: values.resource_capacity_limit_unit || 'GB',
|
||||
});
|
||||
message.success('系统配置已保存');
|
||||
const data = await getSystemConfigs();
|
||||
setConfigs(data);
|
||||
setSaving(false);
|
||||
await load();
|
||||
} catch (e: any) {
|
||||
setSaving(false);
|
||||
message.error(e?.message || '保存失败');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,7 +81,6 @@ const AdminSettings: React.FC = () => {
|
||||
setUploading(configKey);
|
||||
try {
|
||||
const res = await uploadPdf(file, configKey);
|
||||
// Update local state
|
||||
setConfigs(prev => prev.map(c => c.key === configKey ? { ...c, value: res.url } : c));
|
||||
form.setFieldsValue({ [configKey]: res.url });
|
||||
message.success('PDF上传成功');
|
||||
@@ -63,24 +89,22 @@ const AdminSettings: React.FC = () => {
|
||||
} finally {
|
||||
setUploading('');
|
||||
}
|
||||
return false; // prevent default upload
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleLogoUpload = async (file: File) => {
|
||||
setUploading('site_logo');
|
||||
try {
|
||||
const res = await uploadLogo(file);
|
||||
// Update local state
|
||||
setConfigs(prev => prev.map(c => c.key === 'site_logo' ? { ...c, value: res.url } : c));
|
||||
form.setFieldsValue({ site_logo: res.url });
|
||||
setLogoPreview(res.url);
|
||||
message.success('Logo上传成功');
|
||||
} catch {
|
||||
message.error('上传失败');
|
||||
} finally {
|
||||
setUploading('');
|
||||
}
|
||||
return false; // prevent default upload
|
||||
return false;
|
||||
};
|
||||
|
||||
const groupedConfigs: Record<string, SystemConfig[]> = {
|
||||
@@ -106,37 +130,11 @@ const AdminSettings: React.FC = () => {
|
||||
return descMap[config.key] || config.description || '';
|
||||
};
|
||||
|
||||
const getFieldComponent = (config: SystemConfig) => {
|
||||
if (config.key === 'site_logo') {
|
||||
return <LogoUploadField config={config} />;
|
||||
}
|
||||
if (config.key === 'seo_description') {
|
||||
return <Input.TextArea rows={3} placeholder={config.description} size="large" />;
|
||||
}
|
||||
if (config.key === 'seo_keywords') {
|
||||
return <Input placeholder="关键词1, 关键词2, 关键词3" size="large" />;
|
||||
}
|
||||
if (config.key === 'user_login_credits_enabled') {
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<Switch defaultChecked={config.value === 'true'} />
|
||||
<Typography.Text type="secondary" style={{ fontSize: 13 }}>
|
||||
{config.value === 'true' ? '已启用' : '已禁用'}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (config.key === 'user_register_credits' || config.key === 'user_login_credits') {
|
||||
return <Input type="number" min={0} placeholder={config.description} size="large" />;
|
||||
}
|
||||
return <Input placeholder={config.description} size="large" />;
|
||||
};
|
||||
|
||||
const LogoUploadField: React.FC<{ config: SystemConfig }> = ({ config }) => {
|
||||
const hasLogo = config.value && config.value.startsWith('/uploads/');
|
||||
const baseUrl = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
|
||||
const logoUrl = hasLogo ? `${baseUrl}${config.value}` : '';
|
||||
|
||||
|
||||
const handleRemove = () => {
|
||||
setConfigs(prev => prev.map(c => c.key === 'site_logo' ? { ...c, value: '' } : c));
|
||||
form.setFieldsValue({ site_logo: '' });
|
||||
@@ -172,17 +170,17 @@ const AdminSettings: React.FC = () => {
|
||||
</div>
|
||||
{hasLogo ? (
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt="Logo预览"
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
maxHeight: 80,
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt="Logo预览"
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
maxHeight: 80,
|
||||
objectFit: 'contain',
|
||||
border: '1px solid #e2e8f0',
|
||||
borderRadius: 8,
|
||||
padding: 8,
|
||||
}}
|
||||
}}
|
||||
/>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 8 }}>
|
||||
建议尺寸:200x40px,支持 PNG、JPG 格式
|
||||
@@ -200,6 +198,7 @@ const AdminSettings: React.FC = () => {
|
||||
const PdfUploadField: React.FC<{ config: SystemConfig }> = ({ config }) => {
|
||||
const label = config.key === 'user_agreement_url' ? '用户协议' : '隐私政策';
|
||||
const hasFile = config.value && config.value.startsWith('/uploads/');
|
||||
const baseUrl = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
|
||||
return (
|
||||
<div style={{
|
||||
padding: '16px', borderRadius: 10,
|
||||
@@ -214,7 +213,7 @@ const AdminSettings: React.FC = () => {
|
||||
<Space>
|
||||
{hasFile && (
|
||||
<Button size="small" icon={<EyeOutlined />}
|
||||
onClick={() => window.open(`http://localhost:8000${config.value}`, '_blank')}>
|
||||
onClick={() => window.open(`${baseUrl}${config.value}`, '_blank')}>
|
||||
预览
|
||||
</Button>
|
||||
)}
|
||||
@@ -236,6 +235,32 @@ const AdminSettings: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const getFieldComponent = (config: SystemConfig) => {
|
||||
if (config.key === 'site_logo') {
|
||||
return <LogoUploadField config={config} />;
|
||||
}
|
||||
if (config.key === 'seo_description') {
|
||||
return <Input.TextArea rows={3} placeholder={config.description} size="large" />;
|
||||
}
|
||||
if (config.key === 'seo_keywords') {
|
||||
return <Input placeholder="关键词1, 关键词2, 关键词3" size="large" />;
|
||||
}
|
||||
if (config.key === 'user_login_credits_enabled') {
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<Switch defaultChecked={config.value === 'true'} />
|
||||
<Typography.Text type="secondary" style={{ fontSize: 13 }}>
|
||||
{config.value === 'true' ? '已启用' : '已禁用'}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (config.key === 'user_register_credits' || config.key === 'user_login_credits') {
|
||||
return <Input type="number" min={0} placeholder={config.description} size="large" />;
|
||||
}
|
||||
return <Input placeholder={config.description} size="large" />;
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <Card loading variant="outlined" style={{ borderRadius: 12 }} />;
|
||||
}
|
||||
@@ -282,6 +307,49 @@ const AdminSettings: React.FC = () => {
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div style={{ marginBottom: 4 }}>
|
||||
<Typography.Text strong style={{ fontSize: 14, display: 'block', marginBottom: 12, paddingBottom: 8, borderBottom: '1px solid #f0f0f5' }}>
|
||||
资源空间管控
|
||||
</Typography.Text>
|
||||
<div style={{ padding: 16, border: '1px solid #f0f0f5', borderRadius: 10, background: '#fafbfc' }}>
|
||||
<Space align="start" style={{ marginBottom: 16 }}>
|
||||
<DatabaseOutlined style={{ color: '#6366f1', fontSize: 18, marginTop: 2 }} />
|
||||
<div>
|
||||
<Typography.Text strong>全局生成资源容量上限</Typography.Text>
|
||||
<div style={{ color: '#64748b', fontSize: 13, marginTop: 4 }}>
|
||||
开启后会按用户当前有效资源占用量进行提交前拦截;用户个人配置存在时优先级高于全局配置。
|
||||
</div>
|
||||
</div>
|
||||
</Space>
|
||||
<Form.Item
|
||||
name="resource_capacity_enabled"
|
||||
label="启用全局容量管控"
|
||||
valuePropName="checked"
|
||||
extra="关闭时全局不限制;若用户设置了个人配置,则仍按用户个人配置优先判断。"
|
||||
>
|
||||
<Switch checkedChildren="开启" unCheckedChildren="关闭" />
|
||||
</Form.Item>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 180px', gap: 16 }}>
|
||||
<Form.Item
|
||||
name="resource_capacity_limit_value"
|
||||
label="容量数值"
|
||||
extra="最小为1,不能为负数,最多支持3位小数。"
|
||||
rules={[{ required: true, message: '请输入容量数值' }]}
|
||||
>
|
||||
<InputNumber min={1} precision={3} style={{ width: '100%' }} size="large" placeholder="例如 10.500" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="resource_capacity_limit_unit"
|
||||
label="容量单位"
|
||||
extra="MB / GB / TB 固定枚举"
|
||||
rules={[{ required: true, message: '请选择容量单位' }]}
|
||||
>
|
||||
<Select size="large" options={capacityUnitOptions} />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -1,14 +1,55 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button, Card, Checkbox, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch, Table, Tabs, Tag, Typography,
|
||||
Button, Card, Checkbox, Form, Input, InputNumber, message, Modal, Popconfirm, Progress, Select, Space, Switch, Table, Tabs, Tag, Typography,
|
||||
} from 'antd';
|
||||
import {
|
||||
UserOutlined, WalletOutlined, SearchOutlined, StopOutlined, CheckCircleOutlined, PlusOutlined, MenuOutlined, LockOutlined, SettingOutlined, SaveOutlined,
|
||||
UserOutlined, WalletOutlined, SearchOutlined, StopOutlined, CheckCircleOutlined, PlusOutlined, MenuOutlined, LockOutlined, SettingOutlined, SaveOutlined, DatabaseOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { getAdminUsers, adjustCredits, toggleUserStatus, createUser, updateUserMenus, getMenuConfigs, resetUserPassword, getSystemConfigs, updateSystemConfig, updateFrontendUserKind } from '../api';
|
||||
import type { AdminUser, SystemConfig } from '../types';
|
||||
import {
|
||||
adjustCredits,
|
||||
createUser,
|
||||
deleteUserResourceCapacity,
|
||||
getAdminUsers,
|
||||
getMenuConfigs,
|
||||
getSystemConfigs,
|
||||
getUserResourceCapacity,
|
||||
resetUserPassword,
|
||||
saveUserResourceCapacity,
|
||||
toggleUserStatus,
|
||||
updateFrontendUserKind,
|
||||
updateSystemConfig,
|
||||
updateUserMenus,
|
||||
} from '../api';
|
||||
import type { AdminUser, AdminUserResourceCapacityOut, ResourceCapacityUnit, ResourceCapacityUsage, SystemConfig } from '../types';
|
||||
import { formatDate } from '../utils/formatDate';
|
||||
|
||||
const capacityUnitOptions: { value: ResourceCapacityUnit; label: string }[] = [
|
||||
{ value: 'MB', label: 'MB(1024 × 1024 字节)' },
|
||||
{ value: 'GB', label: 'GB(1024 × 1024 × 1024 字节)' },
|
||||
{ value: 'TB', label: 'TB(1024 × 1024 × 1024 × 1024 字节)' },
|
||||
];
|
||||
|
||||
function formatBytes(bytes?: number | null): string {
|
||||
if (bytes === null || bytes === undefined) return '-';
|
||||
const value = Number(bytes || 0);
|
||||
if (value < 1024) return `${value} B`;
|
||||
const units = ['KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
let size = value;
|
||||
let unitIndex = -1;
|
||||
do {
|
||||
size /= 1024;
|
||||
unitIndex += 1;
|
||||
} while (size >= 1024 && unitIndex < units.length - 1);
|
||||
return `${size.toFixed(size >= 100 ? 0 : size >= 10 ? 1 : 2)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
function capacitySourceLabel(capacity?: ResourceCapacityUsage | null): string {
|
||||
if (!capacity || !capacity.enabled) return '未开启';
|
||||
if (capacity.source === 'user') return '个人';
|
||||
if (capacity.source === 'global') return '全局';
|
||||
return '未开启';
|
||||
}
|
||||
|
||||
const AdminUsers: React.FC = () => {
|
||||
const [users, setUsers] = useState<AdminUser[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -22,9 +63,13 @@ const AdminUsers: React.FC = () => {
|
||||
const [allMenus, setAllMenus] = useState<any[]>([]);
|
||||
const [checkedMenus, setCheckedMenus] = useState<string[]>([]);
|
||||
const [resetPwdModal, setResetPwdModal] = useState<{ open: boolean; user: AdminUser | null }>({ open: false, user: null });
|
||||
const [capacityModal, setCapacityModal] = useState<{ open: boolean; user: AdminUser | null; detail: AdminUserResourceCapacityOut | null }>({ open: false, user: null, detail: null });
|
||||
const [capacityLoading, setCapacityLoading] = useState(false);
|
||||
const [capacitySaving, setCapacitySaving] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [createForm] = Form.useForm();
|
||||
const [resetPwdForm] = Form.useForm();
|
||||
const [capacityForm] = Form.useForm();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(20);
|
||||
@@ -66,17 +111,17 @@ const AdminUsers: React.FC = () => {
|
||||
setConfigSaving(true);
|
||||
for (const config of creditConfigs) {
|
||||
const newVal = values[config.key];
|
||||
if (newVal !== undefined && newVal !== config.value) {
|
||||
await updateSystemConfig(config.id, newVal ?? '');
|
||||
if (newVal !== undefined && String(newVal) !== config.value) {
|
||||
await updateSystemConfig(config.id, String(newVal ?? ''));
|
||||
}
|
||||
}
|
||||
message.success('积分配置已保存');
|
||||
const configs = await getSystemConfigs();
|
||||
setCreditConfigs(configs.filter(c => c.key.startsWith('user_') && c.key.includes('credits')));
|
||||
setConfigSaving(false);
|
||||
} catch (e: any) {
|
||||
setConfigSaving(false);
|
||||
message.error(e?.message || '保存失败');
|
||||
} finally {
|
||||
setConfigSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -142,7 +187,65 @@ const AdminUsers: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Build structured menu display: groups with children, and top-level pages
|
||||
const openCapacityModal = async (user: AdminUser) => {
|
||||
setCapacityLoading(true);
|
||||
setCapacityModal({ open: true, user, detail: null });
|
||||
try {
|
||||
const detail = await getUserResourceCapacity(user.id);
|
||||
const initialConfig = detail.userConfig;
|
||||
capacityForm.setFieldsValue({
|
||||
enabled: initialConfig?.enabled ?? false,
|
||||
limitValue: initialConfig?.limitValue ?? detail.effective.limitValue ?? detail.globalConfig.limitValue ?? '1.000',
|
||||
limitUnit: initialConfig?.limitUnit ?? detail.effective.limitUnit ?? detail.globalConfig.limitUnit ?? 'GB',
|
||||
});
|
||||
setCapacityModal({ open: true, user, detail });
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '加载容量配置失败');
|
||||
setCapacityModal({ open: false, user: null, detail: null });
|
||||
} finally {
|
||||
setCapacityLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveCapacity = async () => {
|
||||
const { user } = capacityModal;
|
||||
if (!user) return;
|
||||
try {
|
||||
const values = await capacityForm.validateFields();
|
||||
setCapacitySaving(true);
|
||||
await saveUserResourceCapacity(user.id, {
|
||||
enabled: !!values.enabled,
|
||||
limitValue: String(values.limitValue ?? '1.000'),
|
||||
limitUnit: values.limitUnit || 'GB',
|
||||
});
|
||||
message.success('用户容量配置已保存');
|
||||
setCapacityModal({ open: false, user: null, detail: null });
|
||||
capacityForm.resetFields();
|
||||
load();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '保存失败');
|
||||
} finally {
|
||||
setCapacitySaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRestoreGlobalCapacity = async () => {
|
||||
const { user } = capacityModal;
|
||||
if (!user) return;
|
||||
try {
|
||||
setCapacitySaving(true);
|
||||
await deleteUserResourceCapacity(user.id);
|
||||
message.success('已恢复为全局容量配置');
|
||||
setCapacityModal({ open: false, user: null, detail: null });
|
||||
capacityForm.resetFields();
|
||||
load();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '恢复失败');
|
||||
} finally {
|
||||
setCapacitySaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const menuGroups = allMenus.filter((m: any) => (m.menu_type ?? m.menuType) === 'group');
|
||||
const menuPages = allMenus.filter((m: any) => (m.menu_type ?? m.menuType) !== 'group');
|
||||
const childMap: Record<string, any[]> = {};
|
||||
@@ -229,6 +332,36 @@ const AdminUsers: React.FC = () => {
|
||||
title: '前台归类', dataIndex: 'frontendUserKind', width: 110,
|
||||
render: (v: string) => <Tag color={v === 'internal' ? 'geekblue' : 'default'}>{v === 'internal' ? '内部用户' : '外部用户'}</Tag>,
|
||||
}] : []),
|
||||
...(!isAdminTab ? [{
|
||||
title: '资源容量', dataIndex: 'resourceCapacity', width: 230,
|
||||
render: (capacity: ResourceCapacityUsage | null | undefined) => {
|
||||
const usedText = formatBytes(capacity?.usedBytes || 0);
|
||||
if (!capacity || !capacity.enabled) {
|
||||
return (
|
||||
<div>
|
||||
<Space size={6} style={{ marginBottom: 4 }}>
|
||||
<Tag>未开启</Tag>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>已用 {usedText}</Typography.Text>
|
||||
</Space>
|
||||
<Progress percent={0} size="small" showInfo={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const percent = Math.min(Number(capacity.usagePercent || 0), 100);
|
||||
return (
|
||||
<div>
|
||||
<Space size={6} style={{ marginBottom: 4 }}>
|
||||
<Tag color={capacity.source === 'user' ? 'blue' : 'purple'}>{capacitySourceLabel(capacity)}</Tag>
|
||||
{capacity.exceeded && <Tag color="red">已超额</Tag>}
|
||||
</Space>
|
||||
<Progress percent={percent} size="small" status={capacity.exceeded ? 'exception' : 'active'} />
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{usedText} / {formatBytes(capacity.totalBytes)},可用 {formatBytes(capacity.availableBytes)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
}] : []),
|
||||
{
|
||||
title: '状态', dataIndex: 'isActive', width: 80,
|
||||
render: (v: boolean) => (
|
||||
@@ -244,15 +377,21 @@ const AdminUsers: React.FC = () => {
|
||||
render: (v: string) => <Typography.Text type="secondary" style={{ fontSize: 12 }}>{formatDate(v)}</Typography.Text>,
|
||||
},
|
||||
{
|
||||
title: '操作', key: 'action', width: 320, fixed: 'right' as const,
|
||||
title: '操作', key: 'action', width: 390, fixed: 'right' as const,
|
||||
render: (_: any, r: AdminUser) => (
|
||||
<Space size={4}>
|
||||
<Space size={4} wrap>
|
||||
{!isAdminTab && (
|
||||
<Button type="link" size="small" icon={<WalletOutlined />}
|
||||
onClick={() => { setCreditModal({ open: true, user: r }); form.resetFields(); }}>
|
||||
调整积分
|
||||
</Button>
|
||||
)}
|
||||
{!isAdminTab && (
|
||||
<Button type="link" size="small" icon={<DatabaseOutlined />}
|
||||
onClick={() => openCapacityModal(r)}>
|
||||
容量设置
|
||||
</Button>
|
||||
)}
|
||||
{!isAdminTab && r.frontendUserKind !== 'internal' && (
|
||||
<Button type="link" size="small" onClick={() => handleUpdateFrontendKind(r, 'internal')}>设为内部</Button>
|
||||
)}
|
||||
@@ -338,7 +477,6 @@ const AdminUsers: React.FC = () => {
|
||||
</Card>
|
||||
|
||||
<Card variant="outlined" style={{ borderRadius: 12, border: '1px solid #f0f0f5' }}>
|
||||
{/* Search bar */}
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<Input
|
||||
@@ -393,11 +531,10 @@ const AdminUsers: React.FC = () => {
|
||||
showSizeChanger: true,
|
||||
showTotal: (t) => `共 ${t} 个用户`,
|
||||
}}
|
||||
scroll={{ x: 1000 }}
|
||||
scroll={{ x: 1280 }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{/* Adjust Credits Modal */}
|
||||
<Modal
|
||||
title={<Space><WalletOutlined />调整积分 - {creditModal.user?.username}</Space>}
|
||||
open={creditModal.open}
|
||||
@@ -428,7 +565,77 @@ const AdminUsers: React.FC = () => {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* Create User Modal */}
|
||||
<Modal
|
||||
title={<Space><DatabaseOutlined />容量设置 - {capacityModal.user?.username}</Space>}
|
||||
open={capacityModal.open}
|
||||
confirmLoading={capacitySaving}
|
||||
onOk={handleSaveCapacity}
|
||||
onCancel={() => { setCapacityModal({ open: false, user: null, detail: null }); capacityForm.resetFields(); }}
|
||||
okText="保存个人配置" cancelText="取消" width={560}
|
||||
>
|
||||
<Card loading={capacityLoading} variant="outlined" style={{ marginBottom: 16 }}>
|
||||
<Space direction="vertical" size={6} style={{ width: '100%' }}>
|
||||
<Typography.Text type="secondary">
|
||||
当前生效来源:{capacitySourceLabel(capacityModal.detail?.effective)}
|
||||
{capacityModal.detail?.effective.hasUserConfig ? '(已单独设置)' : '(未单独设置)'}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
已用:{formatBytes(capacityModal.detail?.effective.usedBytes)};
|
||||
总量:{formatBytes(capacityModal.detail?.effective.totalBytes)};
|
||||
可用:{formatBytes(capacityModal.detail?.effective.availableBytes)}
|
||||
</Typography.Text>
|
||||
{capacityModal.detail?.effective.enabled && (
|
||||
<Progress
|
||||
percent={Math.min(Number(capacityModal.detail.effective.usagePercent || 0), 100)}
|
||||
status={capacityModal.detail.effective.exceeded ? 'exception' : 'active'}
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
</Card>
|
||||
<Form form={capacityForm} layout="vertical">
|
||||
<Form.Item
|
||||
name="enabled"
|
||||
label="启用个人容量限制"
|
||||
valuePropName="checked"
|
||||
extra="保存后会生成用户个人配置,优先级高于全局;关闭并保存表示该用户个人明确不限制,不再走全局。"
|
||||
>
|
||||
<Switch checkedChildren="开启" unCheckedChildren="关闭" />
|
||||
</Form.Item>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 180px', gap: 16 }}>
|
||||
<Form.Item
|
||||
name="limitValue"
|
||||
label="容量数值"
|
||||
rules={[{ required: true, message: '请输入容量数值' }]}
|
||||
extra="最小为1,不能为负数,最多支持3位小数。"
|
||||
>
|
||||
<InputNumber min={1} precision={3} style={{ width: '100%' }} size="large" placeholder="例如 10.500" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="limitUnit"
|
||||
label="容量单位"
|
||||
rules={[{ required: true, message: '请选择容量单位' }]}
|
||||
extra="MB / GB / TB 固定枚举"
|
||||
>
|
||||
<Select size="large" options={capacityUnitOptions} />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 8 }}>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
恢复全局设置会删除该用户个人配置,让用户重新按全局规则判断。
|
||||
</Typography.Text>
|
||||
<Popconfirm
|
||||
title="确定恢复为全局容量配置?"
|
||||
onConfirm={handleRestoreGlobalCapacity}
|
||||
disabled={!capacityModal.detail?.hasUserConfig}
|
||||
>
|
||||
<Button disabled={!capacityModal.detail?.hasUserConfig} loading={capacitySaving}>
|
||||
恢复全局设置
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={<Space><UserOutlined />创建用户</Space>}
|
||||
open={createModal}
|
||||
@@ -476,7 +683,6 @@ const AdminUsers: React.FC = () => {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* Menu Permission Modal */}
|
||||
<Modal
|
||||
title={<Space><MenuOutlined />菜单权限 - {menuModal.user?.username} ({menuModal.user?.userType === 'admin' ? '后台菜单' : '前台菜单'})</Space>}
|
||||
open={menuModal.open}
|
||||
@@ -492,14 +698,12 @@ const AdminUsers: React.FC = () => {
|
||||
<div style={{ padding: '12px 16px', background: '#f8fafc', borderRadius: 8, maxHeight: 400, overflow: 'auto' }}>
|
||||
<Checkbox.Group value={checkedMenus} onChange={(vals) => setCheckedMenus(vals as string[])}>
|
||||
<Space direction="vertical" size={8} style={{ width: '100%' }}>
|
||||
{/* Top-level pages */}
|
||||
{topLevelPages.map((m: any) => (
|
||||
<Checkbox key={m.path} value={m.path} style={{ width: '100%' }}>
|
||||
{m.label}
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12, marginLeft: 8 }}>{m.path}</Typography.Text>
|
||||
</Checkbox>
|
||||
))}
|
||||
{/* Groups with their children */}
|
||||
{menuGroups.map((g: any) => {
|
||||
const children = childMap[g.id] || [];
|
||||
if (children.length === 0) return null;
|
||||
@@ -524,7 +728,6 @@ const AdminUsers: React.FC = () => {
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
{/* Reset Password Modal */}
|
||||
<Modal
|
||||
title={<Space><LockOutlined />重置密码 - {resetPwdModal.user?.username}</Space>}
|
||||
open={resetPwdModal.open}
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface User {
|
||||
isAdmin: boolean;
|
||||
userType: string;
|
||||
allowedMenus?: string[] | null;
|
||||
resourceCapacity?: ResourceCapacityUsage | null;
|
||||
}
|
||||
|
||||
export interface CreditRecord {
|
||||
@@ -93,6 +94,43 @@ export interface LoginParams {
|
||||
password: string;
|
||||
}
|
||||
|
||||
|
||||
export type ResourceCapacityUnit = 'MB' | 'GB' | 'TB';
|
||||
export type ResourceCapacitySource = 'user' | 'global' | 'disabled';
|
||||
|
||||
export interface ResourceCapacityUsage {
|
||||
enabled: boolean;
|
||||
source: ResourceCapacitySource;
|
||||
hasUserConfig: boolean;
|
||||
usedBytes: number;
|
||||
availableBytes: number | null;
|
||||
totalBytes: number | null;
|
||||
usagePercent: number | null;
|
||||
exceeded: boolean;
|
||||
limitValue: string | null;
|
||||
limitUnit: ResourceCapacityUnit | null;
|
||||
}
|
||||
|
||||
export interface ResourceCapacityConfigOut {
|
||||
enabled: boolean;
|
||||
limitValue: string;
|
||||
limitUnit: ResourceCapacityUnit;
|
||||
limitBytes: number;
|
||||
}
|
||||
|
||||
export interface ResourceCapacityConfigPayload {
|
||||
enabled: boolean;
|
||||
limitValue?: string | number | null;
|
||||
limitUnit?: ResourceCapacityUnit | null;
|
||||
}
|
||||
|
||||
export interface AdminUserResourceCapacityOut {
|
||||
hasUserConfig: boolean;
|
||||
userConfig: ResourceCapacityConfigOut | null;
|
||||
globalConfig: ResourceCapacityConfigOut;
|
||||
effective: ResourceCapacityUsage;
|
||||
}
|
||||
|
||||
// ── Admin Types ──────────────────────────────────────
|
||||
|
||||
export interface AdminUser {
|
||||
@@ -108,6 +146,7 @@ export interface AdminUser {
|
||||
createdAt: string;
|
||||
lastLoginAt?: string;
|
||||
allowedMenus?: string[] | null;
|
||||
resourceCapacity?: ResourceCapacityUsage | null;
|
||||
}
|
||||
|
||||
export interface AdminStats {
|
||||
|
||||
Reference in New Issue
Block a user