tiny-rdm/frontend/src/components/content_value/ContentToolbar.vue

138 lines
4.2 KiB
Vue
Raw Normal View History

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'
import { computed } from 'vue'
import { isEmpty } from 'lodash'
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,
keyCode: {
type: Array,
default: null,
},
2023-06-27 15:53:29 +08:00
ttl: {
type: Number,
default: -1,
},
})
const dialogStore = useDialog()
const connectionStore = useConnectionStore()
const i18n = useI18n()
const binaryKey = computed(() => {
return !!props.keyCode
})
/**
*
* @type {ComputedRef<string|number[]>}
*/
const keyName = computed(() => {
return !isEmpty(props.keyCode) ? props.keyCode : props.keyPath
})
2023-06-27 15:53:29 +08:00
const onReloadKey = () => {
connectionStore.loadKeyValue(props.server, props.db, keyName.value)
2023-06-27 15:53:29 +08:00
}
2023-07-25 19:12:50 +08:00
const onCopyKey = () => {
ClipboardSetText(props.keyPath)
.then((succ) => {
if (succ) {
$message.success(i18n.t('dialogue.copy_succ'))
2023-07-25 19:12:50 +08:00
}
})
.catch((e) => {
$message.error(e.message)
2023-07-25 19:12:50 +08:00
})
}
const onRenameKey = () => {
if (binaryKey.value) {
$message.error(i18n.t('dialogue.rename_binary_key_fail'))
} else {
dialogStore.openRenameKeyDialog(props.server, props.db, props.keyPath)
}
}
const onDeleteKey = () => {
$dialog.warning(i18n.t('dialogue.remove_tip', { name: props.keyPath }), () => {
connectionStore.deleteKey(props.server, props.db, keyName.value).then((success) => {
if (success) {
$message.success(i18n.t('dialogue.delete_key_succ', { key: props.keyPath }))
}
})
})
2023-06-27 15:53:29 +08:00
}
</script>
<template>
<div class="content-toolbar flex-box-h">
<n-input-group>
<redis-type-tag :type="props.keyType" :binary-key="binaryKey" size="large" />
2023-06-27 15:53:29 +08:00
<n-input v-model:value="props.keyPath">
<template #suffix>
<icon-button :icon="Refresh" size="18" t-tooltip="interface.reload" @click="onReloadKey" />
2023-06-27 15:53:29 +08:00
</template>
</n-input>
<icon-button :icon="Copy" border size="18" t-tooltip="interface.copy_key" @click="onCopyKey" />
2023-06-27 15:53:29 +08:00
</n-input-group>
<n-button-group>
<n-tooltip>
<template #trigger>
<n-button :focusable="false" @click="dialogStore.openTTLDialog(props.ttl)">
2023-06-27 15:53:29 +08:00
<template #icon>
<n-icon :component="Timer" size="18" />
</template>
<template v-if="ttl < 0">
{{ $t('interface.forever') }}
2023-06-27 15:53:29 +08:00
</template>
2023-10-15 15:18:43 +08:00
<template v-else>
{{ Math.floor(ttl/3600) }}:{{ Math.floor((ttl%3600)/60) }}:{{ Math.floor(ttl%60) }}
</template>
2023-06-27 15:53:29 +08:00
</n-button>
</template>
TTL
</n-tooltip>
<icon-button :icon="Edit" border size="18" t-tooltip="interface.rename_key" @click="onRenameKey" />
2023-06-27 15:53:29 +08:00
</n-button-group>
<n-tooltip>
<template #trigger>
<n-button :focusable="false" @click="onDeleteKey">
<template #icon>
<n-icon :component="Delete" size="18" />
2023-06-27 15:53:29 +08:00
</template>
</n-button>
2023-06-27 15:53:29 +08:00
</template>
{{ $t('interface.delete_key') }}
2023-06-27 15:53:29 +08:00
</n-tooltip>
</div>
</template>
<style lang="scss" scoped>
.content-toolbar {
align-items: center;
gap: 5px;
}
</style>