Skip to content

Commit 4c285fb

Browse files
committed
feat: add unsaved changes notice to configuration page and update messages
1 parent 51c3521 commit 4c285fb

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

dashboard/src/i18n/locales/en-US/features/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"messages": {
2929
"configApplied": "Configuration successfully applied. To save, you need to click the save button in the bottom right corner.",
3030
"configApplyError": "Configuration not applied, JSON format error.",
31+
"unsavedChangesNotice": "You have unsaved configuration changes. Click the save button in the bottom-right corner to apply them.",
3132
"saveSuccess": "Configuration saved successfully",
3233
"saveError": "Failed to save configuration",
3334
"loadError": "Failed to load configuration",

dashboard/src/i18n/locales/zh-CN/features/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"messages": {
2929
"configApplied": "配置成功应用。如要保存,需再点击右下角保存按钮。",
3030
"configApplyError": "配置未应用,Json 格式错误。",
31+
"unsavedChangesNotice": "当前配置有未保存修改。请点击右下角保存按钮以生效。",
3132
"saveSuccess": "配置保存成功",
3233
"saveError": "配置保存失败",
3334
"loadError": "配置加载失败",

dashboard/src/views/ConfigPage.vue

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515

1616
</div>
1717
</div>
18+
<v-slide-y-transition>
19+
<div v-if="fetched && hasUnsavedChanges" class="unsaved-changes-banner-wrap">
20+
<v-banner
21+
icon="$warning"
22+
lines="one"
23+
class="unsaved-changes-banner my-4"
24+
>
25+
{{ tm('messages.unsavedChangesNotice') }}
26+
</v-banner>
27+
</div>
28+
</v-slide-y-transition>
1829
<!-- <v-progress-linear v-if="!fetched" indeterminate color="primary"></v-progress-linear> -->
1930

2031
<v-slide-y-transition mode="out-in">
@@ -235,6 +246,12 @@ export default {
235246
});
236247
return items;
237248
},
249+
hasUnsavedChanges() {
250+
if (!this.fetched) {
251+
return false;
252+
}
253+
return this.getConfigSnapshot(this.config_data) !== this.lastSavedConfigSnapshot;
254+
}
238255
},
239256
watch: {
240257
config_data_str(val) {
@@ -269,6 +286,7 @@ export default {
269286
save_message: "",
270287
save_message_success: "",
271288
configContentKey: 0,
289+
lastSavedConfigSnapshot: '',
272290
273291
// 配置类型切换
274292
configType: 'normal', // 'normal' 或 'system'
@@ -383,6 +401,7 @@ export default {
383401
params: params
384402
}).then((res) => {
385403
this.config_data = res.data.data.config;
404+
this.lastSavedConfigSnapshot = this.getConfigSnapshot(this.config_data);
386405
this.fetched = true
387406
this.metadata = res.data.data.metadata;
388407
this.configContentKey += 1;
@@ -407,6 +426,7 @@ export default {
407426
408427
axios.post('/api/config/astrbot/update', postData).then((res) => {
409428
if (res.data.status === "ok") {
429+
this.lastSavedConfigSnapshot = this.getConfigSnapshot(this.config_data);
410430
this.save_message = res.data.message || this.messages.saveSuccess;
411431
this.save_message_snack = true;
412432
this.save_message_success = "success";
@@ -601,6 +621,9 @@ export default {
601621
closeTestChat() {
602622
this.testChatDrawer = false;
603623
this.testConfigId = null;
624+
},
625+
getConfigSnapshot(config) {
626+
return JSON.stringify(config ?? {});
604627
}
605628
},
606629
}
@@ -612,6 +635,26 @@ export default {
612635
text-transform: none !important;
613636
}
614637
638+
.unsaved-changes-banner {
639+
border-radius: 8px;
640+
}
641+
642+
.v-theme--light .unsaved-changes-banner {
643+
background-color: #f1f4f9 !important;
644+
}
645+
646+
.v-theme--dark .unsaved-changes-banner {
647+
background-color: #2d2d2d !important;
648+
}
649+
650+
.unsaved-changes-banner-wrap {
651+
position: sticky;
652+
top: calc(var(--v-layout-top, 64px));
653+
z-index: 20;
654+
width: 100%;
655+
margin-bottom: 6px;
656+
}
657+
615658
/* 按钮切换样式优化 */
616659
.v-btn-toggle .v-btn {
617660
transition: all 0.3s ease !important;

0 commit comments

Comments
 (0)