App.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. }
  98. mounted() {
  99. this.dispatch('config/loadConfig');
  100. this.$watch('apiError', function(newError) {
  101. if (newError) {
  102. this.$notify.error({
  103. title: 'Ошибка API',
  104. dangerouslyUseHTMLString: true,
  105. message: newError.response.config.url + '<br>' + newError.response.statusText
  106. });
  107. }
  108. });
  109. }
  110. toggleCollapse() {
  111. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  112. }
  113. get isCollapse() {
  114. return this.uistate.asideBarCollapse;
  115. }
  116. get asideWidth() {
  117. if (this.uistate.asideBarCollapse) {
  118. return '64px';
  119. } else {
  120. return '170px';
  121. }
  122. }
  123. get buttonCollapseIcon() {
  124. if (this.uistate.asideBarCollapse) {
  125. return 'el-icon-d-arrow-right';
  126. } else {
  127. return 'el-icon-d-arrow-left';
  128. }
  129. }
  130. get appName() {
  131. if (this.isCollapse)
  132. return '<br><br>';
  133. else
  134. return `${this.config.name} <br>v${this.config.version}`;
  135. }
  136. get apiError() {
  137. return this.state.apiError;
  138. }
  139. get rootRoute() {
  140. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  141. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  142. return this.$root.rootRoute;
  143. }
  144. setAppTitle(title) {
  145. if (!title) {
  146. if (this.mode == 'omnireader') {
  147. document.title = `Omni Reader - всегда с вами`;
  148. } else if (this.config) {
  149. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  150. }
  151. } else {
  152. document.title = title;
  153. }
  154. }
  155. itemTitleClass(path) {
  156. return (this.rootRoute == path ? {'bold-font': true} : {});
  157. }
  158. get mode() {
  159. return this.config.mode;
  160. }
  161. get showAsideBar() {
  162. return (this.mode != 'reader' && this.mode != 'omnireader');
  163. }
  164. get isReaderActive() {
  165. return this.rootRoute == '/reader';
  166. }
  167. get showMain() {
  168. return (this.showAsideBar || this.isReaderActive);
  169. }
  170. }
  171. //-----------------------------------------------------------------------------
  172. </script>
  173. <style scoped>
  174. .app-name {
  175. margin-left: 10px;
  176. margin-top: 10px;
  177. text-align: center;
  178. line-height: 140%;
  179. font-weight: bold;
  180. }
  181. .bold-font {
  182. font-weight: bold;
  183. }
  184. .el-container {
  185. height: 100%;
  186. }
  187. .el-aside {
  188. line-height: 1;
  189. background-color: #ccc;
  190. color: #000;
  191. }
  192. .el-main {
  193. padding: 0;
  194. background-color: #E6EDF4;
  195. color: #000;
  196. }
  197. .el-menu-vertical:not(.el-menu--collapse) {
  198. background-color: inherit;
  199. color: inherit;
  200. text-align: left;
  201. width: 100%;
  202. border: 0;
  203. }
  204. .el-menu--collapse {
  205. background-color: inherit;
  206. color: inherit;
  207. border: 0;
  208. }
  209. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  210. background-color: inherit;
  211. color: inherit;
  212. margin-top: 5px;
  213. width: 100%;
  214. height: 64px;
  215. border: 0;
  216. }
  217. .el-menu-item {
  218. font-size: 85%;
  219. }
  220. </style>
  221. <style>
  222. body, html, #app {
  223. margin: 0;
  224. padding: 0;
  225. height: 100%;
  226. font: normal 12pt Arial, Verdana, Sans-serif;
  227. }
  228. @font-face {
  229. font-family: 'ReaderDefaultFont';
  230. src:
  231. url('fonts/reader-default-font.ttf') format('truetype');
  232. }
  233. /*url('fonts/myfont.woff') format('woff'),*/
  234. </style>