App.vue 8.8 KB

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