Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add unsave tab confirm (#687)

寻e3ba3b54d519
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 2b43d835dd..dad5736ca6 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -5,18 +5,20 @@
:date-locale="dateLang"
:theme-overrides="themeOverrides"
>
- <BBModalStack>
- <KBarWrapper>
- <router-view />
- <template v-if="state.notificationList.length > 0">
- <BBNotification
- :placement="'BOTTOM_RIGHT'"
- :notification-list="state.notificationList"
- @close="removeNotification"
- />
- </template>
- </KBarWrapper>
- </BBModalStack>
+ <NDialogProvider>
+ <BBModalStack>
+ <KBarWrapper>
+ <router-view />
+ <template v-if="state.notificationList.length > 0">
+ <BBNotification
+ :placement="'BOTTOM_RIGHT'"
+ :notification-list="state.notificationList"
+ @close="removeNotification"
+ />
+ </template>
+ </KBarWrapper>
+ </BBModalStack>
+ </NDialogProvider>
</NConfigProvider>
</template>
@@ -31,7 +33,7 @@ import { BBNotificationItem } from "./bbkit/types";
import KBarWrapper from "./components/KBar/KBarWrapper.vue";
import BBModalStack from "./bbkit/BBModalStack.vue";
-import { NConfigProvider } from "naive-ui";
+import { NConfigProvider, NDialogProvider } from "naive-ui";
import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
import { t } from "./plugins/i18n";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
@@ -54,6 +56,7 @@ export default defineComponent({
KBarWrapper,
BBModalStack,
NConfigProvider,
+ NDialogProvider,
},
setup() {
const store = useStore();
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index 2380dd77c7..cb85f6850e 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -1138,6 +1138,7 @@ sql-editor:
hint-tips:
confirm-to-delete-this-history: Confirm to delete this history?
confirm-to-delete-this-sheet: Confirm to delete this sheet?
+ confirm-to-close-unsaved-tab: Confirm to close unsaved tab?
please-input-the-tab-label: Please input the tab label!
copy-code: Copy code
notify:
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index fc1fadaae1..e9151361c6 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -1001,6 +1001,7 @@ sql-editor:
hint-tips:
confirm-to-delete-this-history: 确定删除这条记录?
confirm-to-delete-this-sheet: 确定删除这条查询语句?
+ confirm-to-close-unsaved-tab: 确定关闭未保存的标签页?
please-input-the-tab-label: 请输入标签页名称!
copy-code: 复制代码
notify:
diff --git a/frontend/src/views/SqlEditor/TabListContainer.vue b/frontend/src/views/SqlEditor/TabListContainer.vue
index 4bda8df3ab..dec7855c5a 100644
--- a/frontend/src/views/SqlEditor/TabListContainer.vue
+++ b/frontend/src/views/SqlEditor/TabListContainer.vue
@@ -122,7 +122,15 @@
</template>
<script lang="ts" setup>
-import { ref, watch, reactive, nextTick, computed, onMounted } from "vue";
+import {
+ ref,
+ watch,
+ reactive,
+ nextTick,
+ computed,
+ onMounted,
+ onUnmounted,
+} from "vue";
import { debounce, cloneDeep } from "lodash-es";
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
@@ -141,6 +149,7 @@ import {
TabActions,
SheetActions,
} from "../../types";
+import { useDialog } from "naive-ui";
import { getDefaultTab } from "../../store/modules/tab";
import { useSQLEditorConnection } from "../../composables/useSQLEditorConnection";
@@ -288,16 +297,39 @@ const handleAddTab = (tab: AnyTabInfo) => {
recalculateScrollWidth();
});
};
+
+const modal = useDialog();
+
const handleRemoveTab = async (tab: TabInfo) => {
- await removeTab(tab);
- const tabsLength = tabList.value.length;
+ if (!tab.isSaved) {
+ const $modal = modal.create({
+ title: t("sql-editor.hint-tips.confirm-to-close-unsaved-tab"),
+ type: "warning",
+ onPositiveClick() {
+ $modal.destroy();
+ },
+ async onNegativeClick() {
+ await remove();
+ $modal.destroy();
+ },
+ negativeText: t("common.confirm"),
+ positiveText: t("common.cancel"),
+ });
+ } else {
+ await remove();
+ }
+
+ async function remove() {
+ await removeTab(tab);
+ const tabsLength = tabList.value.length;
- if (tabsLength > 0) {
- handleSelectTab(tabList.value[tabsLength - 1]);
+ if (tabsLength > 0) {
+ handleSelectTab(tabList.value[tabsLength - 1]);
+ }
+ nextTick(() => {
+ recalculateScrollWidth();
+ });
}
- nextTick(() => {
- recalculateScrollWidth();
- });
};
const handleSelectTabFromPopselect = (tabId: string) => {
setCurrentTabId(tabId);
@@ -335,6 +367,17 @@ onMounted(async () => {
recalculateScrollWidth();
}
});
+
+// add listener to confirm confrim if close the tab.
+onMounted(() => {
+ window.onbeforeunload = () => {
+ return "false";
+ };
+});
+// remove if unmount view
+onUnmounted(() => {
+ window.onbeforeunload = null;
+});
</script>
<style scoped>