App.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div id="app">
  3. <router-view />
  4. <Setings ref="setingsRef" />
  5. <!-- 检测版本更新 -->
  6. <!-- <Upgrade v-if="isVersion" /> -->
  7. </div>
  8. </template>
  9. <script>
  10. import { mapMutations } from 'vuex';
  11. import Setings from '@/layout/navBars/breadcrumb/setings.vue';
  12. import Upgrade from '@/layout/upgrade/index.vue';
  13. import setting from './setting';
  14. import { Local } from '@/utils/storage.js';
  15. import config from '../package.json';
  16. export default {
  17. name: 'app',
  18. components: { Setings, Upgrade },
  19. provide() {
  20. return {
  21. reload: this.reload,
  22. };
  23. },
  24. data() {
  25. return {
  26. isVersion: false,
  27. };
  28. },
  29. watch: {
  30. // 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要)
  31. $route(to, from) {
  32. const onRoutes = to.meta.activeMenu ? to.meta.activeMenu : to.meta.path;
  33. this.$store.commit('menu/setActivePath', onRoutes);
  34. if (to.name == 'crud_crud') {
  35. this.$store.state.menus.oneLvRoutes.map((e) => {
  36. if (e.path === to.path) {
  37. to.meta.title = e.title;
  38. }
  39. });
  40. }
  41. if (
  42. [
  43. 'product_productAdd',
  44. 'marketing_bargainCreate',
  45. 'marketing_storeSeckillCreate',
  46. 'marketing_storeIntegralCreate',
  47. ].includes(to.name)
  48. ) {
  49. let route = to.matched[1].path.split(':')[0];
  50. this.$store.state.menus.oneLvRoutes.map((e) => {
  51. if (route.indexOf(e.path) != -1) {
  52. to.meta.title = `${e.title} ${to.params.id ? 'ID:' + to.params.id : ''}`;
  53. }
  54. });
  55. }
  56. },
  57. },
  58. methods: {
  59. ...mapMutations('media', ['setDevice']),
  60. handleWindowResize() {
  61. this.handleMatchMedia();
  62. },
  63. handleMatchMedia() {
  64. const matchMedia = window.matchMedia;
  65. if (matchMedia('(max-width: 600px)').matches) {
  66. var deviceWidth = document.documentElement.clientWidth || window.innerWidth;
  67. let css = 'calc(100vw/7.5)';
  68. document.documentElement.style.fontSize = css;
  69. this.setDevice('Mobile');
  70. } else if (matchMedia('(max-width: 992px)').matches) {
  71. this.setDevice('Tablet');
  72. } else {
  73. this.setDevice('Desktop');
  74. }
  75. },
  76. reload() {
  77. this.isRouterAlive = false;
  78. this.$nextTick(function () {
  79. this.isRouterAlive = true;
  80. });
  81. },
  82. // 布局配置弹窗打开
  83. openSetingsDrawer() {
  84. this.bus.$on('openSetingsDrawer', () => {
  85. this.$refs.setingsRef.openDrawer();
  86. });
  87. },
  88. // 获取缓存中的布局配置
  89. getLayoutThemeConfig() {
  90. if (Local.get('themeConfigPrev')) {
  91. this.$store.dispatch('themeConfig/setThemeConfig', Local.get('themeConfigPrev'));
  92. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  93. } else {
  94. Local.set('themeConfigPrev', this.$store.state.themeConfig.themeConfig);
  95. }
  96. },
  97. getVersion() {
  98. this.isVersion = false;
  99. if (this.$route.path !== `${setting.routePre}/login` && this.$route.path !== '/') {
  100. if ((Local.get('version') && Local.get('version') !== config.version) || !Local.get('version'))
  101. this.isVersion = true;
  102. }
  103. },
  104. },
  105. mounted() {
  106. this.handleMatchMedia();
  107. this.openSetingsDrawer();
  108. this.getLayoutThemeConfig();
  109. this.$nextTick((e) => {
  110. // this.getVersion();
  111. });
  112. },
  113. destroyed() {
  114. this.bus.$off('openSetingsDrawer');
  115. },
  116. };
  117. </script>
  118. <style lang="scss">
  119. html,
  120. body {
  121. width: 100%;
  122. height: 100%;
  123. overflow: hidden;
  124. margin: 0;
  125. padding: 0;
  126. }
  127. #app {
  128. width: 100%;
  129. height: 100%;
  130. font-family: PingFang SC, Arial, Microsoft YaHei, sans-serif;
  131. }
  132. // .dialog-fade-enter-active {
  133. // animation: anim-open 0.3s;
  134. // }
  135. // .dialog-fade-leave-active {
  136. // animation: anim-close 0.3s;
  137. // }
  138. // @keyframes anim-open {
  139. // 0% {
  140. // transform: translate3d(100%, 0, 0);
  141. // opacity: 0;
  142. // }
  143. // 100% {
  144. // transform: translate3d(0, 0, 0);
  145. // opacity: 1;
  146. // }
  147. // }
  148. // @keyframes anim-close {
  149. // 0% {
  150. // transform: translate3d(0, 0, 0);
  151. // opacity: 1;
  152. // }
  153. // 100% {
  154. // transform: translate3d(100%, 0, 0);
  155. // opacity: 0;
  156. // }
  157. // }
  158. .ivu-modal-wrap ::v-deep .connect_customerServer_img {
  159. display: none;
  160. }
  161. .right-box .ivu-color-picker .ivu-select-dropdown {
  162. position: absolute;
  163. // width: 300px !important;
  164. left: -73px !important;
  165. }
  166. </style>