Alter IconButton component as NButton to support disable property
This commit is contained in:
parent
19c8e153c3
commit
8e3adbf0c3
|
@ -85,6 +85,7 @@ func (c *ConnectionsStorage) GetConnection(name string) *types.Connection {
|
||||||
for _, group := range conns {
|
for _, group := range conns {
|
||||||
for _, conn := range group.Connections {
|
for _, conn := range group.Connections {
|
||||||
if conn.Name == name {
|
if conn.Name == name {
|
||||||
|
conn.Group = group.GroupName
|
||||||
return &conn
|
return &conn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,9 @@ import { NIcon } from 'naive-ui'
|
||||||
const emit = defineEmits(['click'])
|
const emit = defineEmits(['click'])
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
tooltip: {
|
tooltip: String,
|
||||||
type: String,
|
tTooltip: String,
|
||||||
},
|
icon: [String, Object],
|
||||||
tTooltip: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
type: [String, Object],
|
|
||||||
},
|
|
||||||
size: {
|
size: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 20,
|
default: 20,
|
||||||
|
@ -26,6 +20,18 @@ const props = defineProps({
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 3,
|
default: 3,
|
||||||
},
|
},
|
||||||
|
disabled: Boolean,
|
||||||
|
})
|
||||||
|
|
||||||
|
const disableColor = computed(() => {
|
||||||
|
const baseColor = props.color
|
||||||
|
const grayScale = Math.round(
|
||||||
|
0.299 * parseInt(baseColor.substring(1, 2), 16) +
|
||||||
|
0.587 * parseInt(baseColor.substring(3, 2), 16) +
|
||||||
|
0.114 * parseInt(baseColor.substring(5, 2), 16)
|
||||||
|
)
|
||||||
|
const color = `#${grayScale.toString(16).repeat(3)}`
|
||||||
|
return color
|
||||||
})
|
})
|
||||||
|
|
||||||
const hasTooltip = computed(() => {
|
const hasTooltip = computed(() => {
|
||||||
|
@ -36,15 +42,19 @@ const hasTooltip = computed(() => {
|
||||||
<template>
|
<template>
|
||||||
<n-tooltip v-if="hasTooltip">
|
<n-tooltip v-if="hasTooltip">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<n-icon :color="props.color" :size="props.size" class="icon-btn" @click="emit('click')">
|
<n-button text :disabled="disabled" @click="emit('click')">
|
||||||
<component :is="props.icon" :stroke-width="props.strokeWidth"></component>
|
<n-icon :size="props.size" :color="props.color">
|
||||||
|
<component :is="props.icon" :stroke-width="props.strokeWidth" />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
{{ props.tTooltip ? $t(props.tTooltip) : props.tooltip }}
|
{{ props.tTooltip ? $t(props.tTooltip) : props.tooltip }}
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
<n-icon v-else :color="props.color" :size="props.size" class="icon-btn" @click="emit('click')">
|
<n-button v-else text :disabled="disabled" @click="emit('click')">
|
||||||
<component :is="props.icon" :stroke-width="props.strokeWidth"></component>
|
<n-icon :size="props.size" :color="props.color">
|
||||||
|
<component :is="props.icon" :stroke-width="props.strokeWidth" />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss"></style>
|
<style lang="scss"></style>
|
||||||
|
|
|
@ -7,8 +7,11 @@ import Sort from '../icons/Sort.vue'
|
||||||
import IconButton from '../common/IconButton.vue'
|
import IconButton from '../common/IconButton.vue'
|
||||||
import Filter from '../icons/Filter.vue'
|
import Filter from '../icons/Filter.vue'
|
||||||
import ConnectionTree from './ConnectionTree.vue'
|
import ConnectionTree from './ConnectionTree.vue'
|
||||||
|
import Unlink from '../icons/Unlink.vue'
|
||||||
|
import useConnectionStore from '../../stores/connections.js'
|
||||||
|
|
||||||
const dialogStore = useDialogStore()
|
const dialogStore = useDialogStore()
|
||||||
|
const connectionStore = useConnectionStore()
|
||||||
|
|
||||||
const onSort = () => {
|
const onSort = () => {
|
||||||
dialogStore.openPreferencesDialog()
|
dialogStore.openPreferencesDialog()
|
||||||
|
@ -37,6 +40,15 @@ const onSort = () => {
|
||||||
t-tooltip="new_group"
|
t-tooltip="new_group"
|
||||||
@click="dialogStore.openNewKeyDialog('aa:bb')"
|
@click="dialogStore.openNewKeyDialog('aa:bb')"
|
||||||
/>
|
/>
|
||||||
|
<icon-button
|
||||||
|
:disabled="!connectionStore.anyConnectionOpened"
|
||||||
|
:icon="Unlink"
|
||||||
|
color="#555"
|
||||||
|
size="20"
|
||||||
|
stroke-width="4"
|
||||||
|
t-tooltip="disconnect_all"
|
||||||
|
@click="dialogStore.openNewKeyDialog('aa:bb')"
|
||||||
|
/>
|
||||||
<n-divider style="margin: 0 4px; --n-color: #aaa; width: 2px" vertical />
|
<n-divider style="margin: 0 4px; --n-color: #aaa; width: 2px" vertical />
|
||||||
<icon-button :icon="Sort" color="#555" size="20" stroke-width="4" t-tooltip="sort_conn" @click="onSort" />
|
<icon-button :icon="Sort" color="#555" size="20" stroke-width="4" t-tooltip="sort_conn" @click="onSort" />
|
||||||
<n-input placeholder="">
|
<n-input placeholder="">
|
||||||
|
|
|
@ -80,7 +80,7 @@ const menuOptions = {
|
||||||
icon: renderIcon(CopyLink),
|
icon: renderIcon(CopyLink),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'server_config',
|
key: 'server_edit',
|
||||||
label: i18n.t('edit_conn'),
|
label: i18n.t('edit_conn'),
|
||||||
icon: renderIcon(Config),
|
icon: renderIcon(Config),
|
||||||
},
|
},
|
||||||
|
@ -171,7 +171,7 @@ const openConnection = async (name) => {
|
||||||
await connectionStore.openConnection(name)
|
await connectionStore.openConnection(name)
|
||||||
}
|
}
|
||||||
tabStore.upsertTab({
|
tabStore.upsertTab({
|
||||||
server: nae,
|
server: name,
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error(e.message)
|
message.error(e.message)
|
||||||
|
@ -185,7 +185,7 @@ const dialog = useDialog()
|
||||||
const removeConnection = async (name) => {
|
const removeConnection = async (name) => {
|
||||||
dialog.warning({
|
dialog.warning({
|
||||||
title: i18n.t('warning'),
|
title: i18n.t('warning'),
|
||||||
content: i18n.t('delete_key_tip', { key: name }),
|
content: i18n.t('remove_conn_tip', { conn: name }),
|
||||||
closable: false,
|
closable: false,
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
transformOrigin: 'center',
|
transformOrigin: 'center',
|
||||||
|
@ -195,8 +195,6 @@ const removeConnection = async (name) => {
|
||||||
connectionStore.removeConnection(name).then(({ success, msg }) => {
|
connectionStore.removeConnection(name).then(({ success, msg }) => {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
message.error(msg)
|
message.error(msg)
|
||||||
} else {
|
|
||||||
message.success(i18n.t('delete_key_succ', { key: name }))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"new_conn": "Add New Connection",
|
"new_conn": "Add New Connection",
|
||||||
"new_group": "Add New Group",
|
"new_group": "Add New Group",
|
||||||
|
"disconnect_all": "Disconnect all connections",
|
||||||
"sort_conn": "Resort Connections",
|
"sort_conn": "Resort Connections",
|
||||||
"reload_key": "Reload Current Key",
|
"reload_key": "Reload Current Key",
|
||||||
"close_confirm_title": "Confirm Close",
|
"close_confirm_title": "Confirm Close",
|
||||||
"close_confirm": "Confirm close this tab and connection",
|
"close_confirm": "Confirm close this tab and connection",
|
||||||
"opening_connection": "Opening Connection...",
|
"opening_connection": "Opening Connection...",
|
||||||
|
"remove_conn_tip": "Connection \"{conn}\" will be deleted",
|
||||||
"ttl": "TTL",
|
"ttl": "TTL",
|
||||||
"forever": "Forever",
|
"forever": "Forever",
|
||||||
"rename_key": "Rename Key",
|
"rename_key": "Rename Key",
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
"new_conn": "添加新连接",
|
"new_conn": "添加新连接",
|
||||||
"new_group": "添加新分组",
|
"new_group": "添加新分组",
|
||||||
|
"disconnect_all": "断开所有连接",
|
||||||
"sort_conn": "调整连接顺序",
|
"sort_conn": "调整连接顺序",
|
||||||
"reload_key": "重新载入此键内容",
|
"reload_key": "重新载入此键内容",
|
||||||
"close_confirm_title": "关闭确认",
|
"close_confirm_title": "关闭确认",
|
||||||
"close_confirm": "是否关闭当前连接",
|
"close_confirm": "是否关闭当前连接",
|
||||||
"opening_connection": "正在打开连接...",
|
"opening_connection": "正在打开连接...",
|
||||||
|
"remove_conn_tip": "连接 \"{conn}\" 将会被删除",
|
||||||
"ttl": "TTL",
|
"ttl": "TTL",
|
||||||
"forever": "永久",
|
"forever": "永久",
|
||||||
"rename_key": "重命名键",
|
"rename_key": "重命名键",
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
SetListItem,
|
SetListItem,
|
||||||
SetSetItem,
|
SetSetItem,
|
||||||
UpdateSetItem,
|
UpdateSetItem,
|
||||||
UpdateZSetValue
|
UpdateZSetValue,
|
||||||
} from '../../wailsjs/go/services/connectionService.js'
|
} from '../../wailsjs/go/services/connectionService.js'
|
||||||
import { ConnectionType } from '../consts/connection_type.js'
|
import { ConnectionType } from '../consts/connection_type.js'
|
||||||
import useTabStore from './tab.js'
|
import useTabStore from './tab.js'
|
||||||
|
@ -56,7 +56,7 @@ const useConnectionStore = defineStore('connections', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
groups: [], // all group name
|
groups: [], // all group name
|
||||||
connections: [], // all connections
|
connections: [], // all connections
|
||||||
databases: {, // all databases in opened connections group by name
|
databases: {}, // all databases in opened connections group by name
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
anyConnectionOpened() {
|
anyConnectionOpened() {
|
||||||
|
@ -111,7 +111,7 @@ const useConnectionStore = defineStore('connections', {
|
||||||
key: group.groupName,
|
key: group.groupName,
|
||||||
label: group.groupName,
|
label: group.groupName,
|
||||||
type: ConnectionType.Group,
|
type: ConnectionType.Group,
|
||||||
children
|
children,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ const useConnectionStore = defineStore('connections', {
|
||||||
async getConnectionProfile(name) {
|
async getConnectionProfile(name) {
|
||||||
try {
|
try {
|
||||||
const { data, success } = await GetConnection(name)
|
const { data, success } = await GetConnection(name)
|
||||||
|
console.log(JSON.stringify(data))
|
||||||
if (success) {
|
if (success) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -152,7 +153,7 @@ const useConnectionStore = defineStore('connections', {
|
||||||
keySeparator: ':',
|
keySeparator: ':',
|
||||||
connTimeout: 60,
|
connTimeout: 60,
|
||||||
execTimeout: 60,
|
execTimeout: 60,
|
||||||
markColor: ''
|
markColor: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue