123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <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': vaildAvtive(item) }"
- >
- <i :class="item[iconKey]"></i>
- <span slot="title" :alt="item[pathKey]">{{
- generateTitleLab(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 }"
- >{{ generateTitleLab(item) }}</span
- >
- </template>
- <template v-for="(child, cindex) in item[childrenKey]">
- <el-menu-item
- :index="child[pathKey]"
- @click="open(child)"
- :class="{ 'is-active': vaildAvtive(child) }"
- v-if="validatenull(child[childrenKey])"
- :key="child[labelKey]"
- >
- <i :class="child[iconKey]"></i>
- <span slot="title">{{ generateTitleLab(child) }}</span>
- </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 { validatenull } from '@/utils/validate'
- import config from './config.js'
- import '../../../../public/static/sidebar/iconfont.css'
- import { getValue, generateTitle, getPath } from '@/utils/util'
- 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,
- },
- },
- 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
- },
- nowTagValue() {
- return getValue(this.$route)
- },
- },
- methods: {
- generateTitleLab(item) {
- return generateTitle(item[this.labelKey], (item.meta || {}).title, this)
- },
- vaildAvtive(item) {
- const groupFlag = (item['group'] || []).some((ele) =>
- this.$route.path.includes(ele)
- )
- if (groupFlag)
- // console.info(groupFlag, 'groupFlag', item['group'], this.$route.path, this.nowTagValue, item[this.pathKey])
- 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)
- },
- open(item) {
- if (this.screen <= 1) this.$store.commit('SET_COLLAPSE')
- // this.$router.$winseaviewRouter.group = item.group;
- // this.$router.$winseaviewRouter.meta = item.meta;
- this.$router.push({
- path: getPath({
- name: item[this.labelKey],
- src: item[this.pathKey],
- i18n: (item.meta || {}).i18n,
- }),
- query: item.query,
- })
- },
- },
- }
- </script>
|