Menu.vue 8.3 KB

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