项目菜单配置

news2024/10/9 2:27:03

stores/index.js

import {
	createStore
} from "vuex";
//计算高度
let height = window.innerHeight;

//计算分辨率
let width = window.innerWidth;

let activeIndex = localStorage.getItem("activeIndex");
if (activeIndex == null || activeIndex == "" || activeIndex == undefined) {
	activeIndex = "1";
}

//用户菜单
let menuList = localStorage.getItem("menuList");
if (menuList == undefined || menuList == "null" || menuList == null || menuList == "") {
	menuList = [];
} else {
	menuList = JSON.parse(menuList);
}
const store = createStore({
	state: function () {
		return {
			width: width,
			height: height,
            activeIndex:activeIndex,
            //当前用户的权限
			menuList: menuList,
		};
	},
	mutations: {
		setActiveIndex: function (state, value) {
			state.activeIndex = value;
			localStorage.setItem("activeIndex", value);
		},
        setMenuList: function (state, value) {
			state.menuList = value;
			localStorage.setItem("menuList", JSON.stringify(value));
		},
	},
	modules: {
	},

});
export default store;
	

home.vue

    <el-container :style="getStyle()">
        <!-- <el-header class="pageHeader">
            <el-row justify="end" style="height:100%"></el-row>
        </el-header> -->
        <el-container>
            <el-aside :style="asideStyle">
                <el-scrollbar :height="height - 64">
                    <the-menu @foldMenu="foldMenu"></the-menu>
                </el-scrollbar>
            </el-aside>

            <el-main style="background:#fff;">
				<router-view ></router-view>
			</el-main>
        </el-container>
    </el-container>
</template>

<script setup>
import stores from '../../stores/index.js'
import TheMenu from '@/components/TheMenu.vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()

const asideStyle = ref({})

onMounted( () => {
    getAsideStyle(0)
})

const getStyle = () => {
    let h = stores.state.height;
    return {
        height: h + "px"
    }
}


// flag:0-展开 1-折叠
let  getAsideStyle = (flag) => {

    var h = stores.state.height;
    var style = {
        width: flag == 0 ? "240px": "66px",
        height: h + "px",
        border: "none",
        backgroundColor: '#f7f9fc',
        zIndex: 99
    };
    asideStyle.value = style
}

const foldMenu = (state) => {
    debugger
    getAsideStyle(state)
}

const height = computed(() => {
    //将dept变量中stuffs列表的长度赋值给numberofStuff
    return stores.state.height
})
</script>
<style scoped lang="less">

.el-footer {
    display: flex;
    width: 100%;
    height: 2.375rem;
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    background-color: #589957;
}
</style>

TheMenu.vue

<!--
  Author:lixg
  Date:2022-03-07 14:54
  Describe:菜单组件
-->
<template>
    <div class="menuBox">
        <el-menu v-on:select="handleSelect" :collapse="isCollapse" class="el-menu-vertical-demo" text-color="#03bf8a"
            active-text-color="#ffffff" :default-active="activeIndex" background-color="#f7f9fc">
            <el-menu-item v-bind:index="state.Menu.CompanyAccount.index" class="oneLevelMenu">
                <i class="el-icon-menu-default"></i>
                <template #title>{{ getMenuName(state.Menu.CompanyAccount) }}</template>
            </el-menu-item>
            <el-menu-item v-bind:index="state.Menu.HistoryAccount.index" class="oneLevelMenu">
                <i class="el-icon-menu-default"></i>
                <template #title>{{ getMenuName(state.Menu.HistoryAccount) }}</template>
            </el-menu-item>
        </el-menu>
        <div class="collapse_true" @click="foldMenu(1)" v-show="!isCollapse">
            <div v-for="i in 3"></div>

        </div>
        <div class="collapse_false" @click="foldMenu(0)" v-show="isCollapse">
            <div v-for="i in 3"></div>

        </div>
    </div>
</template>


<script setup>
import { computed, onMounted, reactive, ref, defineEmits } from 'vue'
import SetInfo from '../lib/setting.js'
import stores from '../stores/index.js'
import { useRoute, useRouter } from 'vue-router'
import { v4 as uuidv4 } from 'uuid';

const isCollapse = ref(false)

const router = useRouter()
const route = useRoute()
const emit = defineEmits(['foldMenu'])

const state = reactive({
    Menu: SetInfo.Menu
})

const activeIndex = computed(() => {
    return stores.state.activeIndex
})

let menuList = computed(() => {
    return stores.state.menuList
})

const handleSelect = (index) => {
    if (index == null) {
        index = 1;
    }
    stores.commit("setActiveIndex", index);

    var name = "";
    for (var key in state.Menu) {
        if (state.Menu[key].index == index) {
            name = state.Menu[key].name;

            break;
        }
        if (name != "") {
            break;
        }
    }

    router.push({
        name: name,
        params: { random: uuidv4() },
    });
}


