HomeView.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="home">
  3. <a-layout id="components-layout-demo-top-side-2">
  4. <a-layout-header class="header">
  5. <HomeHeader :leftVisible.sync="leftVisible" :is-login="true" />
  6. </a-layout-header>
  7. <a-layout class="main_body">
  8. <a-drawer
  9. v-if="leftVisible"
  10. placement="left"
  11. :visible="leftVisible"
  12. :get-container="false"
  13. :closable="false"
  14. @close="closeLeft"
  15. width="auto"
  16. :wrap-style="{ position: 'absolute' }"
  17. >
  18. <HomeLeft
  19. :close="
  20. () => {
  21. leftVisible = false;
  22. }
  23. "
  24. />
  25. </a-drawer>
  26. <a-layout-sider
  27. v-model="collapse"
  28. :trigger="null"
  29. :width="asideWidth"
  30. style="background: #fff"
  31. :collapsible="true"
  32. :collapsed-width="collapsedWidth"
  33. >
  34. <HomeAside :collapse.sync="collapse" />
  35. </a-layout-sider>
  36. <!-- 内容 -->
  37. <a-layout-content class="home-page">
  38. <Transition name="fade-transform" mode="out-in">
  39. <router-view
  40. :key="
  41. $route.matched[1]
  42. ? $route.matched[1].name
  43. ? $route.matched[1].name
  44. : -1
  45. : -1
  46. "
  47. />
  48. </Transition>
  49. </a-layout-content>
  50. </a-layout>
  51. </a-layout>
  52. </div>
  53. </template>
  54. <script>
  55. import "@/style/common.css";
  56. import HomeHeader from "@/components/home/HomeHeader.vue";
  57. import HomeAside from "@/components/home/HomeAside.vue";
  58. import HomeLeft from "@/components/home/HomeLeft.vue";
  59. export default {
  60. name: "HomeView",
  61. components: {
  62. HomeHeader,
  63. HomeAside,
  64. HomeLeft,
  65. },
  66. data() {
  67. return {
  68. collapse: true, // 侧边栏是否收起
  69. leftVisible: false,
  70. asideWidth: 160,
  71. collapsedWidth: 60,
  72. contentWidth: "84%",
  73. contentHeight: 450,
  74. };
  75. },
  76. watch: {
  77. $route() {
  78. this.judgeHideAside();
  79. },
  80. },
  81. mounted() {
  82. this.judgeHideAside();
  83. if (this.$route.matched.length === 1) {
  84. this.$router.push({ path: "/dashboard" });
  85. }
  86. },
  87. methods: {
  88. closeLeft() {
  89. this.leftVisible = false;
  90. },
  91. judgeHideAside() {
  92. let name = this.$route.name;
  93. if (!name) {
  94. this.asideWidth = 160;
  95. this.collapsedWidth = 60;
  96. return;
  97. }
  98. if (["dashboard", "notice"].indexOf(name) > -1) {
  99. this.asideWidth = 0;
  100. this.collapsedWidth = 0;
  101. } else if (this.asideWidth === 0) {
  102. this.asideWidth = 160;
  103. this.collapsedWidth = 60;
  104. }
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="less" scoped>
  110. .home {
  111. width: 100%;
  112. height: 100%;
  113. /deep/ .ant-drawer-body {
  114. padding: 0;
  115. height: 100%;
  116. }
  117. .header {
  118. height: 60px;
  119. padding: 0;
  120. line-height: 60px;
  121. }
  122. .main_body {
  123. height: calc(100vh - 60px);
  124. position: relative;
  125. }
  126. .home-page {
  127. display: inline-block;
  128. background: #f0f1f2;
  129. margin: 0;
  130. transition: all 1s;
  131. overflow: hidden;
  132. }
  133. }
  134. /deep/ .ant-drawer-content {
  135. background: rgba(255, 255, 255, 0.85);
  136. }
  137. </style>