App.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. <div class="fit row">
  52. <keep-alive>
  53. <router-view class="col"></router-view>
  54. </keep-alive>
  55. </div>
  56. </template>
  57. <script>
  58. //-----------------------------------------------------------------------------
  59. import Vue from 'vue';
  60. import Component from 'vue-class-component';
  61. import * as utils from '../share/utils';
  62. export default @Component({
  63. watch: {
  64. mode: function() {
  65. this.setAppTitle();
  66. this.redirectIfNeeded();
  67. }
  68. },
  69. })
  70. class App extends Vue {
  71. itemRuText = {
  72. '/cardindex': 'Картотека',
  73. '/reader': 'Читалка',
  74. '/forum': 'Форум-чат',
  75. '/income': 'Поступления',
  76. '/sources': 'Источники',
  77. '/settings': 'Параметры',
  78. '/help': 'Справка',
  79. }
  80. created() {
  81. this.commit = this.$store.commit;
  82. this.dispatch = this.$store.dispatch;
  83. this.state = this.$store.state;
  84. this.uistate = this.$store.state.uistate;
  85. this.config = this.$store.state.config;
  86. //root route
  87. let cachedRoute = '';
  88. let cachedPath = '';
  89. this.$root.rootRoute = () => {
  90. if (this.$route.path != cachedPath) {
  91. cachedPath = this.$route.path;
  92. const m = cachedPath.match(/^(\/[^/]*).*$/i);
  93. cachedRoute = (m ? m[1] : this.$route.path);
  94. }
  95. return cachedRoute;
  96. }
  97. // set-app-title
  98. this.$root.$on('set-app-title', this.setAppTitle);
  99. //global keyHooks
  100. this.keyHooks = [];
  101. this.keyHook = (event) => {
  102. for (const hook of this.keyHooks)
  103. hook(event);
  104. }
  105. this.$root.addKeyHook = (hook) => {
  106. if (this.keyHooks.indexOf(hook) < 0)
  107. this.keyHooks.push(hook);
  108. }
  109. this.$root.removeKeyHook = (hook) => {
  110. const i = this.keyHooks.indexOf(hook);
  111. if (i >= 0)
  112. this.keyHooks.splice(i, 1);
  113. }
  114. document.addEventListener('keyup', (event) => {
  115. this.keyHook(event);
  116. });
  117. document.addEventListener('keydown', (event) => {
  118. this.keyHook(event);
  119. });
  120. window.addEventListener('resize', () => {
  121. this.$root.$emit('resize');
  122. });
  123. }
  124. mounted() {
  125. this.dispatch('config/loadConfig');
  126. this.$watch('apiError', function(newError) {
  127. if (newError) {
  128. let mes = newError.message;
  129. if (newError.response && newError.response.config)
  130. mes = newError.response.config.url + '<br>' + newError.response.statusText;
  131. this.$notify.error({
  132. title: 'Ошибка API',
  133. dangerouslyUseHTMLString: true,
  134. message: mes
  135. });
  136. }
  137. });
  138. this.setAppTitle();
  139. this.redirectIfNeeded();
  140. }
  141. toggleCollapse() {
  142. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  143. this.$root.$emit('resize');
  144. }
  145. get isCollapse() {
  146. return this.uistate.asideBarCollapse;
  147. }
  148. get asideWidth() {
  149. if (this.uistate.asideBarCollapse) {
  150. return 64;
  151. } else {
  152. return 170;
  153. }
  154. }
  155. get buttonCollapseIcon() {
  156. if (this.uistate.asideBarCollapse) {
  157. return 'el-icon-d-arrow-right';
  158. } else {
  159. return 'el-icon-d-arrow-left';
  160. }
  161. }
  162. get appName() {
  163. if (this.isCollapse)
  164. return '<br><br>';
  165. else
  166. return `${this.config.name} <br>v${this.config.version}`;
  167. }
  168. get apiError() {
  169. return this.state.apiError;
  170. }
  171. get rootRoute() {
  172. return this.$root.rootRoute();
  173. }
  174. setAppTitle(title) {
  175. if (!title) {
  176. if (this.mode == 'omnireader') {
  177. document.title = `Omni Reader - всегда с вами`;
  178. } else if (this.config && this.mode !== null) {
  179. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  180. }
  181. } else {
  182. document.title = title;
  183. }
  184. }
  185. itemTitleClass(path) {
  186. return (this.rootRoute == path ? {'bold-font': true} : {});
  187. }
  188. get mode() {
  189. return this.$store.state.config.mode;
  190. }
  191. get showAsideBar() {
  192. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  193. }
  194. set showAsideBar(value) {
  195. }
  196. get isReaderActive() {
  197. return this.rootRoute == '/reader';
  198. }
  199. redirectIfNeeded() {
  200. if ((this.mode == 'reader' || this.mode == 'omnireader') && (!this.isReaderActive)) {
  201. //старый url
  202. const search = window.location.search.substr(1);
  203. const s = search.split('url=');
  204. const url = s[1] || '';
  205. const q = utils.parseQuery(s[0] || '');
  206. if (url) {
  207. q.url = decodeURIComponent(url);
  208. }
  209. window.history.replaceState({}, '', '/');
  210. this.$router.replace({ path: '/reader', query: q });
  211. }
  212. }
  213. }
  214. //-----------------------------------------------------------------------------
  215. </script>
  216. <style scoped>
  217. .app-name {
  218. margin-left: 10px;
  219. margin-top: 10px;
  220. text-align: center;
  221. line-height: 140%;
  222. font-weight: bold;
  223. }
  224. </style>
  225. <style>
  226. body, html, #app {
  227. margin: 0;
  228. padding: 0;
  229. width: 100%;
  230. height: 100%;
  231. font: normal 12pt ReaderDefault;
  232. }
  233. .dborder {
  234. border: 2px solid yellow;
  235. }
  236. .icon-rotate {
  237. vertical-align: middle;
  238. animation: rotating 2s linear infinite;
  239. }
  240. .notify-button-icon {
  241. font-size: 16px !important;
  242. }
  243. @font-face {
  244. font-family: 'ReaderDefault';
  245. src: url('fonts/reader-default.woff') format('woff'),
  246. url('fonts/reader-default.ttf') format('truetype');
  247. }
  248. @font-face {
  249. font-family: 'OpenSans';
  250. src: url('fonts/open-sans.woff') format('woff'),
  251. url('fonts/open-sans.ttf') format('truetype');
  252. }
  253. @font-face {
  254. font-family: 'Roboto';
  255. src: url('fonts/roboto.woff') format('woff'),
  256. url('fonts/roboto.ttf') format('truetype');
  257. }
  258. @font-face {
  259. font-family: 'Rubik';
  260. src: url('fonts/rubik.woff2') format('woff2');
  261. }
  262. @font-face {
  263. font-family: 'Avrile';
  264. src: url('fonts/avrile.woff') format('woff'),
  265. url('fonts/avrile.ttf') format('truetype');
  266. }
  267. @font-face {
  268. font-family: 'Arimo';
  269. src: url('fonts/arimo.woff2') format('woff2');
  270. }
  271. @font-face {
  272. font-family: 'GEO_1';
  273. src: url('fonts/geo_1.woff') format('woff'),
  274. url('fonts/geo_1.ttf') format('truetype');
  275. }
  276. </style>