app.coffee 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Подключение мета информации
  2. document.head.insertAdjacentHTML 'beforeend', '<meta charset="UTF-8">'
  3. document.head.insertAdjacentHTML 'beforeend', '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
  4. # Настройка tailwind
  5. #tailwind.config = require 'tailwind.config.js'
  6. # Подключение основных стилей
  7. document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="main.css">' + stylFns['main.css'] + '</style>')
  8. document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="app/DesignTokens.styl">' + stylFns['app/DesignTokens.styl'] + '</style>')
  9. document.head.insertAdjacentHTML('beforeend', '<style type="text/tailwindcss" file="app/app.styl">' + stylFns['app/app.styl'] + '</style>')
  10. # Маршруты
  11. routes = [
  12. { path: '/', component: require 'app/pages/Home' }
  13. #{ path: '/:path*', component: require 'app/pages/DocumentPage' }
  14. ]
  15. globalThis._ = {}
  16. # Глобальное определение vuejs приложения
  17. globalThis.app = Vue.createApp
  18. name: 'app'
  19. data: () ->
  20. return {
  21. appState:
  22. currentDocument: null
  23. currentLanguage: 'ru'
  24. availableLanguages: ['ru', 'en', 'tj']
  25. loading: true
  26. error: null
  27. }
  28. beforeMount: ->
  29. globalThis.AppDB = new (require 'app/utils/AppDB')()
  30. await globalThis.AppDB.init()
  31. globalThis._ = @
  32. computed:
  33. currentLanguage: ->
  34. @appState.currentLanguage
  35. watch:
  36. currentLanguage:
  37. handler: (newDoc) ->
  38. debug.dir newDoc
  39. @loadDocumentForPath(window.location.pathname)
  40. immediate: true
  41. methods:
  42. initializeApp: ->
  43. # Определяем язык из URL или браузера
  44. @detectLanguage()
  45. # Загружаем документ для текущего пути
  46. @loadDocumentForPath(window.location.pathname)
  47. detectLanguage: ->
  48. # Простая логика определения языка
  49. pathLang = window.location.pathname.split('/')[1]
  50. if pathLang in @appState.availableLanguages
  51. @appState.currentLanguage = pathLang
  52. else
  53. browserLang = navigator.language.split('-')[0]
  54. if browserLang in @appState.availableLanguages
  55. @appState.currentLanguage = browserLang
  56. loadDocumentForPath: (path) ->
  57. try
  58. @appState.loading = true
  59. debug.log ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
  60. doc = await AppDB.getDocumentByPath(path, AppDB.currentLanguage)
  61. debug.dir doc
  62. debug.log "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
  63. @appState.currentDocument = doc
  64. @appState.loading = false
  65. # Устанавливаем заголовок страницы
  66. if doc?.title
  67. document.head.insertAdjacentHTML('beforeend', '<title>' + doc.title + '</title>')
  68. catch error
  69. @appState.error = "Ошибка загрузки документа: " + error
  70. @appState.loading = false
  71. render: (new Function '_ctx', '_cache', renderFns['app/app.pug'])()
  72. components: {
  73. 'hero-section': require('app/shared/HeroSection')
  74. 'image-gallery': require('app/shared/ImageGallery')
  75. }
  76. # Создаем и настраиваем роутер
  77. router = VueRouter.createRouter({
  78. routes: routes
  79. history: VueRouter.createWebHistory()
  80. scrollBehavior: (to, from, savedPosition) ->
  81. if savedPosition
  82. return savedPosition
  83. else
  84. return { x: 0, y: 0 }
  85. })
  86. app.use(router)
  87. app.mount('body')