index.vue 2.4 KB

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