123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <template lang="html">
- <div id="sideMenu">
- <div id="menuBox">
- <el-col :span="24">
- <el-menu :unique-opened="true">
- <template v-for="item in menu">
- <template v-if="!item.children">
- <el-menu-item :index="item.path" @click="selectMenu(item.path)" :key="item.name">
- <i v-if="item.icon" :class="item.icon"></i>
- <span v-if="item.name" slot="title">{{ item.name }}</span>
- </el-menu-item>
- </template>
- <el-submenu v-else :index="item.name || item.path" :key="item.name">
- <template slot="title">
- <i v-if="item && item.icon" :class="item.icon"></i>
- <span v-if="item && item.name" slot="title">{{ item.name }}</span>
- </template>
- <template v-for="(child, childIndex) in item.children">
- <div :key="childIndex" v-if="!child.hidden">
- <el-menu-item :index="item.path || '' + child.path" @click="selectMenu(item.path || '' + child.path)">
- <span v-if="child && child.name" slot="title">{{ child.name }}</span>
- </el-menu-item>
- </div>
- </template>
- </el-submenu>
- </template>
- </el-menu>
- </el-col>
- </div>
- </div>
- </template>
- <script>
- import {
- index,
- menu,
- // department,
- permission,
- adminUser,
- business,
- vip,
- user,
- duijiehui,
- enterpriseProduct,
- enterpriseTrans,
- technical,
- defaultMenu,
- } from '@/util/role_menu.js';
- import * as menus from '@/util/role_menu.js';
- import { mapState, createNamespacedHelpers } from 'vuex';
- const { mapActions } = createNamespacedHelpers('login');
- import _ from 'lodash';
- export default {
- name: 'sideMenu',
- components: {},
- data() {
- return {
- menu: [],
- };
- },
- computed: {
- ...mapState(['user']),
- },
- created() {},
- methods: {
- ...mapActions(['toGetMenu', 'logout']),
- async search() {
- if (!this.user.uid) return;
- if (this.user.role == '0') {
- this.menu.push(
- index,
- menu,
- // department,
- permission,
- adminUser,
- business,
- vip,
- user,
- duijiehui,
- enterpriseProduct,
- enterpriseTrans,
- technical,
- defaultMenu
- );
- return;
- }
- const res = await this.toGetMenu({ id: this.user.uid });
- if (this.$checkRes(res)) {
- let menu = res.data.menus;
- menu = menu.map(i => {
- return { name: i.role_name, path: i.url };
- });
- let duplicate = JSON.parse(JSON.stringify(this.menu));
- duplicate.push(...menu);
- let nm = _.uniqBy(duplicate, 'path');
- this.$set(this, `menu`, nm);
- }
- },
- selectMenu(path) {
- this.$router.push({ path: path });
- },
- },
- watch: {
- user: {
- handler(val, oval) {
- if (val && !_.isEqual(val, oval)) this.search();
- },
- immediate: true,
- },
- },
- };
- </script>
- <style lang="less" scoped></style>
|