cosmos-explorer/src/views/ObjectFieldComponent.vue

108 lines
2.3 KiB
Vue
Raw Normal View History

2021-08-04 01:28:30 +00:00
<template>
2021-08-05 04:38:58 +00:00
<b-table-simple
v-if="typeof tablefield === 'object'"
hover
2021-08-06 03:58:54 +00:00
:small="small"
2021-08-05 04:38:58 +00:00
striped
responsive
>
2021-08-04 01:28:30 +00:00
<b-tr
v-for="(value, name) in tablefield"
:key="name"
>
<b-td
style="text-transform: capitalize; vertical-align: top; width:200px"
>
2021-08-05 04:38:58 +00:00
{{ name }}
2021-08-04 01:28:30 +00:00
</b-td>
<b-td v-if="isTokenField(value)">
{{ formatTokens( value ) }}
</b-td>
<b-td v-else-if="Array.isArray(value)">
<array-field-component :tablefield="value" />
</b-td>
2021-08-05 04:38:58 +00:00
<b-td
v-else-if="typeof (value) ==='object'"
hover
2021-08-06 03:58:54 +00:00
class="overflow-hidden"
2021-08-05 04:38:58 +00:00
>
<b-tabs>
<b-tab
v-for="key in Object.keys(value)"
:key="key"
:title="key"
variant="danger"
>
<array-field-component
v-if="Array.isArray(value[key])"
:tablefield="value[key]"
/>
<object-field-component
v-else-if="typeof value[key] === 'object'"
:tablefield="value[key]"
/>
<span v-else>{{ formatText(value[key]) }} </span>
</b-tab>
</b-tabs>
</b-td>
2021-08-04 01:28:30 +00:00
<b-td v-else>
2021-08-06 03:58:54 +00:00
{{ value }}
2021-08-04 01:28:30 +00:00
</b-td>
</b-tr>
</b-table-simple>
</template>
<script>
import {
2021-08-05 04:38:58 +00:00
BTableSimple, BTr, BTd, BTabs, BTab,
2021-08-04 01:28:30 +00:00
} from 'bootstrap-vue'
2021-08-05 04:38:58 +00:00
import { abbr, isToken, tokenFormatter } from '@/libs/data'
2021-08-04 01:28:30 +00:00
import ArrayFieldComponent from './ArrayFieldComponent.vue'
export default {
name: 'ObjectFieldComponent',
components: {
BTableSimple,
BTr,
BTd,
2021-08-05 04:38:58 +00:00
BTabs,
BTab,
2021-08-04 01:28:30 +00:00
ArrayFieldComponent,
},
props: {
tablefield: {
2021-08-05 04:38:58 +00:00
type: [Array, Object],
2021-08-04 01:28:30 +00:00
default: () => {},
},
2021-08-06 03:58:54 +00:00
small: {
type: Boolean,
default: true,
},
2021-08-04 01:28:30 +00:00
},
methods: {
2021-08-05 04:38:58 +00:00
formatObject(value) {
// console.log(value, typeof (value) === 'object', Object.keys(value))
// if (typeof (value) === 'object' && Object.keys(value).length === 1) {
// console.log(value)
// return value[Object.keys(value)[0]]
// }
return value
},
formatText: v => abbr(v, 60),
2021-08-04 01:28:30 +00:00
eval_value(value) {
return Array.from(value)
},
isTokenField(value) {
return isToken(value)
},
formatTokens(value) {
return tokenFormatter(value)
},
},
}
</script>
2021-08-05 04:38:58 +00:00
<style scoped>
</style>