App.vue 9.3 KB

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