Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="home">
  3. <header class="header">
  4. <div class="left">
  5. 慧牧科技
  6. <el-button
  7. @click="onMenuCollapse"
  8. circle
  9. :icon="menuCollapse? 'el-icon-s-unfold' : 'el-icon-s-fold'"
  10. ></el-button>
  11. </div>
  12. <div class="right">
  13. <span class="warp">
  14. <el-dropdown>
  15. <span class="el-dropdown-link">
  16. 账号管理
  17. <i class="el-icon-arrow-down el-icon--right"></i>
  18. </span>
  19. <el-dropdown-menu slot="dropdown">
  20. <el-dropdown-item>退出登录</el-dropdown-item>
  21. <el-dropdown-item>切换账号</el-dropdown-item>
  22. </el-dropdown-menu>
  23. </el-dropdown>
  24. </span>
  25. <span>
  26. <el-dropdown>
  27. <span class="el-dropdown-link">
  28. 权限切换
  29. <i class="el-icon-arrow-down el-icon--right"></i>
  30. </span>
  31. <el-dropdown-menu slot="dropdown">
  32. <el-dropdown-item disabled>权限一</el-dropdown-item>
  33. <el-dropdown-item divided>权限二</el-dropdown-item>
  34. </el-dropdown-menu>
  35. </el-dropdown>
  36. </span>
  37. </div>
  38. </header>
  39. <section class="section">
  40. <div class="tac">
  41. <div class="col1">
  42. <el-menu
  43. default-active="2"
  44. class="el-menu-vertical-demo"
  45. @open="handleOpen"
  46. @close="handleClose"
  47. :collapse="menuCollapse"
  48. :unique-opened="true"
  49. :default-openeds="defaultUnfoldedMenu"
  50. select="1-1"
  51. background-color="rgba(46,38,87,0)"
  52. text-color="#fff"
  53. active-text-color="#ffd04b"
  54. >
  55. <div v-for="(item) in menuData " :key="item.index">
  56. <el-submenu
  57. v-if="item.childList && item.childList.length > 0"
  58. :index="item.index"
  59. >
  60. <template slot="title">
  61. <i :class="item.iconClassName"></i>
  62. <span slot="title">{{ !menuCollapse? item.optionName : '' }}</span>
  63. <!-- <span slot="title">{{ item.oneMenuName }}</span> -->
  64. </template>
  65. <el-menu-item
  66. v-for="(item1) in item.childList"
  67. :key="item1.index"
  68. :index="item1.index"
  69. :routerName="item1.routerName"
  70. @click="onClickMenu(item1)"
  71. >{{ item1.optionName }}</el-menu-item>
  72. </el-submenu>
  73. <el-menu-item
  74. v-else
  75. :index="item.index"
  76. :disabled="item.disabled"
  77. :routerName="item.routerName"
  78. @click="onClickMenu(item)"
  79. >
  80. <i :class="item.iconClassName"></i>
  81. <span slot="title">{{ !menuCollapse? item.optionName : '' }}</span>
  82. </el-menu-item>
  83. </div>
  84. </el-menu>
  85. </div>
  86. <div class="col2">
  87. <header class="col2_header">
  88. <el-tag
  89. v-for="tag in tags"
  90. :key="tag.routerName"
  91. closable
  92. @close="close(tag)"
  93. @click="clickTag(tag)"
  94. :type="tag.type?tag.type:'info'"
  95. class="item"
  96. >{{tag.name}}</el-tag>
  97. </header>
  98. <div class="warp">
  99. <router-view />
  100. </div>
  101. </div>
  102. </div>
  103. </section>
  104. </div>
  105. </template>
  106. <script>
  107. import { menuData } from "./mencCofig.js";
  108. export default {
  109. data() {
  110. return {
  111. // 菜单配置
  112. menuData,
  113. menuCollapse: false, //是否水平折叠收起菜单
  114. defaultUnfoldedMenu: [menuData[0].index], // 默认展开第一项
  115. tags: []
  116. };
  117. },
  118. created() {
  119. this.defaultUnfoldedMenu = [
  120. localStorage.getItem("defaultUnfoldedMenu")
  121. ];
  122. this.menuCollapse = JSON.parse(localStorage.getItem("menuCollapse"));
  123. this.tags = JSON.parse(localStorage.getItem("tagsNavList")) || [];
  124. },
  125. methods: {
  126. // 收取菜单按钮
  127. onMenuCollapse() {
  128. this.menuCollapse = !this.menuCollapse;
  129. localStorage.setItem("menuCollapse", this.menuCollapse);
  130. this.defaultUnfoldedMenu = [
  131. localStorage.getItem("defaultUnfoldedMenu")
  132. ];
  133. },
  134. // 菜单展开
  135. handleOpen(key, keyPath) {
  136. console.log(key, keyPath);
  137. localStorage.setItem("defaultUnfoldedMenu", "" + key);
  138. },
  139. // 菜单收取
  140. handleClose(key, keyPath) {
  141. console.log(key, keyPath);
  142. },
  143. // 点击菜单项
  144. onClickMenu(item) {
  145. let _this = this;
  146. // 如果要跳转的路由和当前路由一致就 return
  147. if (this.$router.history.current.name == item.routerName) return;
  148. this.$router.push({
  149. name: item.routerName
  150. });
  151. // 如果tags中已经存在 return
  152. let temp = includes(item.routerName);
  153. if (temp) {
  154. this.tags.forEach(item => {
  155. item.type = "info";
  156. });
  157. temp.type = "success";
  158. return;
  159. }
  160. this.tags.forEach(item => {
  161. item.type = "info";
  162. });
  163. this.tags.push({
  164. name: item.optionName,
  165. routerName: item.routerName,
  166. type: "success"
  167. });
  168. this.changeTagColor(item.routerName);
  169. localStorage.setItem("tagsNavList", JSON.stringify(this.tags));
  170. // 查看当前 tags里有没有传进来的路由,返回 true false
  171. function includes(routerName) {
  172. let tags = _this.tags;
  173. return tags.find(item => {
  174. return item.routerName == routerName;
  175. });
  176. }
  177. },
  178. // 点击 tag
  179. clickTag(tag) {
  180. console.log(tag.routerName);
  181. if (this.$router.history.current.name == tag.routerName) return;
  182. this.$router.push({
  183. name: tag.routerName
  184. });
  185. this.changeTagColor(tag.routerName);
  186. localStorage.setItem("tagsNavList", JSON.stringify(this.tags));
  187. },
  188. // 点击 tag 的小×
  189. close(tag) {
  190. console.log(tag);
  191. let spliceIndex = this.tags.findIndex(item => {
  192. return item.routerName == tag.routerName;
  193. });
  194. console.log(spliceIndex);
  195. this.tags.splice(spliceIndex, 1);
  196. localStorage.setItem("tagsNavList", JSON.stringify(this.tags));
  197. },
  198. // 改变tag的颜色 公用的
  199. changeTagColor(routerName) {
  200. this.tags.forEach(item => {
  201. if (item.routerName == routerName) {
  202. item.type = "success";
  203. } else {
  204. item.type = "info";
  205. }
  206. });
  207. }
  208. }
  209. };
  210. </script>
  211. <style lang="scss" scoped>
  212. .home {
  213. height: 100%;
  214. overflow: hidden;
  215. box-sizing: border-box;
  216. background-color: #eee;
  217. display: flex;
  218. flex-direction: column;
  219. .header {
  220. // background-color: #029b62;
  221. // background-color: rgb(46,38,87);
  222. background-color: rgb(85, 70, 148);
  223. height: 40px;
  224. padding: 10px 20px;
  225. margin-bottom: 5px;
  226. display: flex;
  227. justify-content: space-between;
  228. align-items: center;
  229. .left {
  230. font-size: 25px;
  231. color: #fff;
  232. /deep/ .is-circle {
  233. margin-left: 40px;
  234. }
  235. }
  236. .right {
  237. .warp {
  238. margin-right: 20px;
  239. }
  240. }
  241. }
  242. .section {
  243. flex: 1;
  244. box-sizing: border-box;
  245. overflow: auto;
  246. .tac {
  247. flex: 1;
  248. display: flex;
  249. height: 96%;
  250. box-sizing: border-box;
  251. .col1 {
  252. margin-right: 5px;
  253. // background-color: rgb(46,38,87);
  254. background-image: linear-gradient(to bottom, rgb(85, 70, 148) , rgb(41, 33, 85), rgb(41, 33, 85));
  255. }
  256. .col2 {
  257. flex: 1;
  258. background-color: #fff;
  259. padding: 0 15px 15px 15px;
  260. border-radius: 5px;
  261. margin-right: 5px;
  262. height: 100%;
  263. overflow: auto;
  264. .col2_header {
  265. position: relative;
  266. width: 85%;
  267. height: 50px;
  268. overflow: hidden;
  269. border-bottom: 2px solid #eee;
  270. background-color: #fff;
  271. padding: 10px;
  272. display: flex;
  273. align-items: center;
  274. box-sizing: border-box;
  275. z-index: 1;
  276. position: fixed;
  277. .item {
  278. margin-right: 8px;
  279. }
  280. }
  281. .warp {
  282. margin: 15px;
  283. padding-top: 55px;
  284. }
  285. }
  286. }
  287. }
  288. // border: 1px solid #f00;
  289. }
  290. .el-menu-vertical-demo:not(.el-menu--collapse) {
  291. width: 200px;
  292. min-height: 400px;
  293. }
  294. // 下拉菜单
  295. .el-dropdown-link {
  296. cursor: pointer;
  297. color: #fff;
  298. }
  299. .el-icon-arrow-down {
  300. font-size: 12px;
  301. }
  302. </style>