const getMenuName = (menu) => {
    var menuInfo = menuList.value.find(item => {
        return item.title == menu.title;
    })
    if (menuInfo) {
        return menuInfo.title;
    }
    else {
        return menu.title;
    }
}

// 菜单折叠
const foldMenu = (state) => {
    isCollapse.value = state == 1 ? true : false;
    debugger
    emit("foldMenu", state)
}
</script>

<style scoped lang="less">
.el-menu {
    width: "240px",
}

.el-menu .is-active {
    background-color: #03bf8a;
}

.el-icon-menu-default {
    background: url(../img/LayoutContainer/menu-default.png) center no-repeat;
    // background-size: cover;
}

.el-icon-menu-default:before {
    content: "\8d3a";
    font-size: 14px;
    visibility: hidden;
}

.el-menu .is-active .el-icon-menu-default {
    background: url(../img/LayoutContainer/menu-active.png) center no-repeat;
    // background-size: cover;
}

.collapse_true {
    width: 220px;
    height: 28px;
    padding: 10px;
    background: #f0f1f2;
    bottom: 0;
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;

    div {
        width: 40px;
        height: 3px;
        background-color: #999;
    }
}

.collapse_false {
    width: 25px;
    height: 28px;
    margin: 10px 20px;
    background: #f0f1f2;
    bottom: 0;
    position: absolute;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;

    div {
        width: 3px;
        height: 30px;
        background-color: #999;
    }
}
</style>

router/index.js

import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      children:[
        {
          path: '/companyAccount',
          name: 'companyAccount',
          component: () => import('@/views/layout/components/CompanyAccount.vue')
          
        },
        {
          path: '/historyAccount',
          name: 'historyAccount',
          component: () => import('@/views/layout/components/HistoryAccount.vue')
          
        }
      ]
    },
    
  ]
})

export default router

lib/setting.js

const SETTING = {
	//系统菜单配置示例
	Menu: { 
        CompanyAccount: {
			name: "companyAccount",
			title: "菜单1", 
			index: "0",
			children: []
		},
        HistoryAccount: {
			name: "historyAccount",
			title: "菜单2", 
			index: "1",
			children: []
		},
    }
}

export default SETTING 

在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1863482.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

制图工具(14)导出图层字段属性信息表

在制图工具&#xff08;13&#xff09;地理数据库初始化工具中我们提到&#xff0c;有一个参数为&#xff1a;“输入Excel表”&#xff0c;并要求表格中的图层字段属性项需要按工具的帮助文档中的示例进行组织… 如下图&#xff1a; 此外&#xff0c;总有那个一个特别的需求&am…

【单片机毕业设计选题24028】-基于STM32的大棚温湿度采集系统

系统功能: 系统分为手动和自动模式&#xff0c;上电默认为自动模式&#xff0c;自动模式下系统根据采集到的传感器值 自动控制&#xff0c;温度过低后自动开启加热&#xff0c;湿度过高后自动开启通风&#xff0c;光照过低后自动开启补 光&#xff0c;水位过低后自动开启水泵…

Android 界面库 (二) 之 Data binding 详细介绍

1. 简介 回顾我们在前面文章《Android 界面库 (一) 之 View binding 简单使用》中学习的 View Binding&#xff0c;它旨在简化 View 与代码之间的绑定过程。它会在编译时期为每个 XML 布局文件生成相应的绑定类(Binding class)&#xff0c;该类里包含了布局文件每个有 ID 的 Vi…

L59---101.对称二叉树(广搜)---Java版

1.题目描述 2.思路和知识点 &#xff08;1)根节点为空&#xff1a; 如果根节点为空&#xff0c;树是对称的。 (2)递归检查&#xff1a; isMirror 方法递归检查两个子树是否是镜像对称的。 (3)辅助函数 isMirror&#xff1a; 1)如果两个节点都为空&#xff0c;它们是镜像对称的…

php composer 报错

引用文章&#xff1a; Composer设置国内镜像_composer 国内源-CSDN博客 php composer.phar require --prefer-dist yiidoc/yii2-redactor "*" A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the …

day49---数据结构与算法(四)

三. 基础算法 3.1 查找概述 查找算法是一种在数据集中寻找特定数据项的方法。通常&#xff0c;数据集是在计算机程序中存储的&#xff0c;例如数组、链表或散列表。在编写程序时&#xff0c;查找算法是非常重要的&#xff0c;它有助于快速找到所需的数据。在本文中&#xff0…

Linux系统安装Lua语言及Lua外部库

安装Lua Lua语言是一种轻量级、高效且可扩展的脚本语言&#xff0c;具有简洁易学的语法和占用资源少的特点。它支持动态类型&#xff0c;提供了丰富的表达式和运算符&#xff0c;同时具备自动垃圾回收机制和跨平台性。Lua语言易于嵌入到其他应用程序中&#xff0c;并可与其他语…

高性能并行计算华为云实验五:PageRank算法实验

