feat: support duplicate connection profile

This commit is contained in:
tiny-craft 2023-09-08 15:53:56 +08:00
parent b7e9d974cb
commit 04a328159b
6 changed files with 62 additions and 15 deletions

View File

@ -3,7 +3,7 @@ import { every, get, includes, isEmpty, map } from 'lodash'
import { computed, nextTick, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { TestConnection } from 'wailsjs/go/services/connectionService.js'
import useDialog from 'stores/dialog'
import useDialog, { ConnDialogType } from 'stores/dialog'
import Close from '@/components/icons/Close.vue'
import useConnectionStore from 'stores/connections.js'
@ -36,7 +36,7 @@ const generalFormRules = () => {
keySeparator: { required: true, message: requiredMsg, trigger: 'input' },
}
}
const isEditMode = computed(() => !isEmpty(editName.value))
const isEditMode = computed(() => dialogStore.connType === ConnDialogType.EDIT)
const closingConnection = computed(() => {
if (isEmpty(editName.value)) {
return false
@ -133,11 +133,7 @@ const onTestConnection = async () => {
}
const onClose = () => {
if (isEditMode.value) {
dialogStore.closeEditDialog()
} else {
dialogStore.closeNewDialog()
}
dialogStore.closeConnDialog()
}
</script>

View File

@ -73,16 +73,16 @@ const menuOptions = {
label: i18n.t('interface.disconnect'),
icon: renderIcon(Unlink),
},
{
key: 'server_dup',
label: i18n.t('interface.dup_conn'),
icon: renderIcon(CopyLink),
},
{
key: 'server_edit',
label: i18n.t('interface.edit_conn'),
icon: renderIcon(Config),
},
{
key: 'server_dup',
label: i18n.t('interface.dup_conn'),
icon: renderIcon(CopyLink),
},
{
type: 'divider',
key: 'd1',
@ -105,6 +105,11 @@ const menuOptions = {
label: i18n.t('interface.edit_conn'),
icon: renderIcon(Config),
},
{
key: 'server_dup',
label: i18n.t('interface.dup_conn'),
icon: renderIcon(CopyLink),
},
{
type: 'divider',
key: 'd1',
@ -387,6 +392,9 @@ const handleSelectContextMenu = (key) => {
dialogStore.openEditDialog(name)
}
break
case 'server_dup':
dialogStore.openDuplicateDialog(name)
break
case 'server_remove':
removeConnection(name)
break

View File

@ -1,3 +1,7 @@
/**
* all types of connection item
* @enum {number}
*/
export const ConnectionType = {
Group: 0,
Server: 1,

View File

@ -1,3 +1,7 @@
/**
* all redis type
* @enum {string}
*/
export const types = {
STRING: 'STRING',
HASH: 'HASH',
@ -7,6 +11,10 @@ export const types = {
STREAM: 'STREAM',
}
/**
* mark color for redis type
* @enum {string}
*/
export const typesColor = {
[types.STRING]: '#8256DC',
[types.HASH]: '#0171F5',
@ -16,6 +24,10 @@ export const typesColor = {
[types.STREAM]: '#F5C201',
}
/**
* background mark color for redis type
* @enum {string}
*/
export const typesBgColor = {
[types.STRING]: '#F2EDFB',
[types.HASH]: '#E4F0FC',

View File

@ -1,3 +1,7 @@
/**
* string view mode
* @enum {string}
*/
export const types = {
PLAIN_TEXT: 'Plain Text',
JSON: 'JSON',

View File

@ -1,9 +1,20 @@
import { defineStore } from 'pinia'
import useConnectionStore from './connections.js'
/**
* connection dialog type
* @enum {number}
*/
export const ConnDialogType = {
NEW: 0,
EDIT: 1,
}
const useDialogStore = defineStore('dialog', {
state: () => ({
connDialogVisible: false,
/** @type {ConnDialogType} **/
connType: ConnDialogType.NEW,
connParam: null,
groupDialogVisible: false,
@ -59,9 +70,10 @@ const useDialogStore = defineStore('dialog', {
actions: {
openNewDialog() {
this.connParam = null
this.connType = ConnDialogType.NEW
this.connDialogVisible = true
},
closeNewDialog() {
closeConnDialog() {
this.connDialogVisible = false
},
@ -69,10 +81,21 @@ const useDialogStore = defineStore('dialog', {
const connStore = useConnectionStore()
const profile = await connStore.getConnectionProfile(name)
this.connParam = profile || connStore.newDefaultConnection(name)
this.connType = ConnDialogType.EDIT
this.connDialogVisible = true
},
closeEditDialog() {
this.connDialogVisible = false
async openDuplicateDialog(name) {
const connStore = useConnectionStore()
const profile = await connStore.getConnectionProfile(name)
if (profile != null) {
profile.name += '2'
this.connParam = profile
} else {
this.connParam = connStore.newDefaultConnection(name)
}
this.connType = ConnDialogType.NEW
this.connDialogVisible = true
},
openNewGroupDialog() {