统一全系统资源加载、轻量趋势与缓存恢复
This commit is contained in:
@@ -4,6 +4,7 @@ import { Alert, App, Button, Form, Input, Modal, Select, Spin, Switch, Tag } fro
|
||||
import { SettingOutlined } from '@ant-design/icons';
|
||||
import { api } from './api';
|
||||
import { effectiveThinkingEffort, supportsThinkingEffort } from './analysisThinking';
|
||||
import { useDelayedIndicator } from './useDelayedBusy';
|
||||
|
||||
export type AnalysisModelProfile = { id: string; name: string; baseUrl: string; model: string; hasApiKey: boolean; thinkingEnabled: boolean; thinkingEffort: string };
|
||||
export type AnalysisModelSettings = { baseUrl: string; model: string; hasApiKey: boolean; revision: string; activeProfileId: string; thinkingEnabled: boolean; thinkingEffort: string; profiles: AnalysisModelProfile[] };
|
||||
@@ -19,6 +20,7 @@ export function AnalysisApiSettings({ onUnauthorized }: { onUnauthorized: (error
|
||||
useEffect(() => { if (!effortSupported) form.setFieldValue('thinkingEffort', 'auto'); }, [effortSupported, form]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const showLoading = useDelayedIndicator(loading, 150);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [settings, setSettings] = useState<AnalysisModelSettings>();
|
||||
@@ -26,10 +28,11 @@ export function AnalysisApiSettings({ onUnauthorized }: { onUnauthorized: (error
|
||||
const selectedProfile = settings?.profiles.find(profile => profile.id === profileId);
|
||||
const [notice, setNotice] = useState<{ type: 'success' | 'error'; text: string }>();
|
||||
const sequence = useRef(0);
|
||||
const submitLock = useRef(false);
|
||||
const close = () => { if (saving) return; sequence.current += 1; setOpen(false); form.resetFields(); setNotice(undefined); setTesting(false); };
|
||||
const load = async () => {
|
||||
const current = ++sequence.current;
|
||||
setOpen(true); setLoading(true); setSettings(undefined); setProfileId(undefined); setNotice(undefined); form.resetFields();
|
||||
setOpen(true); setLoading(true); setNotice(undefined);
|
||||
try {
|
||||
const value = await api.analysisSettings();
|
||||
if (sequence.current !== current) return;
|
||||
@@ -39,9 +42,10 @@ export function AnalysisApiSettings({ onUnauthorized }: { onUnauthorized: (error
|
||||
} finally { if (sequence.current === current) setLoading(false); }
|
||||
};
|
||||
const submit = async (test: boolean) => {
|
||||
if (!settings) return;
|
||||
if (!settings || submitLock.current) return;
|
||||
let values: AnalysisModelSettingsInput;
|
||||
try { values = await form.validateFields(); } catch { return; }
|
||||
submitLock.current = true;
|
||||
const current = sequence.current;
|
||||
setNotice(undefined); test ? setTesting(true) : setSaving(true);
|
||||
try {
|
||||
@@ -57,7 +61,7 @@ export function AnalysisApiSettings({ onUnauthorized }: { onUnauthorized: (error
|
||||
}
|
||||
} catch (error) {
|
||||
if (sequence.current === current && !onUnauthorized(error)) setNotice({ type: 'error', text: error instanceof Error ? error.message : '操作失败,请重试' });
|
||||
} finally { if (sequence.current === current) { setTesting(false); setSaving(false); } }
|
||||
} finally { submitLock.current = false; if (sequence.current === current) { setTesting(false); setSaving(false); } }
|
||||
};
|
||||
return <>
|
||||
<Button type="text" size="small" icon={<SettingOutlined />} onClick={() => void load()}>API 配置</Button>
|
||||
@@ -66,7 +70,7 @@ export function AnalysisApiSettings({ onUnauthorized }: { onUnauthorized: (error
|
||||
<Button loading={testing} disabled={loading || saving || !settings} onClick={() => void submit(true)}>测试连接</Button>
|
||||
<Button type="primary" loading={saving} disabled={loading || testing || !settings} onClick={() => void submit(false)}>保存并使用</Button>
|
||||
</>}>
|
||||
{loading ? <div style={{ padding: 32, textAlign: 'center' }}><Spin /></div> : <>
|
||||
{showLoading && !settings ? <div style={{ padding: 32, textAlign: 'center' }}><Spin /></div> : <>
|
||||
{settings && <div style={{ marginBottom: 20 }}>
|
||||
<div style={{ marginBottom: 8 }}>选择配置 <Tag color="blue">当前使用:{settings.profiles.find(profile => profile.id === settings.activeProfileId)?.name || settings.model}</Tag></div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
|
||||
Reference in New Issue
Block a user