fix: auto-save personalization toggle
This commit is contained in:
parent
089a3ad0c9
commit
f3206357e9
@ -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' });
|
||||
|
||||
@ -846,7 +846,8 @@
|
||||
<span class="toggle-switch">
|
||||
<input type="checkbox"
|
||||
v-model="personalForm.enabled"
|
||||
@change="clearPersonalizationFeedback">
|
||||
:disabled="personalizationToggleUpdating"
|
||||
@change="handlePersonalizationToggle">
|
||||
<span class="switch-slider"></span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user