Home.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <el-container class ="home-container">
  3. <!-- 头部区域 -->
  4. <el-header>
  5. <div>
  6. <span>犊牛饲喂系统</span>
  7. </div>
  8. <el-button @click="logout" >退出</el-button>
  9. </el-header>
  10. <el-container>
  11. <!-- 侧边栏 -->
  12. <el-aside :width="isCollapse ? '64px' : '200px'">
  13. <div class="toggle-button" @click="toggleCollapse">|||</div>
  14. <!-- 侧边栏菜单区域 -->
  15. <el-menu background-color="#333744" text-color="#fff" active-text-color = "#409Eff" unique-opend :collapse="isCollapse" :collapse-transition="false" router :default-active = "activePath">
  16. <!-- 一级菜单 -->
  17. <!-- index必须是字符串,所以拼接 +'' -->
  18. <el-submenu :index="item.id +''" v-for="item in menuList" :key="item.id">
  19. <!-- 一级菜单的模板区域 -->
  20. <template slot="title">
  21. <!-- <span class = "nav-icon"></span> -->
  22. <i class="iconfont el-icon-s-order"></i>
  23. <span>{{item.name}}</span>
  24. </template>
  25. <!-- 二级菜单 -->
  26. <el-menu-item :index="'/' + items.path" v-for="items in item.children" :key="items.id" @click = "saveNavState(items)">
  27. <template slot="title">
  28. <i class="iconfont el-icon-s-order"></i>
  29. <span>{{items.name}}</span>
  30. </template>
  31. </el-menu-item>
  32. </el-submenu>
  33. </el-menu>
  34. </el-aside>
  35. <!-- 右侧主体内容 -->
  36. <el-container>
  37. <el-main >
  38. <!-- 路由占位符 -->
  39. <router-view></router-view>
  40. </el-main>
  41. <el-footer>
  42. </el-footer>
  43. </el-container>
  44. </el-container>
  45. </el-container>
  46. </template>
  47. <script>
  48. import { ajaxDataGet, ajaxDataPost, ajaxDataPut, ajaxDataDelete, checkButtons} from '@/api/common'
  49. import { parseTime, json2excel } from '@/utils/index.js'
  50. export default {
  51. data() {
  52. return {
  53. editableTabsValue: '2',
  54. editableTabs: [
  55. { title: '首页', name: '/home' },
  56. // { title: '角色列表', name: '/roles' },
  57. ],
  58. tabIndex: 2,
  59. isCollapse:false, //侧边栏是否展开
  60. activePath:"",//侧边栏高亮路径
  61. menuList:[
  62. // {
  63. // name:"数据统计", id:20, order:1,iconclass:'iconfont el-icon-s-order',
  64. // children:[
  65. // {id:101,name:"饲喂过程",iconclass:'iconfont el-icon-message',path: 'FeedProcess'},
  66. // ]
  67. // },
  68. // {
  69. // name:"牛只管理", id:20, order:1,iconclass:'iconfont el-icon-s-order',
  70. // children:[
  71. // {id:201,name:"牛只信息",iconclass:'iconfont el-icon-message',path: 'CowInfo'},
  72. // {id:202,name:"事件记录",iconclass:'iconfont el-icon-message',path: 'EventRecord'},
  73. // ]
  74. // },
  75. // {
  76. // name:"栏舍管理", id:30, order:1,iconclass:'iconfont el-icon-s-order',
  77. // children:[
  78. // {id:303,name:"牛只栏舍",iconclass:'iconfont el-icon-message',path: 'CowCowShed'},
  79. // {id:304,name:"栏舍分组",iconclass:'iconfont el-icon-message',path: 'CowShedGroup'},
  80. // // {id:304,name:"分类参数",iconclass:'iconfont el-icon-message',path: 'users56'},
  81. // // {id:305,name:"产品分类",iconclass:'iconfont el-icon-message',path: 'categories'},
  82. // ]
  83. // },
  84. // {
  85. // name:"配方计划", id:40, order:1,iconclass:'iconfont el-icon-s-order',
  86. // children:[
  87. // {id:403,name:"饲喂计划",iconclass:'iconfont el-icon-message',path: 'FeedPlan'},
  88. // {id:404,name:"配方模板",iconclass:'iconfont el-icon-message',path: 'FormulaTemplate'},
  89. // ]
  90. // },
  91. // {
  92. // name:"基础数据", id:60, order:6,iconclass:'iconfont el-icon-s-order',
  93. // children:[
  94. // {id:601,name:"犊牛类型",iconclass:'iconfont el-icon-message',path: 'CalfType'},
  95. // {id:602,name:"工单类型",iconclass:'iconfont el-icon-message',path: 'WorkOrderType'},
  96. // {id:603,name:"饲喂车管理",iconclass:'iconfont el-icon-message',path: 'FeedCarManagement'},
  97. // // {id:604,name:"疾病类型",iconclass:'iconfont el-icon-message',path: 'DiseaseType'},
  98. // {id:605,name:"预设饲喂模板",iconclass:'iconfont el-icon-message',path: 'FeedTemplate'},
  99. // {id:606,name:"默认标准参数",iconclass:'iconfont el-icon-message',path: 'DefaultPara'},
  100. // {id:607,name:"饲料成本设置",iconclass:'iconfont el-icon-message',path: 'FeedCost'},
  101. // ]
  102. // },
  103. // {
  104. // name:"系统管理", id:60, order:6,iconclass:'iconfont el-icon-s-order',
  105. // children:[
  106. // {id:701,name:"用户管理",iconclass:'iconfont el-icon-message',path: 'User'},
  107. // {id:702,name:"角色管理",iconclass:'iconfont el-icon-message',path: 'Role'},
  108. // ]
  109. // },
  110. ]
  111. }
  112. },
  113. created(){
  114. //处理Store刷新后消失的问题
  115. // 在页面加载时读取sessionStorage
  116. if (sessionStorage.getItem('store')) {
  117. this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
  118. }
  119. // 在页面刷新时将store保存到sessionStorage里
  120. window.addEventListener('beforeunload', () => {
  121. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  122. })
  123. this.getMenuList()
  124. this.activePath = window.sessionStorage.getItem('activePath')
  125. },
  126. methods:{
  127. handleClick(val) {
  128. // console.log(tab, event);
  129. console.log(val.name);
  130. this.$router.push(val.name)
  131. },
  132. removeTab(targetName) {
  133. let tabs = this.editableTabs;
  134. let activeName = this.editableTabsValue;
  135. if (activeName === targetName) {
  136. tabs.forEach((tab, index) => {
  137. if (tab.name === targetName) {
  138. let nextTab = tabs[index + 1] || tabs[index - 1];
  139. if (nextTab) {
  140. activeName = nextTab.name;
  141. }
  142. }
  143. });
  144. }
  145. // this.editableTabsValue = activeName;
  146. // this.editableTabs = tabs.filter(tab => tab.name !== targetName);
  147. },
  148. //退出
  149. logout(){
  150. //清空token
  151. window.sessionStorage.clear()
  152. //跳转登录页
  153. this.$router.push('/login')
  154. },
  155. //获取所有菜单
  156. getMenuList(){
  157. var me = this
  158. ajaxDataPost('/api/v1/system/user/permissions', {}).then(e => {
  159. console.log("getMenuList请求结果:",e)
  160. //打印请求成功结果
  161. if(e.code == 200 ){
  162. me.menuList = e.data.menu_list
  163. me.$store.state.buttonsList = e.data.menu_buttons_path
  164. } else {
  165. me.menuList = []
  166. me.$store.state.buttonsList = []
  167. }
  168. })
  169. },
  170. //折叠展开左侧菜单
  171. toggleCollapse(){
  172. this.isCollapse = ! this.isCollapse
  173. },
  174. //侧边栏高亮显示点击保存路径
  175. saveNavState(items){
  176. var activePath = '/' + items.path
  177. var name = items.name
  178. console.log("activePath",activePath)
  179. window.sessionStorage.setItem('activePath',activePath)
  180. }
  181. }
  182. }
  183. </script>
  184. <!-- 加了scoped,则是仅在此组件里生效 -->
  185. <style scoped>
  186. .nav-icon{display:inline-block;height: 30px;width: 30px; background: url("../assets/images/nlogin-bg1.jpg") no-repeat; }
  187. .home-container{height:100%}
  188. /* el-header一个类名就是一个样式,可以直接赋样式 */
  189. .el-header{background-color:#373d41;display:flex;justify-content:space-between;padding-left:0;align-items: center;color:#fff;font-size:20px;}
  190. .el-header div{display:flex;align-items:center;}
  191. .el-header div span{margin-left:15px;}
  192. .el-aside{background-color:#333744;}
  193. .el-aside .el-menu{border-right: none;text-align: left}
  194. .el-main{background-color:#eaedf1; height:80vh;padding:0px}
  195. .iconfont{margin-right:10px}
  196. .toggle-button{background-color:#4a5064;font-size:10px;line-height:24px;color:#fff;text-align:center;cursor:pointer;}
  197. </style>