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 Copy from '@/components/icons/Copy.vue'
|
|
|
|
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
|
2023-10-11 01:15:23 +08:00
|
|
|
import { computed } from 'vue'
|
2023-11-08 23:45:33 +08:00
|
|
|
import { padStart } 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,
|
2023-10-11 01:15:23 +08:00
|
|
|
keyCode: {
|
|
|
|
type: Array,
|
|
|
|
default: null,
|
|
|
|
},
|
2023-06-27 15:53:29 +08:00
|
|
|
ttl: {
|
|
|
|
type: Number,
|
|
|
|
default: -1,
|
|
|
|
},
|
2023-11-08 23:45:33 +08:00
|
|
|
loading: Boolean,
|
2023-06-27 15:53:29 +08:00
|
|
|
})
|
|
|
|
|
2023-11-08 23:45:33 +08:00
|
|
|
const emit = defineEmits(['reload', 'rename', 'delete'])
|
|
|
|
|
2023-06-27 15:53:29 +08:00
|
|
|
const dialogStore = useDialog()
|
|
|
|
const i18n = useI18n()
|
|
|
|
|
2023-10-11 01:15:23 +08:00
|
|
|
const binaryKey = computed(() => {
|
|
|
|
return !!props.keyCode
|
|
|
|
})
|
|
|
|
|
2023-10-15 21:37:36 +08:00
|
|
|
const ttlString = computed(() => {
|
|
|
|
let s = ''
|
|
|
|
if (props.ttl > 0) {
|
|
|
|
const hours = Math.floor(props.ttl / 3600)
|
|
|
|
s += padStart(hours + ':', 3, '0')
|
|
|
|
const minutes = Math.floor((props.ttl % 3600) / 60)
|
|
|
|
s += padStart(minutes + ':', 3, '0')
|
|
|
|
const seconds = Math.floor(props.ttl % 60)
|
|
|
|
s += padStart(seconds + '', 2, '0')
|
|
|
|
} else if (props.ttl < 0) {
|
|
|
|
s = i18n.t('interface.forever')
|
|
|
|
} else {
|
|
|
|
s = '00:00:00'
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
})
|
|
|
|
|
2023-07-25 19:12:50 +08:00
|
|
|
const onCopyKey = () => {
|
|
|
|
ClipboardSetText(props.keyPath)
|
|
|
|
.then((succ) => {
|
|
|
|
if (succ) {
|
2023-09-07 18:38:34 +08:00
|
|
|
$message.success(i18n.t('dialogue.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-06-27 15:53:29 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="content-toolbar flex-box-h">
|
|
|
|
<n-input-group>
|
2023-10-20 18:34:19 +08:00
|
|
|
<redis-type-tag :binary-key="binaryKey" :type="props.keyType" size="large" />
|
2023-11-08 23:45:33 +08:00
|
|
|
<n-input v-model:value="props.keyPath" readonly>
|
2023-06-27 15:53:29 +08:00
|
|
|
<template #suffix>
|
2023-11-08 23:45:33 +08:00
|
|
|
<icon-button
|
|
|
|
:icon="Refresh"
|
|
|
|
:loading="props.loading"
|
|
|
|
size="18"
|
|
|
|
t-tooltip="interface.reload"
|
|
|
|
@click="emit('reload')" />
|
2023-06-27 15:53:29 +08:00
|
|
|
</template>
|
|
|
|
</n-input>
|
2023-09-07 18:38:34 +08:00
|
|
|
<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>
|
2023-09-06 16:07:20 +08:00
|
|
|
<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>
|
2023-10-15 21:37:36 +08:00
|
|
|
{{ ttlString }}
|
2023-06-27 15:53:29 +08:00
|
|
|
</n-button>
|
|
|
|
</template>
|
2023-10-15 21:37:36 +08:00
|
|
|
TTL{{ `${ttl > 0 ? ': ' + ttl + $t('common.second') : ''}` }}
|
2023-06-27 15:53:29 +08:00
|
|
|
</n-tooltip>
|
2023-11-08 23:45:33 +08:00
|
|
|
<icon-button :icon="Edit" border size="18" t-tooltip="interface.rename_key" @click="emit('rename')" />
|
2023-06-27 15:53:29 +08:00
|
|
|
</n-button-group>
|
2023-10-29 23:05:34 +08:00
|
|
|
<n-tooltip :show-arrow="false">
|
2023-06-27 15:53:29 +08:00
|
|
|
<template #trigger>
|
2023-11-08 23:45:33 +08:00
|
|
|
<n-button :focusable="false" @click="emit('delete')">
|
2023-07-04 00:42:17 +08:00
|
|
|
<template #icon>
|
2023-10-11 01:15:23 +08:00
|
|
|
<n-icon :component="Delete" size="18" />
|
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>
|
2023-09-07 18:38:34 +08:00
|
|
|
{{ $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>
|