123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <template>
- <div class="header-menu">
- <ul class="header-menu-list">
- <li
- class="header-menu-item"
- v-for="(menu, index) of menus"
- :key="menu"
- @click="click(index, menu)"
- :class="{ active: activeIndex == index }"
- >
- {{ menu.text }}
- </li>
- </ul>
- <!-- <ul class="header-menu-dropdown" :class="{ dropdown: dropdown }">
- <li class="header-menu-dropdown-title" @click="clickMenu()"><i class="fa fa-gear"></i>菜单<i class="fa fa-sort-down down"></i></li>
- <ul class="header-menu-dropdown-list">
- <li class="header-menu-dropdown-item" v-for="(menu, index) of menusDropdown" :key="menu" @click="clickSubMenu(index, menu.code)">
- {{ menu.text }}
- </li>
- </ul>
- </ul> -->
- <ul class="header-menu-user">
- <li class="header-menu-user-title">
- <span class="el-dropdown-link"> <i class="fa fa-user"></i>白玉杰 </span>
- <el-dropdown
- size="small"
- trigger="hover"
- :hide-on-click="true"
- v-if="false"
- >
- <span class="el-dropdown-link">
- <i class="fa fa-user"></i>白玉杰
- </span>
- <template #dropdown>
- <el-dropdown-menu :class="$store.state.themeName + ' curDropdown'">
- <el-dropdown-item>
- <el-switch
- size="small"
- active-color="rgb(57, 54, 143)"
- inactive-color="#05bb4c"
- active-text="亮色主题"
- inactive-text="暗色主题"
- v-model="themeName"
- @change="changeTheme()"
- />
- </el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </li>
- </ul>
- </div>
- </template>
- <script>
- import $ from "jquery";
- // import store from '@store/index';
- export default {
- data() {
- return {
- themeName: false,
- menus: [
- {
- id: "monitor",
- text: "驾驶舱",
- path: "/monitor/home",
- isActive: true,
- },
- {
- id: "decision",
- text: "经济运行",
- path: "/decision/pb",
- isActive: false,
- },
- {
- id: "health",
- text: "智慧检修",
- // path: '/sandtable',
- path: "/health/sandtable",
- isActive: false,
- },
- // {
- // id: "decision",
- // text: "决策支持",
- // path: "/decision/decision1",
- // isActive: false,
- // },
- {
- id: "save",
- text: "安全管控",
- path: "/save",
- isActive: false,
- },
- // {
- // id: "znbb",
- // text: "智能报表",
- // path: "/znbb/reportPandect",
- // isActive: false,
- // },
- {
- id: "others",
- text: "其他",
- path: "/others",
- isActive: false,
- },
- ],
- activeIndex: 0,
- // menusDropdown: [
- // {
- // text: "子菜单1",
- // code: "submenu1",
- // },
- // {
- // text: "子菜单2",
- // code: "submenu2",
- // },
- // {
- // text: "子菜单3",
- // code: "submenu3",
- // },
- // ],
- // dropdown: false,
- firsttime: 0,
- };
- },
- mounted() {
- let that = this;
- $(document).keydown((event) => {
- if (event.keyCode == 67) {
- // c
- let firstDate = new Date();
- if (that.firsttime == 0) {
- that.firsttime = firstDate.getTime();
- } else {
- var lastDate = new Date();
- var lastTime = lastDate.getTime();
- if (lastTime - that.firsttime < 1000) {
- that.changeTheme();
- that.firsttime = 0;
- }
- }
- }
- });
- },
- methods: {
- click(index, data) {
- this.activeIndex = index;
- this.$router.push(data.path);
- const ActiveModule = this.menus.find((ele) => {
- return ele.path === data.path;
- });
- if (ActiveModule) {
- this.$store.dispatch("changeModuleName", ActiveModule.text);
- }
- },
- clickSubMenu(index, code) {
- // console.log(index, code);
- },
- clickMenu() {
- this.dropdown = !this.dropdown;
- },
- changeTheme() {
- $("#appBody").toggleClass("dark light");
- this.$store.dispatch("changeTheme", $("#appBody").attr("class"));
- this.$store.state.themeName === "dark"
- ? (this.themeName = false)
- : (this.themeName = true);
- localStorage.setItem("themeName", this.$store.state.themeName);
- },
- },
- computed: {
- activeClass(data) {
- return data.isActive ? "active" : "";
- },
- },
- watch: {
- $route: {
- handler: function (val, oldVal) {
- this.menus.some((t, index) => {
- if (val.path.includes(t.id)) {
- this.activeIndex = index;
- const ActiveModule = this.menus.find((ele) => {
- return ele.path === val.path;
- });
- if (ActiveModule) {
- this.$store.dispatch("changeModuleName", ActiveModule.text);
- }
- }
- });
- },
- //深度观察监听
- deep: true,
- },
- },
- };
- </script>
- <style lang="less">
- .header-menu {
- display: flex;
- flex-direction: row;
- width: 100%;
- height: 100%;
- font-size: @fontsize;
- .header-menu-list {
- margin: 0;
- padding: 0;
- list-style: none;
- margin-left: auto;
- display: flex;
- flex-direction: row;
- height: 100%;
- .header-menu-item {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 9.259vh;
- height: 100%;
- color: @font-color;
- cursor: pointer;
- transition: color 0.2s ease-in-out;
- &.active {
- color: @green;
- position: relative;
- background: @greenLinearTop;
- transition: color 0.2s ease-in-out;
- &::after {
- content: "";
- position: absolute;
- width: 100%;
- height: 0.463vh;
- border: 0.093vh solid @green;
- border-top: 0;
- left: 0;
- bottom: 0;
- box-sizing: border-box;
- }
- }
- }
- }
- .header-menu-dropdown {
- width: 11.111vh;
- height: 100%;
- margin: 0;
- padding: 0;
- list-style: none;
- .header-menu-dropdown-title {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
- color: @gray;
- cursor: pointer;
- i {
- margin: 0 0.741vh;
- transition: all 0.3s;
- }
- }
- .header-menu-dropdown-list {
- display: none;
- margin: 0;
- padding: 0;
- list-style: none;
- margin-left: auto;
- position: absolute;
- .header-menu-dropdown-item {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 11.111vh;
- height: 3.704vh;
- color: @gray;
- cursor: pointer;
- position: relative;
- z-index: 1;
- background-color: fade(@write, 5%);
- &::after {
- content: "";
- position: absolute;
- width: 100%;
- height: 0.463vh;
- border: 0.093vh solid @green;
- border-top: 0;
- left: 0;
- bottom: 0;
- box-sizing: border-box;
- }
- &:hover {
- color: @write;
- background-color: fade(@write, 10%);
- }
- }
- }
- &.dropdown {
- .header-menu-dropdown-title {
- .down {
- transform: rotate(180deg);
- }
- }
- .header-menu-dropdown-list {
- display: flex;
- flex-direction: column;
- }
- }
- }
- .header-menu-user {
- width: 16.667vh;
- height: 100%;
- margin: 0;
- padding: 0;
- list-style: none;
- .header-menu-user-title {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
- color: @gray;
- cursor: pointer;
- i {
- margin: 0 0.741vh;
- }
- }
- }
- }
- </style>
|