App.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. }
  187. }
  188. //-----------------------------------------------------------------------------
  189. </script>
  190. <style scoped>
  191. .app-name {
  192. margin-left: 10px;
  193. margin-top: 10px;
  194. text-align: center;
  195. line-height: 140%;
  196. font-weight: bold;
  197. }
  198. .bold-font {
  199. font-weight: bold;
  200. }
  201. .el-container {
  202. height: 100%;
  203. }
  204. .el-aside {
  205. line-height: 1;
  206. background-color: #ccc;
  207. color: #000;
  208. }
  209. .el-main {
  210. padding: 0;
  211. background-color: #E6EDF4;
  212. color: #000;
  213. }
  214. .el-menu-vertical:not(.el-menu--collapse) {
  215. background-color: inherit;
  216. color: inherit;
  217. text-align: left;
  218. width: 100%;
  219. border: 0;
  220. }
  221. .el-menu--collapse {
  222. background-color: inherit;
  223. color: inherit;
  224. border: 0;
  225. }
  226. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  227. background-color: inherit;
  228. color: inherit;
  229. margin-top: 5px;
  230. width: 100%;
  231. height: 64px;
  232. border: 0;
  233. }
  234. .el-menu-item {
  235. font-size: 85%;
  236. }
  237. </style>
  238. <style>
  239. body, html, #app {
  240. margin: 0;
  241. padding: 0;
  242. height: 100%;
  243. font: normal 12pt ReaderDefault;
  244. }
  245. .el-tabs__content {
  246. flex: 1;
  247. padding: 0 !important;
  248. display: flex;
  249. flex-direction: column;
  250. overflow: hidden;
  251. }
  252. @font-face {
  253. font-family: 'ReaderDefault';
  254. src: url('fonts/reader-default.woff') format('woff'),
  255. url('fonts/reader-default.ttf') format('truetype');
  256. }
  257. @font-face {
  258. font-family: 'OpenSans';
  259. src: url('fonts/open-sans.woff') format('woff'),
  260. url('fonts/open-sans.ttf') format('truetype');
  261. }
  262. @font-face {
  263. font-family: 'Roboto';
  264. src: url('fonts/roboto.woff') format('woff'),
  265. url('fonts/roboto.ttf') format('truetype');
  266. }
  267. @font-face {
  268. font-family: 'Rubik';
  269. src: url('fonts/rubik.woff2') format('woff2');
  270. }
  271. @font-face {
  272. font-family: 'Avrile';
  273. src: url('fonts/avrile.woff') format('woff'),
  274. url('fonts/avrile.ttf') format('truetype');
  275. }
  276. @font-face {
  277. font-family: 'Arimo';
  278. src: url('fonts/arimo.woff2') format('woff2');
  279. }
  280. @font-face {
  281. font-family: 'GEO_1';
  282. src: url('fonts/geo_1.woff') format('woff'),
  283. url('fonts/geo_1.ttf') format('truetype');
  284. }
  285. </style>