index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <el-container class="outter-container">
  3. <el-header>
  4. <h3><img src="../../assets/logo.png" height="50"/></h3>
  5. <div class="user-info">
  6. <i class="el-icon-s-custom"></i>
  7. <span v-html="user.realName" style="margin-right:10px;"></span>
  8. <a href="#" @click="logout()">退出</a>
  9. </div>
  10. </el-header>
  11. <el-container>
  12. <el-aside :width="sidebarWidth" v-loading="loading" class="sidebar">
  13. <div class="sidebar-collpase-btn" @click="collapse=!collapse" style="cursor:pointer">
  14. <i :class="sidbarHandlerClass"></i>
  15. </div>
  16. <el-menu
  17. class="el-menu-vertical-demo"
  18. @open="handleOpen"
  19. @close="handleClose"
  20. @select="handleSelect"
  21. :collapse="collapse"
  22. :collapse-transition="false"
  23. >
  24. <menu-tree-item :routes="menuList"></menu-tree-item>
  25. </el-menu>
  26. </el-aside>
  27. <el-main>
  28. <router-view/>
  29. </el-main>
  30. </el-container>
  31. </el-container>
  32. </template>
  33. <script>
  34. import MenuTreeItem from "@/components/MenuTreeItem"
  35. import menuApi from "@/api/sys/menu"
  36. import userApi from "@/api/sys/user"
  37. export default {
  38. data() {
  39. return {
  40. menuList: [],
  41. loading: false,
  42. collapse: false,
  43. user: {}
  44. };
  45. },
  46. computed:{
  47. sidebarWidth() {
  48. return !this.collapse ? "200px" : "64px";
  49. },
  50. sidbarHandlerClass(){
  51. return {
  52. "iconfont" : true,
  53. "icon-icon_left_arrow" : this.collapse,
  54. "icon-icon_right_arrow" : !this.collapse
  55. }
  56. }
  57. },
  58. methods: {
  59. handleOpen(key, keyPath) {
  60. console.log(key, keyPath);
  61. },
  62. handleClose(key, keyPath) {
  63. console.log(key, keyPath);
  64. },
  65. handleSelect(key, keyPath) {
  66. //console.log(key, keyPath);
  67. this.$router.push({ path: key });
  68. },
  69. logout() {
  70. this.$store.dispatch("user/logout").then(() => {
  71. this.$router.push({ path: "/login" });
  72. });
  73. }
  74. },
  75. components: {
  76. "menu-tree-item" : MenuTreeItem
  77. },
  78. mounted() {
  79. this.loading = true;
  80. userApi.userInfo().then(resp=>{
  81. if(resp.data.result){
  82. this.user = resp.data.data;
  83. }
  84. });
  85. menuApi.getMenuTree().then(response=>{
  86. console.log(response);
  87. var jsonData = response.data;
  88. this.menuList = jsonData.data;
  89. this.loading = false;
  90. }).catch(exception=>{
  91. this.$message.error(exception + "");
  92. this.loading = false;
  93. });
  94. }
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .outter-container {
  99. flex: 1;
  100. }
  101. .el-header {
  102. position: relative;
  103. background-color: #fff;
  104. color: #333;
  105. text-align: left;
  106. height: 70px !important;
  107. line-height:70px;
  108. // border-bottom: 2px solid rgb(36,61,162);
  109. border-bottom: 2px solid #64a63c;
  110. }
  111. .el-header h3 {
  112. margin: 5px;
  113. padding: 0px;
  114. }
  115. .el-aside {
  116. color: #333;
  117. text-align: center;
  118. display: flex;
  119. flex-direction: column;
  120. }
  121. .el-aside .el-menu {
  122. flex: 1;
  123. background-color:rgb(238, 238, 238);
  124. }
  125. .el-main {
  126. background-color: #fff;
  127. color: #333;
  128. text-align: center;
  129. padding: 0px;
  130. }
  131. .el-menu-vertical-demo {
  132. text-align: left;
  133. }
  134. .user-info{
  135. position: absolute;
  136. right:20px;
  137. bottom:10px;
  138. font-size:14px;
  139. line-height: 30px;
  140. a{
  141. color:blue;
  142. cursor: pointer;
  143. text-decoration: none;
  144. }
  145. a:hover{
  146. text-decoration: underline;
  147. }
  148. }
  149. .sidebar{
  150. position:relative;
  151. overflow:visible !important;
  152. }
  153. .sidebar-collpase-btn{
  154. position:absolute;
  155. width:12px;
  156. height:53px;
  157. border-radius: 0px 10px 10px 0px;
  158. top:200px;
  159. right:-12px;
  160. background-color:#eeeeee;
  161. z-index: 10000;
  162. padding-top:30px;
  163. padding-right:4px;
  164. color:black;
  165. font-weight: bold;
  166. }
  167. </style>