App.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <el-container>
  3. <el-aside v-if="showAsideBar" :width="asideWidth">
  4. <div class="app-name"><span v-html="appName"></span></div>
  5. <el-button class="el-button-collapse" @click="toggleCollapse" :icon="buttonCollapseIcon"></el-button>
  6. <el-menu class="el-menu-vertical" :default-active="rootRoute" :collapse="isCollapse" router>
  7. <el-menu-item index="/cardindex">
  8. <i class="el-icon-search"></i>
  9. <span :class="itemTitleClass('/cardindex')" slot="title">{{ this.itemRuText['/cardindex'] }}</span>
  10. </el-menu-item>
  11. <el-menu-item index="/reader">
  12. <i class="el-icon-tickets"></i>
  13. <span :class="itemTitleClass('/reader')" slot="title">{{ this.itemRuText['/reader'] }}</span>
  14. </el-menu-item>
  15. <el-menu-item index="/forum" disabled>
  16. <i class="el-icon-message"></i>
  17. <span :class="itemTitleClass('/forum')" slot="title">{{ this.itemRuText['/forum'] }}</span>
  18. </el-menu-item>
  19. <el-menu-item index="/income">
  20. <i class="el-icon-upload"></i>
  21. <span :class="itemTitleClass('/income')" slot="title">{{ this.itemRuText['/income'] }}</span>
  22. </el-menu-item>
  23. <el-menu-item index="/sources">
  24. <i class="el-icon-menu"></i>
  25. <span :class="itemTitleClass('/sources')" slot="title">{{ this.itemRuText['/sources'] }}</span>
  26. </el-menu-item>
  27. <el-menu-item index="/settings">
  28. <i class="el-icon-setting"></i>
  29. <span :class="itemTitleClass('/settings')" slot="title">{{ this.itemRuText['/settings'] }}</span>
  30. </el-menu-item>
  31. <el-menu-item index="/help">
  32. <i class="el-icon-question"></i>
  33. <span :class="itemTitleClass('/help')" slot="title">{{ this.itemRuText['/help'] }}</span>
  34. </el-menu-item>
  35. </el-menu>
  36. </el-aside>
  37. <el-main v-if="showMain" :style="{padding: (isReaderActive ? 0 : '5px')}">
  38. <keep-alive>
  39. <router-view></router-view>
  40. </keep-alive>
  41. </el-main>
  42. </el-container>
  43. </template>
  44. <script>
  45. //-----------------------------------------------------------------------------
  46. import Vue from 'vue';
  47. import Component from 'vue-class-component';
  48. export default @Component({
  49. watch: {
  50. rootRoute: function() {
  51. this.setAppTitle();
  52. this.redirectIfNeeded();
  53. },
  54. mode: function() {
  55. this.redirectIfNeeded();
  56. }
  57. },
  58. })
  59. class App extends Vue {
  60. itemRuText = {
  61. '/cardindex': 'Картотека',
  62. '/reader': 'Читалка',
  63. '/forum': 'Форум-чат',
  64. '/income': 'Поступления',
  65. '/sources': 'Источники',
  66. '/settings': 'Параметры',
  67. '/help': 'Справка',
  68. }
  69. created() {
  70. this.commit = this.$store.commit;
  71. this.dispatch = this.$store.dispatch;
  72. this.state = this.$store.state;
  73. this.uistate = this.$store.state.uistate;
  74. this.config = this.$store.state.config;
  75. // set-app-title
  76. this.$root.$on('set-app-title', this.setAppTitle);
  77. //global keyHooks
  78. this.keyHooks = [];
  79. this.keyHook = (event) => {
  80. for (const hook of this.keyHooks)
  81. hook(event);
  82. }
  83. this.$root.addKeyHook = (hook) => {
  84. if (this.keyHooks.indexOf(hook) < 0)
  85. this.keyHooks.push(hook);
  86. }
  87. this.$root.removeKeyHook = (hook) => {
  88. const i = this.keyHooks.indexOf(hook);
  89. if (i >= 0)
  90. this.keyHooks.splice(i, 1);
  91. }
  92. document.addEventListener('keyup', (event) => {
  93. this.keyHook(event);
  94. });
  95. document.addEventListener('keydown', (event) => {
  96. this.keyHook(event);
  97. });
  98. window.addEventListener('resize', () => {
  99. this.$root.$emit('resize');
  100. });
  101. }
  102. mounted() {
  103. this.dispatch('config/loadConfig');
  104. this.$watch('apiError', function(newError) {
  105. if (newError) {
  106. this.$notify.error({
  107. title: 'Ошибка API',
  108. dangerouslyUseHTMLString: true,
  109. message: newError.response.config.url + '<br>' + newError.response.statusText
  110. });
  111. }
  112. });
  113. }
  114. toggleCollapse() {
  115. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  116. this.$root.$emit('resize');
  117. }
  118. get isCollapse() {
  119. return this.uistate.asideBarCollapse;
  120. }
  121. get asideWidth() {
  122. if (this.uistate.asideBarCollapse) {
  123. return '64px';
  124. } else {
  125. return '170px';
  126. }
  127. }
  128. get buttonCollapseIcon() {
  129. if (this.uistate.asideBarCollapse) {
  130. return 'el-icon-d-arrow-right';
  131. } else {
  132. return 'el-icon-d-arrow-left';
  133. }
  134. }
  135. get appName() {
  136. if (this.isCollapse)
  137. return '<br><br>';
  138. else
  139. return `${this.config.name} <br>v${this.config.version}`;
  140. }
  141. get apiError() {
  142. return this.state.apiError;
  143. }
  144. get rootRoute() {
  145. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  146. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  147. return this.$root.rootRoute;
  148. }
  149. setAppTitle(title) {
  150. if (!title) {
  151. if (this.mode == 'omnireader') {
  152. document.title = `Omni Reader - всегда с вами`;
  153. } else if (this.config && this.mode !== null) {
  154. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  155. }
  156. } else {
  157. document.title = title;
  158. }
  159. }
  160. itemTitleClass(path) {
  161. return (this.rootRoute == path ? {'bold-font': true} : {});
  162. }
  163. get mode() {
  164. return this.$store.state.config.mode;
  165. }
  166. get showAsideBar() {
  167. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  168. }
  169. get isReaderActive() {
  170. return this.rootRoute == '/reader';
  171. }
  172. get showMain() {
  173. return (this.showAsideBar || this.isReaderActive);
  174. }
  175. redirectIfNeeded() {
  176. if ((this.mode == 'reader' || this.mode == 'omnireader') && (this.rootRoute != '/reader')) {
  177. //старый url
  178. const search = window.location.search.substr(1);
  179. const url = search.split('url=')[1] || '';
  180. if (url) {
  181. window.location = `/#/reader?url=${url}`;
  182. } else {
  183. this.$router.replace('/reader');
  184. }
  185. }
  186. //yandex-метрика для omnireader
  187. if (this.config.branch == 'production' && this.mode == 'omnireader' && !this.yaMetricsDone) {
  188. (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
  189. m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
  190. (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");// eslint-disable-line no-unexpected-multiline
  191. ym(52347334, "init", {// eslint-disable-line no-undef
  192. id:52347334,
  193. clickmap:true,
  194. trackLinks:true,
  195. accurateTrackBounce:true
  196. });
  197. this.yaMetricsDone = true;
  198. }
  199. }
  200. }
  201. //-----------------------------------------------------------------------------
  202. </script>
  203. <style scoped>
  204. .app-name {
  205. margin-left: 10px;
  206. margin-top: 10px;
  207. text-align: center;
  208. line-height: 140%;
  209. font-weight: bold;
  210. }
  211. .bold-font {
  212. font-weight: bold;
  213. }
  214. .el-container {
  215. height: 100%;
  216. }
  217. .el-aside {
  218. line-height: 1;
  219. background-color: #ccc;
  220. color: #000;
  221. }
  222. .el-main {
  223. padding: 0;
  224. background-color: #E6EDF4;
  225. color: #000;
  226. }
  227. .el-menu-vertical:not(.el-menu--collapse) {
  228. background-color: inherit;
  229. color: inherit;
  230. text-align: left;
  231. width: 100%;
  232. border: 0;
  233. }
  234. .el-menu--collapse {
  235. background-color: inherit;
  236. color: inherit;
  237. border: 0;
  238. }
  239. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  240. background-color: inherit;
  241. color: inherit;
  242. margin-top: 5px;
  243. width: 100%;
  244. height: 64px;
  245. border: 0;
  246. }
  247. .el-menu-item {
  248. font-size: 85%;
  249. }
  250. </style>
  251. <style>
  252. body, html, #app {
  253. margin: 0;
  254. padding: 0;
  255. height: 100%;
  256. font: normal 12pt ReaderDefault;
  257. }
  258. .el-tabs__content {
  259. flex: 1;
  260. padding: 0 !important;
  261. display: flex;
  262. flex-direction: column;
  263. overflow: hidden;
  264. }
  265. @font-face {
  266. font-family: 'ReaderDefault';
  267. src: url('fonts/reader-default.woff') format('woff'),
  268. url('fonts/reader-default.ttf') format('truetype');
  269. }
  270. @font-face {
  271. font-family: 'OpenSans';
  272. src: url('fonts/open-sans.woff') format('woff'),
  273. url('fonts/open-sans.ttf') format('truetype');
  274. }
  275. @font-face {
  276. font-family: 'Roboto';
  277. src: url('fonts/roboto.woff') format('woff'),
  278. url('fonts/roboto.ttf') format('truetype');
  279. }
  280. @font-face {
  281. font-family: 'Rubik';
  282. src: url('fonts/rubik.woff2') format('woff2');
  283. }
  284. @font-face {
  285. font-family: 'Avrile';
  286. src: url('fonts/avrile.woff') format('woff'),
  287. url('fonts/avrile.ttf') format('truetype');
  288. }
  289. @font-face {
  290. font-family: 'Arimo';
  291. src: url('fonts/arimo.woff2') format('woff2');
  292. }
  293. @font-face {
  294. font-family: 'GEO_1';
  295. src: url('fonts/geo_1.woff') format('woff'),
  296. url('fonts/geo_1.ttf') format('truetype');
  297. }
  298. </style>