0
1
Fork 0

Create custom title variable

This commit is contained in:
William Buezas 2024-11-06 22:44:01 -03:00
parent dff5820ed4
commit 69abcf6870
3 changed files with 24 additions and 7 deletions

View File

@ -14,6 +14,7 @@ const appStore = useAppStore();
const refreshContentKey = ref(0); const refreshContentKey = ref(0);
const { mainUser, supplantedUser } = storeToRefs(userStore); const { mainUser, supplantedUser } = storeToRefs(userStore);
const { const {
customTitle,
menuTitle, menuTitle,
subtitle, subtitle,
useRightDrawer, useRightDrawer,
@ -58,7 +59,7 @@ const logoutSupplantedUser = async () => {
@click="toggleLeftDrawer" @click="toggleLeftDrawer"
/> />
<QToolbarTitle> <QToolbarTitle>
{{ menuTitle }} {{ customTitle || menuTitle }}
<div v-if="subtitle" class="subtitle text-caption"> <div v-if="subtitle" class="subtitle text-caption">
{{ subtitle }} {{ subtitle }}
</div> </div>

View File

@ -288,7 +288,14 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { inject, onBeforeMount, ref, computed, watch } from 'vue'; import {
inject,
onBeforeMount,
ref,
computed,
watch,
onBeforeUnmount
} from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import VnImg from 'src/components/ui/VnImg.vue'; import VnImg from 'src/components/ui/VnImg.vue';
@ -890,29 +897,31 @@ const onConfirmClick = async params => {
const refreshTitle = () => { const refreshTitle = () => {
const { meta } = route; const { meta } = route;
let title = t(meta.title); const title = t(meta.title);
let subtitle; let subtitle;
let customTitle;
if (selectedCategory.value) { if (selectedCategory.value) {
const _category = categories.value.find( const _category = categories.value.find(
i => i.id === selectedCategory.value i => i.id === selectedCategory.value
); );
if (_category) { if (_category) {
title = _category.name; const categoryName = _category.name;
customTitle = categoryName;
if (selectedType.value) { if (selectedType.value) {
const _type = itemFamilies.value.find( const _type = itemFamilies.value.find(
i => i.id === selectedType.value i => i.id === selectedType.value
); );
if (_type) { if (_type) {
subtitle = title; subtitle = categoryName;
title = _type.name; customTitle = _type.name;
} }
} }
} }
} }
appStore.$patch({ title, subtitle }); appStore.$patch({ title, subtitle, customTitle });
}; };
const onViewModeClick = () => { const onViewModeClick = () => {
@ -965,6 +974,8 @@ onBeforeMount(async () => {
selectedCategory.value = Number(route.params.category); selectedCategory.value = Number(route.params.category);
if (route.params.type) selectedType.value = Number(route.params.type); if (route.params.type) selectedType.value = Number(route.params.type);
}); });
onBeforeUnmount(() => appStore.resetCustomTitle());
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -10,6 +10,7 @@ const { t } = i18n.global;
export const useAppStore = defineStore('hedera', { export const useAppStore = defineStore('hedera', {
state: () => ({ state: () => ({
customTitle: null,
title: null, title: null,
subtitle: null, subtitle: null,
imageUrl: '', imageUrl: '',
@ -160,6 +161,10 @@ export const useAppStore = defineStore('hedera', {
i18n.global.locale.value = _locale; i18n.global.locale.value = _locale;
this.siteLang = _locale; this.siteLang = _locale;
localStorage.setItem('siteLang', _locale); localStorage.setItem('siteLang', _locale);
},
resetCustomTitle() {
this.customTitle = null;
} }
}, },
getters: { getters: {