Home.vue 11 KB

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