Skip to content

Commit e469178

Browse files
authored
Feat/config leave confirm (#5249)
* feat: 配置文件增加未保存提示弹窗 * fix: 移除unsavedChangesDialog插件使用组件方式实现弹窗
1 parent 0a51798 commit e469178

4 files changed

Lines changed: 284 additions & 10 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<v-dialog v-model="isOpen" max-width="480" persistent>
3+
<v-card>
4+
<v-card-title class="dialog-title d-flex align-center justify-space-between">
5+
<span>{{ title }}</span>
6+
<v-btn icon="mdi-close" variant="text" @click="handleClose"></v-btn>
7+
</v-card-title>
8+
<v-card-text>
9+
<div class="message-text">{{ message }}</div>
10+
<div class="action-hints">
11+
<span class="hint-item">{{ confirmHint }}</span>
12+
<span class="hint-item">{{ cancelHint }}</span>
13+
<span class="hint-item">{{ closeHint }}</span>
14+
</div>
15+
</v-card-text>
16+
<v-card-actions>
17+
<v-spacer></v-spacer>
18+
<v-btn color="gray" @click="handleCancel">{{ t('core.common.dialog.cancelButton') }}</v-btn>
19+
<v-btn color="red" @click="handleConfirm" class="confirm-button">{{ t('core.common.dialog.confirmButton') }}</v-btn>
20+
</v-card-actions>
21+
</v-card>
22+
</v-dialog>
23+
</template>
24+
25+
<script setup>
26+
import { ref } from "vue";
27+
import { useI18n } from '@/i18n/composables';
28+
29+
const { t } = useI18n();
30+
31+
const isOpen = ref(false);
32+
const title = ref("");
33+
const message = ref("");
34+
const confirmHint = ref("");
35+
const cancelHint = ref("");
36+
const closeHint = ref("");
37+
let resolvePromise = null;
38+
39+
const open = (options) => {
40+
title.value = options.title || t('core.common.dialog.confirmTitle');
41+
message.value = options.message || t('core.common.dialog.confirmMessage');
42+
confirmHint.value = options.confirmHint || "";
43+
cancelHint.value = options.cancelHint || "";
44+
closeHint.value = options.closeHint || "";
45+
isOpen.value = true;
46+
47+
return new Promise((resolve) => {
48+
resolvePromise = resolve;
49+
});
50+
};
51+
52+
const handleConfirm = () => {
53+
isOpen.value = false;
54+
if (resolvePromise) resolvePromise(true);
55+
};
56+
57+
const handleCancel = () => {
58+
isOpen.value = false;
59+
if (resolvePromise) resolvePromise(false);
60+
};
61+
62+
const handleClose = () => {
63+
isOpen.value = false;
64+
if (resolvePromise) resolvePromise('close');
65+
};
66+
67+
defineExpose({ open });
68+
</script>
69+
70+
71+
<style scoped>
72+
.message-text {
73+
margin-bottom: 8px;
74+
line-height: 1.5;
75+
font-size: 16px;
76+
font-weight: 600;
77+
}
78+
79+
.action-hints {
80+
display: flex;
81+
gap: 15px;
82+
}
83+
84+
.hint-item {
85+
color: var(--v-theme-secondaryText, #666);
86+
font-size: 12px;
87+
opacity: 0.7;
88+
}
89+
90+
.dialog-title {
91+
font-size: 20px;
92+
font-weight: 500;
93+
}
94+
95+
.confirm-button {
96+
color: rgb(239, 68, 68);
97+
}
98+
</style>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,18 @@
112112
"addToConfig": "Added to config",
113113
"fileCount": "Files: {count}",
114114
"done": "Done"
115+
},
116+
"unsavedChangesWarning": {
117+
"dialogTitle": "Unsaved changes",
118+
"leavePage": "You have unsaved changes. Do you want to save before leaving?",
119+
"switchConfig": "Switching config will discard unsaved changes. Do you want to save first?",
120+
"options": {
121+
"save": "Save",
122+
"saveAndSwitch": "Save and switch",
123+
"discardAndSwitch": "Discard changes and switch",
124+
"closeCard": "Close the pop-up window",
125+
"confirm": "confirm",
126+
"cancel": "cancel"
127+
}
115128
}
116129
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,18 @@
112112
"addToConfig": "已加入配置",
113113
"fileCount": "文件:{count}",
114114
"done": "完成"
115+
},
116+
"unsavedChangesWarning": {
117+
"dialogTitle": "未保存的更改",
118+
"leavePage": "当前配置有未保存的更改,切换前是否保存?",
119+
"switchConfig": "切换配置文件会丢失当前未保存的更改,是否先保存?",
120+
"options": {
121+
"save": "保存",
122+
"saveAndSwitch": "保存并切换",
123+
"discardAndSwitch": "放弃更改并切换",
124+
"closeCard": "关闭弹窗",
125+
"confirm": "确定",
126+
"cancel": "取消"
127+
}
115128
}
116129
}

0 commit comments

Comments
 (0)