index.coffee 1.7 KB

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