Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
micro-customization-system
/
micro-portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 996dad78
authored
Oct 19, 2023
by
前端
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
v1.25.0版本需求
1 parent
38b8dd3e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
117 deletions
src/components/DesktopLeftSider/Sub/Menu.vue
src/store/getters.js
src/store/modules/menu.js
src/utils/common/common.js
src/components/DesktopLeftSider/Sub/Menu.vue
View file @
996dad7
...
@@ -278,6 +278,18 @@ export default {
...
@@ -278,6 +278,18 @@ export default {
return param;
return param;
};
};
// 树形数据扁平化 v1.25.0版本添加
const unfoldTree = (list) => {
let arr = [];
list.forEach((k) => {
arr.push(k);
if (k.children && k.children.length) {
arr.push(...unfoldTree(k.children));
}
});
return arr;
};
// 获取菜单树接口
// 获取菜单树接口
const getServerTree = async (isInit) => {
const getServerTree = async (isInit) => {
const menuService = new MenuService();
const menuService = new MenuService();
...
@@ -294,6 +306,9 @@ export default {
...
@@ -294,6 +306,9 @@ export default {
// 数据存入state
// 数据存入state
store.commit("menu/SET_MENU_LIST", state.menuList);
store.commit("menu/SET_MENU_LIST", state.menuList);
// 所有权限数据存入state v1.25.0版本添加
store.commit("menu/SET_PERMISSION_LIST", unfoldTree(resData));
// 初始化操作
// 初始化操作
let showEmpty = false;
let showEmpty = false;
...
@@ -304,10 +319,14 @@ export default {
...
@@ -304,10 +319,14 @@ export default {
curBreadcrumb = JSON.parse(curBreadcrumb);
curBreadcrumb = JSON.parse(curBreadcrumb);
resData.forEach((item) => {
resData.forEach((item) => {
const { menuName: pMenuName } = item.origin;
const { menuName: pMenuName } = item.origin;
item.showSubList = pMenuName === (curBreadcrumb[0]?curBreadcrumb[0].name:'');
item.showSubList =
pMenuName === (curBreadcrumb[0] ? curBreadcrumb[0].name : "");
item.children.forEach((cItem, cIndex) => {
item.children.forEach((cItem, cIndex) => {
cItem.subItemActive = false;
cItem.subItemActive = false;
if (cItem.origin.menuName === (curBreadcrumb[1]&&curBreadcrumb[1].name)) {
if (
cItem.origin.menuName ===
(curBreadcrumb[1] && curBreadcrumb[1].name)
) {
cItem.subItemActive = true;
cItem.subItemActive = true;
curBreadcrumb[1].id = cItem.id;
curBreadcrumb[1].id = cItem.id;
}
}
...
...
src/store/getters.js
View file @
996dad7
...
@@ -16,7 +16,8 @@ const getters = {
...
@@ -16,7 +16,8 @@ const getters = {
menuList
:
state
=>
state
.
menu
.
menuList
,
menuList
:
state
=>
state
.
menu
.
menuList
,
logo
:
state
=>
state
.
app
.
logo
,
logo
:
state
=>
state
.
app
.
logo
,
title
:
state
=>
state
.
app
.
title
,
title
:
state
=>
state
.
app
.
title
,
smallLogo
:
state
=>
state
.
app
.
smallLogo
smallLogo
:
state
=>
state
.
app
.
smallLogo
,
permissionList
:
state
=>
state
.
menu
.
permissionList
,
// 所有的权限列表 v1.25.0版本添加
}
}
export
default
getters
;
export
default
getters
;
\ No newline at end of file
\ No newline at end of file
src/store/modules/menu.js
View file @
996dad7
...
@@ -4,94 +4,102 @@ let state = {
...
@@ -4,94 +4,102 @@ let state = {
curBreadCrumb
:
[],
curBreadCrumb
:
[],
updateMenu
:
false
,
updateMenu
:
false
,
curMenuAuth
:
[],
curMenuAuth
:
[],
menuList
:[],
//菜单数据
menuList
:
[],
//菜单数据
permissionList
:
[],
// 权限列表 v1.25.0版本添加
};
};
let
init
=
false
;
let
init
=
false
;
try
{
try
{
const
breadCrumbStorage
=
localStorage
.
getItem
(
'breadcrumb'
);
const
breadCrumbStorage
=
localStorage
.
getItem
(
"breadcrumb"
);
if
(
breadCrumbStorage
)
{
if
(
breadCrumbStorage
)
{
state
.
curBreadCrumb
=
JSON
.
parse
(
breadCrumbStorage
);
state
.
curBreadCrumb
=
JSON
.
parse
(
breadCrumbStorage
);
init
=
true
;
init
=
true
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{}
}
const
checkRepeatedData
=
(
data
,
type
)
=>
{
const
checkRepeatedData
=
(
data
,
type
)
=>
{
let
arr
=
[];
let
arr
=
[];
let
newArr
=
[];
let
newArr
=
[];
data
.
forEach
(
item
=>
{
data
.
forEach
(
(
item
)
=>
{
if
(
arr
.
indexOf
(
item
[
type
])
<
0
)
{
if
(
arr
.
indexOf
(
item
[
type
])
<
0
)
{
arr
.
push
(
item
[
type
]);
arr
.
push
(
item
[
type
]);
newArr
.
push
(
item
);
newArr
.
push
(
item
);
}
}
});
});
return
newArr
;
return
newArr
;
}
}
;
export
default
{
export
default
{
namespaced
:
true
,
namespaced
:
true
,
state
,
state
,
mutations
:
{
mutations
:
{
// 推入用户菜单
// 推入用户菜单
ADD_USER_MENU
(
state
,
data
)
{
ADD_USER_MENU
(
state
,
data
)
{
state
.
menu
=
data
;
state
.
menu
=
data
;
},
},
// 设置折叠状态
// 设置折叠状态
SET_COLLAPSE_STATUS
(
state
,
data
)
{
SET_COLLAPSE_STATUS
(
state
,
data
)
{
state
.
is_collapse
=
data
;
state
.
is_collapse
=
data
;
},
},
// 设置面包屑
// 设置面包屑
SET_BREAD_CRUMB
(
state
,
data
)
{
SET_BREAD_CRUMB
(
state
,
data
)
{
state
.
curBreadCrumb
=
checkRepeatedData
(
data
,
'name'
);
state
.
curBreadCrumb
=
checkRepeatedData
(
data
,
"name"
);
state
.
curBreadCrumb
=
JSON
.
parse
(
JSON
.
stringify
(
state
.
curBreadCrumb
));
state
.
curBreadCrumb
=
JSON
.
parse
(
JSON
.
stringify
(
state
.
curBreadCrumb
));
localStorage
.
setItem
(
'breadcrumb'
,
JSON
.
stringify
(
state
.
curBreadCrumb
));
localStorage
.
setItem
(
"breadcrumb"
,
JSON
.
stringify
(
state
.
curBreadCrumb
));
},
},
ADD_BREAD_CRUMB
(
state
,
data
)
{
ADD_BREAD_CRUMB
(
state
,
data
)
{
if
(
!
init
)
{
if
(
!
init
)
{
let
joinData
=
[...
state
.
curBreadCrumb
,
...
data
];
let
joinData
=
[...
state
.
curBreadCrumb
,
...
data
];
state
.
curBreadCrumb
=
joinData
;
state
.
curBreadCrumb
=
joinData
;
localStorage
.
setItem
(
'breadcrumb'
,
JSON
.
stringify
(
joinData
));
localStorage
.
setItem
(
"breadcrumb"
,
JSON
.
stringify
(
joinData
));
}
init
=
false
;
},
// 子系统操作更新菜单
UPDATE_MENU
(
state
,
data
)
{
state
.
updateMenu
=
data
;
},
// 菜单权限
SET_MENU_AUTH
(
state
,
data
)
{
state
.
curMenuAuth
=
data
;
},
// 存入菜单数据
SET_MENU_LIST
(
state
,
data
){
state
.
menuList
=
data
;
}
}
init
=
false
;
},
// 子系统操作更新菜单
UPDATE_MENU
(
state
,
data
)
{
state
.
updateMenu
=
data
;
},
// 菜单权限
SET_MENU_AUTH
(
state
,
data
)
{
state
.
curMenuAuth
=
data
;
},
// 存入菜单数据
SET_MENU_LIST
(
state
,
data
)
{
state
.
menuList
=
data
;
},
},
actions
:
{
// 推入用户菜单
setUserMenu
({
commit
},
data
)
{
commit
(
'ADD_USER_MENU'
,
data
)
},
// 设置折叠状态
setCollapseStatus
({
commit
},
data
)
{
commit
(
'SET_COLLAPSE_STATUS'
,
data
)
},
// 设置面包屑
setBreadCrumb
({
commit
},
data
)
{
commit
(
'SET_BREAD_CRUMB'
,
data
)
},
addBreadCrumb
({
commit
},
data
)
{
commit
(
'ADD_BREAD_CRUMB'
,
data
)
},
// 子系统操作更新菜单
updateMenu
({
commit
},
data
)
{
commit
(
'UPDATE_MENU'
,
data
)
},
setMenuAuth
({
commit
},
data
)
{
commit
(
'SET_MENU_AUTH'
,
data
)
},
}
}
\ No newline at end of file
\ No newline at end of file
// 存入权限列表数据 v1.25.0版本添加
SET_PERMISSION_LIST
(
state
,
data
)
{
state
.
permissionList
=
data
;
},
},
actions
:
{
// 推入用户菜单
setUserMenu
({
commit
},
data
)
{
commit
(
"ADD_USER_MENU"
,
data
);
},
// 设置折叠状态
setCollapseStatus
({
commit
},
data
)
{
commit
(
"SET_COLLAPSE_STATUS"
,
data
);
},
// 设置面包屑
setBreadCrumb
({
commit
},
data
)
{
commit
(
"SET_BREAD_CRUMB"
,
data
);
},
addBreadCrumb
({
commit
},
data
)
{
commit
(
"ADD_BREAD_CRUMB"
,
data
);
},
// 子系统操作更新菜单
updateMenu
({
commit
},
data
)
{
commit
(
"UPDATE_MENU"
,
data
);
},
setMenuAuth
({
commit
},
data
)
{
commit
(
"SET_MENU_AUTH"
,
data
);
},
// 触发存入权限数据方法
setPermissionList
({
commit
},
data
)
{
commit
(
"SET_PERMISSION_LIST"
,
data
);
},
},
};
src/utils/common/common.js
View file @
996dad7
import
store
from
'@/store/index'
import
store
from
"@/store/index"
;
import
MenuService
from
"services/Menu"
;
import
MenuService
from
"services/Menu"
;
export
const
Common
=
{
export
const
Common
=
{
setAuthBtn
(
resData
)
{
setAuthBtn
(
resData
)
{
let
data
=
resData
||
store
.
getters
.
curMenuAuth
.
data
let
data
=
resData
||
store
.
getters
.
curMenuAuth
.
data
;
//console.log('setAuthBtn', data)
//console.log('setAuthBtn', data)
const
authBtnEl
=
document
.
getElementsByTagName
(
'button'
)
const
authBtnEl
=
document
.
getElementsByTagName
(
"button"
);
const
authStringArr
=
[
'新增'
,
'编辑'
,
'删除'
,
'导出'
,
'导入'
,
'修改'
,
'解绑'
,
'选择试驾车辆'
,
'新增车辆'
,
'查看'
]
const
authStringArr
=
[
"新增"
,
"编辑"
,
"删除"
,
"导出"
,
"导入"
,
"修改"
,
"解绑"
,
"选择试驾车辆"
,
"新增车辆"
,
"查看"
,
];
if
(
authBtnEl
&&
authBtnEl
.
length
>
0
)
{
if
(
authBtnEl
&&
authBtnEl
.
length
>
0
)
{
if
(
data
&&
data
.
length
>
0
)
{
if
(
data
&&
data
.
length
>
0
)
{
authBtnEl
.
forEach
(
elItem
=>
{
authBtnEl
.
forEach
(
(
elItem
)
=>
{
let
flag
=
true
let
flag
=
true
;
let
authFlag
=
false
let
authFlag
=
false
;
const
elText
=
elItem
.
innerText
const
elText
=
elItem
.
innerText
;
authStringArr
.
forEach
(
authItem
=>
{
authStringArr
.
forEach
(
(
authItem
)
=>
{
if
(
elText
.
includes
(
authItem
))
{
if
(
elText
.
includes
(
authItem
))
{
authFlag
=
true
authFlag
=
true
;
return
return
;
}
}
})
})
;
if
(
authFlag
)
{
if
(
authFlag
)
{
data
.
forEach
(
labelItem
=>
{
data
.
forEach
(
(
labelItem
)
=>
{
if
(
flag
)
{
if
(
flag
)
{
elItem
.
style
.
display
=
'none'
elItem
.
style
.
display
=
"none"
;
if
(
elText
.
includes
(
labelItem
.
label
))
{
if
(
elText
.
includes
(
labelItem
.
label
))
{
elItem
.
style
.
display
=
'inline-block'
elItem
.
style
.
display
=
"inline-block"
;
flag
=
false
flag
=
false
;
}
}
}
}
})
})
;
}
}
})
})
;
}
}
}
}
},
},
getAuthData
()
{
getAuthData
()
{
return
store
.
getters
.
curMenuAuth
.
data
||
[]
return
store
.
getters
.
curMenuAuth
.
data
||
[]
;
},
},
// 获取二级菜单权限
// 获取二级菜单权限
...
@@ -47,67 +58,71 @@ export const Common = {
...
@@ -47,67 +58,71 @@ export const Common = {
store
.
dispatch
(
"menu/setMenuAuth"
,
{
menuName
,
data
});
store
.
dispatch
(
"menu/setMenuAuth"
,
{
menuName
,
data
});
}
}
},
},
(
err
)
=>
{
}
(
err
)
=>
{}
);
);
},
},
// 动态设置面包屑
// 动态设置面包屑
setBreadCrumbs
(
url
)
{
setBreadCrumbs
(
url
)
{
let
list
=
store
.
state
.
menu
.
menuList
;
let
list
=
store
.
state
.
menu
.
menuList
;
let
m
=
''
let
m
=
""
;
if
(
!
url
)
{
if
(
!
url
)
{
return
false
;
return
false
;
}
}
let
o
=
list
.
find
(
k
=>
{
let
o
=
list
.
find
(
(
k
)
=>
{
let
n
=
(
k
.
children
||
[]).
find
(
j
=>
j
.
origin
.
frontRoute
==
url
);
let
n
=
(
k
.
children
||
[]).
find
(
(
j
)
=>
j
.
origin
.
frontRoute
==
url
);
if
(
n
)
{
if
(
n
)
{
m
=
n
;
m
=
n
;
return
k
return
k
;
}
}
})
})
;
let
arr
=
[]
let
arr
=
[]
;
// 一级菜单
// 一级菜单
if
(
o
)
{
if
(
o
)
{
arr
.
push
({
name
:
o
.
label
,
path
:
o
.
origin
.
frontRoute
})
arr
.
push
({
name
:
o
.
label
,
path
:
o
.
origin
.
frontRoute
})
;
}
}
// 二级菜单
// 二级菜单
if
(
m
)
{
if
(
m
)
{
arr
.
push
({
name
:
m
.
label
,
path
:
m
.
origin
.
frontRoute
})
arr
.
push
({
name
:
m
.
label
,
path
:
m
.
origin
.
frontRoute
})
;
}
}
// 控制菜单展开
// 控制菜单展开
if
(
o
&&
m
)
{
if
(
o
&&
m
)
{
list
.
map
(
k
=>
{
list
.
map
(
(
k
)
=>
{
if
(
k
.
label
==
o
.
label
)
{
if
(
k
.
label
==
o
.
label
)
{
k
.
showSubList
=
true
k
.
showSubList
=
true
;
}
else
{
}
else
{
k
.
showSubList
=
false
;
k
.
showSubList
=
false
;
}
}
(
k
.
children
||
[]).
map
(
j
=>
{
(
k
.
children
||
[]).
map
(
(
j
)
=>
{
if
(
j
.
origin
.
frontRoute
==
m
.
origin
.
frontRoute
)
{
if
(
j
.
origin
.
frontRoute
==
m
.
origin
.
frontRoute
)
{
j
.
subItemActive
=
true
j
.
subItemActive
=
true
;
}
else
{
}
else
{
j
.
subItemActive
=
false
;
j
.
subItemActive
=
false
;
}
}
})
})
;
})
})
;
}
}
store
.
dispatch
(
"menu/setBreadCrumb"
,
arr
);
store
.
dispatch
(
"menu/setBreadCrumb"
,
arr
);
store
.
commit
(
'menu/SET_MENU_LIST'
,
list
)
store
.
commit
(
"menu/SET_MENU_LIST"
,
list
);
},
},
// 公共页面跳转方法
// 公共页面跳转方法
navigateTo
:
function
(
options
){
navigateTo
:
function
(
options
)
{},
},
// 判断是否有权限
// 判断是否有权限
hasPermission
:
function
(
pid
){
let
list
=
Common
.
getAuthData
()
hasPermission
:
function
(
pid
,
checkAll
)
{
let
list
=
Common
.
getAuthData
();
// 针对所有页面的权限按钮,为了兼容一个权限按钮控制多个页面 v1.25.0版本需求添加
if
(
checkAll
)
{
list
=
state
.
store
.
getters
.
permissionList
.
data
||
[];
}
console
.
log
(
list
);
if
(
!
list
||
list
.
length
<=
0
)
{
if
(
!
list
||
list
.
length
<=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -118,6 +133,18 @@ export const Common = {
...
@@ -118,6 +133,18 @@ export const Common = {
return
true
;
return
true
;
}
}
},
},
// 全局判断是否有权限(针对所有页面的权限按钮,为了兼容一个权限按钮控制多个页面) v1.25.0版本需求添加
isPermission
:
function
()
{},
// 隐藏菜单和header的路由
// 隐藏菜单和header的路由
hiddenMenu
:
[
'/monitor/activeLocation'
,
'/monitor/resident'
,
'/monitor/monitor'
,
'/monitor/fence'
,
'/monitor/replay'
,
'/monitor/historyLocation'
,
'monitor/zoneCar'
]
hiddenMenu
:
[
}
"/monitor/activeLocation"
,
"/monitor/resident"
,
"/monitor/monitor"
,
"/monitor/fence"
,
"/monitor/replay"
,
"/monitor/historyLocation"
,
"monitor/zoneCar"
,
],
};
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment