Compare commits

..

3 Commits

2 changed files with 93 additions and 6 deletions

View File

@ -135,7 +135,7 @@ const onKeyShortcut = (e) => {
return
case 'd':
if (e.metaKey) {
if (e.metaKey && isMacOS()) {
onDelete()
}
return

View File

@ -26,6 +26,7 @@ import RedisTypeTag from '@/components/common/RedisTypeTag.vue'
import usePreferencesStore from 'stores/preferences.js'
import { typesIconStyle } from '@/consts/support_redis_type.js'
import { nativeRedisKey } from '@/utils/key_convert.js'
import { isMacOS } from '@/utils/platform.js'
const props = defineProps({
server: String,
@ -280,6 +281,96 @@ const handleKeyRight = () => {
}
}
const handleKeyDelete = () => {
const selectedKey = get(selectedKeys.value, 0)
if (selectedKey == null) {
return
}
let node = browserStore.getNode(selectedKey)
if (node == null) {
return
}
const { db = 0, key: nodeKey, redisKey: rk = '', redisKeyCode: rkc, label } = node || {}
const redisKey = rkc || rk
const redisKeyName = !!rkc ? label : redisKey
switch (node.type) {
case ConnectionType.RedisKey:
dialogStore.openDeleteKeyDialog(props.server, db, isEmpty(redisKey) ? '*' : redisKey + ':*')
break
case ConnectionType.RedisValue:
$dialog.warning(i18n.t('dialogue.remove_tip', { name: redisKeyName }), () => {
browserStore.deleteKey(props.server, db, redisKey).then((success) => {
if (success) {
$message.success(i18n.t('dialogue.delete.success', { key: redisKeyName }))
}
})
})
break
}
}
const handleKeyCopy = () => {
const selectedKey = get(selectedKeys.value, 0)
if (selectedKey == null) {
return
}
let node = browserStore.getNode(selectedKey)
if (node == null) {
return
}
if (node.type === ConnectionType.RedisValue) {
ClipboardSetText(nativeRedisKey(node.redisKeyCode || node.redisKey))
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ'))
}
})
.catch((e) => {
$message.error(e.message)
})
}
}
const onKeyShortcut = (e) => {
switch (e.key) {
case 'ArrowUp':
handleKeyUp()
break
case 'ArrowDown':
handleKeyDown()
break
case 'ArrowLeft':
handleKeyLeft()
break
case 'ArrowRight':
handleKeyRight()
break
case 'c':
if (e.metaKey) {
handleKeyCopy()
}
break
case 'Delete':
handleKeyDelete()
break
case 'd':
if (e.metaKey && isMacOS()) {
handleKeyDelete()
}
break
case 'F5':
handleSelectContextMenu('value_reload')
break
case 'r':
if (e.metaKey && isMacOS()) {
handleSelectContextMenu('value_reload')
}
break
}
}
const handleSelectContextMenu = (action) => {
contextMenuParam.show = false
const selectedKey = get(selectedKeys.value, 0)
@ -752,11 +843,7 @@ defineExpose({
class="fill-height"
virtual-scroll
:keyboard="false"
@keydown.up="handleKeyUp"
@keydown.down="handleKeyDown"
@keydown.left="handleKeyLeft"
@keydown.right="handleKeyRight"
@keydown.delete="handleSelectContextMenu('value_remove')"
@keydown="onKeyShortcut"
@update:selected-keys="onUpdateSelectedKeys"
@update:expanded-keys="onUpdateExpanded"
@update:checked-keys="onUpdateCheckedKeys">