| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- # app/router/index.coffee
- config = require 'app/config'
- # Импорт компонентов страниц
- HomePage = require 'app/pages/Home/index.coffee'
- NotFoundPage = require 'app/pages/NotFound/index.coffee'
- CatalogPage = require 'app/pages/Catalog/index.coffee'
- ProductPage = require 'app/pages/Product/index.coffee'
- CartPage = require 'app/pages/Cart/index.coffee'
- AdminPage = require 'app/pages/Admin/index.coffee'
- # Импорт дочерних страниц админ-панели
- AdminDashboard = require 'app/pages/Admin/Dashboard/index.coffee'
- AdminProducts = require 'app/pages/Admin/Products/index.coffee'
- AdminCategories = require 'app/pages/Admin/Categories/index.coffee'
- AdminImport = require 'app/pages/Admin/Import/index.coffee'
- AdminMedia = require 'app/pages/Admin/Media/index.coffee'
- # Middleware для проверки прав доступа
- authGuard = (to, from, next) ->
- log 'Проверка прав доступа для route:', to.path
- # Здесь будет логика проверки пользователя из глобального состояния
- if to.matched.some (record) -> record.meta.requiresAuth
- # Проверка авторизации
- userData = localStorage.getItem('user')
- if userData
- try
- user = JSON.parse(userData)
- user.role = 'admin'
- if user.role == 'admin'
- next()
- else
- log '🚫 Доступ запрещен: недостаточно прав'
- next('/')
- catch
- log '🚫 Ошибка проверки пользователя'
- next('/')
- else
- log '🚫 Пользователь не авторизован'
- next()
- else
- next()
- domainMiddleware = (to, from, next) ->
- log 'Обработка динамического домена для route'
- # Логика обработки домена будет интегрирована позже
- next()
- router = VueRouter.createRouter({
- history: VueRouter.createWebHistory()
- routes: [
- {
- path: '/'
- name: 'Home'
- component: HomePage
- beforeEnter: [domainMiddleware]
- }
- {
- path: '/catalog'
- name: 'Catalog'
- component: CatalogPage
- beforeEnter: [domainMiddleware]
- }
- {
- path: '/catalog/:category?'
- name: 'CatalogCategory'
- component: CatalogPage
- beforeEnter: [domainMiddleware]
- }
- {
- path: '/product/:id'
- name: 'Product'
- component: ProductPage
- beforeEnter: [domainMiddleware]
- }
- {
- path: '/cart'
- name: 'Cart'
- component: CartPage
- beforeEnter: [domainMiddleware]
- }
- {
- path: '/admin'
- name: 'Admin'
- component: AdminPage
- meta: { requiresAuth: true }
- beforeEnter: [domainMiddleware, authGuard]
- redirect: '/admin/dashboard'
- children: [
- {
- path: 'dashboard'
- name: 'AdminDashboard'
- component: AdminDashboard
- meta: {
- title: 'Дашборд',
- breadcrumb: 'Дашборд'
- }
- }
- {
- path: 'products'
- name: 'AdminProducts'
- component: AdminProducts
- meta: {
- title: 'Управление товарами',
- breadcrumb: 'Товары'
- }
- }
- {
- path: 'categories'
- name: 'AdminCategories'
- component: AdminCategories
- meta: {
- title: 'Управление категориями',
- breadcrumb: 'Категории'
- }
- }
- {
- path: 'import'
- name: 'AdminImport'
- component: AdminImport
- meta: {
- title: 'Импорт товаров',
- breadcrumb: 'Импорт'
- }
- }
- {
- path: 'media'
- name: 'AdminMedia'
- component: AdminMedia
- meta: {
- title: 'Медиа-менеджер',
- breadcrumb: 'Медиа'
- }
- }
- {
- path: 'import/:step?'
- name: 'AdminImportStep'
- component: AdminImport
- meta: {
- title: 'Импорт товаров',
- breadcrumb: 'Импорт'
- }
- }
- ]
- }
- {
- path: '/:pathMatch(.*)*'
- name: 'NotFound'
- component: NotFoundPage
- beforeEnter: [domainMiddleware]
- }
- ]
- })
- # Глобальные обработчики роутера
- router.beforeEach (to, from, next) ->
- #log "Переход с \"#{from.path}\" на \"#{to.path}\""
-
- # Установка заголовка страницы
- if to.meta?.title
- document.title = "#{to.meta.title} - Браер-Колор"
- else if to.name
- document.title = "#{to.name} - Браер-Колор"
-
- next()
- router.afterEach (to, from) ->
- #log "Навигация завершена на \"#{to.path}\""
- # Глобальный обработчик ошибок навигации
- router.onError (error) ->
- log '💥 Ошибка навигации:', error
- console.error('Ошибка навигации:', error)
- module.exports = router
|