Menu.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div class="menu">
  3. <ul class="menu-list">
  4. <li class="menu-item" v-for="(menu, index) of currentMenu" :key="menu" @click="click(index)" :class="{ active: activeIndex == index }" @mouseenter="subMenuShow(menu.children, index)">
  5. <router-link v-if="!menu.children" :to="{ path: menu.path, query: { root: currRoot } }">
  6. <el-tooltip class="item" effect="dark" :content="menu.text" placement="right" :show-after="500">
  7. <div class="menu-icon svg-icon" :class="activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'">
  8. <SvgIcon :svgid="menu.icon"></SvgIcon>
  9. </div>
  10. </el-tooltip>
  11. </router-link>
  12. <div v-if="menu.children" class="sub-menu-item">
  13. <div class="menu-icon svg-icon" :class="activeIndex == index ? 'svg-icon-green' : 'svg-icon-gray'">
  14. <SvgIcon :svgid="menu.icon"></SvgIcon>
  15. </div>
  16. </div>
  17. </li>
  18. </ul>
  19. </div>
  20. <div class="sub-menu" v-show="isShowSubMenu">
  21. <ul class="menu-list">
  22. <li class="menu-item" v-for="(menu, index) of subMenu" @click="subclick(index)" :key="menu" :class="{ active: subIndex == index }">
  23. <router-link :to="{ path: menu.path, query: { root: currRoot } }">
  24. <div class="menu-icon svg-icon">
  25. <SvgIcon :svgid="menu.icon"></SvgIcon>
  26. </div>
  27. <div class="sub-menu-text" :class="subIndex == index ? 'green' : 'gray'">{{ menu.text }}</div>
  28. </router-link>
  29. </li>
  30. </ul>
  31. </div>
  32. </template>
  33. <script>
  34. import SvgIcon from "@com/coms/icon/svg-icon.vue";
  35. export default {
  36. components: {
  37. SvgIcon,
  38. },
  39. props: {
  40. root: { type: String, default: "monitor" },
  41. },
  42. data() {
  43. return {
  44. currRoot: "monitor",
  45. menuData: [
  46. {
  47. id: "monitor",
  48. text: "状态监视",
  49. data: [
  50. {
  51. text: "驾驶舱",
  52. icon: "svg-lead-cockpit",
  53. path: "/",
  54. },
  55. {
  56. text: "基础矩阵",
  57. icon: "svg-matrix",
  58. path: "/lightmatrix1",
  59. },
  60. {
  61. text: "风场明细矩阵",
  62. icon: "svg-mx-matrix",
  63. path: "/lightmatrix2",
  64. },
  65. {
  66. text: "欠发矩阵",
  67. icon: "svg-qf-matrix",
  68. path: "/lightmatrix3",
  69. },
  70. {
  71. text: "光伏明细矩阵",
  72. icon: "svg-gf-matrix",
  73. path: "/lightmatrix",
  74. },
  75. {
  76. text: "状态监视",
  77. icon: "svg-state-watch",
  78. path: "/status",
  79. },
  80. {
  81. text: "Agc",
  82. icon: "svg-agc",
  83. path: "/agc",
  84. },
  85. ],
  86. },
  87. {
  88. id: "datacenter",
  89. text: "数据管理",
  90. data: [],
  91. },
  92. {
  93. id: "statistic",
  94. text: "统计分析",
  95. data: [],
  96. },
  97. {
  98. id: "health",
  99. text: "健康管理",
  100. data: [
  101. {
  102. text: "健康管理1",
  103. icon: "svg-wind-site",
  104. path: "/health1",
  105. },
  106. {
  107. text: "健康管理2",
  108. icon: "svg-wind-site",
  109. path: "/health2",
  110. },
  111. {
  112. text: "健康管理3",
  113. icon: "svg-wind-site",
  114. path: "/health3",
  115. },
  116. {
  117. text: "健康管理4",
  118. icon: "svg-wind-site",
  119. path: "/health4",
  120. },
  121. {
  122. text: "健康管理5",
  123. icon: "svg-wind-site",
  124. path: "/health5",
  125. },
  126. {
  127. text: "健康管理6",
  128. icon: "svg-wind-site",
  129. path: "/health6",
  130. },
  131. {
  132. text: "健康管理7",
  133. icon: "svg-wind-site",
  134. path: "/health7",
  135. },
  136. ],
  137. },
  138. {
  139. id: "decision",
  140. text: "决策支持",
  141. data: [
  142. {
  143. text: "决策支持1",
  144. icon: "svg-matrix",
  145. path: "/decision1",
  146. },
  147. // {
  148. // text: "决策支持2",
  149. // icon: "svg-matrix",
  150. // path: "/decision2",
  151. // },
  152. // {
  153. // text: "决策支持3",
  154. // icon: "svg-matrix",
  155. // path: "/decision3",
  156. // },
  157. // {
  158. // text: "决策支持4",
  159. // icon: "svg-matrix",
  160. // path: "/decision4",
  161. // },
  162. ],
  163. },
  164. {
  165. id: "knowledge",
  166. text: "知识管理",
  167. data: [],
  168. },
  169. {
  170. id: "report",
  171. text: "智能报表",
  172. data: [],
  173. },
  174. ],
  175. activeIndex: 0,
  176. isShowSubMenu: false,
  177. parentIndex: null,
  178. subMenu: [],
  179. subIndex: null,
  180. };
  181. },
  182. methods: {
  183. click(index) {
  184. this.activeIndex = index;
  185. this.subIndex = null;
  186. },
  187. subMenuShow(children, index) {
  188. if (children) {
  189. this.isShowSubMenu = true;
  190. this.parentIndex = index;
  191. } else {
  192. this.isShowSubMenu = false;
  193. this.parentIndex = null;
  194. }
  195. this.subMenu = children;
  196. },
  197. subclick(index) {
  198. this.activeIndex = this.parentIndex;
  199. this.subIndex = index;
  200. },
  201. },
  202. computed: {
  203. currentMenu() {
  204. let data = this.menuData.filter((t) => {
  205. return t.id == this.currRoot;
  206. })[0].data;
  207. return data;
  208. },
  209. },
  210. watch: {
  211. // 监听路由
  212. $route: {
  213. handler: function(val, oldVal) {
  214. if (val.query.root) this.currRoot = val.query.root;
  215. this.currentMenu.some((element, index) => {
  216. if (element.path == val.path) {
  217. this.activeIndex = index;
  218. return true;
  219. }
  220. });
  221. },
  222. //深度观察监听
  223. deep: true,
  224. },
  225. root: {
  226. handler: function(val, oldVal) {
  227. this.currRoot = val;
  228. },
  229. },
  230. currentMenu: {
  231. handler: function(val, oldVal) {
  232. if (val && val.length > 0) {
  233. // 基于 root 和 currRoot 为一致
  234. // 进行页面刷新
  235. // 防止 刷新页面也同步执行切换页面逻辑
  236. if (this.root == this.currRoot) {
  237. this.activeIndex = 0;
  238. this.$router.push({
  239. path: val[0].path,
  240. query: { root: this.currRoot },
  241. });
  242. }
  243. }
  244. },
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="less">
  250. .menu {
  251. padding-top: 1.481vh;
  252. .menu-list {
  253. margin: 0;
  254. padding: 0;
  255. list-style: none;
  256. .menu-item {
  257. padding: 1.481vh 0;
  258. text-align: center;
  259. .menu-icon {
  260. display: flex;
  261. justify-content: center;
  262. }
  263. &.active i {
  264. color: #05bb4c;
  265. transition: color 1s;
  266. }
  267. }
  268. }
  269. i {
  270. font-size: 2.222vh;
  271. color: rgba(255, 255, 255, 50%);
  272. }
  273. }
  274. .sub-menu {
  275. position: absolute;
  276. top: 0;
  277. left: 5.3704vh;
  278. width: 138px;
  279. height: 100%;
  280. padding-top: 1.481vh;
  281. background: fade(#192a26, 75);
  282. border-right: 1px solid fade(@green, 50);
  283. box-shadow: inset 11px 0px 20px 0px fade(#021412, 60);
  284. .menu-list {
  285. margin: 0;
  286. padding: 0;
  287. list-style: none;
  288. .menu-item {
  289. display: flex;
  290. text-align: center;
  291. line-height: 1.5;
  292. padding: 8px 0;
  293. background: #121d1c;
  294. a {
  295. display: flex;
  296. width: 100%;
  297. height: 100%;
  298. padding: 0 1.4815vh;
  299. font-size: @fontsize-s;
  300. text-decoration: unset;
  301. .menu-icon {
  302. display: flex;
  303. align-items: center;
  304. svg {
  305. width: 14px;
  306. height: 14px;
  307. use {
  308. fill: fade(@green, 75);
  309. }
  310. }
  311. }
  312. }
  313. &.active {
  314. background: #323e70;
  315. .menu-icon {
  316. display: flex;
  317. svg use {
  318. fill: fade(@white, 75);
  319. }
  320. }
  321. }
  322. .sub-menu-text {
  323. margin-left: 1.1111vh;
  324. color: @gray-l;
  325. }
  326. & + .menu-item {
  327. border-top: 1px solid fade(@darkgray, 40);
  328. }
  329. }
  330. }
  331. i {
  332. font-size: 2.222vh;
  333. color: rgba(255, 255, 255, 50%);
  334. }
  335. }
  336. </style>