From 124627d724eb6ece23f405ba096477fb934e280d Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:26:35 +0800 Subject: [PATCH] refactor: wrapping element with drag and resize behavior as a standalone component --- frontend/src/AppContent.vue | 88 ++++--------- .../components/common/ResizeableWrapper.vue | 122 ++++++++++++++++++ .../components/content/ContentValueTab.vue | 12 +- frontend/src/langs/en.json | 2 +- frontend/src/langs/zh-cn.json | 2 +- 5 files changed, 152 insertions(+), 74 deletions(-) create mode 100644 frontend/src/components/common/ResizeableWrapper.vue diff --git a/frontend/src/AppContent.vue b/frontend/src/AppContent.vue index 3ffa147..d4b060e 100644 --- a/frontend/src/AppContent.vue +++ b/frontend/src/AppContent.vue @@ -16,6 +16,7 @@ import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue' import { EventsOn, WindowIsFullscreen, WindowIsMaximised, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js' import { isMacOS } from '@/utils/platform.js' import iconUrl from '@/assets/images/icon.png' +import ResizeableWrapper from '@/components/common/ResizeableWrapper.vue' const themeVars = useThemeVars() @@ -25,8 +26,6 @@ const props = defineProps({ const data = reactive({ navMenuWidth: 60, - hoverResize: false, - resizing: false, toolbarHeight: 45, }) @@ -38,33 +37,10 @@ const logPaneRef = ref(null) // provide('preferences', preferences) const saveSidebarWidth = debounce(prefStore.savePreferences, 1000, { trailing: true }) -const handleResize = (evt) => { - if (data.resizing) { - prefStore.setAsideWidth(Math.max(evt.clientX - data.navMenuWidth, 300)) - saveSidebarWidth() - } +const handleResize = () => { + saveSidebarWidth() } -const stopResize = () => { - data.resizing = false - document.removeEventListener('mousemove', handleResize) - document.removeEventListener('mouseup', stopResize) -} - -const startResize = () => { - data.resizing = true - document.addEventListener('mousemove', handleResize) - document.addEventListener('mouseup', stopResize) -} - -const asideWidthVal = computed(() => { - return prefStore.behavior.asideWidth + 'px' -}) - -const dragging = computed(() => { - return data.hoverResize || data.resizing -}) - watch( () => tabStore.nav, (nav) => { @@ -166,15 +142,6 @@ onMounted(async () => { -
@@ -196,23 +163,19 @@ onMounted(async () => { style="--wails-draggable: none"> -
-
+
+ -
-
+ class="app-side flex-item-expand" /> +
{
-
-
- -
-
+
+ + +
@@ -282,6 +241,7 @@ onMounted(async () => { //overflow: hidden; height: 100%; background-color: v-bind('themeVars.tabColor'); + border-right: 1px solid v-bind('themeVars.borderColor'); } } @@ -305,10 +265,6 @@ onMounted(async () => { border-right-color: v-bind('themeVars.primaryColor'); } -.dragging { - cursor: col-resize !important; -} - .fade-enter-from, .fade-leave-to { opacity: 0; diff --git a/frontend/src/components/common/ResizeableWrapper.vue b/frontend/src/components/common/ResizeableWrapper.vue new file mode 100644 index 0000000..828e7d0 --- /dev/null +++ b/frontend/src/components/common/ResizeableWrapper.vue @@ -0,0 +1,122 @@ + + + + + diff --git a/frontend/src/components/content/ContentValueTab.vue b/frontend/src/components/content/ContentValueTab.vue index 8c66b97..99beaf1 100644 --- a/frontend/src/components/content/ContentValueTab.vue +++ b/frontend/src/components/content/ContentValueTab.vue @@ -17,12 +17,12 @@ const tabStore = useTabStore() const connectionStore = useConnectionStore() const onCloseTab = (tabIndex) => { - $dialog.warning(i18n.t('dialogue.close_confirm'), () => { - const tab = get(tabStore.tabs, tabIndex) - if (tab != null) { + const tab = get(tabStore.tabs, tabIndex) + if (tab != null) { + $dialog.warning(i18n.t('dialogue.close_confirm', { name: tab.name }), () => { connectionStore.closeConnection(tab.name) - } - }) + }) + } } const tabMarkColor = computed(() => { @@ -53,7 +53,7 @@ const tab = computed(() =>