index.coffee 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # app/pages/Admin/index.coffee
  2. if globalThis.stylFns and globalThis.stylFns['app/pages/Admin/index.styl']
  3. styleElement = document.createElement('style')
  4. styleElement.type = 'text/css'
  5. styleElement.textContent = globalThis.stylFns['app/pages/Admin/index.styl']
  6. document.head.appendChild(styleElement)
  7. module.exports = {
  8. props:
  9. domainSettings:
  10. type: Object
  11. default: -> {}
  12. language:
  13. type: String
  14. default: 'ru'
  15. data: ->
  16. {
  17. user: null
  18. breadcrumbs: []
  19. }
  20. computed:
  21. currentRoute: -> @$route
  22. methods:
  23. logout: ->
  24. localStorage.removeItem('user')
  25. @$router.push('/')
  26. @$emit('show-notification', 'Вы вышли из админ-панели', 'info')
  27. updateBreadcrumbs: ->
  28. crumbs = [{ path: '/admin', name: 'Админ-панель' }]
  29. if @$route.matched.length > 1
  30. @$route.matched.slice(1).forEach (route) =>
  31. if route.meta?.breadcrumb
  32. crumbs.push({
  33. path: route.path,
  34. name: route.meta.breadcrumb
  35. })
  36. @breadcrumbs = crumbs
  37. getBreadcrumbName: (path, segment) ->
  38. names =
  39. '/admin': 'Админ-панель'
  40. '/admin/dashboard': 'Дашборд'
  41. '/admin/products': 'Товары'
  42. '/admin/categories': 'Категории'
  43. '/admin/import': 'Импорт'
  44. '/admin/media': 'Медиа'
  45. return names[path] || segment.charAt(0).toUpperCase() + segment.slice(1)
  46. watch:
  47. '$route.path': ->
  48. @updateBreadcrumbs()
  49. mounted: ->
  50. userData = localStorage.getItem('user')
  51. if userData
  52. try
  53. @user = JSON.parse(userData)
  54. catch
  55. @user = null
  56. @updateBreadcrumbs()
  57. render: (new Function '_ctx', '_cache', globalThis.renderFns['app/pages/Admin/index.pug'])()
  58. }