refactor: refs #6994 update VnJsonValue component props and improve descriptor handling
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-02-24 14:50:57 +01:00
parent 1bf34ff443
commit 0e7a8e61d3
3 changed files with 38 additions and 36 deletions

View File

@ -1,11 +1,11 @@
<script setup> <script setup>
import { watch, computed } from 'vue'; import { computed, watch } from 'vue';
import { toDateString } from 'src/filters'; import { toDateString } from 'src/filters';
import { useDescriptorStore } from 'src/stores/useDescriptorStore'; import { useDescriptorStore } from 'src/stores/useDescriptorStore';
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
const props = defineProps({ const props = defineProps({
prop: { type: Object, default: undefined }, value: { type: [String, Number, Boolean, Object], default: undefined },
name: { type: String, default: undefined },
}); });
const maxStrLen = 512; const maxStrLen = 512;
@ -13,8 +13,7 @@ let t = '';
let cssClass = ''; let cssClass = '';
let type; let type;
const descriptorStore = useDescriptorStore(); const descriptorStore = useDescriptorStore();
const propsValue = computed(() => props.value.val);
const propsValue = computed(() => props.prop.val.val);
const updateValue = () => { const updateValue = () => {
type = typeof propsValue.value; type = typeof propsValue.value;
@ -57,30 +56,21 @@ const updateValue = () => {
} }
}; };
watch(() => propsValue.value, updateValue); watch(() => props.value, updateValue);
updateValue(); updateValue();
</script> </script>
<template> <template>
<span :title="props.prop.name">{{ props.prop.nameI18n }}: </span>
<span <span
:title=" :title="type === 'string' && value.length > maxStrLen ? value : ''"
type === 'string' && propsValue.value?.length > maxStrLen
? propsValue.value
: ''
"
:class="{ :class="{
[cssClass]: t !== '', [cssClass]: t !== '',
'json-link': descriptorStore.has(props.prop.name), 'json-link': descriptorStore.has(name),
}" }"
> >
{{ t }} {{ name }}
<component <component v-if="value.id" :is="descriptorStore.has(name)" :id="value.id" />
v-if="props.prop.val.id"
:is="descriptorStore.has(props.prop.name)"
:id="props.prop.val.id"
/>
</span> </span>
</template> </template>
@ -104,8 +94,4 @@ updateValue();
color: #cd7c7c; color: #cd7c7c;
font-style: italic; font-style: italic;
} }
.json-link {
text-decoration: underline;
cursor: pointer;
}
</style> </style>

View File

@ -561,9 +561,8 @@ watch(
}}: }}:
</span> </span>
<VnJsonValue <VnJsonValue
:value=" :value="value.val"
value.val.val :name="prop.name"
"
/> />
</QItem> </QItem>
</QCardSection> </QCardSection>
@ -619,19 +618,27 @@ watch(
:key="prop2Index" :key="prop2Index"
class="q-pa-none text-grey" class="q-pa-none text-grey"
> >
<span
class="json-field"
:title="prop.name"
>
{{ prop.nameI18n }}:
</span>
<VnJsonValue <VnJsonValue
:prop="prop" :value="prop.val"
class="q-pr-xs" :name="prop.name"
/> />
<span <span
v-if=" v-if="
prop2Index < log.props.length prop2Index <
log.props.length &&
!log.expand
" "
class="q-mr-xs" class="q-mr-xs"
>, >,
</span> </span>
<span <span
v-if="prop.val.id" v-if="prop.val.id && log.expand"
class="id-value" class="id-value"
> >
#{{ prop.val.id }} #{{ prop.val.id }}
@ -644,7 +651,8 @@ watch(
> >
<VnJsonValue <VnJsonValue
:value="prop.old.val" :value="prop.old"
:name="prop.name"
/> />
<span <span
v-if="prop.old.id" v-if="prop.old.id"

View File

@ -3,23 +3,31 @@ import { defineStore } from 'pinia';
export const useDescriptorStore = defineStore('descriptorStore', () => { export const useDescriptorStore = defineStore('descriptorStore', () => {
const descriptors = ref({}); const descriptors = ref({});
const loaded = ref(false);
function set() { function set() {
const files = import.meta.glob(`src/**/*DescriptorProxy.vue`); const files = import.meta.glob(`src/**/*DescriptorProxy.vue`);
const moduleParser = {
user: 'account',
client: 'customer',
};
for (const file in files) { for (const file in files) {
descriptors.value[file.split('/').at(-1).slice(0, -19).toLowerCase() + 'Fk'] = console.log('fasd', file.split('/').at(-1).slice(0, -19).toLowerCase());
defineAsyncComponent(() => import(file)); const name = file.split('/').at(-1).slice(0, -19).toLowerCase();
const descriptor = moduleParser[name] ?? name;
//Ver pq no funciona account//user
descriptors.value[descriptor + 'Fk'] = defineAsyncComponent(() =>
import(file)
);
} }
loaded.value = true;
} }
function get() { function get() {
if (!loaded.value) set(); if (!Object.keys(descriptors.value).length) set();
} }
function has(name) { function has(name) {
get(); get();
console.log('descriptors.value: ', descriptors.value);
return descriptors.value[name]; return descriptors.value[name];
} }