App.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. this.$root.$emit('resize');
  116. }
  117. get isCollapse() {
  118. return this.uistate.asideBarCollapse;
  119. }
  120. get asideWidth() {
  121. if (this.uistate.asideBarCollapse) {
  122. return '64px';
  123. } else {
  124. return '170px';
  125. }
  126. }
  127. get buttonCollapseIcon() {
  128. if (this.uistate.asideBarCollapse) {
  129. return 'el-icon-d-arrow-right';
  130. } else {
  131. return 'el-icon-d-arrow-left';
  132. }
  133. }
  134. get appName() {
  135. if (this.isCollapse)
  136. return '<br><br>';
  137. else
  138. return `${this.config.name} <br>v${this.config.version}`;
  139. }
  140. get apiError() {
  141. return this.state.apiError;
  142. }
  143. get rootRoute() {
  144. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  145. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  146. return this.$root.rootRoute;
  147. }
  148. setAppTitle(title) {
  149. if (!title) {
  150. if (this.mode == 'omnireader') {
  151. document.title = `Omni Reader - всегда с вами`;
  152. } else if (this.config) {
  153. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  154. }
  155. } else {
  156. document.title = title;
  157. }
  158. }
  159. itemTitleClass(path) {
  160. return (this.rootRoute == path ? {'bold-font': true} : {});
  161. }
  162. get mode() {
  163. return this.config.mode;
  164. }
  165. get showAsideBar() {
  166. return (this.mode != 'reader' && this.mode != 'omnireader');
  167. }
  168. get isReaderActive() {
  169. return this.rootRoute == '/reader';
  170. }
  171. get showMain() {
  172. return (this.showAsideBar || this.isReaderActive);
  173. }
  174. }
  175. //-----------------------------------------------------------------------------
  176. </script>
  177. <style scoped>
  178. .app-name {
  179. margin-left: 10px;
  180. margin-top: 10px;
  181. text-align: center;
  182. line-height: 140%;
  183. font-weight: bold;
  184. }
  185. .bold-font {
  186. font-weight: bold;
  187. }
  188. .el-container {
  189. height: 100%;
  190. }
  191. .el-aside {
  192. line-height: 1;
  193. background-color: #ccc;
  194. color: #000;
  195. }
  196. .el-main {
  197. padding: 0;
  198. background-color: #E6EDF4;
  199. color: #000;
  200. }
  201. .el-menu-vertical:not(.el-menu--collapse) {
  202. background-color: inherit;
  203. color: inherit;
  204. text-align: left;
  205. width: 100%;
  206. border: 0;
  207. }
  208. .el-menu--collapse {
  209. background-color: inherit;
  210. color: inherit;
  211. border: 0;
  212. }
  213. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  214. background-color: inherit;
  215. color: inherit;
  216. margin-top: 5px;
  217. width: 100%;
  218. height: 64px;
  219. border: 0;
  220. }
  221. .el-menu-item {
  222. font-size: 85%;
  223. }
  224. </style>
  225. <style>
  226. body, html, #app {
  227. margin: 0;
  228. padding: 0;
  229. height: 100%;
  230. font: normal 12pt ReaderDefault;
  231. }
  232. @font-face {
  233. font-family: 'ReaderDefault';
  234. src: url('fonts/reader-default.woff') format('woff'),
  235. url('fonts/reader-default.ttf') format('truetype');
  236. }
  237. @font-face {
  238. font-family: 'OpenSans';
  239. src: url('fonts/open-sans.woff') format('woff'),
  240. url('fonts/open-sans.ttf') format('truetype');
  241. }
  242. @font-face {
  243. font-family: 'Roboto';
  244. src: url('fonts/roboto.woff') format('woff'),
  245. url('fonts/roboto.ttf') format('truetype');
  246. }
  247. @font-face {
  248. font-family: 'Archivo';
  249. src: url('fonts/archivo.woff2') format('woff2');
  250. }
  251. @font-face {
  252. font-family: 'Rubik';
  253. src: url('fonts/rubik.woff2') format('woff2');
  254. }
  255. @font-face {
  256. font-family: 'Avrile';
  257. src: url('fonts/avrile.woff') format('woff'),
  258. url('fonts/avrile.ttf') format('truetype');
  259. }
  260. </style>