App.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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">Картотека</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">Читалка</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">Форум-чат</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">Поступления</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">Источники</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">Параметры</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">Справка</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. if ((this.mode == 'reader' || this.mode == 'omnireader') && (newValue != '/reader')) {
  52. this.$router.replace('/reader');
  53. }
  54. },
  55. },
  56. })
  57. class App extends Vue {
  58. created() {
  59. this.commit = this.$store.commit;
  60. this.dispatch = this.$store.dispatch;
  61. this.state = this.$store.state;
  62. this.uistate = this.$store.state.uistate;
  63. this.config = this.$store.state.config;
  64. //global keyHooks
  65. this.keyHooks = [];
  66. this.keyHook = (event) => {
  67. for (const hook of this.keyHooks)
  68. hook(event);
  69. }
  70. this.$root.addKeyHook = (hook) => {
  71. if (this.keyHooks.indexOf(hook) < 0)
  72. this.keyHooks.push(hook);
  73. }
  74. this.$root.removeKeyHook = (hook) => {
  75. const i = this.keyHooks.indexOf(hook);
  76. if (i >= 0)
  77. this.keyHooks.splice(i, 1);
  78. }
  79. document.addEventListener('keyup', (event) => {
  80. this.keyHook(event);
  81. });
  82. document.addEventListener('keydown', (event) => {
  83. this.keyHook(event);
  84. });
  85. }
  86. mounted() {
  87. this.dispatch('config/loadConfig');
  88. this.$watch('apiError', function(newError) {
  89. if (newError) {
  90. this.$notify.error({
  91. title: 'Ошибка API',
  92. dangerouslyUseHTMLString: true,
  93. message: newError.response.config.url + '<br>' + newError.response.statusText
  94. });
  95. }
  96. });
  97. }
  98. toggleCollapse() {
  99. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  100. }
  101. get isCollapse() {
  102. return this.uistate.asideBarCollapse;
  103. }
  104. get asideWidth() {
  105. if (this.uistate.asideBarCollapse) {
  106. return '64px';
  107. } else {
  108. return '170px';
  109. }
  110. }
  111. get buttonCollapseIcon() {
  112. if (this.uistate.asideBarCollapse) {
  113. return 'el-icon-d-arrow-right';
  114. } else {
  115. return 'el-icon-d-arrow-left';
  116. }
  117. }
  118. get appName() {
  119. if (this.isCollapse)
  120. return '<br><br>';
  121. else
  122. return `${this.config.name} <br>v${this.config.version}`;
  123. }
  124. get apiError() {
  125. return this.state.apiError;
  126. }
  127. get rootRoute() {
  128. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  129. return (m ? m[1] : this.$route.path);
  130. }
  131. itemTitleClass(path) {
  132. return (this.rootRoute == path ? {'bold-font': true} : {});
  133. }
  134. get mode() {
  135. return this.config.mode;
  136. }
  137. get showAsideBar() {
  138. return (this.mode != 'reader' && this.mode != 'omnireader');
  139. }
  140. get isReaderActive() {
  141. return this.rootRoute == '/reader';
  142. }
  143. get showMain() {
  144. return (this.showAsideBar || this.isReaderActive);
  145. }
  146. }
  147. //-----------------------------------------------------------------------------
  148. </script>
  149. <style scoped>
  150. .app-name {
  151. margin-left: 10px;
  152. margin-top: 10px;
  153. text-align: center;
  154. line-height: 140%;
  155. font-weight: bold;
  156. }
  157. .bold-font {
  158. font-weight: bold;
  159. }
  160. .el-container {
  161. height: 100%;
  162. }
  163. .el-aside {
  164. line-height: 1;
  165. background-color: #ccc;
  166. color: #000;
  167. }
  168. .el-main {
  169. padding: 0;
  170. background-color: #E6EDF4;
  171. color: #000;
  172. }
  173. .el-menu-vertical:not(.el-menu--collapse) {
  174. background-color: inherit;
  175. color: inherit;
  176. text-align: left;
  177. width: 100%;
  178. border: 0;
  179. }
  180. .el-menu--collapse {
  181. background-color: inherit;
  182. color: inherit;
  183. border: 0;
  184. }
  185. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  186. background-color: inherit;
  187. color: inherit;
  188. margin-top: 5px;
  189. width: 100%;
  190. height: 64px;
  191. border: 0;
  192. }
  193. .el-menu-item {
  194. font-size: 85%;
  195. }
  196. </style>
  197. <style>
  198. body, html, #app {
  199. margin: 0;
  200. padding: 0;
  201. height: 100%;
  202. font: normal 12pt Arial, Verdana, Sans-serif;
  203. }
  204. </style>