App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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">
  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, oldValue) {
  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. }
  65. mounted() {
  66. this.dispatch('config/loadConfig');
  67. this.$watch('apiError', function(newError, oldError) {
  68. if (newError) {
  69. this.$notify.error({
  70. title: 'Ошибка API',
  71. dangerouslyUseHTMLString: true,
  72. message: newError.response.config.url + '<br>' + newError.response.statusText
  73. });
  74. }
  75. });
  76. }
  77. toggleCollapse() {
  78. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  79. }
  80. get isCollapse() {
  81. return this.uistate.asideBarCollapse;
  82. }
  83. get asideWidth() {
  84. if (this.uistate.asideBarCollapse) {
  85. return '64px';
  86. } else {
  87. return '170px';
  88. }
  89. }
  90. get buttonCollapseIcon() {
  91. if (this.uistate.asideBarCollapse) {
  92. return 'el-icon-d-arrow-right';
  93. } else {
  94. return 'el-icon-d-arrow-left';
  95. }
  96. }
  97. get appName() {
  98. if (this.isCollapse)
  99. return '<br><br>';
  100. else
  101. return `${this.config.name} <br>v${this.config.version}`;
  102. }
  103. get apiError() {
  104. return this.state.apiError;
  105. }
  106. get rootRoute() {
  107. const m = this.$route.path.match(/^(\/[^\/]*).*$/i);
  108. return (m ? m[1] : this.$route.path);
  109. }
  110. itemTitleClass(path) {
  111. return (this.rootRoute == path ? {'bold-font': true} : {});
  112. }
  113. get mode() {
  114. return this.config.mode;
  115. }
  116. get showAsideBar() {
  117. return (this.mode != 'reader' && this.mode != 'omnireader');
  118. }
  119. get showMain() {
  120. return (this.showAsideBar || this.rootRoute == '/reader');
  121. }
  122. }
  123. //-----------------------------------------------------------------------------
  124. </script>
  125. <style scoped>
  126. .app-name {
  127. margin-left: 10px;
  128. margin-top: 10px;
  129. text-align: center;
  130. line-height: 140%;
  131. font-weight: bold;
  132. }
  133. .bold-font {
  134. font-weight: bold;
  135. }
  136. .el-container {
  137. height: 100%;
  138. }
  139. .el-aside {
  140. line-height: 1;
  141. background-color: #ccc;
  142. color: #000;
  143. }
  144. .el-main {
  145. padding: 5px;
  146. background-color: #E6EDF4;
  147. color: #000;
  148. }
  149. .el-menu-vertical:not(.el-menu--collapse) {
  150. background-color: inherit;
  151. color: inherit;
  152. text-align: left;
  153. width: 100%;
  154. border: 0;
  155. }
  156. .el-menu--collapse {
  157. background-color: inherit;
  158. color: inherit;
  159. border: 0;
  160. }
  161. .el-button-collapse, .el-button-collapse:focus, .el-button-collapse:active, .el-button-collapse:hover {
  162. background-color: inherit;
  163. color: inherit;
  164. margin-top: 5px;
  165. width: 100%;
  166. height: 64px;
  167. border: 0;
  168. }
  169. .el-menu-item {
  170. font-size: 85%;
  171. }
  172. </style>
  173. <style>
  174. body, html, #app {
  175. margin: 0;
  176. padding: 0;
  177. height: 100%;
  178. font: normal 12pt Arial, Verdana, Sans-serif;
  179. }
  180. </style>