App.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <q-layout view="lhr lpr lfr">
  3. <q-drawer v-model="showAsideBar" :width="asideWidth">
  4. <div class="app-name"><span v-html="appName"></span></div>
  5. <q-btn class="el-button-collapse" @click="toggleCollapse"></q-btn>
  6. <q-list>
  7. <q-item clickable v-ripple>
  8. <q-item-section avatar>
  9. <q-icon name="inbox" />
  10. </q-item-section>
  11. <q-item-section>Inbox</q-item-section>
  12. </q-item>
  13. </q-list>
  14. <!--el-menu class="el-menu-vertical" :default-active="rootRoute" :collapse="isCollapse" router>
  15. <el-menu-item index="/cardindex">
  16. <i class="el-icon-search"></i>
  17. <span :class="itemTitleClass('/cardindex')" slot="title">{{ this.itemRuText['/cardindex'] }}</span>
  18. </el-menu-item>
  19. <el-menu-item index="/reader">
  20. <i class="el-icon-tickets"></i>
  21. <span :class="itemTitleClass('/reader')" slot="title">{{ this.itemRuText['/reader'] }}</span>
  22. </el-menu-item>
  23. <el-menu-item index="/forum" disabled>
  24. <i class="el-icon-message"></i>
  25. <span :class="itemTitleClass('/forum')" slot="title">{{ this.itemRuText['/forum'] }}</span>
  26. </el-menu-item>
  27. <el-menu-item index="/income">
  28. <i class="el-icon-upload"></i>
  29. <span :class="itemTitleClass('/income')" slot="title">{{ this.itemRuText['/income'] }}</span>
  30. </el-menu-item>
  31. <el-menu-item index="/sources">
  32. <i class="el-icon-menu"></i>
  33. <span :class="itemTitleClass('/sources')" slot="title">{{ this.itemRuText['/sources'] }}</span>
  34. </el-menu-item>
  35. <el-menu-item index="/settings">
  36. <i class="el-icon-setting"></i>
  37. <span :class="itemTitleClass('/settings')" slot="title">{{ this.itemRuText['/settings'] }}</span>
  38. </el-menu-item>
  39. <el-menu-item index="/help">
  40. <i class="el-icon-question"></i>
  41. <span :class="itemTitleClass('/help')" slot="title">{{ this.itemRuText['/help'] }}</span>
  42. </el-menu-item>
  43. </el-menu-->
  44. </q-drawer>
  45. <q-page-container>
  46. <keep-alive>
  47. <router-view></router-view>
  48. </keep-alive>
  49. </q-page-container>
  50. </q-layout>
  51. </template>
  52. <script>
  53. //-----------------------------------------------------------------------------
  54. import Vue from 'vue';
  55. import Component from 'vue-class-component';
  56. import * as utils from '../share/utils';
  57. export default @Component({
  58. watch: {
  59. mode: function() {
  60. this.setAppTitle();
  61. this.redirectIfNeeded();
  62. }
  63. },
  64. })
  65. class App extends Vue {
  66. itemRuText = {
  67. '/cardindex': 'Картотека',
  68. '/reader': 'Читалка',
  69. '/forum': 'Форум-чат',
  70. '/income': 'Поступления',
  71. '/sources': 'Источники',
  72. '/settings': 'Параметры',
  73. '/help': 'Справка',
  74. }
  75. created() {
  76. this.commit = this.$store.commit;
  77. this.dispatch = this.$store.dispatch;
  78. this.state = this.$store.state;
  79. this.uistate = this.$store.state.uistate;
  80. this.config = this.$store.state.config;
  81. // set-app-title
  82. this.$root.$on('set-app-title', this.setAppTitle);
  83. //global keyHooks
  84. this.keyHooks = [];
  85. this.keyHook = (event) => {
  86. for (const hook of this.keyHooks)
  87. hook(event);
  88. }
  89. this.$root.addKeyHook = (hook) => {
  90. if (this.keyHooks.indexOf(hook) < 0)
  91. this.keyHooks.push(hook);
  92. }
  93. this.$root.removeKeyHook = (hook) => {
  94. const i = this.keyHooks.indexOf(hook);
  95. if (i >= 0)
  96. this.keyHooks.splice(i, 1);
  97. }
  98. document.addEventListener('keyup', (event) => {
  99. this.keyHook(event);
  100. });
  101. document.addEventListener('keydown', (event) => {
  102. this.keyHook(event);
  103. });
  104. window.addEventListener('resize', () => {
  105. this.$root.$emit('resize');
  106. });
  107. }
  108. mounted() {
  109. this.dispatch('config/loadConfig');
  110. this.$watch('apiError', function(newError) {
  111. if (newError) {
  112. let mes = newError.message;
  113. if (newError.response && newError.response.config)
  114. mes = newError.response.config.url + '<br>' + newError.response.statusText;
  115. this.$notify.error({
  116. title: 'Ошибка API',
  117. dangerouslyUseHTMLString: true,
  118. message: mes
  119. });
  120. }
  121. });
  122. this.setAppTitle();
  123. this.redirectIfNeeded();
  124. }
  125. toggleCollapse() {
  126. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  127. this.$root.$emit('resize');
  128. }
  129. get isCollapse() {
  130. return this.uistate.asideBarCollapse;
  131. }
  132. get asideWidth() {
  133. if (this.uistate.asideBarCollapse) {
  134. return 64;
  135. } else {
  136. return 170;
  137. }
  138. }
  139. get buttonCollapseIcon() {
  140. if (this.uistate.asideBarCollapse) {
  141. return 'el-icon-d-arrow-right';
  142. } else {
  143. return 'el-icon-d-arrow-left';
  144. }
  145. }
  146. get appName() {
  147. if (this.isCollapse)
  148. return '<br><br>';
  149. else
  150. return `${this.config.name} <br>v${this.config.version}`;
  151. }
  152. get apiError() {
  153. return this.state.apiError;
  154. }
  155. get rootRoute() {
  156. const m = this.$route.path.match(/^(\/[^/]*).*$/i);
  157. this.$root.rootRoute = (m ? m[1] : this.$route.path);
  158. return this.$root.rootRoute;
  159. }
  160. setAppTitle(title) {
  161. if (!title) {
  162. if (this.mode == 'omnireader') {
  163. document.title = `Omni Reader - всегда с вами`;
  164. } else if (this.config && this.mode !== null) {
  165. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  166. }
  167. } else {
  168. document.title = title;
  169. }
  170. }
  171. itemTitleClass(path) {
  172. return (this.rootRoute == path ? {'bold-font': true} : {});
  173. }
  174. get mode() {
  175. return this.$store.state.config.mode;
  176. }
  177. get showAsideBar() {
  178. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  179. }
  180. get isReaderActive() {
  181. return this.rootRoute == '/reader';
  182. }
  183. redirectIfNeeded() {
  184. if ((this.mode == 'reader' || this.mode == 'omnireader') && (!this.isReaderActive)) {
  185. //старый url
  186. const search = window.location.search.substr(1);
  187. const s = search.split('url=');
  188. const url = s[1] || '';
  189. const q = utils.parseQuery(s[0] || '');
  190. if (url) {
  191. q.url = decodeURIComponent(url);
  192. }
  193. window.history.replaceState({}, '', '/');
  194. this.$router.replace({ path: '/reader', query: q });
  195. }
  196. }
  197. }
  198. //-----------------------------------------------------------------------------
  199. </script>
  200. <style scoped>
  201. .app-name {
  202. margin-left: 10px;
  203. margin-top: 10px;
  204. text-align: center;
  205. line-height: 140%;
  206. font-weight: bold;
  207. }
  208. </style>
  209. <style>
  210. body, html, #app {
  211. margin: 0;
  212. padding: 0;
  213. font: normal 12pt ReaderDefault;
  214. }
  215. .dborder {
  216. border: 2px solid yellow;
  217. }
  218. @font-face {
  219. font-family: 'ReaderDefault';
  220. src: url('fonts/reader-default.woff') format('woff'),
  221. url('fonts/reader-default.ttf') format('truetype');
  222. }
  223. @font-face {
  224. font-family: 'OpenSans';
  225. src: url('fonts/open-sans.woff') format('woff'),
  226. url('fonts/open-sans.ttf') format('truetype');
  227. }
  228. @font-face {
  229. font-family: 'Roboto';
  230. src: url('fonts/roboto.woff') format('woff'),
  231. url('fonts/roboto.ttf') format('truetype');
  232. }
  233. @font-face {
  234. font-family: 'Rubik';
  235. src: url('fonts/rubik.woff2') format('woff2');
  236. }
  237. @font-face {
  238. font-family: 'Avrile';
  239. src: url('fonts/avrile.woff') format('woff'),
  240. url('fonts/avrile.ttf') format('truetype');
  241. }
  242. @font-face {
  243. font-family: 'Arimo';
  244. src: url('fonts/arimo.woff2') format('woff2');
  245. }
  246. @font-face {
  247. font-family: 'GEO_1';
  248. src: url('fonts/geo_1.woff') format('woff'),
  249. url('fonts/geo_1.ttf') format('truetype');
  250. }
  251. </style>