Commit 8c283f3a by 冒粤蓉

improve menu

1 parent b9bcab4c
......@@ -31,6 +31,5 @@
"> 1%",
"last 2 versions",
"not dead"
],
"proxy": "https://baidu.com"
]
}
......@@ -7,13 +7,13 @@
:class="{'ant-menu-submenu-open': item.showSubList}"
v-for="item in menuList"
:key="item.origin.menuNo"
@click="titleClick(item, $event)" >
@click="titleClick(item)" >
<div class="ant-menu-submenu-title" style="padding-left: 24px;">
<DesktopOutlined v-if="item.origin.icon === 'DesktopOutlined'" />
<CarOutlined v-if="item.origin.icon === 'CarOutlined'" />
<SettingOutlined v-if="!item.origin.icon" />
<span>{{item.origin.menuName}}</span>
<i class="ant-menu-submenu-arrow" v-if="item.children.length > 0"></i>
<i class="ant-menu-submenu-arrow"></i>
</div>
<!-- ant-menu-item-selected ant-menu-item-active -->
......@@ -21,14 +21,41 @@
<ul class="ant-menu-sub ant-menu ant-menu-inline"
v-if="item.showSubList"
>
<li class="ant-menu-item"
:class="{'ant-menu-item-selected': cItem.subItemActive}"
style="padding-left: 48px;"
v-for="cItem in item.children"
:key="cItem.origin.menuNo"
@click.stop="cItemClick(cItem.origin.path || '', cItem, item)">
{{cItem.origin.menuName}}
</li>
<template v-for="cItem in item.children"
:key="cItem.origin.menuNo">
<!-- 三级菜单 -->
<li v-if="cItem.children && cItem.children.length > 0"
class="ant-menu-submenu ant-menu-submenu-inline"
:class="{'ant-menu-submenu-open': cItem.showSubList}"
@click.stop="cItemClick(cItem.origin.path || '', cItem, item)">
<div aria-haspopup="true"
@click="titleClick(cItem)"
title="Submenu" class="ant-menu-submenu-title"
aria-expanded="true"
aria-owns="sub3$Menu" style="padding-left: 48px;">
{{cItem.origin.menuName}}
<i class="ant-menu-submenu-arrow"></i>
</div>
<template v-if="cItem.showSubList">
<ul class="ant-menu ant-menu-inline ant-menu-sub"
v-for="thirdChildrenItem in cItem.children"
:key="thirdChildrenItem.origin.menuNo">
<li class="ant-menu-item"
:class="{'ant-menu-item-selected': thirdChildrenItem.subItemActive}"
style="padding-left: 72px;"
@click.stop="subMenuClicked(thirdChildrenItem, cItem, item)">{{thirdChildrenItem.origin.menuName}}</li>
</ul>
</template>
</li>
<!-- 二级菜单 -->
<li v-else
class="ant-menu-item"
:class="{'ant-menu-item-selected': cItem.subItemActive}"
style="padding-left: 48px;"
@click.stop="cItemClick(cItem.origin.path || '', cItem, item)">
{{cItem.origin.menuName}}
</li>
</template>
</ul>
</li>
</ul>
......@@ -58,54 +85,131 @@ export default {
SettingOutlined,
},
setup(props, context) {
const { ctx } = getCurrentInstance();
const store = useStore();
const state = reactive({
menuList: menuTreeLocalList,
curMainTitle: '',
curBreadCrumb: {
parent: {},
children: []
}
});
console.log('ctx', ctx);
// 点击主菜单标题
const titleClick = (item, e) => {
const titleClick = (item) => {
item.showSubList = !item.showSubList;
state.curMainTitle = item.origin.menuName;
};
// 高亮被选中的子集标题
const setActive = (arr) =>{
arr.forEach(cEle => {
cEle.subItemActive = false;
if(cEle.children) {
setActive(cEle.children);
}
})
}
// 点击三级菜单做存储
const subMenuClicked = (thisItem, parentItem, item) => {
let showEmpty = false;
const pOrigin = parentItem.origin,
thisOrigin = thisItem.origin,
itemOrigin = item.origin;
// 高亮被选中的标题
state.menuList.forEach(ele => {
const children = ele.children;
setActive(children);
})
thisItem.subItemActive = true;
state.curBreadCrumb.parent = {
menuName: itemOrigin.menuName,
path: itemOrigin.path || '/noData'
}
state.curBreadCrumb.children = {
menuName: pOrigin.menuName,
path: pOrigin.path || '/noData',
active: false,
children: {
menuName: thisOrigin.menuName,
path: thisOrigin.path || '/noData',
active: true,
}
};
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
let path = thisOrigin.path ? thisOrigin.path : '/noData';
if(path === '/noData') {
showEmpty = true;
}
store.dispatch('app/setCommonData', { showEmpty });
history.pushState(null, path, path);
}
// 点击二级菜单标题
const cItemClick = (path, cItem, parentItem) => {
const cOrigin = cItem.origin;
const pOrigin = parentItem.origin;
let showEmpty = false;
// 激活active类
// 高亮被选中的标题
state.menuList.forEach(ele => {
const children = ele.children;
children.forEach(cEle => {
cEle.subItemActive = false;
})
setActive(children);
})
cItem.subItemActive = true;
state.curBreadCrumb.parent['menuName'] = parentItem.origin.menuName;
state.curBreadCrumb.children = [{
state.curBreadCrumb.parent = {
menuName: pOrigin.menuName,
path: pOrigin.path || '/noData'
}
state.curBreadCrumb.children = {
menuName: cOrigin.menuName,
path: cOrigin.path || '/404',
path: cOrigin.path || '/noData',
active: true
}];
};
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
path = path ? path : '/404';
if(path === '/404') {
path = path ? path : '/noData';
if(path === '/noData') {
showEmpty = true;
}
store.dispatch('app/setCommonData', { showEmpty });
history.pushState(null, path, path);
}
// 遍历多个子级
const getChildrenArr = (server, localEle) => {
var children = [];
const serverChildren = server.children;
const localChildren = localEle.children;
for (const key1 in serverChildren) {
var sMenuNo = serverChildren[key1].origin.menuNo;
var serverNextChildren = serverChildren[key1].children;
if(localChildren) {
for (const key2 in localChildren) {
let nextChildren = [];
var localChildrenEle = localChildren[key2].origin;
var localNextChildren = localChildren[key2].children;
if(serverNextChildren) {
nextChildren = getChildrenArr(serverChildren[key1], localChildren[key2]);
}
if(sMenuNo == localChildrenEle.menuNo) {
children.push({origin: localChildrenEle, children: nextChildren});
break;
}
if (key2 == localChildren.length - 1) {
children.push({origin: serverChildren[key1].origin, children: nextChildren});
}
}
} else {
children.push({ origin: serverChildren[key1].origin, children: serverNextChildren });
}
}
return children;
}
// 合并本地和后台返回的菜单数据
const mergeData = (server, localArr) => {
var serverMenuNo = server.origin.menuNo;
......@@ -121,18 +225,8 @@ export default {
return server;
} else {
var children = [];
for (const key in server.children) {
var sMenuNo = server.children[key].origin.menuNo;
for (const key in localEle.children) {
var localChildrenEle = localEle.children[key].origin;
if(sMenuNo == localChildrenEle.menuNo) {
children.push({origin: localChildrenEle});
break;
}
if (key == localEle.children.length - 1) {
children.push({origin: server.children[key].origin});
}
}
if(server.children) {
children = getChildrenArr(server, localEle);
}
return {origin: localEle.origin, 'children': children}
}
......@@ -140,7 +234,7 @@ export default {
// 遍历菜单列表并合并
const getMenuTree = (serverArr, localArr) => {
var arr = []
var arr = [];
for (const key in serverArr) {
arr.push(mergeData(serverArr[key], localArr));
}
......@@ -165,36 +259,57 @@ export default {
state.menuList = getNewTree;
// 同步面包屑
// const getBreadCrumb = JSON.parse(localStorage.getItem('breadCrumb'));
// const breadChildren = getBreadCrumb ? getBreadCrumb.children[0] : '';
// let parentMenuName = getBreadCrumb ? getBreadCrumb.parent.menuName : firstParent.menuName,
// childrenMenuName = breadChildren.menuName || firstChildren.menuName,
// childrenPath = breadChildren.path || firstChildren.menuName || '';
const getBreadCrumb = store.getters.curBreadCrumb;
const breadChildren = getBreadCrumb.children ? getBreadCrumb.children[0] : firstChildren;
let parentMenuName = getBreadCrumb.parent ? getBreadCrumb.parent.menuName : firstParent.menuName,
childrenMenuName = breadChildren.menuName,
childrenPath = breadChildren.path || firstChildren.path || '';
state.curBreadCrumb.parent['menuName'] = parentMenuName;
state.curBreadCrumb.children.push({
const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren;
let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent,
childrenMenuName = getCurChildren.menuName,
childrenPath = getCurChildren.path || '',
getCurNextChildren = getCurChildren.children;
state.curBreadCrumb.parent = {
menuName: getCurParent.menuName,
path: getCurParent.path
};
let getCurNextChildrenArr = {
menuName: childrenMenuName,
path: childrenPath,
active: true
});
};
if(getCurNextChildren) {
getCurNextChildrenArr.active = false;
getCurNextChildrenArr.children = {
menuName: getCurNextChildren.menuName,
path: getCurNextChildren.path,
active: true
};
}
state.curBreadCrumb.children = getCurNextChildrenArr;
// 同步激活样式
getNewTree.forEach((item, index) => {
item.showSubList = item.origin.menuName == parentMenuName ? true: false;
item.showSubList = item.origin.menuName == getCurParent.menuName ? true: false;
item.children.forEach((cItem, cIndex) => {
cItem.subItemActive = cItem.origin.menuName === childrenMenuName ? true: false;
cItem.showSubList = cItem.origin.menuName == childrenMenuName ? true: false;
const nextChildren = cItem.children;
if(nextChildren && getCurNextChildren) {
nextChildren.forEach((nItem) => {
nItem.subItemActive = nItem.origin.menuName === getCurNextChildren.menuName ? true: false;
})
}
})
});
if(childrenPath === '/404' || childrenPath === '/') {
if(childrenPath === '/noData' || childrenPath === '/'
|| getCurNextChildren.path === '/noData' || getCurNextChildren.path === '/') {
showEmpty = true;
}
store.dispatch('app/setCommonData', { showEmpty });
history.pushState(null, childrenPath, childrenPath);
let thisPath = childrenPath;
if(getCurNextChildren) {
thisPath = getCurNextChildren.path;
}
history.pushState(null, thisPath, thisPath);
store.dispatch('menu/setBreadCrumb', state.curBreadCrumb);
}
}, err => {
......@@ -209,7 +324,8 @@ export default {
return {
...toRefs(state),
titleClick,
cItemClick
cItemClick,
subMenuClicked
}
}
......
......@@ -63,23 +63,20 @@ export default {
name: curParent.menuName + ' / '
});
}
if(curChildren && curChildren.length > 0) {
curChildren.forEach((item, index, arr) => {
if(index === arr.length - 1) {
breadCrumbList.push({
name: item.menuName,
path: item.path,
active: item.active
});
} else {
breadCrumbList.push({
name: item.menuName + ' / ',
path: item.path,
active: item.active
});
}
if(curChildren) {
const nextChildren = curChildren.children;
breadCrumbList.push({
name: nextChildren ? curChildren.menuName + ' / ': curChildren.menuName,
path: curChildren.path,
active: curChildren.active
});
if(nextChildren) {
breadCrumbList.push({
name: nextChildren.menuName,
path: nextChildren.path,
active: nextChildren.active
});
}
}
return breadCrumbList;
})
......
......@@ -5,7 +5,6 @@
const menuTree = [
{
origin: {
parentId: 0,
menuName: "设备管理",
menuNo: 201,
type: 1,
......@@ -14,7 +13,6 @@ const menuTree = [
children: [
{
origin: {
parentId: 201,
menuName: "ODB管理",
menuNo: 20101,
type: 2,
......@@ -25,7 +23,6 @@ const menuTree = [
},
{
origin: {
parentId: 0,
menuName: "系统管理",
menuNo: 101,
type: 1,
......@@ -34,7 +31,6 @@ const menuTree = [
children: [
{
origin: {
parentId: 101,
menuName: "用户管理",
menuNo: 10101,
type: 2,
......@@ -43,16 +39,6 @@ const menuTree = [
},
{
origin: {
parentId: 101,
menuName: "用户组管理",
menuNo: 10102,
type: 2,
path: '/404'
}
},
{
origin: {
parentId: 101,
menuName: "角色管理",
menuNo: 10103,
type: 2,
......@@ -61,7 +47,6 @@ const menuTree = [
},
{
origin: {
parentId: 101,
menuName: "菜单管理",
menuNo: 10104,
type: 2,
......@@ -70,7 +55,6 @@ const menuTree = [
},
{
origin: {
parentId: 101,
menuName: "组织管理",
menuNo: 10105,
type: 2,
......@@ -79,7 +63,6 @@ const menuTree = [
},
{
origin: {
parentId: 101,
menuName: "字典管理",
menuNo: 10106,
type: 2,
......@@ -88,7 +71,6 @@ const menuTree = [
},
{
origin: {
parentId: 101,
menuName: "操作日志",
menuNo: 10107,
type: 2,
......
......@@ -37,34 +37,7 @@ module.exports = {
.set("components", resolve("src/components"))
.set("config", resolve("src/config"))
.set("utils", resolve("src/utils"))
.set("services", resolve("src/services"));
// config.module.rule('fonts')
// .use('url-loader')
// .loader('url-loader')
// .options({
// limit: 4096, // 小于4kb将会被打包成 base64
// fallback: {
// loader: 'file-loader',
// options: {
// name: 'fonts/[name].[hash:8].[ext]',
// publicPath
// }
// }
// })
// .end();
// config.module.rule('images')
// .use('url-loader')
// .loader('url-loader')
// .options({
// limit: 4096, // 小于4kb将会被打包成 base64
// fallback: {
// loader: 'file-loader',
// options: {
// name: 'img/[name].[hash:8].[ext]',
// publicPath
// }
// }
// })
.set("services", resolve("src/services"))
},
css: {
loaderOptions: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!