document.head.insertAdjacentHTML('beforeend','') PouchDB = require 'app/utils/pouch' # Иконки для меню (упрощенные компоненты) MenuIcons = SliderIcon: template: """ """ ProductsIcon: template: """ """ ClientsIcon: template: """ """ BlogIcon: template: """ """ RoutesIcon: template: """ """ SettingsIcon: template: """ """ module.exports = name: 'AdminPanel' components: MenuIcons render: (new Function '_ctx', '_cache', renderFns['app/pages/Admin/index.pug'])() data: -> return { currentDomain: window.location.hostname theme: localStorage.getItem('theme') || 'light' mobileMenuOpen: false sidebarCollapsed: false notificationsOpen: false currentDomainSettings: null user: null mainMenuItems: [ { id: 'slider' name: 'Слайдер' path: '/admin/slider' icon: 'SliderIcon' } { id: 'products' name: 'Товары' path: '/admin/products' icon: 'ProductsIcon' } { id: 'clients' name: 'Клиенты' path: '/admin/clients' icon: 'ClientsIcon' } ] contentMenuItems: [ { id: 'blog' name: 'Блог' path: '/admin/blog' icon: 'BlogIcon' } { id: 'routes' name: 'Маршруты' path: '/admin/routes' icon: 'RoutesIcon' } ] systemMenuItems: [ { id: 'settings' name: 'Настройки' path: '/admin/settings' icon: 'SettingsIcon' } ] breadcrumbs: [] notifications: [] unreadNotifications: 0 } computed: currentRoute: -> @$route.path.split('/').pop() || 'settings' userInitials: -> return 'АД' unless @user?.name names = @user.name.split(' ') if names.length >= 2 (names[0][0] + names[1][0]).toUpperCase() else @user.name.substring(0, 2).toUpperCase() methods: navigateTo: (path) -> @mobileMenuOpen = false @$router.push(path) getMenuItemClass: (item) -> baseClass = 'admin__nav-item' isActive = @currentRoute == item.id if isActive return "#{baseClass} admin__nav-item--active" else return "#{baseClass} admin__nav-item--inactive" toggleTheme: -> @theme = if @theme == 'light' then 'dark' else 'light' localStorage.setItem 'theme', @theme document.documentElement.classList.toggle 'dark' @$root.theme = @theme refreshData: -> @showNotification 'Данные обновлены' markAsRead: (notificationId) -> notification = @notifications.find (n) -> n.id == notificationId if notification && !notification.read notification.read = true @unreadNotifications -= 1 logout: -> localStorage.removeItem 'user' @user = null @$router.push('/') @showNotification 'Вы успешно вышли из системы' loadDomainSettings: -> PouchDB.getDocument("domain_settings:#{@currentDomain}") .then (settings) => @currentDomainSettings = settings .catch (error) => console.log 'Настройки домена не найдены, используются значения по умолчанию' @currentDomainSettings = null loadUserData: -> userData = localStorage.getItem 'user' if userData try @user = JSON.parse userData catch @user = null else # Заглушка для демонстрации @user = { name: 'Администратор Системы', role: 'admin' } updateBreadcrumbs: -> routeName = @currentRoute breadcrumbMap = slider: { title: 'Слайдер' } products: { title: 'Товары' } clients: { title: 'Клиенты' } blog: { title: 'Блог' } routes: { title: 'Маршруты' } settings: { title: 'Настройки' } current = breadcrumbMap[routeName] if current @breadcrumbs = [ { title: 'Главная', path: '/admin' } { title: current.title } ] else @breadcrumbs = [{ title: 'Главная' }] showNotification: (message, type = 'success') -> @$root.showNotification?(message, type) || console.log("#{type}: #{message}") watch: currentRoute: immediate: true handler: -> @updateBreadcrumbs() mounted: -> @loadDomainSettings() @loadUserData() # Инициализация темы if @theme == 'dark' document.documentElement.classList.add 'dark' # Заглушка для уведомлений @notifications = [ { id: 1 title: 'Новый заказ получен' time: '5 мин назад' read: false icon: 'SettingsIcon' } { id: 2 title: 'Обновление системы' time: '1 час назад' read: false icon: 'SettingsIcon' } ] @unreadNotifications = @notifications.filter((n) -> !n.read).length