2023-07-25 19:12:50 +08:00
|
|
|
<script setup>
|
|
|
|
import { computed, h, reactive, ref } from 'vue'
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
import ContentToolbar from './ContentToolbar.vue'
|
2023-08-02 17:57:39 +08:00
|
|
|
import AddLink from '@/components/icons/AddLink.vue'
|
2023-10-30 00:54:45 +08:00
|
|
|
import { NButton, NCode, NIcon, NInput, useThemeVars } from 'naive-ui'
|
2023-08-02 17:57:39 +08:00
|
|
|
import { types, types as redisTypes } from '@/consts/support_redis_type.js'
|
|
|
|
import EditableTableColumn from '@/components/common/EditableTableColumn.vue'
|
|
|
|
import useDialogStore from 'stores/dialog.js'
|
2023-10-11 01:15:23 +08:00
|
|
|
import { includes, isEmpty, keys, some, values } from 'lodash'
|
2023-10-30 00:54:45 +08:00
|
|
|
import bytes from 'bytes'
|
2023-10-31 17:29:56 +08:00
|
|
|
import { decodeTypes, formatTypes } from '@/consts/value_view_type.js'
|
2023-11-05 11:57:52 +08:00
|
|
|
import useBrowserStore from 'stores/browser.js'
|
2023-07-25 19:12:50 +08:00
|
|
|
|
|
|
|
const i18n = useI18n()
|
2023-10-30 00:54:45 +08:00
|
|
|
const themeVars = useThemeVars()
|
|
|
|
|
2023-07-25 19:12:50 +08:00
|
|
|
const props = defineProps({
|
|
|
|
name: String,
|
|
|
|
db: Number,
|
|
|
|
keyPath: String,
|
2023-10-11 01:15:23 +08:00
|
|
|
keyCode: {
|
|
|
|
type: Array,
|
|
|
|
default: null,
|
|
|
|
},
|
2023-07-25 19:12:50 +08:00
|
|
|
ttl: {
|
|
|
|
type: Number,
|
|
|
|
default: -1,
|
|
|
|
},
|
|
|
|
value: Object,
|
2023-09-28 16:01:58 +08:00
|
|
|
size: Number,
|
2023-10-30 00:54:45 +08:00
|
|
|
length: Number,
|
2023-10-31 17:29:56 +08:00
|
|
|
viewAs: {
|
|
|
|
type: String,
|
|
|
|
default: formatTypes.PLAIN_TEXT,
|
|
|
|
},
|
|
|
|
decode: {
|
|
|
|
type: String,
|
|
|
|
default: decodeTypes.NONE,
|
|
|
|
},
|
2023-07-25 19:12:50 +08:00
|
|
|
})
|
|
|
|
|
2023-10-11 01:15:23 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @type {ComputedRef<string|number[]>}
|
|
|
|
*/
|
|
|
|
const keyName = computed(() => {
|
|
|
|
return !isEmpty(props.keyCode) ? props.keyCode : props.keyPath
|
|
|
|
})
|
|
|
|
|
2023-08-24 01:34:42 +08:00
|
|
|
const filterOption = [
|
2023-07-25 19:12:50 +08:00
|
|
|
{
|
|
|
|
value: 1,
|
2023-09-07 18:38:34 +08:00
|
|
|
label: i18n.t('common.field'),
|
2023-07-25 19:12:50 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 2,
|
2023-09-07 18:38:34 +08:00
|
|
|
label: i18n.t('common.value'),
|
2023-07-25 19:12:50 +08:00
|
|
|
},
|
2023-08-24 01:34:42 +08:00
|
|
|
]
|
2023-07-25 19:12:50 +08:00
|
|
|
const filterType = ref(1)
|
|
|
|
|
2023-11-05 11:57:52 +08:00
|
|
|
const browserStore = useBrowserStore()
|
2023-07-25 19:12:50 +08:00
|
|
|
const dialogStore = useDialogStore()
|
|
|
|
const keyType = redisTypes.STREAM
|
|
|
|
const idColumn = reactive({
|
|
|
|
key: 'id',
|
|
|
|
title: 'ID',
|
|
|
|
align: 'center',
|
|
|
|
titleAlign: 'center',
|
|
|
|
resizable: true,
|
|
|
|
})
|
|
|
|
const valueColumn = reactive({
|
|
|
|
key: 'value',
|
2023-09-07 18:38:34 +08:00
|
|
|
title: i18n.t('common.value'),
|
2023-07-25 19:12:50 +08:00
|
|
|
align: 'center',
|
|
|
|
titleAlign: 'center',
|
|
|
|
resizable: true,
|
|
|
|
filterOptionValue: null,
|
|
|
|
filter(value, row) {
|
|
|
|
const v = value.toString()
|
|
|
|
if (filterType.value === 1) {
|
|
|
|
// filter key
|
|
|
|
return some(keys(row.value), (key) => includes(key, v))
|
|
|
|
} else {
|
|
|
|
// filter value
|
|
|
|
return some(values(row.value), (val) => includes(val, v))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// sorter: (row1, row2) => row1.value - row2.value,
|
|
|
|
// ellipsis: {
|
|
|
|
// tooltip: true
|
|
|
|
// },
|
|
|
|
render: (row) => {
|
|
|
|
return h(NCode, { language: 'json', wordWrap: true }, { default: () => JSON.stringify(row.value) })
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const actionColumn = {
|
|
|
|
key: 'action',
|
2023-09-07 18:38:34 +08:00
|
|
|
title: i18n.t('interface.action'),
|
2023-07-25 19:12:50 +08:00
|
|
|
width: 60,
|
|
|
|
align: 'center',
|
|
|
|
titleAlign: 'center',
|
|
|
|
fixed: 'right',
|
|
|
|
render: (row) => {
|
|
|
|
return h(EditableTableColumn, {
|
|
|
|
bindKey: row.id,
|
|
|
|
readonly: true,
|
|
|
|
onDelete: async () => {
|
|
|
|
try {
|
2023-11-05 11:57:52 +08:00
|
|
|
const { success, msg } = await browserStore.removeStreamValues(
|
2023-07-25 19:12:50 +08:00
|
|
|
props.name,
|
|
|
|
props.db,
|
2023-10-11 01:15:23 +08:00
|
|
|
keyName.value,
|
2023-07-25 19:12:50 +08:00
|
|
|
row.id,
|
|
|
|
)
|
|
|
|
if (success) {
|
2023-11-05 11:57:52 +08:00
|
|
|
browserStore.loadKeyValue(props.name, props.db, keyName.value).then((r) => {})
|
2023-09-07 18:38:34 +08:00
|
|
|
$message.success(i18n.t('dialogue.delete_key_succ', { key: row.id }))
|
2023-07-25 19:12:50 +08:00
|
|
|
// update display value
|
|
|
|
// if (!isEmpty(removed)) {
|
|
|
|
// for (const elem of removed) {
|
|
|
|
// delete props.value[elem]
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} else {
|
2023-08-24 00:44:19 +08:00
|
|
|
$message.error(msg)
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const columns = reactive([idColumn, valueColumn, actionColumn])
|
|
|
|
|
|
|
|
const tableData = computed(() => {
|
|
|
|
const data = []
|
|
|
|
for (const elem of props.value) {
|
|
|
|
data.push({
|
|
|
|
id: elem.id,
|
|
|
|
value: elem.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
})
|
2023-08-20 14:42:36 +08:00
|
|
|
|
2023-07-25 19:12:50 +08:00
|
|
|
const onAddRow = () => {
|
2023-10-11 01:15:23 +08:00
|
|
|
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.STREAM)
|
2023-07-25 19:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const filterValue = ref('')
|
|
|
|
const onFilterInput = (val) => {
|
|
|
|
valueColumn.filterOptionValue = val
|
|
|
|
}
|
|
|
|
|
|
|
|
const onChangeFilterType = (type) => {
|
|
|
|
onFilterInput(filterValue.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
const clearFilter = () => {
|
|
|
|
idColumn.filterOptionValue = null
|
|
|
|
valueColumn.filterOptionValue = null
|
|
|
|
}
|
|
|
|
|
|
|
|
const onUpdateFilter = (filters, sourceColumn) => {
|
|
|
|
switch (filterType.value) {
|
|
|
|
case filterOption[0].value:
|
|
|
|
idColumn.filterOptionValue = filters[sourceColumn.key]
|
|
|
|
break
|
|
|
|
case filterOption[1].value:
|
|
|
|
valueColumn.filterOptionValue = filters[sourceColumn.key]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="content-wrapper flex-box-v">
|
2023-10-11 01:15:23 +08:00
|
|
|
<content-toolbar
|
|
|
|
:db="props.db"
|
2023-10-31 17:29:56 +08:00
|
|
|
:decode="props.decode"
|
2023-10-11 01:15:23 +08:00
|
|
|
:key-code="props.keyCode"
|
2023-10-20 18:34:19 +08:00
|
|
|
:key-path="props.keyPath"
|
2023-10-11 01:15:23 +08:00
|
|
|
:key-type="keyType"
|
|
|
|
:server="props.name"
|
2023-10-30 00:54:45 +08:00
|
|
|
:ttl="ttl"
|
2023-10-31 17:29:56 +08:00
|
|
|
:view-as="props.viewAs"
|
2023-10-30 00:54:45 +08:00
|
|
|
class="value-item-part" />
|
|
|
|
<div class="tb2 value-item-part flex-box-h">
|
2023-07-25 19:12:50 +08:00
|
|
|
<div class="flex-box-h">
|
|
|
|
<n-input-group>
|
|
|
|
<n-select
|
|
|
|
v-model:value="filterType"
|
|
|
|
:consistent-menu-width="false"
|
|
|
|
:options="filterOption"
|
|
|
|
style="width: 120px"
|
2023-08-24 15:23:25 +08:00
|
|
|
@update:value="onChangeFilterType" />
|
2023-07-25 19:12:50 +08:00
|
|
|
<n-input
|
|
|
|
v-model:value="filterValue"
|
2023-09-07 18:38:34 +08:00
|
|
|
:placeholder="$t('interface.search')"
|
2023-07-25 19:12:50 +08:00
|
|
|
clearable
|
|
|
|
@clear="clearFilter"
|
2023-08-24 15:23:25 +08:00
|
|
|
@update:value="onFilterInput" />
|
2023-07-25 19:12:50 +08:00
|
|
|
</n-input-group>
|
|
|
|
</div>
|
2023-10-30 00:54:45 +08:00
|
|
|
<div class="flex-item-expand"></div>
|
2023-10-20 18:34:19 +08:00
|
|
|
<n-button :focusable="false" plain @click="onAddRow">
|
2023-07-25 19:12:50 +08:00
|
|
|
<template #icon>
|
|
|
|
<n-icon :component="AddLink" size="18" />
|
|
|
|
</template>
|
2023-09-07 18:38:34 +08:00
|
|
|
{{ $t('interface.add_row') }}
|
2023-07-25 19:12:50 +08:00
|
|
|
</n-button>
|
|
|
|
</div>
|
2023-10-30 00:54:45 +08:00
|
|
|
<div class="value-wrapper value-item-part fill-height flex-box-h">
|
2023-07-25 19:12:50 +08:00
|
|
|
<n-data-table
|
|
|
|
:key="(row) => row.id"
|
2023-10-20 18:34:19 +08:00
|
|
|
:bordered="false"
|
|
|
|
:bottom-bordered="false"
|
2023-07-25 19:12:50 +08:00
|
|
|
:columns="columns"
|
|
|
|
:data="tableData"
|
|
|
|
:single-column="true"
|
|
|
|
:single-line="false"
|
|
|
|
flex-height
|
|
|
|
max-height="100%"
|
|
|
|
size="small"
|
|
|
|
striped
|
|
|
|
virtual-scroll
|
2023-08-24 15:23:25 +08:00
|
|
|
@update:filters="onUpdateFilter" />
|
2023-07-25 19:12:50 +08:00
|
|
|
</div>
|
2023-10-30 00:54:45 +08:00
|
|
|
|
|
|
|
<div class="value-footer flex-box-h">
|
|
|
|
<n-text v-if="!isNaN(props.length)">{{ $t('interface.entries') }}: {{ props.length }}</n-text>
|
|
|
|
<n-divider v-if="!isNaN(props.length)" vertical />
|
|
|
|
<n-text v-if="!isNaN(props.size)">{{ $t('interface.memory_usage') }}: {{ bytes(props.size) }}</n-text>
|
|
|
|
<div class="flex-item-expand"></div>
|
|
|
|
</div>
|
2023-07-25 19:12:50 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-10-30 00:54:45 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.value-footer {
|
|
|
|
border-top: v-bind('themeVars.borderColor') 1px solid;
|
|
|
|
background-color: v-bind('themeVars.tableHeaderColor');
|
|
|
|
}
|
|
|
|
</style>
|