123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <template>
- <el-aside :width="!isCollapse ? '250px' : '100px'" class="asideBox">
- <div class="homeBox">
- <div class="logoItem" :class="{ 'flexCenter ': isCollapse }">
- <div
- class="logoImg"
- v-show="isCollapse"
- @click="
- handleChangeMenuUrl(
- { name: '驾驶舱', id: 1, path: 'cockpitManage', iconName: 'gps' },
- `/home/cockpitManage?name=驾驶舱`
- )
- "
- >
- <SvgIcons
- name="dnao"
- class="dnao"
- width="40px"
- height="40px"
- color="#222"
- ></SvgIcons>
- </div>
- <span v-if="!isCollapse" @click="
- handleChangeMenuUrl(
- { name: '驾驶舱', id: 1, path: 'cockpitManage', iconName: 'gps' },
- `/home/cockpitManage?name=驾驶舱`
- )
- " :class="isCollapse ? 'stop-animation' : 'active-animation'">
- 风机运行管理平台
- </span>
- </div>
- </div>
- <el-menu
- collapse-transition
- ref="menu"
- class="mt-3 el-menu-vertical-demo"
- @open="handleOpen"
- @close="handleClose"
- background-color="#eff1f3"
- text-color="#000"
- active-text-color="#0754a1"
- :router="true"
- :default-active="defaultActive"
- :unique-opened="true"
- :collapse="isCollapse"
- >
- <div v-for="item in routerList" :key="item.id">
- <el-submenu
- :index="item.path"
- v-if="item.children && item.children.length > 0"
- >
- <template slot="title">
- <i class="el-icon-menu" v-if="isElPrefix(item.iconName)"></i>
- <i v-else class="svnIcon"
- ><svg-icon :icon-class="item.iconName"
- /></i>
- <span>{{ item.name }}</span>
- </template>
- <el-menu-item
- v-for="child in item.children"
- :key="child.id"
- :index="`/home/${item.path}/${child.path}?id=${child.id}&name=${child.name}`"
- >
- <i class="el-icon-menu" v-if="isElPrefix(child.iconName)"></i>
- <i v-else class="svnIcon"
- ><svg-icon :icon-class="child.iconName"
- /></i>
- <span>{{ child.name }}</span>
- </el-menu-item>
- </el-submenu>
- <el-menu-item
- :key="item.id"
- :index="`/home/${item.path}?id=${item.id}&name=${item.name}`"
- v-else
- >
- <i class="el-icon-menu" v-if="isElPrefix(item.iconName)"></i>
- <i v-else class="svnIcon"><svg-icon :icon-class="item.iconName" /></i>
- <span>{{ item.name }}</span>
- </el-menu-item>
- </div>
- </el-menu>
- <div class="foldBox flexCenter">
- <span v-show="isCollapse" class="el-icon-s-unfold icon" @click="debouncedToggleCollapse(false)">
- 展开
- </span>
- <span v-show="!isCollapse" class="el-icon-s-fold icon" @click="debouncedToggleCollapse(true)">
- 收起
- </span>
- </div>
- </el-aside>
- </template>
- <script>
- import debounce from "lodash/debounce";
- import { orgList } from "./mockData";
- export default {
- data() {
- return {
- isCollapse: false,
- orgList: orgList,
- searchInputValue: "",
- defaultActive: "",
- activeIndex: false,
- keyObject: {},
- routerList: [
- {
- id: 1,
- path: "cockpitManage",
- name: "驾驶舱",
- iconName: "gps",
- meta: {
- hidden: false,
- },
- children: [
- {
- id: 11,
- iconName: "gps",
- path: "electronic-map",
- name: "电子地图",
- meta: {
- hidden: false,
- },
- },
- ],
- },
- ],
- };
- },
- created() {
- this.routerList = [
- ...this.routerList,
- ...this.$store.state.auth.dynamicRouter,
- ];
- console.log(this.routerList, "组件内dynamicRouter");
- // Debounce the toggle collapse function to prevent rapid toggling
- this.debouncedToggleCollapse = debounce(this.toggleCollapse, 300);
- },
- computed: {
- // currentMenuIndex() {
- // return this.$store.state.breadStore?.currentUrl?.routeUrl;
- // },
- },
- watch: {
- // currentMenuIndex: {
- // deep: true,
- // handler(newVale, oldVal) {
- // if (newVale) {
- // this.$refs.menu.close(newVale);
- // }
- // },
- // },
- keyObject: {
- deep: true,
- handler(newVale) {
- if (newVale && newVale.key === this.defaultActive) {
- this.getBreadcrumbList(newVale.keyPath);
- }
- },
- },
- },
- methods: {
- isElPrefix(str) {
- const regex = /^el-/;
- return regex.test(str);
- },
- getBreadcrumbList(keyPath) {
- const urls = keyPath;
- const result = urls.map((url, index) => {
- const params = new URLSearchParams(url.split("?")[1]);
- const id = params.get("id");
- const name = params.get("name");
- const routeUrl = url;
- if (index === urls.length - 1) {
- return { id, name, routeUrl, currentPage: true };
- }
- return { id, name, routeUrl };
- });
- this.$store.commit("breadStore/ADD_BREAD", result);
- return result;
- },
- handleOpen(key, keyPath) {
- this.activeIndex = false;
- this.keyObject = {
- key,
- keyPath,
- };
- },
- handleClose(key, keyPath) {
- this.activeIndex = false;
- this.keyObject = {
- key,
- keyPath,
- };
- },
- // shrinkTree() {
- // this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
- // },
- // handleChangeRouter() {
- // this.activeIndex = true;
- // this.defaultActive = "";
- // this.$store.commit("breadStore/ADD_BREAD", []);
- // this.$refs.menu.close(`/orgsPage?id=${orgList.id}&name=${orgList.name}`);
- // this.$router.push("/");
- // },
- handleChangeMenuUrl(item, key) {
- this.defaultActive = key;
- if (item) {
- item.activeIndex = true;
- }
- this.$router.push({
- path: key,
- });
- },
- toggleCollapse(value) {
- this.isCollapse = value;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .el-menu-vertical-demo:not(.el-menu--collapse) {
- width: 200px;
- min-height: 400px;
- }
- ::v-deep .el-submenu__title {
- display: flex;
- align-items: center;
- }
- .asideBox {
- position: relative;
- padding-bottom: 40px;
- padding-top: 16px;
- box-sizing: border-box;
- display: flex;
- align-items: flex-start;
- justify-content: flex-start;
- flex-direction: column;
- border-right: 1px solid #d8d8d8;
- position: relative;
- .homeBox {
- width: 100%;
- padding: 0 20px;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: flex-start;
- box-sizing: border-box;
- .logoItem {
- display: flex;
- width: 100%;
- cursor: pointer;
- box-sizing: border-box;
- span {
- line-height: 50px;
- margin: 0 auto;
- }
- .logoImg {
- img {
- height: 100%;
- width: inherit;
- }
- width: 50px;
- height: 50px;
- }
- }
- .search {
- display: flex;
- width: 100%;
- align-items: center;
- justify-content: center;
- .el-icon-search {
- margin-top: 28px;
- }
- .el-input {
- width: inherit;
- }
- }
- .frame {
- display: flex;
- justify-content: space-between;
- align-items: center;
- color: #666;
- width: 100%;
- margin-top: 20px;
- margin-bottom: 10px;
- cursor: pointer;
- .homeIndex {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 18px;
- .home_active {
- margin-right: 2px;
- }
- p {
- color: #666;
- font-size: 18px;
- }
- }
- &:hover {
- p {
- color: #19436d;
- }
- transition: width 0.5s ease, transform 0.5s ease;
- transform-origin: left;
- }
- .left {
- left: 50%;
- transform: scaleX(0);
- }
- .right {
- left: 0;
- transform: scaleX(0);
- }
- }
- }
- .el-menu {
- margin-bottom: 10px;
- border: none;
- overflow-y: auto;
- width: 100% !important;
- height: 100%;
- }
- }
- .flexCenter {
- display: flex;
- align-items: center !important;
- justify-content: center !important;
- }
- // .foldBox {
- // position: fixed;
- // bottom: 10px;
- // left: 20px;
- // padding: 10px;
- // .icon {
- // cursor: pointer;
- // color: #666;
- // font-size: 14px;
- // }
- // }
- /* 添加过渡效果 */
- .foldBox .icon {
- transition: opacity 0.3s ease;
- }
- /* 菜单 icon 居中展示 */
- .foldBox {
- display: flex;
- align-items: center;
- }
- .foldBox .icon {
- cursor: pointer;
- color: #666;
- font-size: 14px;
- margin-right: 8px;
- /* 调整图标与文字之间的间距 */
- }
- .foldBox .icon:last-child {
- margin-right: 0;
- /* 最后一个图标不设置右边距 */
- }
- ::v-deep .el-submenu__title {
- display: flex;
- align-items: center;
- }
- ::v-deep .el-submenu__icon-arrow {
- right: 30px;
- }
- ::v-deep .svnIcon {
- vertical-align: middle;
- margin-right: 5px;
- width: 24px;
- text-align: center;
- font-size: 18px;
- }
- ::-webkit-scrollbar {
- width: 6px;
- display: none;
- }
- ::-webkit-scrollbar-thumb {
- border-radius: 10px;
- background-color: #aaabaa;
- cursor: pointer;
- }
- ::-webkit-scrollbar-thumb:hover {
- background-color: #efeff0;
- }
- ::-webkit-scrollbar-track-piece {
- background-color: #efeff0;
- border-radius: 10px;
- }
- .asideBox:hover ::-webkit-scrollbar {
- display: block !important;
- }
- </style>
|