mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
чиним билд08
This commit is contained in:
@@ -23,26 +23,30 @@ const router = createRouter({
|
|||||||
name: 'requests',
|
name: 'requests',
|
||||||
component: () => import('@/views/RequestsView.vue'),
|
component: () => import('@/views/RequestsView.vue'),
|
||||||
meta: { requiresAuth: true }
|
meta: { requiresAuth: true }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/admin/dashboard',
|
||||||
|
name: 'admin-dashboard',
|
||||||
|
component: () => import('@/views/AdminDashboardView.vue'),
|
||||||
|
meta: { requiresAdmin: true }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
console.log('Проверка маршрута:', to.path)
|
if (to.meta.requiresAdmin) {
|
||||||
|
const adminToken = localStorage.getItem('admin_token')
|
||||||
if (to.meta.requiresAuth) {
|
if (!adminToken) {
|
||||||
console.log('Маршрут требует авторизации')
|
next('/admin')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if (to.meta.requiresAuth) {
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
console.log('Токен:', token ? 'Присутствует' : 'Отсутствует')
|
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
console.log('Перенаправление на /login')
|
|
||||||
next('/login')
|
next('/login')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Разрешаем переход')
|
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
24
frontend/src/views/AdminDashboardView.vue
Normal file
24
frontend/src/views/AdminDashboardView.vue
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<template>
|
||||||
|
<div class="min-h-full">
|
||||||
|
<header class="bg-white shadow">
|
||||||
|
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
|
||||||
|
<h1 class="text-3xl font-bold text-gray-900">
|
||||||
|
Панель администратора
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<div class="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||||
|
<div class="px-4 py-6 sm:px-0">
|
||||||
|
<div class="border-4 border-dashed border-gray-200 rounded-lg h-96 flex items-center justify-center">
|
||||||
|
<p class="text-gray-500">Здесь будет содержимое панели администратора</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
// Здесь будет логика панели администратора
|
||||||
|
</script>
|
89
frontend/src/views/AdminLoginView.vue
Normal file
89
frontend/src/views/AdminLoginView.vue
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<template>
|
||||||
|
<div class="min-h-full flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="max-w-md w-full space-y-8">
|
||||||
|
<div>
|
||||||
|
<h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
|
||||||
|
Вход для администратора
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<form class="mt-8 space-y-6" @submit.prevent="handleLogin">
|
||||||
|
<div class="rounded-md shadow-sm -space-y-px">
|
||||||
|
<div>
|
||||||
|
<label for="username" class="sr-only">Имя пользователя</label>
|
||||||
|
<input
|
||||||
|
id="username"
|
||||||
|
v-model="username"
|
||||||
|
name="username"
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
class="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||||
|
placeholder="Имя пользователя"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="password" class="sr-only">Пароль</label>
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
v-model="password"
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
required
|
||||||
|
class="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||||
|
placeholder="Пароль"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
|
||||||
|
:disabled="loading"
|
||||||
|
>
|
||||||
|
<span v-if="loading">Загрузка...</span>
|
||||||
|
<span v-else>Войти</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="error" class="text-red-600 text-center">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const username = ref('')
|
||||||
|
const password = ref('')
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref('')
|
||||||
|
|
||||||
|
const handleLogin = async () => {
|
||||||
|
loading.value = true
|
||||||
|
error.value = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post('/api/auth/admin', {
|
||||||
|
username: username.value,
|
||||||
|
password: password.value
|
||||||
|
})
|
||||||
|
|
||||||
|
// Сохраняем токен администратора
|
||||||
|
localStorage.setItem('admin_token', response.data.access_token)
|
||||||
|
localStorage.setItem('is_admin', 'true')
|
||||||
|
|
||||||
|
// Перенаправляем на панель администратора
|
||||||
|
await router.push('/admin/dashboard')
|
||||||
|
} catch (e: any) {
|
||||||
|
error.value = e.response?.data?.detail || 'Неверное имя пользователя или пароль'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Reference in New Issue
Block a user