Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 8316-orderCardWithVnCardBeta

This commit is contained in:
Alex Moreno 2025-01-15 12:06:17 +01:00
commit 3cef713058
3 changed files with 33 additions and 17 deletions

View File

@ -1,29 +1,17 @@
<script setup> <script setup>
import { ref, onMounted, useSlots } from 'vue'; import { onMounted, useSlots } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useHasContent } from 'src/composables/useHasContent';
const { t } = useI18n(); const { t } = useI18n();
const quasar = useQuasar(); const quasar = useQuasar();
const stateStore = useStateStore(); const stateStore = useStateStore();
const slots = useSlots(); const slots = useSlots();
const hasContent = ref(false); const hasContent = useHasContent('#right-panel');
const rightPanel = ref(null);
onMounted(() => { onMounted(() => {
rightPanel.value = document.querySelector('#right-panel');
if (!rightPanel.value) return;
const observer = new MutationObserver(() => {
hasContent.value = rightPanel.value.childNodes.length;
});
observer.observe(rightPanel.value, {
subtree: true,
childList: true,
attributes: true,
});
if ((!slots['right-panel'] && !hasContent.value) || quasar.platform.is.mobile) if ((!slots['right-panel'] && !hasContent.value) || quasar.platform.is.mobile)
stateStore.rightDrawer = false; stateStore.rightDrawer = false;
}); });

View File

@ -2,9 +2,10 @@
import RightMenu from './RightMenu.vue'; import RightMenu from './RightMenu.vue';
import VnSearchbar from 'components/ui/VnSearchbar.vue'; import VnSearchbar from 'components/ui/VnSearchbar.vue';
import VnTableFilter from '../VnTable/VnTableFilter.vue'; import VnTableFilter from '../VnTable/VnTableFilter.vue';
import { onBeforeMount, computed } from 'vue'; import { onBeforeMount, computed, ref } from 'vue';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useHasContent } from 'src/composables/useHasContent';
const $props = defineProps({ const $props = defineProps({
section: { section: {
@ -55,6 +56,8 @@ const isMainSection = computed(() => {
} }
return isSame; return isSame;
}); });
const searchbarId = 'section-searchbar';
const hasContent = useHasContent(`#${searchbarId}`);
onBeforeMount(() => { onBeforeMount(() => {
if ($props.dataKey) if ($props.dataKey)
@ -69,12 +72,13 @@ onBeforeMount(() => {
<template> <template>
<slot name="searchbar"> <slot name="searchbar">
<VnSearchbar <VnSearchbar
v-if="searchBar" v-if="searchBar && !hasContent"
v-bind="arrayDataProps" v-bind="arrayDataProps"
:data-key="dataKey" :data-key="dataKey"
:label="$t(`${prefix}.search`)" :label="$t(`${prefix}.search`)"
:info="$t(`${prefix}.searchInfo`)" :info="$t(`${prefix}.searchInfo`)"
/> />
<div :id="searchbarId"></div>
</slot> </slot>
<RightMenu> <RightMenu>

View File

@ -0,0 +1,24 @@
import { onMounted, ref } from 'vue';
export function useHasContent(selector) {
const container = ref({});
const hasContent = ref();
onMounted(() => {
container.value = document.querySelector(selector);
if (!container.value) return;
const observer = new MutationObserver(() => {
if (document.querySelector(selector))
hasContent.value = !!container.value.childNodes.length;
});
observer.observe(container.value, {
subtree: true,
childList: true,
attributes: true,
});
});
return hasContent;
}