NewNavFire.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <div class="New-nav">
  4. <div class="main-title">{{ Title }}</div>
  5. <!-- menu区域 -->
  6. <div class="nav-menu">
  7. <div class="nav-menu-left">
  8. <div v-for="(item, index) in leftMenus" :key="index">
  9. <div :class="activeIndex == index ? 'nav-menu-active' : 'nav-menu-unactive'" :key="index" @click="menuClick({ item, index })">
  10. <div style="color: #ddd">{{ item.name }}</div>
  11. <div v-if="activeIndex == index && isShowMenuItem" class="nav-menu-item">
  12. <div class="nav-menu-content">
  13. <div class="nav-menu-List">
  14. <div
  15. :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
  16. v-for="(ite, ind) in item.MenuItemList"
  17. :key="ind"
  18. @click.stop="menuItemClick(ind)"
  19. >{{ ite.name }}</div
  20. >
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="nav-menu-right">
  28. <div v-for="(item, index) in rightMenus" :key="index + 4">
  29. <div
  30. :class="activeIndex == index + 4 ? 'nav-menu-active' : 'nav-menu-unactive'"
  31. :key="index + 4"
  32. @click="menuClick({ item, index: index + 4 })"
  33. >
  34. <div style="color: #ddd">{{ item.name }}</div>
  35. <div v-if="activeIndex == index + 4 && isShowMenuItem" class="nav-menu-item">
  36. <div class="nav-menu-content">
  37. <div class="nav-menu-List">
  38. <div
  39. :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"
  40. v-for="(ite, ind) in item.MenuItemList"
  41. :key="ind"
  42. @click.stop="menuItemClick(ind)"
  43. >{{ ite.name }}</div
  44. >
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script lang="ts" setup>
  55. import { onMounted, onUnmounted, ref, watch, computed } from 'vue';
  56. import { useRouter, useRoute } from 'vue-router';
  57. let props = defineProps({
  58. Title: {
  59. type: String,
  60. default: '',
  61. },
  62. });
  63. let menuList = ref<any[]>([
  64. {
  65. name: '智能通风',
  66. targatUrl: '/configurable/ventNew/home',
  67. },
  68. {
  69. name: '火灾监控',
  70. targatUrl: '/configurable/fireNew/home',
  71. },
  72. {
  73. name: '粉尘监控',
  74. targatUrl: '/configurable/dustNew/home',
  75. },
  76. {
  77. name: '瓦斯监控',
  78. MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
  79. },
  80. {
  81. name: '灾害预警',
  82. MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],
  83. },
  84. ]); //一级菜单列表
  85. let activeIndex = ref(0); //当前激活menu索引
  86. const router = useRouter();
  87. const route = useRoute();
  88. let isShowMenuItem = ref(false); //是否显示menuItem下拉选项菜单
  89. let menuItemActive = ref(0); //menuItem当前激活选项
  90. const leftMenus = computed(() => menuList.value.slice(0, 4));
  91. const rightMenus = computed(() => menuList.value.slice(4));
  92. function menuClick(data) {
  93. activeIndex.value = data.index;
  94. isShowMenuItem.value = !isShowMenuItem.value;
  95. router.push({ path: data.item.targatUrl });
  96. }
  97. function menuItemClick(index) {
  98. menuItemActive.value = index;
  99. isShowMenuItem.value = false;
  100. }
  101. function updateActiveState(path: string) {
  102. menuList.value.forEach((menu, index) => {
  103. // 处理有直接链接的菜单项
  104. if (menu.targatUrl === path) {
  105. activeIndex.value = index;
  106. isShowMenuItem.value = false;
  107. return;
  108. }
  109. // 处理有子菜单的菜单项
  110. if (menu.MenuItemList) {
  111. const itemIndex = menu.MenuItemList.findIndex((item) => item.targatUrl === path);
  112. if (itemIndex !== -1) {
  113. activeIndex.value = index;
  114. menuItemActive.value = itemIndex;
  115. isShowMenuItem.value = true;
  116. }
  117. }
  118. });
  119. }
  120. watch(
  121. () => route.path,
  122. (newPath) => {
  123. updateActiveState(newPath);
  124. }
  125. );
  126. onMounted(() => {
  127. updateActiveState(route.path);
  128. });
  129. </script>
  130. <style lang="less" scoped>
  131. @import '/@/design/theme.less';
  132. @font-face {
  133. font-family: 'douyuFont';
  134. src: url('/@/assets/font/douyuFont.otf');
  135. }
  136. .New-nav {
  137. position: relative;
  138. width: 100%;
  139. height: 100%;
  140. .main-title {
  141. width: 518px;
  142. height: 100%;
  143. display: flex;
  144. align-items: center;
  145. font-family: 'douyuFont';
  146. font-size: 25px;
  147. position: absolute;
  148. left: 50%;
  149. transform: translateX(-50%);
  150. width: auto;
  151. padding: 0;
  152. }
  153. .nav-menu {
  154. position: absolute;
  155. top: 0;
  156. left: 675px;
  157. height: 100%;
  158. display: flex;
  159. position: static; // 移除绝对定位
  160. display: flex;
  161. width: auto;
  162. .nav-menu-left {
  163. display: flex;
  164. flex-direction: row;
  165. align-items: center;
  166. float: left;
  167. .nav-menu-active {
  168. position: relative;
  169. cursor: pointer;
  170. width: 100px;
  171. height: 40px;
  172. margin-top: 10px;
  173. margin-right: 40px;
  174. line-height: 35px;
  175. text-align: center;
  176. font-size: 16px;
  177. background: url(/src/assets/images/fireNew/2-1.png) no-repeat;
  178. background-size: 100% 100%;
  179. }
  180. .nav-menu-unactive {
  181. position: relative;
  182. cursor: pointer;
  183. width: 100px;
  184. height: 40px;
  185. margin-top: 10px;
  186. margin-right: 40px;
  187. line-height: 35px;
  188. text-align: center;
  189. font-size: 16px;
  190. background: url(/src/assets/images/fireNew/2-2.png) no-repeat;
  191. background-size: 100% 100%;
  192. }
  193. }
  194. .nav-menu-right {
  195. display: flex;
  196. flex-direction: row;
  197. align-items: center;
  198. float: left;
  199. margin-left: 42%;
  200. .nav-menu-active {
  201. position: relative;
  202. cursor: pointer;
  203. width: 100px;
  204. height: 40px;
  205. margin-top: 10px;
  206. margin-right: 40px;
  207. line-height: 35px;
  208. text-align: center;
  209. font-size: 16px;
  210. background: url(/src/assets/images/fireNew/2-3.png) no-repeat;
  211. background-size: 100% 100%;
  212. }
  213. .nav-menu-unactive {
  214. position: relative;
  215. cursor: pointer;
  216. width: 100px;
  217. height: 40px;
  218. margin-top: 10px;
  219. margin-right: 40px;
  220. line-height: 35px;
  221. text-align: center;
  222. font-size: 16px;
  223. background: url(/src/assets/images/fireNew/2-4.png) no-repeat;
  224. background-size: 100% 100%;
  225. }
  226. }
  227. .nav-menu-item {
  228. position: absolute;
  229. top: 23px;
  230. width: 130px;
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. box-sizing: border-box;
  235. .nav-menu-content {
  236. width: 100%;
  237. height: 100%;
  238. overflow-y: auto;
  239. margin-top: 25%;
  240. .nav-menu-List {
  241. background: url('@/assets/images/vent/homeNew/menuList.png') no-repeat;
  242. background-size: 100% 100%;
  243. }
  244. .menu-item-active {
  245. color: #ddd;
  246. z-index: 999;
  247. width: 100%;
  248. height: 36px;
  249. line-height: 36px;
  250. font-size: 14px;
  251. background: url('@/assets/images/fireNew/2-2.png') no-repeat;
  252. background-size: 100% 100%;
  253. }
  254. .menu-item-unactive {
  255. color: #ddd;
  256. width: 100%;
  257. height: 40px;
  258. line-height: 40px;
  259. font-size: 14px;
  260. }
  261. }
  262. }
  263. @keyframes fadeIn {
  264. from {
  265. opacity: 0;
  266. }
  267. to {
  268. opacity: 1;
  269. }
  270. }
  271. /* 定义淡出动画 */
  272. @keyframes fadeOut {
  273. from {
  274. opacity: 1;
  275. }
  276. to {
  277. opacity: 0;
  278. }
  279. }
  280. }
  281. .userInfo {
  282. width: 120px;
  283. float: right;
  284. background: url(/src/assets/images/vent/homeNew/user.png) no-repeat;
  285. background-size: 100% 100%;
  286. position: absolute;
  287. top: 14px;
  288. right: 0;
  289. .userName {
  290. margin-left: 40px;
  291. font-size: 20px;
  292. }
  293. }
  294. }
  295. </style>