目录 一、实验目的 二、实验说明 三、实验过程 3.1 创建PageRank源码 3.2 makefile的创建和编译 3.3 主机配置文件建立与运行监测 四、实验结果与分析 4.1 采用默认的节点数量及迭代次数进行测试 4.2 分析并行化下节点数量与耗时的变化规律 4.3 分析迭代次数与耗时的变…

2024广东省职业技能大赛云计算赛项实战——集群部署GitLab Agent

集群部署GitLab Agent 前言 题目如下&#xff1a; 部署GitLab Agent 将Kubernetes集群添加到demo-2048项目中&#xff0c;并命名为kubernetes-agent&#xff0c;项目命名空间选择gitlab-ci。 说是部署GitLab Agent,但据我了解&#xff0c;Agent就是Runner&#xff0c;看题目…

5.How Fast Should You Be When Learning?(你应该用多快的速度学习? (一))

Normally when I talk about learing quickly, I’m using speed as a synonym for efficiency.Use more effective methods and you’ll learn more in less time.All else being equal, that means you’re learing faster. 通常我在谈到快速学习时&#xff0c;是把“速度&qu…

【神经网络】神经元的基本结构和训练过程

&#x1f388;个人主页&#xff1a;豌豆射手^ &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共同学习、交流进步&#xff01; 神经元的基本结构和训练过程 …

Redis数据库(三):Redis数据库三种特殊数据类型

除了上一篇博客讲的五种基本数据类型外&#xff0c;Redis还有三种特殊的数据类型&#xff0c;它们有着不同的应用场景&#xff0c;这一篇博客&#xff0c;我们来学习它。 目录 一、geospatial 地理空间 1.1 添加地理位置 1.2 返回给定名称的纬度和经度 1.3 返回两个给定位…

小柴冲刺嵌入式系统设计师系列总目录

工作两年 逐渐意识到基础知识的重要性✌️ 意识到掌握了这个证书好像就已经掌握了80%工作中用到的知识了。剩下的就在工作的实战中学习 来和小柴一起冲刺软考吧&#xff01;加油&#x1f61c; 【小柴冲刺软考中级嵌入式系统设计师系列】总目录 前言 专栏目标&#xff1a;冲刺…

ros2_control 使用教程

系列文章目录 前言 0.1 欢迎阅读 ros2_control 文档&#xff01; ros2_control 是一个使用&#xff08;ROS 2&#xff09;对机器人进行&#xff08;实时&#xff09;控制的框架。其软件包是对 ROS&#xff08;机器人操作系统&#xff09;中使用的 ros_control 软件包的重写。r…

NetSuite CSV导入类型与记录类型梳理

最近有用户问到我们的一个问题是&#xff0c;哪些数据可以使用CSV导入&#xff0c;哪些数据不能使用CSV导入&#xff0c;干脆咱们就整理出来可使用CSV导入功能的类型和记录类型&#xff0c;供大家直接参考&#xff5e; 但是有一些内容或多或少由于每个企业的环境不一样而有所不…

jenkins环境搭建--关于jenkins在Ubuntu下的安装篇(一)

在ubuntu下使用命令进行下载安装包&#xff1a; 关于jenkins的安装有多种&#xff0c;可以借助docker容器进行安装&#xff0c;也可以通过传统方法手动一步步的进行安装&#xff0c;以下介绍手动一步步的安装方法&#xff0c;后续我们将解释关于jenkins的相关配置以及实战使用…

mongodb 查询语句学习笔记

基础查询 正则查询 {status: A,$or: [{ qty: { $lt: 30 } }, { item: { $regex: ^p } }] }AND 查询 { "size.h": { $lt: 15 }, "size.uom": "in", status: "D" }OR 查询 { $or: [ { status: "A" }, { qty: { $lt: 30 } …

万界星空科技自动化运维管理---设备管理

在信息化管理体系建设中&#xff0c;设备管理系统被看作是重中之重。因为设备是工厂生产中的主体、生命线&#xff0c;随着科学技术的不断发展、智能制造的产业升级&#xff0c;生产设备日益智能化、自动化&#xff0c;设备在现代工业生产中的作用和影响也随之增大&#xff0c;…

智能体——父亲兴趣爱好助手

&#x1f3bc;个人主页&#xff1a;【Y小夜】 &#x1f60e;作者简介&#xff1a;一位双非学校的大二学生&#xff0c;编程爱好者&#xff0c; 专注于基础和实战分享&#xff0c;欢迎私信咨询&#xff01; &#x1f386;入门专栏&#xff1a;&#x1f387;【MySQL&#xff0…

Sectigo或RapidSSL DV通配符SSL证书哪个性价比更高?

在当前的网络安全领域&#xff0c;选择一款合适的SSL证书对于保护网站和用户数据至关重要。Sectigo和RapidSSL作为市场上知名的SSL证书提供商&#xff0c;以其高性价比和快速的服务响应而受到市场的青睐。本文将对Sectigo和RapidSSL DV通配符证书进行深入对比&#xff0c;帮助用…