2026-03-30 02:56:16 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2026-02-28 15:29:12 +08:00
|
|
|
import { PageContainer } from '@ant-design/pro-components';
|
2026-03-30 02:56:16 +00:00
|
|
|
import { Table, Input, Button, message, Card, Space } from 'antd';
|
2026-02-28 15:29:12 +08:00
|
|
|
import { listConfigs, updateConfig } from '@/services/api';
|
2026-03-30 02:56:16 +00:00
|
|
|
import type { SystemConfig } from '@/types/api';
|
|
|
|
|
import type { ColumnsType } from 'antd/es/table';
|
2026-02-28 15:29:12 +08:00
|
|
|
|
|
|
|
|
const ConfigsPage: React.FC = () => {
|
2026-03-30 02:56:16 +00:00
|
|
|
const [data, setData] = useState<SystemConfig[]>([]);
|
2026-02-28 15:29:12 +08:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [editingKey, setEditingKey] = useState('');
|
|
|
|
|
const [editValue, setEditValue] = useState('');
|
|
|
|
|
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const res = await listConfigs();
|
|
|
|
|
if (res?.code === 0) setData(res.data?.list || []);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => { fetchData(); }, []);
|
|
|
|
|
|
|
|
|
|
const handleSave = async (key: string) => {
|
|
|
|
|
const res = await updateConfig(key, editValue);
|
|
|
|
|
if (res?.code === 0) {
|
|
|
|
|
message.success('更新成功');
|
|
|
|
|
setEditingKey('');
|
|
|
|
|
fetchData();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
const columns: ColumnsType<SystemConfig> = [
|
2026-02-28 15:29:12 +08:00
|
|
|
{ title: '配置名称', dataIndex: 'configName', key: 'configName' },
|
|
|
|
|
{ title: '配置键', dataIndex: 'configKey', key: 'configKey' },
|
|
|
|
|
{
|
2026-03-30 02:56:16 +00:00
|
|
|
title: '配置值',
|
|
|
|
|
dataIndex: 'configValue',
|
|
|
|
|
key: 'configValue',
|
|
|
|
|
render: (v, record) =>
|
2026-02-28 15:29:12 +08:00
|
|
|
editingKey === record.configKey
|
|
|
|
|
? <Input value={editValue} onChange={(e) => setEditValue(e.target.value)} style={{ width: 300 }} />
|
|
|
|
|
: v,
|
|
|
|
|
},
|
|
|
|
|
{ title: '分组', dataIndex: 'configGroup', key: 'configGroup' },
|
|
|
|
|
{ title: '备注', dataIndex: 'remark', key: 'remark', ellipsis: true },
|
|
|
|
|
{
|
2026-03-30 02:56:16 +00:00
|
|
|
title: '操作',
|
|
|
|
|
key: 'action',
|
|
|
|
|
render: (_, record) =>
|
|
|
|
|
editingKey === record.configKey ? (
|
|
|
|
|
<Space>
|
|
|
|
|
<a onClick={() => handleSave(record.configKey)}>保存</a>
|
|
|
|
|
<a onClick={() => setEditingKey('')}>取消</a>
|
|
|
|
|
</Space>
|
|
|
|
|
) : (
|
|
|
|
|
<a onClick={() => { setEditingKey(record.configKey); setEditValue(record.configValue); }}>编辑</a>
|
|
|
|
|
),
|
2026-02-28 15:29:12 +08:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PageContainer>
|
2026-03-30 02:56:16 +00:00
|
|
|
<Card bordered={false}>
|
|
|
|
|
<Table<SystemConfig>
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={data}
|
|
|
|
|
rowKey="configKey"
|
|
|
|
|
loading={loading}
|
|
|
|
|
pagination={false}
|
|
|
|
|
/>
|
2026-02-28 15:29:12 +08:00
|
|
|
</Card>
|
|
|
|
|
</PageContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ConfigsPage;
|