App.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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(newValue) {
  51. this.setAppTitle();
  52. if ((this.mode == 'reader' || this.mode == 'omnireader') && (newValue != '/reader')) {
  53. //старый url
  54. const search = window.location.search.substr(1);
  55. const url = search.split('url=')[1] || '';
  56. if (url) {
  57. window.location = `/#/reader?url=${url}`;
  58. } else {
  59. this.$router.replace('/reader');
  60. }
  61. }
  62. },
  63. },
  64. })
  65. class App extends Vue {
  66. itemRuText = {
  67. '/cardindex': 'Картотека',
  68. '/reader': 'Читалка',
  69. '/forum': 'Форум-чат',
  70. '/income': 'Поступления',
  71. '/sources': 'Источники',
  72. '/settings': 'Параметры',
  73. '/help': 'Справка',
  74. }
  75. created() {
  76. this.commit = this.$store.commit;
  77. this.dispatch = this.$store.dispatch;
  78. this.state = this.$store.state;
  79. this.uistate = this.$store.state.uistate;
  80. this.config = this.$store.state.config;
  81. // set-app-title
  82. this.$root.$on('set-app-title', this.setAppTitle);
  83. //global keyHooks
  84. this.keyHooks = [];
  85. this.keyHook = (event) => {
  86. for (const hook of this.keyHooks)
  87. hook(event);
  88. }
  89. this.$root.addKeyHook = (hook) => {
  90. if (this.keyHooks.indexOf(hook) < 0)
  91. this.keyHooks.push(hook);
  92. }
  93. this.$root.removeKeyHook = (hook) => {
  94. const i = this.keyHooks.indexOf(hook);
  95. if (i >= 0)
  96. this.keyHooks.splice(i, 1);
  97. }
  98. document.addEventListener('keyup', (event) => {
  99. this.keyHook(event);
  100. });
  101. document.addEventListener('keydown', (event) => {
  102. this.keyHook(event);
  103. });
  104. window.addEventListener('resize', () => {
  105. this.$root.$emit('resize');
  106. });
  107. }
  108. mounted() {
  109. this.dispatch('config/loadConfig');
  110. this.$watch('apiError', function(newError) {
  111. if (newError) {
  112. this.$notify.error({
  113. title: 'Ошибка API',
  114. dangerouslyUseHTMLString: true,
  115. message: newError.response.config.url + '<br>' + newError.response.statusText
  116. });
  117. }
  118. });
  119. }
  120. toggleCollapse() {
  121. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  122. this.$root.$emit('resize');
  123. }
  124. get isCollapse() {
  125. return this.uistate.asideBarCollapse;
  126. }
  127. get asideWidth() {
  128. if (this.uistate.asideBarCollapse) {
  129. return '64px';
  130. } else {
  131. return '170px';
  132. }
  133. }
  134. get buttonCollapseIcon() {
  135. if (this.uistate.asideBarCollapse) {
  136. return 'el-icon-d-arrow-right';
  137. } else {
  138. return 'el-icon-d-arrow-left';
  139. }
  140. }
  141. get appName() {
  142. if (this.isCollapse)
  143. return '<br><br>';
  144. else
  145. return `${this.config.name} <br>v${this.config.version}`;
  146. }
  147. get apiError() {
  148. return this.state.apiError;
  149. }
  150. get rootRoute() {
  151. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  152. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  153. return this.$root.rootRoute;
  154. }
  155. setAppTitle(title) {
  156. if (!title) {
  157. if (this.mode == 'omnireader') {
  158. document.title = `Omni Reader - всегда с вами`;
  159. } else if (this.config && this.mode !== null) {
  160. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  161. }
  162. } else {
  163. document.title = title;
  164. }
  165. }
  166. itemTitleClass(path) {
  167. return (this.rootRoute == path ? {'bold-font': true} : {});
  168. }
  169. get mode() {
  170. return this.config.mode;
  171. }
  172. get showAsideBar() {
  173. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  174. }
  175. get isReaderActive() {
  176. return this.rootRoute == '/reader';
  177. }
  178. get showMain() {
  179. return (this.showAsideBar || this.isReaderActive);
  180. }
  181. }
  182. //-----------------------------------------------------------------------------
  183. </script>
  184. <style scoped>
  185. .app-name {
  186. margin-left: 10px;
  187. margin-top: 10px;
  188. text-align: center;
  189. line-height: 140%;
  190. font-weight: bold;
  191. }
  192. .bold-font {
  193. font-weight: bold;
  194. }
  195. .el-container {
  196. height: 100%;
  197. }
  198. .el-aside {
  199. line-height: 1;
  200. background-color: #ccc;
  201. color: #000;
  202. }
  203. .el-main {
  204. padding: 0;
  205. background-color: #E6EDF4;
  206. color: #000;
  207. }
  208. .el-menu-vertical:not(.el-menu--collapse) {
  209. background-color: inherit;
  210. color: inherit;
  211. text-align: left;
  212. width: 100%;
  213. border: 0;
  214. }
  215. .el-menu--collapse {
  216. background-color: inherit;
  217. color: inherit;
  218. border: 0;
  219. }
  220. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  221. background-color: inherit;
  222. color: inherit;
  223. margin-top: 5px;
  224. width: 100%;
  225. height: 64px;
  226. border: 0;
  227. }
  228. .el-menu-item {
  229. font-size: 85%;
  230. }
  231. </style>
  232. <style>
  233. body, html, #app {
  234. margin: 0;
  235. padding: 0;
  236. height: 100%;
  237. font: normal 12pt ReaderDefault;
  238. }
  239. .el-tabs__content {
  240. flex: 1;
  241. padding: 0 !important;
  242. display: flex;
  243. flex-direction: column;
  244. overflow: hidden;
  245. }
  246. @font-face {
  247. font-family: 'ReaderDefault';
  248. src: url('fonts/reader-default.woff') format('woff'),
  249. url('fonts/reader-default.ttf') format('truetype');
  250. }
  251. @font-face {
  252. font-family: 'OpenSans';
  253. src: url('fonts/open-sans.woff') format('woff'),
  254. url('fonts/open-sans.ttf') format('truetype');
  255. }
  256. @font-face {
  257. font-family: 'Roboto';
  258. src: url('fonts/roboto.woff') format('woff'),
  259. url('fonts/roboto.ttf') format('truetype');
  260. }
  261. @font-face {
  262. font-family: 'Rubik';
  263. src: url('fonts/rubik.woff2') format('woff2');
  264. }
  265. @font-face {
  266. font-family: 'Avrile';
  267. src: url('fonts/avrile.woff') format('woff'),
  268. url('fonts/avrile.ttf') format('truetype');
  269. }
  270. @font-face {
  271. font-family: 'Arimo';
  272. src: url('fonts/arimo.woff2') format('woff2');
  273. }
  274. @font-face {
  275. font-family: 'GEO_1';
  276. src: url('fonts/geo_1.woff') format('woff'),
  277. url('fonts/geo_1.ttf') format('truetype');
  278. }
  279. </style>