App.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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.$notify.error({
  142. title: 'Ошибка API',
  143. dangerouslyUseHTMLString: true,
  144. message: mes
  145. });
  146. }
  147. });
  148. this.setAppTitle();
  149. this.redirectIfNeeded();
  150. }
  151. toggleCollapse() {
  152. this.commit('uistate/setAsideBarCollapse', !this.uistate.asideBarCollapse);
  153. this.$root.$emit('resize');
  154. }
  155. get isCollapse() {
  156. return this.uistate.asideBarCollapse;
  157. }
  158. get asideWidth() {
  159. if (this.uistate.asideBarCollapse) {
  160. return 64;
  161. } else {
  162. return 170;
  163. }
  164. }
  165. get buttonCollapseIcon() {
  166. if (this.uistate.asideBarCollapse) {
  167. return 'el-icon-d-arrow-right';
  168. } else {
  169. return 'el-icon-d-arrow-left';
  170. }
  171. }
  172. get appName() {
  173. if (this.isCollapse)
  174. return '<br><br>';
  175. else
  176. return `${this.config.name} <br>v${this.config.version}`;
  177. }
  178. get apiError() {
  179. return this.state.apiError;
  180. }
  181. get rootRoute() {
  182. return this.$root.rootRoute();
  183. }
  184. setAppTitle(title) {
  185. if (!title) {
  186. if (this.mode == 'omnireader') {
  187. document.title = `Omni Reader - всегда с вами`;
  188. } else if (this.config && this.mode !== null) {
  189. document.title = `${this.config.name} - ${this.itemRuText[this.$root.rootRoute]}`;
  190. }
  191. } else {
  192. document.title = title;
  193. }
  194. }
  195. itemTitleClass(path) {
  196. return (this.rootRoute == path ? {'bold-font': true} : {});
  197. }
  198. get mode() {
  199. return this.$store.state.config.mode;
  200. }
  201. get showAsideBar() {
  202. return (this.mode !== null && this.mode != 'reader' && this.mode != 'omnireader');
  203. }
  204. set showAsideBar(value) {
  205. }
  206. get isReaderActive() {
  207. return this.rootRoute == '/reader';
  208. }
  209. redirectIfNeeded() {
  210. if ((this.mode == 'reader' || this.mode == 'omnireader') && (!this.isReaderActive)) {
  211. //старый url
  212. const search = window.location.search.substr(1);
  213. const s = search.split('url=');
  214. const url = s[1] || '';
  215. const q = utils.parseQuery(s[0] || '');
  216. if (url) {
  217. q.url = decodeURIComponent(url);
  218. }
  219. window.history.replaceState({}, '', '/');
  220. this.$router.replace({ path: '/reader', query: q });
  221. }
  222. }
  223. }
  224. //-----------------------------------------------------------------------------
  225. </script>
  226. <style scoped>
  227. .app-name {
  228. margin-left: 10px;
  229. margin-top: 10px;
  230. text-align: center;
  231. line-height: 140%;
  232. font-weight: bold;
  233. }
  234. </style>
  235. <style>
  236. body, html, #app {
  237. margin: 0;
  238. padding: 0;
  239. width: 100%;
  240. height: 100%;
  241. font: normal 12pt ReaderDefault;
  242. }
  243. .dborder {
  244. border: 2px solid yellow !important;
  245. }
  246. .icon-rotate {
  247. vertical-align: middle;
  248. animation: rotating 2s linear infinite;
  249. }
  250. .notify-button-icon {
  251. font-size: 16px !important;
  252. }
  253. @font-face {
  254. font-family: 'ReaderDefault';
  255. src: url('fonts/reader-default.woff') format('woff'),
  256. url('fonts/reader-default.ttf') format('truetype');
  257. }
  258. @font-face {
  259. font-family: 'OpenSans';
  260. src: url('fonts/open-sans.woff') format('woff'),
  261. url('fonts/open-sans.ttf') format('truetype');
  262. }
  263. @font-face {
  264. font-family: 'Roboto';
  265. src: url('fonts/roboto.woff') format('woff'),
  266. url('fonts/roboto.ttf') format('truetype');
  267. }
  268. @font-face {
  269. font-family: 'Rubik';
  270. src: url('fonts/rubik.woff2') format('woff2');
  271. }
  272. @font-face {
  273. font-family: 'Avrile';
  274. src: url('fonts/avrile.woff') format('woff'),
  275. url('fonts/avrile.ttf') format('truetype');
  276. }
  277. @font-face {
  278. font-family: 'Arimo';
  279. src: url('fonts/arimo.woff2') format('woff2');
  280. }
  281. @font-face {
  282. font-family: 'GEO_1';
  283. src: url('fonts/geo_1.woff') format('woff'),
  284. url('fonts/geo_1.ttf') format('truetype');
  285. }
  286. </style>