审查视图

src/components/NavMenu/index.vue 6.7 KB
朱兆平 authored
1 2
<template>
        <el-menu default-active="$route.path"
小范 authored
3
                 :class="collapsed?'logo-collapse-width':'logo-width'"
朱兆平 authored
4 5 6
                 background-color="#26384c"
                 text-color="#fff"
                 active-text-color="#ffd04b"
7
                 style="overflow-y:scroll;border-right:none;"
朱兆平 authored
8 9 10 11 12 13
                 @open="handleopen"
                 @close="handleclose"
                 @select="handleselect"
                 unique-opened
                 router
                 :collapse="collapsed">
小范 authored
14 15 16 17 18 19 20
            <!--                 class="el-menu-vertical-demo"-->

            <!--            <el-radio-group v-model="collapsed" style="margin-left: 200px;">-->
<!--                <el-radio-button :label="false">展开</el-radio-button>-->
<!--                <el-radio-button :label="true">收起</el-radio-button>-->
<!--            </el-radio-group>-->
朱兆平 authored
21
            <div align="center" style="height: 66px;line-height: 66px;">
22
<!--                <img id="logo" src="~@/assets/logo1.png">-->
朱兆平 authored
23
                <h1 id="logo-text" style="color:white;display: inline-block;font-weight: 600;font-size: 15px;line-height: 50px"> &nbsp; &nbsp;物流公共信息服务平台</h1>
朱兆平 authored
24 25 26 27 28
            </div>
            <template v-for="(item,index) in menu">
                <el-submenu :index="index+''" v-if="item.hasChild">
                    <template slot="title">
                        <i :class="item.iconCls"></i>
朱兆平 authored
29
                        <span slot="title" class="my-el-menu-item">{{item.name}}</span>
朱兆平 authored
30 31 32 33
                    </template>
                    <el-menu-item v-for="child in item.children"
                                  :index="child.path"
                                  :key="child.permissionId"
小范 authored
34 35
                                  v-if="!child.hidden"
                                  class="el-submenu__title">
朱兆平 authored
36 37 38 39 40
                        {{child.name}}
                    </el-menu-item>
                </el-submenu>
                <el-menu-item v-if="!item.hasChild" :index="item.path">
                    <i :class="item.iconCls"></i>
朱兆平 authored
41
                    <span slot="title" class="my-el-menu-item">{{item.name}}</span>
朱兆平 authored
42 43 44 45 46 47 48
                </el-menu-item>
            </template>
        </el-menu>
</template>

<script>
    import {userMenu} from '@/api/perm_api';
朱兆平 authored
49
    import {mapActions, mapGetters} from 'vuex'
朱兆平 authored
50
    import ChangeIcon from './ChangeIcon'
朱兆平 authored
51 52
    export default {
        name: 'NavMenus',
小范 authored
53
        props:['collapsed'],
朱兆平 authored
54
        components:{ChangeIcon},
朱兆平 authored
55 56
        data() {
            return {
小范 authored
57
                rotate:false,
朱兆平 authored
58
                menu:[]
朱兆平 authored
59 60 61
            }
        },
        methods: {
朱兆平 authored
62 63 64 65 66 67 68 69 70 71
            initMenu:function(){
                if (this.getUserMenuStore.length > 0){
                    this.menu = this.getUserMenuStore;
                }else {
                    this.getUserMenu();
                }
            },
            ...mapActions( // 语法糖
                ['setUserMenuStore'] // 相当于this.$store.dispatch('modifyName'),提交这个方法
            ),
小范 authored
72 73 74 75 76 77
            start(){
                this.rotate=!this.rotate;
            },
            collapse:function(){
                this.collapsed=!this.collapsed;
            },
朱兆平 authored
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            onSubmit() {
                console.log('submit!');
            },
            handleopen() {
                console.log('handleopen');
            },
            handleclose() {
                console.log('handleclose');
            },
            handleselect: function (a, b) {
                this.reload()
            },
            showMenu(i,status){
                this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-'+i)[0].style.display=status?'block':'none';
            },
            getUserMenu:function(){
                const _this=this;
                const para={
朱兆平 authored
96
                    userId:JSON.parse(sessionStorage.getItem('user')).userId
朱兆平 authored
97 98 99 100
                };
                userMenu(para).then((res) => {
                    console.log("ce"+res.data);
                    _this.menu = res.data.data;
朱兆平 authored
101
                    this.setUserMenuStore(_this.menu);
朱兆平 authored
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
                }).catch((error) => {
                    if(null!= error.response && error.response!==undefined){
                        let status= error.response.status;
                        let msg = error.response.statusText;
                        _this.$message({
                            //  饿了么的消息弹窗组件
                            message: msg,
                            type: "error"
                        });
                    }else {
                        _this.$message({
                            //  饿了么的消息弹窗组件
                            message: error,
                            type: "error"
                        });
                    }
                });
            },
            reload() {
                this.$nextTick(function () {
                    this.$router.push({
                        path: this.$router.path,
                        query:{
                            t: new Date().getTime()
                        }
                    })
                })
            },
朱兆平 authored
130 131 132 133 134 135 136 137 138 139 140
            changeIcon: function () {
                this.$nextTick(function(){
                    let doms = document.getElementsByClassName('el-submenu__icon-arrow el-icon-arrow-down');
                    if (doms && doms.length>0){
                        let domArr = Array.from(doms)
                        domArr.forEach(function (item,index) {
                            item.className = "el-submenu__icon-arrow el-icon-caret-bottom";
                        })
                    }
                })
            }
朱兆平 authored
141
        },
朱兆平 authored
142 143 144
        computed: {
            ...mapGetters(['getUserMenuStore']) // 动态计算属性,相当于this.$store.getters.resturantName
        },
朱兆平 authored
145
        mounted() {
朱兆平 authored
146 147
        },
        created() {
朱兆平 authored
148
            this.initMenu();
朱兆平 authored
149 150 151 152 153 154 155
        },
        watch: {
            menu(value) {
                this.$nextTick(function(){
                    this.changeIcon();
                })
            }
朱兆平 authored
156 157 158
        }
    }
</script>
朱兆平 authored
159 160 161 162 163 164
<style>
    .my-el-menu-item{
        color:#bcbfc5;
    }
</style>
<style lang="scss">
朱兆平 authored
165 166

</style>
小范 authored
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
<style scoped lang="scss">
    .go{
        transform:rotate(-180deg);
    }
    .el-menu-vertical-demo{
        position: relative;
    }
    .tools{
        position:absolute;

    }
    .logo-width{
    }
    .logo-collapse-width{
        width:90px;

    }
小范 authored
184 185 186
    /*el-submenu__title:hover {*/
    /*    background-color: #4f6273;*/
    /*    border-left: 3px solid #be1fd9*/
小范 authored
187
小范 authored
188 189 190 191 192 193 194
    /*}*/
    /*.el-submenu:hover {*/
    /*    border-left: 25px solid #be1fd9;*/

    /*}*/
    .el-submenu__title:hover {
        border-left: 23px solid #be1fd9
小范 authored
195
    }
朱兆平 authored
196
</style>