ruoyi框架修改
修改主题色
topleft布局改为自定义topleft布局
涉及到的文件 src/settings.js,src/layout/index.vue ,src/components/TopNav ,src/layout/components/Navbar.vue
避免修改原文件,将src/components/TopNav
,src/layout/components/Navbar.vue
同级目录下复制一份 分别重命名为NewTopNav
,NewNavbar
第一步将菜单导航布局改为topleft
src/settings.js
topNav: true,
第二步将菜单导航布局改为topleft
src/layout/index.vue
主要修改点 navbar
位置修改,对应的样式修改
<template>
<div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }">
<div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
<!-- <navbar /> -->
<div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
<new-navbar></new-navbar>
<div :class="{ 'fixed-header': fixedHeader }">
<sidebar v-if="!sidebar.hide" class="sidebar-container" />
<tags-view v-if="needTagsView" />
</div>
<app-main />
<right-panel>
<settings />
</right-panel>
</div>
</div>
</template>
<script>
import RightPanel from '@/components/RightPanel'
import { AppMain, Navbar, Settings, Sidebar, TagsView, NewNavbar } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex'
import variables from '@/assets/styles/variables.scss'
export default {
name: 'Layout',
components: {
AppMain,
Navbar,
RightPanel,
Settings,
Sidebar,
TagsView,
NewNavbar,
},
mixins: [ResizeMixin],
computed: {
...mapState({
theme: state => state.settings.theme,
sideTheme: state => state.settings.sideTheme,
sidebar: state => state.app.sidebar,
device: state => state.app.device,
needTagsView: state => state.settings.tagsView,
fixedHeader: state => state.settings.fixedHeader
}),
classObj() {
return {
hideSidebar: !this.sidebar.opened,
openSidebar: this.sidebar.opened,
withoutAnimation: this.sidebar.withoutAnimation,
mobile: this.device === 'mobile'
}
},
variables() {
return variables;
}
},
methods: {
handleClickOutside() {
this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
}
}
}
</script>
<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";
.app-wrapper {
@include clearfix;
position: relative;
height: 100%;
width: 100%;
&.mobile.openSidebar {
position: fixed;
top: 0;
}
}
.drawer-bg {
background: #000;
opacity: 0.3;
width: 100%;
top: 0;
height: 100%;
position: absolute;
z-index: 999;
}
.fixed-header {
position: fixed;
top: 0;
right: 0;
z-index: 9;
width: calc(100% - #{$base-sidebar-width});
transition: width 0.28s;
}
.hideSidebar .fixed-header {
width: calc(100% - 54px);
}
.sidebarHide .fixed-header {
width: 100%;
}
.mobile .fixed-header {
width: 100%;
}
</style>
第三步将顶部菜单topNav 替换为 NewTopNav
第四步将顶部菜单导航加上下拉
el-menu
的mode
改为horizontal
- 原来的菜单注释掉,改为
sidebar-item
此处没有兼容更多菜单的情况,如果要兼容或者要根据项目需求修改
思路:可以将visibleNumber
传入sidebar-item
,在sidebar-item
中,将NewTopNav/index
已经注释掉的el-menu-item
的逻辑加上
第五步自定义重写顶部菜单项
src/layout/components/NewTopNav/index.vue
isHiddeTop:true
在顶部菜单中隐藏该菜单项
routeName
:对应路由的name
meta
:会在meta对象中插入配置
rewriteConfig
:路由中除meta外,插入配置
//重写部分头部菜单信息 isHiddeTop :隐藏头部菜单
const topNavRewrite = [{
routeName: 'Ms',
meta: {
title: "专业工具",
},
rewriteConfig: {}
}, {
routeName: 'Inventory',
rewriteConfig: {
isHiddeTop: true,
}
}, {
routeName: 'ProductTracking',
rewriteConfig: {
isHiddeTop: true,
}
}, {
routeName: 'OnlineService',
rewriteConfig: {
isHiddeTop: true,
}
}]
//计算属性中改下routers
computed: {
// 所有的路由信息
routers() {
let topbarRouters = this.$store.state.permission.topbarRouters
//处理顶部菜单显隐
function treeForeach(tree, func) {
let node, list = [...tree]
while (node = list.shift()) {
func(node)
node.children && list.push(...node.children)
}
}
let OnlineService //线上服务
treeForeach(topbarRouters, (item) => {
if (item.name == 'OnlineService') {
OnlineService = deepClone(item)
}
//合并菜单配置
let isConfig = topNavRewrite.find(top => top.routeName == item.name)
if (isConfig) {
if (isConfig.rewriteConfig) {
for (const key in isConfig.rewriteConfig) {
item[key] = isConfig.rewriteConfig[key]
}
}
if (isConfig.meta) {
item.meta = {
...item.meta,
...isConfig.meta
}
}
}
//隐藏下一级箭头
if (item.children) {
let isAllChilds = item.children.every(ii => ii.isHiddeTop)
if (isAllChilds) {
item.alwaysShow = false
}
}
})
// 头部菜单插入子项
OnlineService.isHiddeTop = false;
this.$store.state.permission.topbarRouters.splice(3, 0, OnlineService)
//
return this.$store.state.permission.topbarRouters;
},
}