zhanghua
2025-08-04 b4668a820cb11703613c59d6529898e230be0b28
src/layout/components/Navbar.vue
@@ -1,10 +1,6 @@
<template>
  <div class="navbar">
    <hamburger
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    />
    <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
    <breadcrumb class="breadcrumb-container" />
    <!-- 固定右上角 -->
@@ -14,17 +10,13 @@
      <el-dropdown trigger="click" ref="eldrop" style="margin-right: 20px">
        <div class="avatar-wrapper" style="font-size: 20px">
          {{ selectStaff ? selectStaff.org.name : "" }}-{{
            selectStaff ? selectStaff.sysRole.name : ""
            selectStaff && selectStaff.sysRole ? selectStaff.sysRole.name : ""
          }}
          <i class="el-icon-caret-bottom"></i>
        </div>
        <el-dropdown-menu slot="dropdown" align="center">
          <el-dropdown-item
            v-for="item in staffs"
            @click.native="changeStaff(item)"
            :key="item.id"
          >
            {{ item ? item.org.name : "" }}-{{ item ? item.sysRole.name : "" }}
          <el-dropdown-item v-for="item in staffs" @click.native="changeStaff(item)" :key="item.id">
            {{ item ? item.org.name : "" }}-{{ item && item.sysRole ? item.sysRole.name : "" }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
@@ -88,6 +80,17 @@
      // await this.$store.dispatch('user/logout')
      this.$router.push(`/login`);
    },
    loadStaffs() {
      const selectStaff = JSON.parse(localStorage.getItem("selectStaff"));
      if (selectStaff) {
        this.selectStaff = selectStaff;
      }
      const staffs = JSON.parse(localStorage.getItem("staffs"));
      console.log('Navbar-created');
      if (staffs) {
        this.staffs = staffs;
      }
  },
  beforeCreate() {
    const user = JSON.parse(localStorage.getItem("user"));
@@ -95,15 +98,15 @@
      this.$router.push(`/login`);
    }
  },
  },
  created() {
    const selectStaff = JSON.parse(localStorage.getItem("selectStaff"));
    if (selectStaff) {
      this.selectStaff = selectStaff;
    }
    const staffs = JSON.parse(localStorage.getItem("staffs"));
    if (staffs) {
      this.staffs = staffs;
    }
    this.loadStaffs();
  },
  mounted() {
    this.$EventBus.$on("updateStaffs", (data) => {
      this.loadStaffs();
    });
  },
};
</script>
@@ -188,7 +191,9 @@
}
.el-dropdown-menu {
  max-height: 400px; /*设置菜单高度为200px*/
  overflow-y: auto; /*设置滚动条*/
  max-height: 400px;
  /*设置菜单高度为200px*/
  overflow-y: auto;
  /*设置滚动条*/
}
</style>