1
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button, Card, Form, Input, InputNumber, Modal, message, Select, Space, Switch, Tabs, Typography, Upload,
|
||||
Button, Card, Form, Input, InputNumber, message, Select, Space, Switch, Tabs, Typography, Upload,
|
||||
} from 'antd';
|
||||
import {
|
||||
SettingOutlined, SaveOutlined, UploadOutlined, FilePdfOutlined, EyeOutlined, DatabaseOutlined, PlusOutlined, VideoCameraOutlined, RobotOutlined,
|
||||
SettingOutlined, SaveOutlined, UploadOutlined, FilePdfOutlined, EyeOutlined, DatabaseOutlined, VideoCameraOutlined, RobotOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
createSystemConfig,
|
||||
@@ -28,8 +28,6 @@ const AdminSettings: React.FC = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [uploading, setUploading] = useState('');
|
||||
const [addModalOpen, setAddModalOpen] = useState(false);
|
||||
const [addForm] = Form.useForm();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -50,6 +48,8 @@ const AdminSettings: React.FC = () => {
|
||||
setConfigs(data);
|
||||
const formValues: Record<string, any> = {};
|
||||
data.forEach(c => { formValues[c.key] = c.value; });
|
||||
// 预扣积分默认值
|
||||
if (!formValues.optimize_hold_credits) formValues.optimize_hold_credits = '5';
|
||||
formValues.resource_capacity_enabled = capacity.enabled;
|
||||
formValues.resource_capacity_limit_value = capacity.limitValue || '1.000';
|
||||
formValues.resource_capacity_limit_unit = capacity.limitUnit || 'GB';
|
||||
@@ -71,6 +71,18 @@ const AdminSettings: React.FC = () => {
|
||||
await updateSystemConfig(config.id, String(newVal ?? ''));
|
||||
}
|
||||
}
|
||||
// AI创作预扣积分 - 不存在则创建
|
||||
const holdVal = values.optimize_hold_credits;
|
||||
if (holdVal !== undefined && holdVal !== null && holdVal !== '') {
|
||||
const existing = configs.find(c => c.key === 'optimize_hold_credits');
|
||||
if (existing) {
|
||||
if (String(holdVal) !== existing.value) {
|
||||
await updateSystemConfig(existing.id, String(holdVal));
|
||||
}
|
||||
} else {
|
||||
await createSystemConfig('optimize_hold_credits', String(holdVal), 'AI创作预扣积分数量(防止并发超卖)');
|
||||
}
|
||||
}
|
||||
await saveGlobalResourceCapacity({
|
||||
enabled: !!values.resource_capacity_enabled,
|
||||
limitValue: String(values.resource_capacity_limit_value ?? '1.000'),
|
||||
@@ -333,20 +345,6 @@ const AdminSettings: React.FC = () => {
|
||||
return <Input placeholder={config.description} size="large" />;
|
||||
};
|
||||
|
||||
const handleAddConfig = async () => {
|
||||
try {
|
||||
const values = await addForm.validateFields();
|
||||
const res = await createSystemConfig(values.key, values.value, values.description || '');
|
||||
setConfigs(prev => [...prev, res]);
|
||||
form.setFieldsValue({ [res.key]: res.value });
|
||||
setAddModalOpen(false);
|
||||
addForm.resetFields();
|
||||
message.success('配置已添加');
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '添加失败');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <Card loading variant="outlined" style={{ borderRadius: 12 }} />;
|
||||
}
|
||||
@@ -402,6 +400,14 @@ const AdminSettings: React.FC = () => {
|
||||
{getFieldComponent(config)}
|
||||
</Form.Item>
|
||||
))}
|
||||
{/* AI创作预扣积分 - 固定显示 */}
|
||||
<Form.Item
|
||||
name="optimize_hold_credits"
|
||||
label={<span style={{ fontWeight: 500 }}>AI创作预扣积分数量</span>}
|
||||
extra="AI创作时预扣积分数量,用于防止并发超卖。预扣后按实际消耗多退少补"
|
||||
>
|
||||
<Input type="number" min={1} placeholder="默认5" size="large" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
),
|
||||
@@ -536,34 +542,12 @@ const AdminSettings: React.FC = () => {
|
||||
<Tabs items={tabItems} defaultActiveKey="basic" />
|
||||
</Card>
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Button icon={<PlusOutlined />} onClick={() => setAddModalOpen(true)}>添加配置</Button>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<Button type="primary" icon={<SaveOutlined />} onClick={handleSave} loading={saving}
|
||||
size="large" style={{ borderRadius: 8, minWidth: 140 }}>
|
||||
保存配置
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
title="添加系统配置"
|
||||
open={addModalOpen}
|
||||
onOk={handleAddConfig}
|
||||
onCancel={() => { setAddModalOpen(false); addForm.resetFields(); }}
|
||||
okText="添加"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Form form={addForm} layout="vertical">
|
||||
<Form.Item name="key" label="配置键名" rules={[{ required: true, message: '请输入配置键名' }]}>
|
||||
<Input placeholder="例如: optimize_hold_credits" />
|
||||
</Form.Item>
|
||||
<Form.Item name="value" label="配置值" rules={[{ required: true, message: '请输入配置值' }]}>
|
||||
<Input placeholder="例如: 5" />
|
||||
</Form.Item>
|
||||
<Form.Item name="description" label="描述">
|
||||
<Input placeholder="配置说明(可选)" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user