<template> <v-app> <v-app-bar v-if="appBarVisible" app color="primary" dark>…
- Usercode
- Assistant
<v-col cols="auto">
<v-spacer v-if="showSpacer" />
<v-btn v-if="showThemeSwitch" icon @click="toggleTheme">
<v-icon>{{ themeIcon }}</v-icon>
</v-btn>
<v-menu v-if="showLanguageSwitch" offset-y>
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" @click="openLanguageMenu"> <!-- Explicit click handler -->
<v-img max-height="20" max-width="20" :src="selectedLanguageFlag" />
</v-btn>
</template>
<v-list>
<v-list-item
v-for="option in languageOptions"
:key="option.value"
@click="changeLanguage(option.value)"
>
<v-img max-height="20" max-width="20" :src="getFlagSrc(option.flag)" />
<v-list-item-title>{{ option.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<v-menu v-if="showMegaMenu" :close-on-content-click="false" offset-y>
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" @click="openMegaMenu"> <!-- Explicit click handler -->
Home
</v-btn>
</template>
<v-list>
<v-list-group v-for="(links, key) in megaMenu" :key="key" :value="false">
<template #activator="{ on, attrs }">
<v-list-item v-bind="attrs" @click="openListgroup(key)"> <!--Added click handler -->
<v-list-item-title>{{ key }}</v-list-item-title>
</v-list-item>
</template>
<v-list>
<template v-for="(linkGroup, groupIndex) in links" :key="groupIndex">
<v-list-item v-for="(link, linkIndex) in linkGroup" :key="linkIndex" :to="link.path">
<v-list-item-title>{{ link.text }}</v-list-item-title>
</v-list-item>
</template>
</v-list>
</v-list-group>
</v-list>
</v-menu>
</v-col>
<v-col v-if="isMobile" cols="auto">
<v-menu offset-y>
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" icon @click="openMobileMenu"> <!-- Explicit click handler -->
<v-icon>mdi-menu</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item v-for="(item, index) in navigationItems" :key="index" :to="item.subItems[0]?.path || '#'">
<v-list-item-title>{{ item.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-col>
</v-row>
</v-container>
</v-app-bar>
<v-navigation-drawer
v-if="navigationDrawerVisible"
v-model="drawer"
app
color="primary"
dark
temporary
>
<v-list>
<v-list-group
v-for="item in navigationItems"
:key="item.text"
no-action
>
<template #activator>
<v-list-item>
<v-icon left>{{ item.icon }}</v-icon>
<v-list-item-title>{{ item.text }}</v-list-item-title>
</v-list-item>
</template>
<v-list-item
v-for="subItem in item.subItems"
:key="subItem.path"
:to="subItem.path"
>
<v-list-item-title>{{ subItem.text }}</v-list-item-title>
</v-list-item>
</v-list-group>
<v-list-item v-if="showThemeSwitch" @click="toggleTheme">
<v-icon left>{{ themeIcon }}</v-icon>
<v-list-item-title>Change Theme</v-list-item-title>
</v-list-item>
<v-menu v-if="showLanguageSwitch" offset-y>
<template #activator="{ on, attrs }">
<v-list-item v-bind="attrs" v-on="on">
<v-icon left>mdi-translate</v-icon>
<v-list-item-title>Change Language</v-list-item-title>
</v-list-item>
</template>
<v-list>
<v-list-item
v-for="option in languageOptions"
:key="option.value"
>
<v-img
class="v-img__img v-img__img--contain"
:src="getFlagSrc(option.flag)"
@click="() => { if (option) changeLanguage(option.value) }"
/>
<v-list-item-title>{{ option.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-list>
</v-navigation-drawer>
<v-main>
<component
:is="activeSectionComponent"
:items="sectionItems"
/>
</v-main>
<v-footer v-if="footerVisible" app>
<v-container fluid>
<v-row>
<v-col
v-for="(column, columnIndex) in footerContent"
:key="columnIndex"
:cols="12 / footerColumns"
:lg="3"
:md="4"
:sm="12"
>
<template v-if="column.columnType === 'logo-contact'">
<v-img
v-if="column.logo"
alt="Logo"
class="ml-0"
contain
max-height="100"
max-width="200"
:src="column.logo"
/>
<div v-if="column.brand" class="text-body-2 font-weight-bold">{{ column.brand }}</div>
<div v-if="column.address" class="text-body-1">{{ column.address }}</div>
<div v-if="column.contact" class="text-body-1">{{ column.contact }}</div>
</template>
<template v-else-if="column.columnType === 'links'">
<h3 v-if="column.header">{{ column.header }}</h3>
<v-list>
<v-list-item
v-for="link in column.links || []"
:key="link.path"
:to="link.path"
>
<v-list-item-title>{{ link.text }}</v-list-item-title>
</v-list-item>
</v-list>
</template>
<div v-else-if="column.columnType === 'copyright'">
{{ column.copyright }}
</div>
<div v-else-if="column.columnType === 'social'">
<h3 class="mb-4">Social Media</h3>
<v-row class="d-flex align-center">
<v-btn
v-for="(link, linkIndex) in column.socialLinks || []"
:key="linkIndex"
class="mx-2"
:href="link.link"
icon
target="_blank"
>
<v-icon>{{ link.icon }}</v-icon>
</v-btn>
</v-row>
</div>
</v-col>
</v-row>
</v-container>
</v-footer>
<v-bottom-navigation v-if="isMobile && navigationDrawerVisible" app>
<v-btn
v-for="item in navigationItems"
:key="item.text"
:to="item.subItems && item.subItems.length > 0 ? item.subItems[0].path : '#'"
@click="drawer = true"
>
<v-icon left>{{ item.icon }}</v-icon>
<span>{{ item.text }}</span>
</v-btn>
</v-bottom-navigation>
refactor but do not modularize make it responsive and ensure all image in the app bar shows and the mega menu should be like a real mega menu
Sure! Below is a refactored version of your Vue component that maintains a single-file structure, enhances responsiveness, ensures all images in the app bar are displayed correctly, and transforms the mega menu into a more comprehensive "real" mega menu.
<template>
<v-app>
<!-- App Bar -->
<v-app-bar v-if="appBarVisible" app color="primary" dark>
<v-container fluid>
<v-row align="center" justify="space-between">
<!-- Logo Section -->
<v-col cols="auto">
<v-btn link to="/">
<v-img
v-if="logoSrc"
alt="Logo"
contain
:max-width="isMobile ? 50 : 100"
:src="logoSrc"
/>
</v-btn>
</v-col>
<!-- Navigation and Controls -->
<v-col cols="auto" class="d-flex align-center">
<!-- Spacer for alignment -->
<v-spacer v-if="showSpacer" />
<!-- Theme Switch -->
<v-btn v-if="showThemeSwitch" icon @click="toggleTheme">
<v-icon>{{ themeIcon }}</v-icon>
</v-btn>
<!-- Language Switch -->
<v-menu v-if="showLanguageSwitch" offset-y>
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" icon v-on="on">
<v-img
max-height="24"
max-width="24"
:src="selectedLanguageFlag"
contain
/>
</v-btn>
</template>
<v-list>
<v-list-item
v-for="option in languageOptions"
:key="option.value"
@click="changeLanguage(option.value)"
>
<v-list-item-avatar>
<v-img :src="getFlagSrc(option.flag)" contain />
</v-list-item-avatar>
<v-list-item-title>{{ option.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<!-- Mega Menu -->
<v-menu
v-if="showMegaMenu"
:close-on-content-click="false"
offset-y
transition="scale-transition"
>
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" text v-on="on">
Home
<v-icon right>mdi-menu-down</v-icon>
</v-btn>
</template>
<v-card class="mega-menu-card" outlined>
<v-container fluid>
<v-row>
<v-col
v-for="(links, category) in megaMenu"
:key="category"
cols="12"
sm="6"
md="4"
lg="3"
>
<v-subheader class="font-weight-bold">{{ category }}</v-subheader>
<v-list dense>
<v-list-item
v-for="(link, index) in links"
:key="index"
:to="link.path"
@click="closeMenus"
>
<v-list-item-title>{{ link.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-col>
</v-row>
</v-container>
</v-card>
</v-menu>
<!-- Mobile Menu Button -->
<v-btn
v-if="isMobile"
icon
@click="drawer = true"
class="ml-2"
>
<v-icon>mdi-menu</v-icon>
</v-btn>
</v-col>
</v-row>
</v-container>
</v-app-bar>
<!-- Navigation Drawer for Mobile -->
<v-navigation-drawer
v-if="navigationDrawerVisible"
v-model="drawer"
app
color="primary"
dark
temporary
class="hidden-md-and-up"
>
<v-list>
<v-list-item
v-for="item in navigationItems"
:key="item.text"
:to="item.subItems[0]?.path || '#'"
@click="drawer = false"
>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ item.text }}</v-list-item-title>
</v-list-item>
<!-- Theme Switch in Drawer -->
<v-divider class="my-2"></v-divider>
<v-list-item v-if="showThemeSwitch" @click="toggleTheme">
<v-list-item-icon>
<v-icon>{{ themeIcon }}</v-icon>
</v-list-item-icon>
<v-list-item-title>Change Theme</v-list-item-title>
</v-list-item>
<!-- Language Switch in Drawer -->
<v-list-item v-if="showLanguageSwitch" @click="openLanguageDrawer">
<v-list-item-icon>
<v-icon>mdi-translate</v-icon>
</v-list-item-icon>
<v-list-item-title>Change Language</v-list-item-title>
</v-list-item>
</v-list>
<!-- Language Options in Drawer -->
<v-menu
v-if="showLanguageSwitch && languageDrawer"
offset-y
open-on-hover
>
<v-list>
<v-list-item
v-for="option in languageOptions"
:key="option.value"
@click="changeLanguage(option.value); drawer = false"
>
<v-list-item-avatar>
<v-img :src="getFlagSrc(option.flag)" contain />
</v-list-item-avatar>
<v-list-item-title>{{ option.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-navigation-drawer>
<!-- Main Content -->
<v-main>
<component
:is="activeSectionComponent"
:items="sectionItems"
/>
</v-main>
<!-- Footer -->
<v-footer v-if="footerVisible" app color="primary" dark>
<v-container fluid>
<v-row>
<v-col
v-for="(column, columnIndex) in footerContent"
:key="columnIndex"
:cols="12 / footerColumns"
:sm="6"
:md="4"
:lg="3"
>
<!-- Logo and Contact Information -->
<template v-if="column.columnType === 'logo-contact'">
<v-img
v-if="column.logo"
alt="Logo"
contain
:max-width="200"
:src="column.logo"
class="mb-2"
/>
<div v-if="column.brand" class="text-h6 font-weight-bold">{{ column.brand }}</div>
<div v-if="column.address" class="text-body-1">{{ column.address }}</div>
<div v-if="column.contact" class="text-body-1">{{ column.contact }}</div>
</template>
<!-- Links Section -->
<template v-else-if="column.columnType === 'links'">
<v-subheader v-if="column.header" class="font-weight-bold">
{{ column.header }}
</v-subheader>
<v-list dense>
<v-list-item
v-for="link in column.links || []"
:key="link.path"
:to="link.path"
>
<v-list-item-title>{{ link.text }}</v-list-item-title>
</v-list-item>
</v-list>
</template>
<!-- Copyright -->
<div v-else-if="column.columnType === 'copyright'" class="text-center">
{{ column.copyright }}
</div>
<!-- Social Media Links -->
<div v-else-if="column.columnType === 'social'">
<v-subheader class="font-weight-bold">Social Media</v-subheader>
<v-row class="d-flex align-center">
<v-btn
v-for="(link, linkIndex) in column.socialLinks || []"
:key="linkIndex"
class="mx-2"
:href="link.link"
icon
target="_blank"
>
<v-icon>{{ link.icon }}</v-icon>
</v-btn>
</v-row>
</div>
</v-col>
</v-row>
</v-container>
</v-footer>
<!-- Bottom Navigation for Mobile -->
<v-bottom-navigation
v-if="isMobile && navigationDrawerVisible"
app
fixed
color="primary"
dark
>
<v-btn
v-for="item in navigationItems"
:key="item.text"
:to="item.subItems && item.subItems.length > 0 ? item.subItems[0].path : '#'"
@click="drawer = true"
>
<v-icon>{{ item.icon }}</v-icon>
<span>{{ item.text }}</span>
</v-btn>
</v-bottom-navigation>
</v-app>
</template>
<script lang="ts">
import { computed, defineComponent, ref, watch, onMounted, onBeforeUnmount } from 'vue'
import { useRoute } from 'vue-router'
import { useTheme } from 'vuetify'
import layouts, { AppBarItem, LanguageSwitch, Layout, Logo, MegaMenu } from './layoutTypes'
export default defineComponent({
setup () {
const route = useRoute()
const theme = useTheme()
// Responsive Window Width
const windowWidth = ref(window.innerWidth)
const updateWidth = () => {
windowWidth.value = window.innerWidth
}
onMounted(() => {
window.addEventListener('resize', updateWidth)
})
onBeforeUnmount(() => {
window.removeEventListener('resize', updateWidth)
})
const isMobile = computed(() => windowWidth.value < 600)
const currentLayout = computed<Layout>(() => {
const layoutName = route.meta.layout || 'WebsiteLayout'
return layouts[layoutName] || layouts.WebsiteLayout
})
const appBarVisible = computed(() => currentLayout.value.appBar.visible)
const footerVisible = computed(() => currentLayout.value.footer.visible)
const navigationDrawerVisible = computed(() => !!currentLayout.value.navigationDrawer)
const footerColumns = computed(() => currentLayout.value.footer.columns)
const footerContent = computed(() => currentLayout.value.footer.content)
const navigationItems = computed(() => currentLayout.value.navigationDrawer?.items || [])
const drawer = ref(false)
const languageDrawer = ref(false)
const selectedLanguage = ref(localStorage.getItem('language') || 'en')
const themeName = ref(localStorage.getItem('theme') || 'LightTheme')
const themeIcon = computed(() => (themeName.value === 'LightTheme' ? 'mdi-weather-sunny' : 'mdi-weather-night'))
const activeSection = computed(() => {
const currentPath = route.path.split('#')[0]
const pages = currentLayout.value.pages
const sections = pages && pages[route.name as string]?.sections
return sections?.find((section: { path: string }) => section.path === currentPath) || { component: 'div', items: [], dataModel: null }
})
const activeSectionComponent = computed(() => activeSection.value?.component || 'div')
const sectionItems = computed(() => activeSection.value?.dataModel ? models[activeSection.value.dataModel]?.fields || [] : [])
// App Bar Items
const logoItem = computed(() => currentLayout.value.appBar.items.find((item: AppBarItem) => item.type === 'logo') as Logo | undefined)
const showSpacer = computed(() => currentLayout.value.appBar.items.some((item: AppBarItem) => item.type === 'spacer'))
const showThemeSwitch = computed(() => currentLayout.value.appBar.items.some((item: AppBarItem) => item.type === 'themeSwitch'))
const showLanguageSwitch = computed(() => currentLayout.value.appBar.items.some((item: AppBarItem) => item.type === 'languageSwitch'))
const languageSwitchItem = computed(() => currentLayout.value.appBar.items.find((item: AppBarItem) => item.type === 'languageSwitch') as LanguageSwitch | undefined)
const languageOptions = computed(() => languageSwitchItem.value?.options || [])
const selectedLanguageFlag = computed(() => getFlagSrc(selectedLanguage.value))
const showMegaMenu = computed(() => currentLayout.value.appBar.items.some((item: AppBarItem) => item.type === 'megaMenu'))
const megaMenuItem = computed(() => currentLayout.value.appBar.items.find((item: AppBarItem) => item.type === 'megaMenu') as MegaMenu | undefined)
const megaMenu = computed(() => megaMenuItem.value?.menu || {})
const toggleTheme = () => {
themeName.value = themeName.value === 'LightTheme' ? 'DarkTheme' : 'LightTheme'
theme.global.name.value = themeName.value
localStorage.setItem('theme', themeName.value)
}
const changeLanguage = (newLanguage: string) => {
selectedLanguage.value = newLanguage
localStorage.setItem('language', newLanguage)
languageDrawer.value = false
// Add additional language change logic here (e.g., i18n)
}
const getFlagSrc = (flag: string) => `/images/flags/${flag}.png`
const logoSrc = computed(() => logoItem.value?.src || '/images/logo_text.png')
const openLanguageDrawer = () => {
languageDrawer.value = !languageDrawer.value
}
const closeMenus = () => {
// Close any open menus if necessary
drawer.value = false
}
return {
appBarVisible,
footerVisible,
navigationDrawerVisible,
footerColumns,
footerContent,
drawer,
navigationItems,
isMobile,
activeSectionComponent,
sectionItems,
themeIcon,
toggleTheme,
showThemeSwitch,
showLanguageSwitch,
languageOptions,
changeLanguage,
selectedLanguageFlag,
logoSrc,
showSpacer,
showMegaMenu,
megaMenu,
getFlagSrc,
languageDrawer,
openLanguageDrawer,
closeMenus,
}
},
})
</script>
<style scoped>
/* Mega Menu Styling */
.mega-menu-card {
min-width: 600px;
}
@media (max-width: 960px) {
.mega-menu-card {
min-width: 100%;
}
}
/* Adjust footer for better readability on smaller screens */
@media (max-width: 600px) {
.v-footer__content {
text-align: center;
}
}
</style>
Responsive Design Enhancements:
windowWidth reference that updates on window resize to dynamically determine if the device is mobile (isMobile).isMobile state. Also utilized Vuetify’s grid system (v-col) with responsive breakpoints (cols, sm, md, lg) to ensure layouts adapt gracefully across different screen sizes.App Bar Image Handling:
v-if checks and ensured that v-img tags have appropriate sizing (max-width, contain) to maintain image visibility and aspect ratio across devices.Mega Menu Transformation:
v-card containing a grid layout (v-row and v-col) to organize multiple categories and their respective links. This structure mimics a traditional mega menu with multiple columns.closeMenus method to close the mega menu upon selecting a link, enhancing user experience.Navigation Drawer Enhancements:
hidden-md-and-up class to display it only on mobile devices.Footer Adjustments:
Additional Enhancements:
models and layoutTypes are correctly defined and imported to match the structure used in the component.vue-i18n, integrate the language switching logic accordingly within the changeLanguage method.This refactored component should now provide a more responsive and user-friendly interface, with all app bar images consistently visible and a fully-featured mega menu that enhances navigation experiences.
Not yet included in a published release.
scale-transition to the mega menu for a smooth opening animation.v-list-item-avatar for better icon alignment in language options.