优化一些功能
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { GetSettings, SaveSettings } from '@wails/go/app/App'
|
||||
import { types } from '@wails/go/models'
|
||||
|
||||
export interface RetryStage {
|
||||
maxElapsed: number
|
||||
@@ -8,6 +10,7 @@ export interface RetryStage {
|
||||
|
||||
export interface Settings {
|
||||
timeApiUrl: string
|
||||
activity: string
|
||||
traceEnabled: boolean
|
||||
traceMaxBody: number
|
||||
logLevel: string
|
||||
@@ -17,8 +20,6 @@ export interface Settings {
|
||||
seckillMode: number // 0=标准, 1=激进
|
||||
}
|
||||
|
||||
const App = window.go.app.App
|
||||
|
||||
const defaultRetryStages: RetryStage[] = [
|
||||
{ maxElapsed: 4, interval: 120 },
|
||||
{ maxElapsed: 12, interval: 200 },
|
||||
@@ -28,11 +29,12 @@ const defaultRetryStages: RetryStage[] = [
|
||||
|
||||
const settings = ref<Settings>({
|
||||
timeApiUrl: '',
|
||||
activity: '',
|
||||
traceEnabled: false,
|
||||
traceMaxBody: 0,
|
||||
logLevel: 'info',
|
||||
concurrency: 150,
|
||||
attempts: 1,
|
||||
attempts: 2,
|
||||
retryStages: [...defaultRetryStages],
|
||||
seckillMode: 1
|
||||
})
|
||||
@@ -42,14 +44,15 @@ export function useSettings() {
|
||||
|
||||
const loadSettings = async () => {
|
||||
try {
|
||||
const cfg = await App.GetSettings()
|
||||
const cfg = await GetSettings()
|
||||
settings.value = {
|
||||
timeApiUrl: cfg.timeApiUrl || '',
|
||||
activity: cfg.activity || '',
|
||||
traceEnabled: !!cfg.traceEnabled,
|
||||
traceMaxBody: cfg.traceMaxBody || 0,
|
||||
logLevel: cfg.logLevel || 'info',
|
||||
concurrency: cfg.concurrency || 150,
|
||||
attempts: cfg.attempts || 1,
|
||||
attempts: cfg.attempts || 2,
|
||||
retryStages: cfg.retryStages && cfg.retryStages.length > 0
|
||||
? cfg.retryStages
|
||||
: [...defaultRetryStages],
|
||||
@@ -62,13 +65,13 @@ export function useSettings() {
|
||||
|
||||
const saveSettings = async (newSettings: Settings) => {
|
||||
try {
|
||||
const d = await App.SaveSettings(newSettings)
|
||||
const d = await SaveSettings(types.Config.createFrom(newSettings))
|
||||
if (d.success) {
|
||||
settings.value = { ...newSettings }
|
||||
showToast('设置已保存', '配置已生效', 'success')
|
||||
return true
|
||||
} else {
|
||||
showToast('保存失败', d.error || '', 'error')
|
||||
showToast('保存失败', '后端未返回成功状态', 'error')
|
||||
return false
|
||||
}
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user