| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss">'+stylFns['app/pages/Admin/index.styl']+'</style>')
- PouchDB = require 'app/utils/pouch'
- # Иконки для меню (упрощенные компоненты)
- MenuIcons =
- SliderIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16"></path>
- </svg>
- """
-
- ProductsIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path>
- </svg>
- """
-
- ClientsIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
- </svg>
- """
-
- BlogIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
- </svg>
- """
-
- RoutesIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path>
- </svg>
- """
-
- SettingsIcon:
- template: """
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
- </svg>
- """
- 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
|