App.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  79. get config() {
  80. return this.$store.state.config;
  81. }
  82. get rootRoute() {
  83. return this.$root.getRootRoute();
  84. }
  85. setAppTitle(title) {
  86. if (!title) {
  87. document.title = 'inpx-web';
  88. } else {
  89. document.title = title;
  90. }
  91. }
  92. }
  93. export default vueComponent(App);
  94. //-----------------------------------------------------------------------------
  95. </script>
  96. <style scoped>
  97. </style>
  98. <style>
  99. body, html, #app {
  100. margin: 0;
  101. padding: 0;
  102. width: 100%;
  103. height: 100%;
  104. font: normal 12px GameDefault;
  105. }
  106. .dborder {
  107. border: 2px solid yellow;
  108. }
  109. .icon-rotate {
  110. vertical-align: middle;
  111. animation: rotating 2s linear infinite;
  112. }
  113. @keyframes rotating {
  114. from {
  115. transform: rotate(0deg);
  116. } to {
  117. transform: rotate(360deg);
  118. }
  119. }
  120. @font-face {
  121. font-family: 'GameDefault';
  122. src: url('fonts/web-default.woff') format('woff'),
  123. url('fonts/web-default.ttf') format('truetype');
  124. }
  125. </style>