flaschengeist-frontend/src/layouts/MainLayout.vue

193 lines
4.5 KiB
Vue
Raw Normal View History

2020-10-02 07:13:14 +00:00
<template>
2020-10-09 16:04:32 +00:00
<q-layout view="hHh lpr lFf">
<q-header elevated class="bg-primary text-white">
2020-10-02 07:13:14 +00:00
<q-toolbar>
<!-- Button um Navigationsleiset ein und auszublenden. Nötig bei Desktop? -->
2020-10-02 07:13:14 +00:00
<q-btn
dense
2020-10-09 16:04:32 +00:00
flat
2020-10-02 07:13:14 +00:00
round
icon="menu"
@click="leftDrawerOpen = !leftDrawerOpen"
v-if="!leftDrawerOpen"
2020-10-02 07:13:14 +00:00
/>
<q-toolbar-title>
2020-10-09 16:04:32 +00:00
<q-avatar>
<img src="logo.svg" />
2020-10-09 16:04:32 +00:00
</q-avatar>
<span class="gt-xs">
Flaschengeist
</span>
2020-10-02 07:13:14 +00:00
</q-toolbar-title>
<!-- Hier kommen die Shortlinks hin -->
<div>
<q-btn flat round dense icon="sim_card" />
<q-btn flat round dense icon="gamepad" />
</div>
<q-btn
flat
round
dense
icon="mdi-exit-to-app"
@click="$router.push({ name: 'login' })"
/>
2020-10-02 07:13:14 +00:00
</q-toolbar>
</q-header>
<q-drawer
show-if-above
2020-10-09 16:04:32 +00:00
v-model="leftDrawerOpen"
side="left"
2020-10-02 07:13:14 +00:00
bordered
:mini="leftDrawerMini"
@click.capture="leftDrawerClicker"
2020-10-02 07:13:14 +00:00
>
<!-- Plugins -->
<q-list>
<essential-link
v-for="(link, index) in links"
2020-10-13 09:27:27 +00:00
:key="'main' + index"
:title="link.title"
:link="link.link"
:icon="link.icon"
/>
<essential-link
v-for="(link, index) in $flaschengeist_plugins"
2020-10-13 09:27:27 +00:00
:key="'plugin' + index"
:title="link.title"
:link="link.link"
:icon="link.icon"
/>
</q-list>
<q-separator />
2020-10-09 16:04:32 +00:00
<!-- Plugin functions -->
2020-10-13 09:27:27 +00:00
<!-- <router-view name="plugin-nav" /> -->
<q-list>
<essential-link
v-for="(link, index) in pluginChildLinks"
:key="'childPlugin' + index"
:title="link.title"
:link="link.link"
:icon="link.icon"
/>
</q-list>
<q-btn @click="showRoute" label="test"></q-btn>
2020-10-09 16:04:32 +00:00
<div class="q-mini-drawer-hide absolute" style="top: 15px; right: -11px">
<q-btn
size="sm"
dense
round
unelevated
color="secondary"
icon="chevron_left"
@click="leftDrawerMini = true"
/>
</div>
2020-10-02 07:13:14 +00:00
</q-drawer>
<q-page-container>
<router-view />
</q-page-container>
</q-layout>
</template>
<script lang="ts">
import EssentialLink from 'components/navigation/EssentialLink.vue';
2020-10-13 09:27:27 +00:00
import { Screen } from 'quasar';
import { PluginMainLink } from 'boot/plugins';
import { defineComponent, ref, computed } from '@vue/composition-api';
2020-10-02 07:13:14 +00:00
2020-10-09 16:04:32 +00:00
const links = [
2020-10-13 09:27:27 +00:00
{
name: 'home',
title: 'home',
icon: 'mdi-home',
children: [
{ title: 'Neues Home', link: 'newHome', icon: 'mdi-google-home' },
{ title: 'Altes Home', link: 'oldHome', icon: 'mdi-home-modern' }
]
},
{
name: 'about',
title: 'about',
link: 'about',
icon: 'mdi-information',
children: [
{
title: 'Neues About',
link: 'newAbout',
icon: 'mdi-information-outline'
},
{
title: 'Altes About',
link: 'oldAbout',
icon: 'mdi-information-variant'
}
]
}
2020-10-09 16:04:32 +00:00
];
2020-10-13 09:27:27 +00:00
declare module 'vue/types/vue' {
interface Vue {
$flaschengeist_plugins: PluginMainLink[];
}
}
2020-10-02 07:13:14 +00:00
export default defineComponent({
name: 'MainLayout',
components: { EssentialLink },
2020-10-13 09:27:27 +00:00
setup(_, ctx) {
const leftDrawer = ref(false);
const leftDrawerOpen = ref(
computed({
get: () => (leftDrawer.value || Screen.gt.sm ? true : false),
set: (val: boolean) => (leftDrawer.value = val)
})
);
const leftDrawerMini = ref(false);
function leftDrawerClicker() {
if (leftDrawerMini.value) {
leftDrawerMini.value = false;
}
}
2020-10-02 07:13:14 +00:00
2020-10-13 09:27:27 +00:00
const pluginChildLinks = computed(() => {
const test:
| PluginMainLink
| undefined = ctx.root.$flaschengeist_plugins.find(
(plugin: PluginMainLink) => {
return plugin.name == ctx.root.$route.matched[1].name;
}
);
console.log(test);
if (typeof test == undefined) {
return [];
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
return test.children;
}
});
function showRoute() {
console.log(ctx.root.$route);
}
return {
leftDrawerOpen,
leftDrawerMini,
leftDrawerClicker,
links,
pluginChildLinks,
showRoute
};
}
2020-10-02 07:13:14 +00:00
});
</script>