| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 | <!-- eslint-disable vue/multi-word-component-names --><template>  <div class="New-nav">    <div class="main-title">{{ Title }}</div>    <!-- menu区域 -->    <div class="nav-menu">      <div v-if="!disabled" class="nav-menu-left">        <div v-for="(item, index) in leftMenus" :key="index">          <div :class="activeIndex == index ? 'nav-menu-active' : 'nav-menu-unactive'" :key="index" @click="menuClick({ item, index })">            <div style="color: #ddd">{{ item.name }}</div>            <div v-if="activeIndex == index && isShowMenuItem" class="nav-menu-item">              <div class="nav-menu-content">                <div class="nav-menu-List">                  <div                    :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"                    v-for="(ite, ind) in item.MenuItemList"                    :key="ind"                    @click.stop="menuItemClick(ind)"                    >{{ ite.name }}</div                  >                </div>              </div>            </div>          </div>        </div>      </div>      <div v-if="!disabled" class="nav-menu-right">        <div v-for="(item, index) in rightMenus" :key="index + 4">          <div            :class="activeIndex == index + 4 ? 'nav-menu-active' : 'nav-menu-unactive'"            :key="index + 4"            @click="menuClick({ item, index: index + 4 })"          >            <div style="color: #ddd">{{ item.name }}</div>            <div v-if="activeIndex == index + 4 && isShowMenuItem && !disabled" class="nav-menu-item">              <div class="nav-menu-content">                <div class="nav-menu-List">                  <div                    :class="menuItemActive == ind ? 'menu-item-active' : 'menu-item-unactive'"                    v-for="(ite, ind) in item.MenuItemList"                    :key="ind"                    @click.stop="menuItemClick(ind)"                    >{{ ite.name }}</div                  >                </div>              </div>            </div>          </div>        </div>      </div>    </div>  </div></template><script lang="ts" setup>import { onMounted, onUnmounted, ref, watch, computed } from 'vue';import { useRouter, useRoute } from 'vue-router';let props = defineProps({  Title: {    type: String,    default: '',  },  disabled: {    type: Boolean,    default: false,  },});let menuList = ref<any[]>([  {    name: '智能通风',    targatUrl: '/micro-vent-3dModal/configurable/ventNew/home',  },  {    name: '火灾监控',    targatUrl: '/micro-vent-3dModal/configurable/fireNew/home',  },  {    name: '粉尘监控',    targatUrl: '/micro-vent-3dModal/configurable/dustNew/home',  },  {    name: '瓦斯监控',    MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],  },  {    name: '灾害预警',    MenuItemList: [{ name: '多灾融合预警' }, { name: '通风监测预警' }, { name: '火灾监测预警' }, { name: '粉尘监测预警' }, { name: '瓦斯监测预警' }],  },]); //一级菜单列表let activeIndex = ref(0); //当前激活menu索引const router = useRouter();const route = useRoute();let isShowMenuItem = ref(false); //是否显示menuItem下拉选项菜单let menuItemActive = ref(0); //menuItem当前激活选项const leftMenus = computed(() => menuList.value.slice(0, 4));const rightMenus = computed(() => menuList.value.slice(4));function menuClick(data) {  activeIndex.value = data.index;  isShowMenuItem.value = !isShowMenuItem.value;  router.push({ path: data.item.targatUrl });}function menuItemClick(index) {  menuItemActive.value = index;  isShowMenuItem.value = false;}function updateActiveState(path: string) {  menuList.value.forEach((menu, index) => {    // 处理有直接链接的菜单项    if (menu.targatUrl === path) {      activeIndex.value = index;      isShowMenuItem.value = false;      return;    }    // 处理有子菜单的菜单项    if (menu.MenuItemList) {      const itemIndex = menu.MenuItemList.findIndex((item) => item.targatUrl === path);      if (itemIndex !== -1) {        activeIndex.value = index;        menuItemActive.value = itemIndex;        isShowMenuItem.value = true;      }    }  });}watch(  () => route.path,  (newPath) => {    updateActiveState(newPath);  },  {    immediate: true,  });onMounted(() => {  updateActiveState(route.path);});</script><style lang="less" scoped>@import '/@/design/theme.less';@font-face {  font-family: 'douyuFont';  src: url('/@/assets/font/douyuFont.otf');}.New-nav {  position: relative;  width: 100%;  height: 100%;  .main-title {    width: 518px;    height: 100%;    display: flex;    align-items: center;    font-family: 'douyuFont';    font-size: 25px;    position: absolute;    left: 50%;    transform: translateX(-50%);    width: auto;    padding: 0;    color: #fff;  }  .nav-menu {    position: absolute;    top: 0;    left: 675px;    height: 100%;    display: flex;    position: static; // 移除绝对定位    display: flex;    width: auto;    .nav-menu-left {      display: flex;      flex-direction: row;      align-items: center;      float: left;      .nav-menu-active {        position: relative;        cursor: pointer;        width: 100px;        height: 40px;        margin-top: 10px;        margin-right: 40px;        line-height: 35px;        text-align: center;        font-size: 16px;        background: url(/src/assets/images/fireNew/2-1.png) no-repeat;        background-size: 100% 100%;      }      .nav-menu-unactive {        position: relative;        cursor: pointer;        width: 100px;        height: 40px;        margin-top: 10px;        margin-right: 40px;        line-height: 35px;        text-align: center;        font-size: 16px;        background: url(/src/assets/images/fireNew/2-2.png) no-repeat;        background-size: 100% 100%;      }    }    .nav-menu-right {      display: flex;      flex-direction: row;      align-items: center;      float: left;      margin-left: 42%;      .nav-menu-active {        position: relative;        cursor: pointer;        width: 100px;        height: 40px;        margin-top: 10px;        margin-right: 40px;        line-height: 35px;        text-align: center;        font-size: 16px;        background: url(/src/assets/images/fireNew/2-3.png) no-repeat;        background-size: 100% 100%;      }      .nav-menu-unactive {        position: relative;        cursor: pointer;        width: 100px;        height: 40px;        margin-top: 10px;        margin-right: 40px;        line-height: 35px;        text-align: center;        font-size: 16px;        background: url(/src/assets/images/fireNew/2-4.png) no-repeat;        background-size: 100% 100%;      }    }    .nav-menu-item {      position: absolute;      top: 23px;      width: 130px;      display: flex;      flex-direction: column;      align-items: center;      box-sizing: border-box;      .nav-menu-content {        width: 100%;        height: 100%;        overflow-y: auto;        margin-top: 25%;        .nav-menu-List {          background: url('@/assets/images/vent/homeNew/menuList.png') no-repeat;          background-size: 100% 100%;        }        .menu-item-active {          color: #ddd;          z-index: 999;          width: 100%;          height: 36px;          line-height: 36px;          font-size: 14px;          background: url('@/assets/images/fireNew/2-2.png') no-repeat;          background-size: 100% 100%;        }        .menu-item-unactive {          color: #ddd;          width: 100%;          height: 40px;          line-height: 40px;          font-size: 14px;        }      }    }    @keyframes fadeIn {      from {        opacity: 0;      }      to {        opacity: 1;      }    }    /* 定义淡出动画 */    @keyframes fadeOut {      from {        opacity: 1;      }      to {        opacity: 0;      }    }  }  .userInfo {    width: 120px;    float: right;    background: url(/src/assets/images/vent/homeNew/user.png) no-repeat;    background-size: 100% 100%;    position: absolute;    top: 14px;    right: 0;    .userName {      margin-left: 40px;      font-size: 20px;    }  }}</style>
 |