123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <script>
- import menuList from '@/data/json/menuList.json'
- import {requireImg} from "@/utils/requireImg";
- export default {
- props: {
- collapse: Boolean,
- },
- data() {
- return {
- selectedKey: [],
- iconVerticalAlign: '',
- asideStyle: {},
- menuList,
- }
- },
- watch: {
- collapse(val) {
- this.suitHeight(val)
- },
- $route() {
- this.getCurrRoute()
- this.$forceUpdate();
- }
- },
- mounted() {
- this.suitHeight(this.collapse)
- },
- emits: ['update:collapse'],
- setup(props, context) {
- const methods = {
- toggleCollapse() {
- const val = !props.collapse
- context.emit('update:collapse', val)
- },
- }
- return methods
- },
- methods: {
- requireImg,
- suitHeight(val) {
- this.getCurrRoute()
- this.$nextTick(() => {
- // let height = document.getElementsByClassName('home')[0].clientHeight
- this.asideStyle = { height: `100%` }
- if (val)
- this.asideStyle.width = '60px'
- if (this.collapse) {
- document.getElementsByClassName("aside-collapse")[0].style.textAlign = 'center'
- document.getElementsByClassName("aside-collapse")[0].style.marginLeft = '0'
- this.iconVerticalAlign = '';
- } else {
- document.getElementsByClassName("aside-collapse")[0].style.textAlign = ''
- document.getElementsByClassName("aside-collapse")[0].style.marginLeft = '5%'
- this.iconVerticalAlign = 'text-top';
- }
- })
- },
- getCurrRoute() {
- this.$nextTick(()=>{
- if (this.$route.matched.length>1) {
- this.selectedKey = [this.$route.matched[1].path+'']
- }
- let index = this.menuList.findIndex(i=>i.router==this.selectedKey)
- this.handleClickMenuItem(this.menuList[index])
- this.$forceUpdate()
- })
- },
- handleClickMenuItem(item) {
- this.$store.menuStore().currMenu = item;
- },
- handleSelected(item) {
- this.$router.push({path: item.key})
- },
- },
- }
- </script>
- <template>
- <div class="aside">
- <a-menu
- class="menu"
- theme="dark"
- :style="asideStyle"
- v-model:selectedKeys="selectedKey"
- mode="inline"
- @select="handleSelected"
- >
- <a-menu-item-group key="g1">
- <template slot="title">
- <div style="height: 12px"></div>
- <div class="aside-collapse" style="color: white; cursor: pointer;margin-left: 5%" @click="toggleCollapse">
- <a-icon style="font-size: 18px;vertical-align: text-top" type="menu-fold" v-if="!collapse" />
- <a-icon style="font-size: 18px;vertical-align: text-top;" type="menu-unfold" v-if="collapse" />
- <span style="margin-left: 15px;vertical-align: top" v-if="!collapse">展开/收起</span>
- </div>
- </template>
- </a-menu-item-group>
- <a-menu-item v-for="item in menuList" :key="item.router" @click="handleClickMenuItem(item)" >
- <span class="anticon" :style="{verticalAlign: iconVerticalAlign}">
- <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
- </span>
- <span >
- {{ item.name }}
- </span>
- </a-menu-item>
- </a-menu>
- </div>
- </template>
- <style lang="less" scoped>
- @menu-dark-bg: #266a99;
- @menu-dark-submenu-bg: #266a99;
- @menu-dark-color: #fff;
- @menu-dark-arrow-color: #fff;
- @menu-dark-highlight-color: #fff;
- .aside-collapse {
- width: 100%;
- }
- .aside-collapse:hover {
- span {
- color: #2ba8e4;
- }
- i {
- color: #2ba8e4;
- }
- }
- .aside {
- //width: 100%;
- height: 100%;
- /*菜单样式*/
- /deep/ .ant-menu-sub {
- box-shadow: none !important;
- }
- /deep/ .ant-menu-item-selected {
- color: @menu-dark-selected-item-text-color !important;
- }
- .ant-menu-inline-collapsed > .ant-menu-item {
- padding: 0 !important;
- margin-left: 0 !important;
- padding-left: 33% !important;
- }
- /deep/ .ant-menu-inline-collapsed > .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item {
- padding: 0 !important;
- margin-left: 0 !important;
- padding-left: 33% !important;
- }
- }
- </style>
|