main.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-container>
  3. <el-aside width="200px">
  4. <AsideMenu :collapse="isCollapseMenu" />
  5. </el-aside>
  6. <el-container>
  7. <el-header>
  8. <el-row>
  9. <el-col :span="4" style="text-align: left;padding-left: 10px;">
  10. <i class="el-icon-star-on"></i>
  11. &nbsp;
  12. <label style="font-size: 16px;">真不错</label>
  13. </el-col>
  14. <el-col :span="2" :offset="18">
  15. <el-dropdown style="cursor: pointer;">
  16. <el-avatar icon="el-icon-user-solid" style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);"/>
  17. <el-dropdown-menu slot="dropdown">
  18. <el-dropdown-item>
  19. <router-link :to="{name: 'Logout'}">退出登录</router-link>
  20. </el-dropdown-item>
  21. </el-dropdown-menu>
  22. </el-dropdown>
  23. </el-col>
  24. </el-row>
  25. </el-header>
  26. <el-main :style="{height: (screenHeight - 60) + 'px', padding: 0 + 'px ' + 10 + 'px', paddingTop: 10 + 'px'}">
  27. <transition name="el-fade-in-linear">
  28. <router-view />
  29. </transition>
  30. </el-main>
  31. </el-container>
  32. </el-container>
  33. </template>
  34. <script>
  35. import AsideMenu from '@/components/layout/aside-menu'
  36. export default {
  37. name: 'Main',
  38. components: {
  39. AsideMenu
  40. },
  41. data () {
  42. return {
  43. screenHeight: document.documentElement.clientHeight, // 获取可视屏幕高度
  44. isCollapseMenu: false
  45. }
  46. },
  47. watch: {
  48. screenHeight (val) {
  49. // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  50. if (!this.timer) {
  51. // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  52. this.screenHeight = val
  53. this.timer = true
  54. const that = this
  55. setTimeout(function () {
  56. that.timer = false
  57. }, 400)
  58. }
  59. }
  60. },
  61. mounted () {
  62. const that = this
  63. window.onresize = () => {
  64. return (() => {
  65. window.screenHeight = document.documentElement.clientHeight
  66. that.screenHeight = window.screenHeight
  67. })()
  68. }
  69. },
  70. methods: {
  71. collapseMenu () {
  72. /* el-aside有一个默认值为300,暂时没有很好的方式来处理伸缩菜单栏来处理样式问题... */
  73. this.isCollapseMenu = !!this.isCollapseMenu
  74. }
  75. }
  76. }
  77. </script>
  78. <style>
  79. .el-header, .el-footer {
  80. background-color: #fff;
  81. color: #333;
  82. text-align: center;
  83. line-height: 60px;
  84. padding-left: 0px;
  85. padding-right: 0px;
  86. }
  87. .el-footer {
  88. height: 40px !important;
  89. line-height: 40px !important;
  90. }
  91. .el-main {
  92. background-color: #eee;
  93. color: #333;
  94. text-align: center;
  95. padding: 0px;
  96. }
  97. body > .el-container {
  98. margin-bottom: 40px;
  99. }
  100. .el-container:nth-child(5) .el-aside,
  101. .el-container:nth-child(6) .el-aside {
  102. line-height: 260px;
  103. }
  104. .el-container:nth-child(7) .el-aside {
  105. line-height: 320px;
  106. }
  107. .el-icon-star-on{
  108. color:yellow;
  109. font-size:50px;
  110. }
  111. </style>