index.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <Mains v-if="headMenuNoShow" />
  3. <Defaults v-else-if="getThemeConfig.layout === 'defaults'" />
  4. <Classic v-else-if="getThemeConfig.layout === 'classic'" />
  5. <Transverse v-else-if="getThemeConfig.layout === 'transverse'" />
  6. <Columns v-else-if="getThemeConfig.layout === 'columns'" />
  7. </template>
  8. <script>
  9. import { Local } from '@/utils/storage.js';
  10. import { mapMutations } from 'vuex';
  11. import { getNewTagList } from '@/libs/util';
  12. import Mains from '@/layout/component/main.vue';
  13. export default {
  14. name: 'layout',
  15. components: {
  16. Defaults: () => import('@/layout/main/defaults.vue'),
  17. Classic: () => import('@/layout/main/classic.vue'),
  18. Transverse: () => import('@/layout/main/transverse.vue'),
  19. Columns: () => import('@/layout/main/columns.vue'),
  20. Mains: () => import('@/layout/component/main.vue'),
  21. },
  22. data() {
  23. return {
  24. headMenuNoShow: false,
  25. };
  26. },
  27. computed: {
  28. // 获取布局配置信息
  29. getThemeConfig() {
  30. return this.$store.state.themeConfig.themeConfig;
  31. },
  32. tagNavList() {
  33. return this.$store.state.app.tagNavList;
  34. },
  35. },
  36. watch: {
  37. $route(newRoute) {
  38. this.headMenuNoShow = this.$route.meta.fullScreen;
  39. const { name, query, params, meta, path } = newRoute;
  40. this.addTag({
  41. route: { name, query, params, meta, path },
  42. type: 'push',
  43. });
  44. this.setBreadCrumb(newRoute);
  45. this.setTagNavList(getNewTagList(this.tagNavList, newRoute));
  46. },
  47. },
  48. created() {
  49. this.headMenuNoShow = this.$route.meta.fullScreen;
  50. this.onLayoutResize();
  51. window.addEventListener('resize', this.onLayoutResize);
  52. },
  53. methods: {
  54. ...mapMutations(['setBreadCrumb', 'setTagNavList', 'addTag', 'setLocal', 'setHomeRoute', 'closeTag']),
  55. // 窗口大小改变时(适配移动端)
  56. onLayoutResize() {
  57. if (!Local.get('oldLayout')) Local.set('oldLayout', this.$store.state.themeConfig.themeConfig.layout);
  58. const clientWidth = document.body.clientWidth;
  59. if (clientWidth < 1000) {
  60. this.$store.state.themeConfig.themeConfig.isCollapse = false;
  61. this.bus.$emit('layoutMobileResize', {
  62. layout: 'defaults',
  63. clientWidth,
  64. });
  65. } else {
  66. this.bus.$emit('layoutMobileResize', {
  67. layout: Local.get('oldLayout') ? Local.get('oldLayout') : this.$store.state.themeConfig.themeConfig.layout,
  68. clientWidth,
  69. });
  70. }
  71. },
  72. },
  73. distroyed() {
  74. window.removeEventListener('resize', this.onLayoutResize);
  75. },
  76. };
  77. </script>