Skip to content

Commit 3cbb696

Browse files
committed
v3.8.2 开启TopNav没有子菜单情况隐藏侧边栏
1 parent c7235ec commit 3cbb696

File tree

43 files changed

+75
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+75
-70
lines changed

src/assets/styles/sidebar.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
position: relative;
88
}
99

10+
.sidebarHide {
11+
margin-left: 0!important;
12+
}
13+
1014
.sidebar-container {
1115
-webkit-transition: width .28s;
1216
transition: width 0.28s;

src/components/TopNav/index.vue

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
for (var item in router.children) {
7272
if (router.children[item].parentPath === undefined) {
7373
if(router.path === "/") {
74-
router.children[item].path = "/redirect/" + router.children[item].path;
74+
router.children[item].path = "/" + router.children[item].path;
7575
} else {
7676
if(!this.ishttp(router.children[item].path)) {
7777
router.children[item].path = router.path + "/" + router.children[item].path;
@@ -87,22 +87,23 @@ export default {
8787
// 默认激活的菜单
8888
activeMenu() {
8989
const path = this.$route.path;
90-
let activePath = this.defaultRouter();
90+
let activePath = path;
9191
if (path.lastIndexOf("/") > 0) {
9292
const tmpPath = path.substring(1, path.length);
9393
activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
94+
this.$store.dispatch('app/toggleSideBarHide', false);
9495
} else if ("/index" == path || "" == path) {
9596
if (!this.isFrist) {
9697
this.isFrist = true;
9798
} else {
9899
activePath = "index";
99100
}
101+
this.$store.dispatch('app/toggleSideBarHide', true);
102+
} else if(!this.$route.children) {
103+
activePath = path;
104+
this.$store.dispatch('app/toggleSideBarHide', true);
100105
}
101-
var routes = this.activeRoutes(activePath);
102-
if (routes.length === 0) {
103-
activePath = this.currentIndex || this.defaultRouter()
104-
this.activeRoutes(activePath);
105-
}
106+
this.activeRoutes(activePath);
106107
return activePath;
107108
},
108109
},
@@ -121,29 +122,21 @@ export default {
121122
const width = document.body.getBoundingClientRect().width / 3;
122123
this.visibleNumber = parseInt(width / 85);
123124
},
124-
// 默认激活的路由
125-
defaultRouter() {
126-
let router;
127-
Object.keys(this.routers).some((key) => {
128-
if (!this.routers[key].hidden) {
129-
router = this.routers[key].path;
130-
return true;
131-
}
132-
});
133-
return router;
134-
},
135125
// 菜单选择事件
136126
handleSelect(key, keyPath) {
137127
this.currentIndex = key;
128+
const route = this.routers.find(item => item.path === key);
138129
if (this.ishttp(key)) {
139130
// http(s):// 路径新窗口打开
140131
window.open(key, "_blank");
141-
} else if (key.indexOf("/redirect") !== -1) {
142-
// /redirect 路径内部打开
143-
this.$router.push({ path: key.replace("/redirect", "") });
132+
} else if (!route || !route.children) {
133+
// 没有子路由路径内部打开
134+
this.$router.push({ path: key });
135+
this.$store.dispatch('app/toggleSideBarHide', true);
144136
} else {
145137
// 显示左侧联动菜单
146138
this.activeRoutes(key);
139+
this.$store.dispatch('app/toggleSideBarHide', false);
147140
}
148141
},
149142
// 当前激活的路由
@@ -159,7 +152,6 @@ export default {
159152
if(routes.length > 0) {
160153
this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
161154
}
162-
return routes;
163155
},
164156
ishttp(url) {
165157
return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1

src/layout/components/Settings/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default {
108108
value: val
109109
})
110110
if (!val) {
111+
this.$store.dispatch('app/toggleSideBarHide', false);
111112
this.$store.commit("SET_SIDEBAR_ROUTERS", this.$store.state.permission.defaultRoutes);
112113
}
113114
}
@@ -162,7 +163,7 @@ export default {
162163
this.sideTheme = val;
163164
},
164165
saveSetting() {
165-
this.$modal.loading("正在保存到本地,请稍后...");
166+
this.$modal.loading("正在保存到本地,请稍候...");
166167
this.$cache.local.set(
167168
"layout-setting",
168169
`{
@@ -178,7 +179,7 @@ export default {
178179
setTimeout(this.$modal.closeLoading(), 1000)
179180
},
180181
resetSetting() {
181-
this.$modal.loading("正在清除设置缓存并刷新,请稍后...");
182+
this.$modal.loading("正在清除设置缓存并刷新,请稍候...");
182183
this.$cache.local.remove("layout-setting")
183184
setTimeout("window.location.reload()", 1000)
184185
}

src/layout/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div :class="classObj" class="app-wrapper" :style="{'--current-color': theme}">
33
<div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
4-
<sidebar class="sidebar-container"/>
5-
<div :class="{hasTagsView:needTagsView}" class="main-container">
4+
<sidebar v-if="!sidebar.hide" class="sidebar-container" />
5+
<div :class="{hasTagsView:needTagsView,sidebarHide:sidebar.hide}" class="main-container">
66
<div :class="{'fixed-header':fixedHeader}">
77
<navbar />
88
<tags-view v-if="needTagsView" />
@@ -98,7 +98,7 @@ export default {
9898
}
9999
100100
.hideSidebar .fixed-header {
101-
width: calc(100% - 54px)
101+
width: calc(100% - 54px);
102102
}
103103
104104
.mobile .fixed-header {

src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ export const constantRoutes = [
164164
}
165165
]
166166

167+
// 防止连续点击多次路由报错
168+
let routerPush = Router.prototype.push;
169+
Router.prototype.push = function push(location) {
170+
return routerPush.call(this, location).catch(err => err)
171+
}
172+
167173
export default new Router({
168174
base: process.env.VUE_APP_APP_NAME ? process.env.VUE_APP_APP_NAME : "/",
169175
mode: 'history', // 去掉url中的#

src/store/modules/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Cookies from 'js-cookie'
33
const state = {
44
sidebar: {
55
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
6-
withoutAnimation: false
6+
withoutAnimation: false,
7+
hide: false
78
},
89
device: 'desktop',
910
size: Cookies.get('size') || 'medium'
@@ -30,6 +31,9 @@ const mutations = {
3031
SET_SIZE: (state, size) => {
3132
state.size = size
3233
Cookies.set('size', size)
34+
},
35+
SET_SIDEBAR_HIDE: (state, status) => {
36+
state.sidebar.hide = status
3337
}
3438
}
3539

@@ -45,6 +49,9 @@ const actions = {
4549
},
4650
setSize({ commit }, size) {
4751
commit('SET_SIZE', size)
52+
},
53+
toggleSideBarHide({ commit }, status) {
54+
commit('SET_SIDEBAR_HIDE', status)
4855
}
4956
}
5057

src/store/modules/permission.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ const permission = {
1818
state.defaultRoutes = constantRoutes.concat(routes)
1919
},
2020
SET_TOPBAR_ROUTES: (state, routes) => {
21-
// 顶部导航菜单默认添加统计报表栏指向首页
22-
const index = [{
23-
path: 'index',
24-
meta: { title: '统计报表', icon: 'dashboard'}
25-
}]
26-
state.topbarRouters = routes.concat(index);
21+
state.topbarRouters = routes
2722
},
2823
SET_SIDEBAR_ROUTERS: (state, routes) => {
2924
state.sidebarRouters = routes

src/views/bpm/form/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<doc-alert title="工作流" url="https://doc.iocoder.cn/bpm" />
44

55
<!-- 搜索工作栏 -->
6-
<el-form :model="queryParams" ref="queryForm" size="small" inline="true" v-show="showSearch" label-width="68px">
6+
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
77
<el-form-item label="表单名" prop="name">
88
<el-input v-model="queryParams.name" placeholder="请输入表单名" clearable @keyup.enter.native="handleQuery"/>
99
</el-form-item>

src/views/bpm/group/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<doc-alert title="工作流" url="https://doc.iocoder.cn/bpm" />
44

55
<!-- 搜索工作栏 -->
6-
<el-form :model="queryParams" ref="queryForm" size="small" inline="true" v-show="showSearch" label-width="68px">
6+
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
77
<el-form-item label="组名" prop="name">
88
<el-input v-model="queryParams.name" placeholder="请输入组名" clearable @keyup.enter.native="handleQuery"/>
99
</el-form-item>

src/views/bpm/model/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<doc-alert title="工作流" url="https://doc.iocoder.cn/bpm" />
44

55
<!-- 搜索工作栏 -->
6-
<el-form :model="queryParams" ref="queryForm" size="small" inline="true" v-show="showSearch" label-width="68px">
6+
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
77
<el-form-item label="流程标识" prop="key">
88
<el-input v-model="queryParams.key" placeholder="请输入流程标识" clearable style="width: 240px;"
99
@keyup.enter.native="handleQuery"/>

0 commit comments

Comments
 (0)