App.vue 7.3 KB

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