优化前端

This commit is contained in:
yml2213
2026-06-26 10:56:25 +08:00
parent 88a386b588
commit 54b5bd90ae
39 changed files with 6796 additions and 216 deletions
+65
View File
@@ -0,0 +1,65 @@
import { ref } from 'vue'
import { useToast } from './useToast'
export interface Settings {
timeApiUrl: string
traceEnabled: boolean
traceMaxBody: number
logLevel: string
concurrency: number
attempts: number
}
const App = window.go.main.App
const settings = ref<Settings>({
timeApiUrl: '',
traceEnabled: false,
traceMaxBody: 0,
logLevel: 'info',
concurrency: 80,
attempts: 1
})
export function useSettings() {
const { showToast } = useToast()
const loadSettings = async () => {
try {
const cfg = await App.GetSettings()
settings.value = {
timeApiUrl: cfg.timeApiUrl || '',
traceEnabled: !!cfg.traceEnabled,
traceMaxBody: cfg.traceMaxBody || 0,
logLevel: cfg.logLevel || 'info',
concurrency: cfg.concurrency || 80,
attempts: cfg.attempts || 1
}
} catch (e: any) {
showToast('读取设置失败', e.message, 'error')
}
}
const saveSettings = async (newSettings: Settings) => {
try {
const d = await App.SaveSettings(newSettings)
if (d.success) {
settings.value = { ...newSettings }
showToast('设置已保存', '配置已生效', 'success')
return true
} else {
showToast('保存失败', d.error || '', 'error')
return false
}
} catch (e: any) {
showToast('保存失败', e.message, 'error')
return false
}
}
return {
settings,
loadSettings,
saveSettings
}
}