App.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="fit row">
  3. <Api ref="api" />
  4. <Notify ref="notify" />
  5. <StdDialog ref="stdDialog" />
  6. <router-view v-slot="{ Component }">
  7. <keep-alive>
  8. <component :is="Component" class="col" />
  9. </keep-alive>
  10. </router-view>
  11. </div>
  12. </template>
  13. <script>
  14. //-----------------------------------------------------------------------------
  15. import vueComponent from './vueComponent.js';
  16. //import * as utils from '../share/utils';
  17. import Notify from './share/Notify.vue';
  18. import StdDialog from './share/StdDialog.vue';
  19. import Api from './Api/Api.vue';
  20. import Search from './Search/Search.vue';
  21. const componentOptions = {
  22. components: {
  23. Api,
  24. Notify,
  25. StdDialog,
  26. Search,
  27. },
  28. watch: {
  29. },
  30. };
  31. class App {
  32. _options = componentOptions;
  33. created() {
  34. this.commit = this.$store.commit;
  35. //root route
  36. let cachedRoute = '';
  37. let cachedPath = '';
  38. this.$root.getRootRoute = () => {
  39. if (this.$route.path != cachedPath) {
  40. cachedPath = this.$route.path;
  41. const m = cachedPath.match(/^(\/[^/]*).*$/i);
  42. cachedRoute = (m ? m[1] : this.$route.path);
  43. }
  44. return cachedRoute;
  45. }
  46. this.$root.isMobileDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
  47. this.$root.setAppTitle = this.setAppTitle;
  48. //global keyHooks
  49. this.keyHooks = [];
  50. this.keyHook = (event) => {
  51. for (const hook of this.keyHooks)
  52. hook(event);
  53. }
  54. this.$root.addKeyHook = (hook) => {
  55. if (this.keyHooks.indexOf(hook) < 0)
  56. this.keyHooks.push(hook);
  57. }
  58. this.$root.removeKeyHook = (hook) => {
  59. const i = this.keyHooks.indexOf(hook);
  60. if (i >= 0)
  61. this.keyHooks.splice(i, 1);
  62. }
  63. document.addEventListener('keyup', (event) => {
  64. this.keyHook(event);
  65. });
  66. document.addEventListener('keypress', (event) => {
  67. this.keyHook(event);
  68. });
  69. document.addEventListener('keydown', (event) => {
  70. this.keyHook(event);
  71. });
  72. }
  73. mounted() {
  74. this.$root.api = this.$refs.api;
  75. this.$root.notify = this.$refs.notify;
  76. this.$root.stdDialog = this.$refs.stdDialog;
  77. this.setAppTitle();
  78. (async() => {
  79. try {
  80. const api = this.$root.api;
  81. const config = await api.config();
  82. this.commit('setConfig', config);
  83. } catch (e) {
  84. this.$root.stdDialog.alert(e.message, 'Ошибка');
  85. }
  86. })();
  87. }
  88. get config() {
  89. return this.$store.state.config;
  90. }
  91. get rootRoute() {
  92. return this.$root.getRootRoute();
  93. }
  94. setAppTitle(title) {
  95. if (!title) {
  96. document.title = 'inpx-web';
  97. } else {
  98. document.title = title;
  99. }
  100. }
  101. }
  102. export default vueComponent(App);
  103. //-----------------------------------------------------------------------------
  104. </script>
  105. <style scoped>
  106. </style>
  107. <style>
  108. body, html, #app {
  109. margin: 0;
  110. padding: 0;
  111. width: 100%;
  112. height: 100%;
  113. font: normal 12px GameDefault;
  114. }
  115. .dborder {
  116. border: 2px solid yellow;
  117. }
  118. .icon-rotate {
  119. vertical-align: middle;
  120. animation: rotating 2s linear infinite;
  121. }
  122. @keyframes rotating {
  123. from {
  124. transform: rotate(0deg);
  125. } to {
  126. transform: rotate(360deg);
  127. }
  128. }
  129. @font-face {
  130. font-family: 'GameDefault';
  131. src: url('fonts/web-default.woff') format('woff'),
  132. url('fonts/web-default.ttf') format('truetype');
  133. }
  134. </style>