feat: navigation
This commit is contained in:
@@ -4,11 +4,6 @@ import { useRouter } from 'vue-router';
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const navigateTo = (path: string) => {
|
|
||||||
localStorage.setItem('app-selection', path)
|
|
||||||
router.push(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
to: string
|
to: string
|
||||||
title: string
|
title: string
|
||||||
@@ -25,7 +20,7 @@ defineProps<{
|
|||||||
<p class="w-56">{{ content }}</p>
|
<p class="w-56">{{ content }}</p>
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<Button @click="navigateTo(to)" severity="contrast" size="small">Перейти</Button>
|
<Button @click="router.push(to)" severity="contrast" size="small">Перейти</Button>
|
||||||
</template>
|
</template>
|
||||||
</Card>
|
</Card>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,25 +1,23 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { Button, Toolbar } from 'primevue';
|
import { Button, Toolbar } from 'primevue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useNavModalStore } from '../../stores/nav-modal.store';
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const logout = () => {
|
|
||||||
localStorage.removeItem('app-selection')
|
|
||||||
router.replace('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const navModalStore = useNavModalStore()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header >
|
<header >
|
||||||
<Toolbar>
|
<Toolbar style="border-radius: 0; border-top: none; border-left: none; border-right: none">
|
||||||
<template #start>
|
<template #start>
|
||||||
<p class="font-bold">{{ $route.matched?.[$route.matched.length - 2]?.name }} / {{ route.name }}</p>
|
<p class="font-bold">{{ $route.matched?.[$route.matched.length - 2]?.name }} / {{ route.name }}</p>
|
||||||
</template>
|
</template>
|
||||||
<template #end>
|
<template #end>
|
||||||
<Button severity="danger" :size="'small'" @click="logout">Выйти</Button>
|
<Button severity="secondary" size="small" @click="navModalStore.changeVisibility">
|
||||||
|
<span class="pi pi-list"></span>
|
||||||
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
40
frontend/src/components/modals/NavModal.vue
Normal file
40
frontend/src/components/modals/NavModal.vue
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Button, Drawer } from 'primevue';
|
||||||
|
import { useNavModalStore } from '../../stores/nav-modal.store';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
const navModalStore = useNavModalStore()
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
navModalStore.changeVisibility()
|
||||||
|
router.replace('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Route {
|
||||||
|
name: string
|
||||||
|
path: string
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
routes: Route[]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Drawer v-model:visible="navModalStore.visible">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<RouterLink :style="{ color: route.fullPath.endsWith(r.path) && 'var(--p-primary-color)' }" @click="() => {
|
||||||
|
navModalStore.changeVisibility()
|
||||||
|
}" v-for="r in routes" :to="r.path">{{ r.name }}
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<Button severity="danger" :size="'small'" class="w-full" @click="logout">Выйти</Button>
|
||||||
|
</template>
|
||||||
|
</Drawer>
|
||||||
|
</template>
|
||||||
@@ -9,6 +9,7 @@ import { createPinia } from 'pinia'
|
|||||||
import { router } from './router/router'
|
import { router } from './router/router'
|
||||||
import Tooltip from 'primevue/tooltip'
|
import Tooltip from 'primevue/tooltip'
|
||||||
|
|
||||||
|
|
||||||
createApp(App).directive('tooltip', Tooltip).use(router).use(createPinia()).use(Config, {
|
createApp(App).directive('tooltip', Tooltip).use(router).use(createPinia()).use(Config, {
|
||||||
theme: {
|
theme: {
|
||||||
preset: Aura,
|
preset: Aura,
|
||||||
|
|||||||
3
frontend/src/pages/pages/GrebenPage.vue
Normal file
3
frontend/src/pages/pages/GrebenPage.vue
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<h1>GREBEN</h1>
|
||||||
|
</template>
|
||||||
14
frontend/src/pages/pages/UserPage.vue
Normal file
14
frontend/src/pages/pages/UserPage.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { RouterView, useRoute, type RouteRecordRaw } from 'vue-router';
|
||||||
|
import NavModal, { type Route } from '../../components/modals/NavModal.vue';
|
||||||
|
import { routes } from '../../router/router';
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const lastRouteName = route.matched[route.matched.length - 2].path
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NavModal :routes="<Route[]>routes[routes.findIndex(r => r.path == lastRouteName)].children" />
|
||||||
|
<RouterView />
|
||||||
|
</template>
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { RouterView } from 'vue-router';
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<RouterView />
|
|
||||||
</template>
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
||||||
import Index from "../pages/Index.vue";
|
import Index from "../pages/Index.vue";
|
||||||
import UserPage from "../pages/user/UserPage.vue";
|
import UserPage from "../pages/pages/UserPage.vue";
|
||||||
import PostTablePage from "../pages/tables/PostTablePage.vue";
|
import PostTablePage from "../pages/tables/PostTablePage.vue";
|
||||||
|
import GrebenPage from "../pages/pages/GrebenPage.vue";
|
||||||
|
|
||||||
export const routes: RouteRecordRaw[] = [{
|
export const routes: RouteRecordRaw[] = [{
|
||||||
path: "/",
|
path: "/",
|
||||||
@@ -17,9 +18,13 @@ export const routes: RouteRecordRaw[] = [{
|
|||||||
component: PostTablePage,
|
component: PostTablePage,
|
||||||
path: '/user/post',
|
path: '/user/post',
|
||||||
name: 'Новости'
|
name: 'Новости'
|
||||||
|
}, {
|
||||||
|
component: GrebenPage,
|
||||||
|
path: '/user/greben',
|
||||||
|
name: 'Страница гребня'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}]
|
}] as const
|
||||||
|
|
||||||
export const router = createRouter({
|
export const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
|
|||||||
16
frontend/src/stores/nav-modal.store.ts
Normal file
16
frontend/src/stores/nav-modal.store.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
|
export interface NavModalState {
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useNavModalStore = defineStore('nav-modal', {
|
||||||
|
state: (): NavModalState => ({
|
||||||
|
visible: false
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
changeVisibility() {
|
||||||
|
this.visible = !this.visible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user