Administrator
2022-04-11 79d9fc857559982b00b68b2d709807bdc4cd286f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
    <div class="menu-wrapper">
        <template v-for="item in menu">
            <el-menu-item v-if="validatenull(item[childrenKey]) && vaildRoles(item)"
                          :index="item[pathKey]"
                          @click="open(item)"
                          :key="item[labelKey]"
                          :class="{'is-active':vaildActive(item)}">
                <i :class="item[iconKey]"></i>
                <span slot="title"
                      :alt="item[pathKey]">{{generateTitle(item)}}</span>
 
            </el-menu-item>
            <el-submenu v-else-if="!validatenull(item[childrenKey])&&vaildRoles(item)"
                        :index="item[pathKey]"
                        :key="item[labelKey]">
                <template slot="title">
                    <i :class="item[iconKey]"></i>
                    <span slot="title"
                          :class="{'el-menu--display':collapse && first}">{{generateTitle(item)}}</span>
                    <!-- <div v-show="generateTitle(item) == '保安单位许可备案审批'"
                         style="position: absolute;
                        top: -2px;
                        z-index: 99;
                        width: 28px;
                        height: 28px;
                        border-radius: 50%;
                        background: red;
                        font-size: 12px;
                        color: #fff;
                        text-align: center;
                        line-height: 28px !important;
                        transform: translate(-80%, 0) scale(0.8)">
                        {{xkTotal}}
                    </div> -->
                </template>
                <template v-for="(child,cindex) in item[childrenKey]">
                    <el-menu-item :index="child[pathKey],cindex"
                                  @click="open(child)"
                                  :class="{'is-active':vaildActive(child)}"
                                  v-if="validatenull(child[childrenKey])"
                                  :key="child[labelKey]">
                        <i :class="child[iconKey]"></i>
                        <span slot="title">{{generateTitle(child)}}</span>
                        <!-- <div v-show="generateTitle(child) == '保安服务许可申请'"
                             style="position: absolute;
                          top: -2px;
                          z-index: 99;
                          width: 28px;
                          height: 28px;
                          border-radius: 50%;
                          background: red;
                          font-size: 12px;
                          color: #fff;
                          text-align: center;
                          line-height: 28px !important;
                          transform: translate(-80%, 0) scale(0.8)">
                            {{xkTotal}}
                        </div> -->
                    </el-menu-item>
                    <sidebar-item v-else
                                  :menu="[child]"
                                  :key="cindex"
                                  :props="props"
                                  :screen="screen"
                                  :collapse="collapse"></sidebar-item>
 
                </template>
            </el-submenu>
        </template>
    </div>
</template>
<script>
 
import { mapGetters } from "vuex";
import { isURL, validatenull } from "@/util/validate";
import config from "./config.js";
 
export default {
    name: "sidebarItem",
    data () {
        return {
            config: config
        };
    },
    props: {
        menu: {
            type: Array
        },
        screen: {
            type: Number
        },
        first: {
            type: Boolean,
            default: false
        },
        props: {
            type: Object,
            default: () => {
                return {};
            }
        },
        collapse: {
            type: Boolean
        },
        xkTotal: {
            type: Number
        }
    },
    beforeCreate () {
 
    },
    created () {
 
    },
    mounted () {
 
    },
    computed: {
        ...mapGetters(["roles"]),
        labelKey () {
            return this.props.label || this.config.propsDefault.label;
        },
        pathKey () {
            return this.props.path || this.config.propsDefault.path;
        },
        iconKey () {
            return this.props.icon || this.config.propsDefault.icon;
        },
        childrenKey () {
            return this.props.children || this.config.propsDefault.children;
        },
        isOpenKey () {
            return this.props.isOpen || this.config.propsDefault.isOpen;
        },
        nowTagValue () {
            return this.$router.$avueRouter.getValue(this.$route);
        }
    },
    methods: {
        generateTitle (item) {
            return this.$router.$avueRouter.generateTitle(
                item[this.labelKey],
                (item.meta || {}).i18n
            );
        },
        vaildActive (item) {
            if (this.validIsOpen(item)) {
                return false;
            }
            const groupFlag = (item["group"] || []).some(ele =>
                this.$route.path.includes(ele)
            );
            return this.nowTagValue === item[this.pathKey] || groupFlag;
        },
        vaildRoles (item) {
            item.meta = item.meta || {};
            return item.meta.roles ? item.meta.roles.includes(this.roles) : true;
        },
        validatenull (val) {
            return validatenull(val);
        },
        validIsOpen (item) {
            if (item[this.isOpenKey] === 2 && isURL(item[this.pathKey])) {
                return true;
            }
        },
        open (item) {
            if (this.screen <= 1) this.$store.commit("SET_COLLAPSE");
            if (this.validIsOpen(item)) {
                window.open(item[this.pathKey]);
            } else {
                this.$router.$avueRouter.group = item.group;
                this.$router.$avueRouter.meta = item.meta;
                this.$router.push({
                    path: this.$router.$avueRouter.getPath({
                        name: item[this.labelKey],
                        src: item[this.pathKey]
                    }, item.meta),
                    query: item.query
                });
            }
        }
    }
};
</script>