App.vue 8.0 KB

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