index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div :class="classObj" class="app-wrapper">
  3. <div v-if="classObj.mobile && sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
  4. <sidebar class="sidebar-container" />
  5. <navbar />
  6. <div class="main-container">
  7. <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
  8. <hr />
  9. <app-main />
  10. </div>
  11. </div>
  12. </template>
  13. <script lang="ts">
  14. import { Component } from "vue-property-decorator";
  15. import { mixins } from "vue-class-component";
  16. import { DeviceType, AppModule } from "@/store/modules/app";
  17. import { AppMain, Navbar, Sidebar, Breadcrumb } from "./components";
  18. import ResizeMixin from "./mixin/resize";
  19. @Component({
  20. name: "Layout",
  21. components: {
  22. AppMain,
  23. Navbar,
  24. Sidebar,
  25. Breadcrumb,
  26. },
  27. })
  28. export default class extends mixins(ResizeMixin) {
  29. get classObj() {
  30. return {
  31. hideSidebar: !this.sidebar.opened,
  32. openSidebar: this.sidebar.opened,
  33. withoutAnimation: this.sidebar.withoutAnimation,
  34. mobile: this.device === DeviceType.Mobile,
  35. };
  36. }
  37. private handleClickOutside() {
  38. AppModule.CloseSideBar(false);
  39. }
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .app-wrapper {
  44. @include clearfix;
  45. position: relative;
  46. height: 100%;
  47. width: 100%;
  48. }
  49. .drawer-bg {
  50. background: #000;
  51. opacity: 0.3;
  52. width: 100%;
  53. top: 0;
  54. height: 100%;
  55. position: absolute;
  56. z-index: 999;
  57. }
  58. .main-container {
  59. height: calc(100% - 50px);
  60. transition: margin-left 0.28s;
  61. margin-left: $sideBarWidth;
  62. position: relative;
  63. overflow-y: hidden;
  64. }
  65. .sidebar-container {
  66. transition: width 0.28s;
  67. width: $sideBarWidth !important;
  68. height: 100%;
  69. position: fixed;
  70. font-size: 0px;
  71. top: 0;
  72. bottom: 0;
  73. left: 0;
  74. z-index: 1001;
  75. overflow: hidden;
  76. }
  77. .hideSidebar {
  78. .main-container {
  79. margin-left: 54px;
  80. }
  81. .sidebar-container {
  82. width: 54px !important;
  83. }
  84. }
  85. /* for mobile response 适配移动端 */
  86. .mobile {
  87. .main-container {
  88. margin-left: 0px;
  89. }
  90. .sidebar-container {
  91. transition: transform 0.28s;
  92. width: $sideBarWidth !important;
  93. }
  94. &.openSidebar {
  95. position: fixed;
  96. top: 0;
  97. }
  98. &.hideSidebar {
  99. .sidebar-container {
  100. pointer-events: none;
  101. transition-duration: 0.3s;
  102. transform: translate3d(-$sideBarWidth, 0, 0);
  103. }
  104. }
  105. }
  106. .withoutAnimation {
  107. .main-container,
  108. .sidebar-container {
  109. transition: none;
  110. }
  111. }
  112. </style>