NewNavFire.vue 8.3 KB

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