App.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. let mes = newError.message;
  107. if (newError.response && newError.response.config)
  108. mes = newError.response.config.url + '<br>' + newError.response.statusText;
  109. this.$notify.error({
  110. title: 'Ошибка API',
  111. dangerouslyUseHTMLString: true,
  112. message: mes
  113. });
  114. }
  115. });
  116. }
  117. toggleCollapse() {
  118. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  119. this.$root.$emit('resize');
  120. }
  121. get isCollapse() {
  122. return this.uistate.asideBarCollapse;
  123. }
  124. get asideWidth() {
  125. if (this.uistate.asideBarCollapse) {
  126. return '64px';
  127. } else {
  128. return '170px';
  129. }
  130. }
  131. get buttonCollapseIcon() {
  132. if (this.uistate.asideBarCollapse) {
  133. return 'el-icon-d-arrow-right';
  134. } else {
  135. return 'el-icon-d-arrow-left';
  136. }
  137. }
  138. get appName() {
  139. if (this.isCollapse)
  140. return '<br><br>';
  141. else
  142. return `${this.config.name} <br>v${this.config.version}`;
  143. }
  144. get apiError() {
  145. return this.state.apiError;
  146. }
  147. get rootRoute() {
  148. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  149. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  150. return this.$root.rootRoute;
  151. }
  152. setAppTitle(title) {
  153. if (!title) {
  154. if (this.mode == 'omnireader') {
  155. document.title = `Omni Reader - всегда с вами`;
  156. } else if (this.config && this.mode !== null) {
  157. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  158. }
  159. } else {
  160. document.title = title;
  161. }
  162. }
  163. itemTitleClass(path) {
  164. return (this.rootRoute == path ? {'bold-font': true} : {});
  165. }
  166. get mode() {
  167. return this.$store.state.config.mode;
  168. }
  169. get showAsideBar() {
  170. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  171. }
  172. get isReaderActive() {
  173. return this.rootRoute == '/reader';
  174. }
  175. get showMain() {
  176. return (this.showAsideBar || this.isReaderActive);
  177. }
  178. redirectIfNeeded() {
  179. if ((this.mode == 'reader' || this.mode == 'omnireader') && (this.rootRoute != '/reader')) {
  180. //старый url
  181. const search = window.location.search.substr(1);
  182. const url = search.split('url=')[1] || '';
  183. if (url) {
  184. window.location = `/#/reader?url=${url}`;
  185. } else {
  186. this.$router.replace('/reader');
  187. }
  188. }
  189. //yandex-метрика для omnireader
  190. if (this.config.branch == 'production' && this.mode == 'omnireader' && !this.yaMetricsDone) {
  191. (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
  192. 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)})
  193. (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");// eslint-disable-line no-unexpected-multiline
  194. ym(52347334, "init", {// eslint-disable-line no-undef
  195. id:52347334,
  196. clickmap:true,
  197. trackLinks:true,
  198. accurateTrackBounce:true
  199. });
  200. this.yaMetricsDone = true;
  201. }
  202. }
  203. }
  204. //-----------------------------------------------------------------------------
  205. </script>
  206. <style scoped>
  207. .app-name {
  208. margin-left: 10px;
  209. margin-top: 10px;
  210. text-align: center;
  211. line-height: 140%;
  212. font-weight: bold;
  213. }
  214. .bold-font {
  215. font-weight: bold;
  216. }
  217. .el-container {
  218. height: 100%;
  219. }
  220. .el-aside {
  221. line-height: 1;
  222. background-color: #ccc;
  223. color: #000;
  224. }
  225. .el-main {
  226. padding: 0;
  227. background-color: #E6EDF4;
  228. color: #000;
  229. }
  230. .el-menu-vertical:not(.el-menu--collapse) {
  231. background-color: inherit;
  232. color: inherit;
  233. text-align: left;
  234. width: 100%;
  235. border: 0;
  236. }
  237. .el-menu--collapse {
  238. background-color: inherit;
  239. color: inherit;
  240. border: 0;
  241. }
  242. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  243. background-color: inherit;
  244. color: inherit;
  245. margin-top: 5px;
  246. width: 100%;
  247. height: 64px;
  248. border: 0;
  249. }
  250. .el-menu-item {
  251. font-size: 85%;
  252. }
  253. </style>
  254. <style>
  255. body, html, #app {
  256. margin: 0;
  257. padding: 0;
  258. height: 100%;
  259. font: normal 12pt ReaderDefault;
  260. }
  261. .el-tabs__content {
  262. flex: 1;
  263. padding: 0 !important;
  264. display: flex;
  265. flex-direction: column;
  266. overflow: hidden;
  267. }
  268. @font-face {
  269. font-family: 'ReaderDefault';
  270. src: url('fonts/reader-default.woff') format('woff'),
  271. url('fonts/reader-default.ttf') format('truetype');
  272. }
  273. @font-face {
  274. font-family: 'OpenSans';
  275. src: url('fonts/open-sans.woff') format('woff'),
  276. url('fonts/open-sans.ttf') format('truetype');
  277. }
  278. @font-face {
  279. font-family: 'Roboto';
  280. src: url('fonts/roboto.woff') format('woff'),
  281. url('fonts/roboto.ttf') format('truetype');
  282. }
  283. @font-face {
  284. font-family: 'Rubik';
  285. src: url('fonts/rubik.woff2') format('woff2');
  286. }
  287. @font-face {
  288. font-family: 'Avrile';
  289. src: url('fonts/avrile.woff') format('woff'),
  290. url('fonts/avrile.ttf') format('truetype');
  291. }
  292. @font-face {
  293. font-family: 'Arimo';
  294. src: url('fonts/arimo.woff2') format('woff2');
  295. }
  296. @font-face {
  297. font-family: 'GEO_1';
  298. src: url('fonts/geo_1.woff') format('woff'),
  299. url('fonts/geo_1.ttf') format('truetype');
  300. }
  301. </style>