Home.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <style lang="scss">
  2. @import '../style/home.scss';
  3. .head{
  4. width:30px;
  5. height:30px;
  6. border-radius:50%;
  7. float:left;
  8. margin:10px;
  9. }
  10. </style>
  11. <template>
  12. <el-container>
  13. <el-header class="header">
  14. <h1><img height="60px" src="../images/logo.png" alt=""> <span>
  15. <!-- <el-divider direction="vertical"></el-divider> -->
  16. {{now}}</span></h1>
  17. <!-- <img class="logo" src="../images/logo.png" alt=""> -->
  18. <div class="settings">
  19. <span>
  20. <i class="el-icon-s-custom"></i>
  21. {{info.name}}
  22. </span>
  23. <span class="logout" @click="logout"><i class="el-icon-switch-button"></i> 退出登录</span>
  24. </div>
  25. </el-header>
  26. <el-container class="main">
  27. <!-- 左侧菜单 -->
  28. <el-aside class="left-aside" width="210px">
  29. <el-menu background-color='#151932' text-color='#ffffff' :unique-opened='true' :default-active="$route.path" router class="left-menue" active-text-color="#ffffff">
  30. <template v-for="(item, index) in $router.options.routes" >
  31. <el-menu-item v-show="permission(item.name)" v-if='item.show&&item.isLeaf' :index="item.path" :key='index'>
  32. <i :class="item.icon"></i>
  33. <span slot="title">{{item.name}}</span>
  34. </el-menu-item>
  35. <el-submenu v-show="permission(item.name)" v-if='item.show&&!item.isLeaf' :index="'index_'+index" :key='index'>
  36. <template slot="title">
  37. <i :class="item.icon"></i>
  38. <span>{{item.name}}</span>
  39. </template>
  40. <el-menu-item-group>
  41. <el-menu-item class="child" v-for="(child,idx) in item.children" :key="index+'_'+idx" :index="child.path" v-show='!child.hide'>
  42. {{child.name}}
  43. </el-menu-item>
  44. </el-menu-item-group>
  45. </el-submenu>
  46. </template>
  47. </el-menu>
  48. </el-aside>
  49. <!-- 右侧内容 -->
  50. <el-container>
  51. <el-main>
  52. <transition name="fade" mode="out-in"><router-view :info='info' :community='community'></router-view></transition>
  53. </el-main>
  54. <!-- <el-footer>Footer</el-footer> -->
  55. </el-container>
  56. </el-container>
  57. </el-container>
  58. </template>
  59. <script>
  60. export default {
  61. name: 'home',
  62. data() {
  63. return {
  64. menuList:[],
  65. path:'',
  66. info:{},
  67. community_list:[],
  68. community:{},
  69. menu:[],
  70. now:(new Date()).toLocaleDateString()+" "+(new Date()).toLocaleTimeString()
  71. };
  72. },
  73. methods: {
  74. getDate(){
  75. this.now=(new Date()).toLocaleDateString()+" "+(new Date()).toLocaleTimeString()
  76. },
  77. logout(){
  78. localStorage.setItem('token','')
  79. this.$api.logout().then(res=>{
  80. this.$router.push({path:'/login'})
  81. })
  82. },
  83. permission(name){
  84. let permissions=this.info.permissions||[];
  85. let list=[];
  86. for(let i=0;i<permissions.length;i++){
  87. list.push(permissions[i].name)
  88. }
  89. if(list.indexOf(name)<0){
  90. return false;
  91. }else{
  92. return true;
  93. }
  94. },
  95. getData(){
  96. this.$api.getInfo().then(res=>{
  97. this.info=res.data.data
  98. })
  99. }
  100. },
  101. created(){
  102. // console.log(this.$route)
  103. this.getData()
  104. var that=this;
  105. setInterval(function(){
  106. that.getDate();
  107. },1000)
  108. }
  109. };
  110. </script>