App.vue 8.9 KB

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