Home.vue 11 KB

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