2023-06-27 15:53:29 +08:00
|
|
|
<script setup>
|
2023-08-02 17:57:39 +08:00
|
|
|
import { validType } from '@/consts/support_redis_type.js'
|
|
|
|
import useDialog from 'stores/dialog.js'
|
|
|
|
import Delete from '@/components/icons/Delete.vue'
|
|
|
|
import Edit from '@/components/icons/Edit.vue'
|
|
|
|
import Refresh from '@/components/icons/Refresh.vue'
|
|
|
|
import Timer from '@/components/icons/Timer.vue'
|
|
|
|
import RedisTypeTag from '@/components/common/RedisTypeTag.vue'
|
2023-06-27 15:53:29 +08:00
|
|
|
import { useI18n } from 'vue-i18n'
|
2023-08-02 17:57:39 +08:00
|
|
|
import IconButton from '@/components/common/IconButton.vue'
|
|
|
|
import useConnectionStore from 'stores/connections.js'
|
|
|
|
import Copy from '@/components/icons/Copy.vue'
|
|
|
|
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
|
2023-06-27 15:53:29 +08:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
server: String,
|
|
|
|
db: Number,
|
|
|
|
keyType: {
|
|
|
|
type: String,
|
|
|
|
validator(value) {
|
|
|
|
return validType(value)
|
|
|
|
},
|
|
|
|
default: 'STRING',
|
|
|
|
},
|
|
|
|
keyPath: String,
|
|
|
|
ttl: {
|
|
|
|
type: Number,
|
|
|
|
default: -1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const dialogStore = useDialog()
|
|
|
|
const connectionStore = useConnectionStore()
|
|
|
|
const i18n = useI18n()
|
|
|
|
|
|
|
|
const onReloadKey = () => {
|
|
|
|
connectionStore.loadKeyValue(props.server, props.db, props.keyPath)
|
|
|
|
}
|
|
|
|
|
2023-07-25 19:12:50 +08:00
|
|
|
const onCopyKey = () => {
|
|
|
|
ClipboardSetText(props.keyPath)
|
|
|
|
.then((succ) => {
|
|
|
|
if (succ) {
|
2023-08-24 00:44:19 +08:00
|
|
|
$message.success(i18n.t('copy_succ'))
|
2023-07-25 19:12:50 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
2023-08-24 00:44:19 +08:00
|
|
|
$message.error(e.message)
|
2023-07-25 19:12:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-04 00:42:17 +08:00
|
|
|
const onDeleteKey = () => {
|
2023-08-24 00:44:19 +08:00
|
|
|
$dialog.warning(i18n.t('remove_tip', { name: props.keyPath }), () => {
|
2023-07-06 01:22:14 +08:00
|
|
|
connectionStore.deleteKey(props.server, props.db, props.keyPath).then((success) => {
|
2023-07-04 00:42:17 +08:00
|
|
|
if (success) {
|
2023-08-24 00:44:19 +08:00
|
|
|
$message.success(i18n.t('delete_key_succ', { key: props.keyPath }))
|
2023-07-04 00:42:17 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2023-06-27 15:53:29 +08:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="content-toolbar flex-box-h">
|
|
|
|
<n-input-group>
|
2023-07-25 19:12:50 +08:00
|
|
|
<redis-type-tag :type="props.keyType" size="large" />
|
2023-06-27 15:53:29 +08:00
|
|
|
<n-input v-model:value="props.keyPath">
|
|
|
|
<template #suffix>
|
2023-08-02 19:40:57 +08:00
|
|
|
<icon-button :icon="Refresh" size="18" t-tooltip="reload" @click="onReloadKey" />
|
2023-06-27 15:53:29 +08:00
|
|
|
</template>
|
|
|
|
</n-input>
|
2023-08-02 19:40:57 +08:00
|
|
|
<icon-button :icon="Copy" border size="18" t-tooltip="copy_key" @click="onCopyKey" />
|
2023-06-27 15:53:29 +08:00
|
|
|
</n-input-group>
|
|
|
|
<n-button-group>
|
|
|
|
<n-tooltip>
|
|
|
|
<template #trigger>
|
|
|
|
<n-button @click="dialogStore.openTTLDialog(props.ttl)">
|
|
|
|
<template #icon>
|
|
|
|
<n-icon :component="Timer" size="18" />
|
|
|
|
</template>
|
|
|
|
<template v-if="ttl < 0">
|
|
|
|
{{ $t('forever') }}
|
|
|
|
</template>
|
|
|
|
<template v-else> {{ ttl }} {{ $t('second') }}</template>
|
|
|
|
</n-button>
|
|
|
|
</template>
|
|
|
|
TTL
|
|
|
|
</n-tooltip>
|
2023-07-03 17:53:28 +08:00
|
|
|
<icon-button
|
|
|
|
:icon="Edit"
|
2023-08-02 19:40:57 +08:00
|
|
|
border
|
2023-07-03 17:53:28 +08:00
|
|
|
size="18"
|
2023-08-02 19:40:57 +08:00
|
|
|
t-tooltip="rename_key"
|
2023-08-24 15:23:25 +08:00
|
|
|
@click="dialogStore.openRenameKeyDialog(props.server, props.db, props.keyPath)" />
|
2023-07-03 17:53:28 +08:00
|
|
|
<!-- <n-button @click="dialogStore.openRenameKeyDialog(props.server, props.db, props.keyPath)">-->
|
|
|
|
<!-- <template #icon>-->
|
|
|
|
<!-- <n-icon :component="Edit" size="18" />-->
|
|
|
|
<!-- </template>-->
|
|
|
|
<!-- {{ $t('rename_key') }}-->
|
|
|
|
<!-- </n-button>-->
|
2023-06-27 15:53:29 +08:00
|
|
|
</n-button-group>
|
|
|
|
<n-tooltip>
|
|
|
|
<template #trigger>
|
2023-07-04 00:42:17 +08:00
|
|
|
<n-button>
|
|
|
|
<template #icon>
|
|
|
|
<n-icon :component="Delete" size="18" @click="onDeleteKey" />
|
2023-06-27 15:53:29 +08:00
|
|
|
</template>
|
2023-07-04 00:42:17 +08:00
|
|
|
</n-button>
|
2023-06-27 15:53:29 +08:00
|
|
|
</template>
|
|
|
|
{{ $t('delete_key') }}
|
|
|
|
</n-tooltip>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.content-toolbar {
|
|
|
|
align-items: center;
|
|
|
|
gap: 5px;
|
|
|
|
}
|
|
|
|
</style>
|