From 61e702e5d5e15ed63ec4d01e1f149ebcffc631f2 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 18 Jul 2023 15:27:15 +0800 Subject: [PATCH] feat: add connection mark color --- .../components/dialogs/ConnectionDialog.vue | 8 +- .../components/dialogs/KeyFilterDialog.vue | 2 +- .../src/components/sidebar/BrowserTree.vue | 84 +++++++++++-------- .../src/components/sidebar/ConnectionTree.vue | 18 +++- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/frontend/src/components/dialogs/ConnectionDialog.vue b/frontend/src/components/dialogs/ConnectionDialog.vue index 9b65157..c72f249 100644 --- a/frontend/src/components/dialogs/ConnectionDialog.vue +++ b/frontend/src/components/dialogs/ConnectionDialog.vue @@ -59,7 +59,7 @@ const showTestConnFailResult = computed(() => { return !isEmpty(testResult.value) && showTestResult.value === true }) const formLabelWidth = computed(() => { - // Compatible with long english word + // compatible with long english word if (tab.value === 'advanced' && i18n.locale.value === 'en') { return '140px' } @@ -70,21 +70,21 @@ const generalFormRef = ref(null) const advanceFormRef = ref(null) const onSaveConnection = async () => { - // Validate general form + // validate general form await generalFormRef.value?.validate((err) => { if (err) { nextTick(() => (tab.value = 'general')) } }) - // Validate advance form + // validate advance form await advanceFormRef.value?.validate((err) => { if (err) { nextTick(() => (tab.value = 'advanced')) } }) - // Store new connection + // store new connection const { success, msg } = await connectionStore.saveConnection(editName.value, generalForm.value) if (!success) { message.error(msg) diff --git a/frontend/src/components/dialogs/KeyFilterDialog.vue b/frontend/src/components/dialogs/KeyFilterDialog.vue index 790b7c0..93d7ba6 100644 --- a/frontend/src/components/dialogs/KeyFilterDialog.vue +++ b/frontend/src/components/dialogs/KeyFilterDialog.vue @@ -90,7 +90,7 @@ const onClose = () => { - + diff --git a/frontend/src/components/sidebar/BrowserTree.vue b/frontend/src/components/sidebar/BrowserTree.vue index f6fe09d..41079ae 100644 --- a/frontend/src/components/sidebar/BrowserTree.vue +++ b/frontend/src/components/sidebar/BrowserTree.vue @@ -46,6 +46,18 @@ const data = computed(() => { ] }) +const backgroundColor = computed(() => { + const { markColor: hex = '' } = connectionStore.serverProfile[props.server] || {} + if (isEmpty(hex)) { + return '' + } + const bigint = parseInt(hex.slice(1), 16) + const r = (bigint >> 16) & 255 + const g = (bigint >> 8) & 255 + const b = bigint & 255 + return `rgba(${r}, ${g}, ${b}, 0.2)` +}) + const contextMenuParam = reactive({ show: false, x: 0, @@ -171,7 +183,6 @@ onMounted(async () => { try { // TODO: Show loading list status loadingConnections.value = true - // nextTick(connectionStore.initConnection) } finally { loadingConnections.value = false } @@ -449,37 +460,44 @@ const handleOutsideContextMenu = () => { - + diff --git a/frontend/src/components/sidebar/ConnectionTree.vue b/frontend/src/components/sidebar/ConnectionTree.vue index c982601..2787618 100644 --- a/frontend/src/components/sidebar/ConnectionTree.vue +++ b/frontend/src/components/sidebar/ConnectionTree.vue @@ -118,10 +118,20 @@ const menuOptions = { } const renderLabel = ({ option }) => { - // switch (option.type) { - // case ConnectionType.Server: - // return h(ConnectionTreeItem, { title: option.label }) - // } + if (option.type === ConnectionType.Server) { + const { markColor = '' } = connectionStore.serverProfile[option.name] || {} + return h( + 'div', + { + style: { + // color: markColor, + borderRadius: '3px', + backgroundColor: markColor, + }, + }, + { default: () => option.label } + ) + } return option.label }