diff --git a/static/app.js b/static/app.js index 128d5cd..5edf295 100644 --- a/static/app.js +++ b/static/app.js @@ -260,6 +260,7 @@ async function bootstrapApp() { personalizationStatus: '', personalizationError: '', personalizationMaxConsiderations: 10, + personalizationToggleUpdating: false, overlayPressActive: false, personalForm: { enabled: false, @@ -2197,6 +2198,42 @@ async function bootstrapApp() { this.overlayPressActive = false; }, + async handlePersonalizationToggle() { + if (this.personalizationToggleUpdating) { + return; + } + const newValue = !!this.personalForm.enabled; + const previousValue = !newValue; + this.personalizationToggleUpdating = true; + this.personalizationStatus = ''; + this.personalizationError = ''; + try { + const resp = await fetch('/api/personalization', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ enabled: newValue }) + }); + const result = await resp.json(); + if (!resp.ok || !result.success) { + throw new Error(result.error || '更新失败'); + } + const statusLabel = newValue ? '已启用' : '已停用'; + this.personalizationStatus = statusLabel; + setTimeout(() => { + if (this.personalizationStatus === statusLabel) { + this.personalizationStatus = ''; + } + }, 2000); + } catch (error) { + this.personalForm.enabled = previousValue; + this.personalizationError = error.message || '更新失败'; + } finally { + this.personalizationToggleUpdating = false; + } + }, + async handleLogout() { try { const resp = await fetch('/logout', { method: 'POST' }); diff --git a/static/index.html b/static/index.html index 88e08cd..9404bc3 100644 --- a/static/index.html +++ b/static/index.html @@ -846,7 +846,8 @@ + :disabled="personalizationToggleUpdating" + @change="handlePersonalizationToggle">