Commit 8c283f3a by 冒粤蓉

improve menu

1 parent b9bcab4c
...@@ -31,6 +31,5 @@ ...@@ -31,6 +31,5 @@
"> 1%", "> 1%",
"last 2 versions", "last 2 versions",
"not dead" "not dead"
], ]
"proxy": "https://baidu.com"
} }
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
:class="{'ant-menu-submenu-open': item.showSubList}" :class="{'ant-menu-submenu-open': item.showSubList}"
v-for="item in menuList" v-for="item in menuList"
:key="item.origin.menuNo" :key="item.origin.menuNo"
@click="titleClick(item, $event)" > @click="titleClick(item)" >
<div class="ant-menu-submenu-title" style="padding-left: 24px;"> <div class="ant-menu-submenu-title" style="padding-left: 24px;">
<DesktopOutlined v-if="item.origin.icon === 'DesktopOutlined'" /> <DesktopOutlined v-if="item.origin.icon === 'DesktopOutlined'" />
<CarOutlined v-if="item.origin.icon === 'CarOutlined'" /> <CarOutlined v-if="item.origin.icon === 'CarOutlined'" />
<SettingOutlined v-if="!item.origin.icon" /> <SettingOutlined v-if="!item.origin.icon" />
<span>{{item.origin.menuName}}</span> <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> </div>
<!-- ant-menu-item-selected ant-menu-item-active --> <!-- ant-menu-item-selected ant-menu-item-active -->
...@@ -21,14 +21,41 @@ ...@@ -21,14 +21,41 @@
<ul class="ant-menu-sub ant-menu ant-menu-inline" <ul class="ant-menu-sub ant-menu ant-menu-inline"
v-if="item.showSubList" v-if="item.showSubList"
> >
<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" <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}" :class="{'ant-menu-item-selected': cItem.subItemActive}"
style="padding-left: 48px;" style="padding-left: 48px;"
v-for="cItem in item.children"
:key="cItem.origin.menuNo"
@click.stop="cItemClick(cItem.origin.path || '', cItem, item)"> @click.stop="cItemClick(cItem.origin.path || '', cItem, item)">
{{cItem.origin.menuName}} {{cItem.origin.menuName}}
</li> </li>
</template>
</ul> </ul>
</li> </li>
</ul> </ul>
...@@ -58,54 +85,131 @@ export default { ...@@ -58,54 +85,131 @@ export default {
SettingOutlined, SettingOutlined,
}, },
setup(props, context) { setup(props, context) {
const { ctx } = getCurrentInstance();
const store = useStore(); const store = useStore();
const state = reactive({ const state = reactive({
menuList: menuTreeLocalList, menuList: menuTreeLocalList,
curMainTitle: '',
curBreadCrumb: { curBreadCrumb: {
parent: {}, parent: {},
children: [] children: []
} }
}); });
console.log('ctx', ctx);
// 点击主菜单标题 // 点击主菜单标题
const titleClick = (item, e) => { const titleClick = (item) => {
item.showSubList = !item.showSubList; 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 cItemClick = (path, cItem, parentItem) => {
const cOrigin = cItem.origin; const cOrigin = cItem.origin;
const pOrigin = parentItem.origin;
let showEmpty = false; let showEmpty = false;
// 激活active类
// 高亮被选中的标题
state.menuList.forEach(ele => { state.menuList.forEach(ele => {
const children = ele.children; const children = ele.children;
children.forEach(cEle => { setActive(children);
cEle.subItemActive = false;
})
}) })
cItem.subItemActive = true; cItem.subItemActive = true;
state.curBreadCrumb.parent['menuName'] = parentItem.origin.menuName; state.curBreadCrumb.parent = {
state.curBreadCrumb.children = [{ menuName: pOrigin.menuName,
path: pOrigin.path || '/noData'
}
state.curBreadCrumb.children = {
menuName: cOrigin.menuName, menuName: cOrigin.menuName,
path: cOrigin.path || '/404', path: cOrigin.path || '/noData',
active: true active: true
}]; };
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb)); localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
path = path ? path : '/404'; path = path ? path : '/noData';
if(path === '/404') { if(path === '/noData') {
showEmpty = true; showEmpty = true;
} }
store.dispatch('app/setCommonData', { showEmpty }); store.dispatch('app/setCommonData', { showEmpty });
history.pushState(null, path, path); 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) => { const mergeData = (server, localArr) => {
var serverMenuNo = server.origin.menuNo; var serverMenuNo = server.origin.menuNo;
...@@ -121,18 +225,8 @@ export default { ...@@ -121,18 +225,8 @@ export default {
return server; return server;
} else { } else {
var children = []; var children = [];
for (const key in server.children) { if(server.children) {
var sMenuNo = server.children[key].origin.menuNo; children = getChildrenArr(server, localEle);
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});
}
}
} }
return {origin: localEle.origin, 'children': children} return {origin: localEle.origin, 'children': children}
} }
...@@ -140,7 +234,7 @@ export default { ...@@ -140,7 +234,7 @@ export default {
// 遍历菜单列表并合并 // 遍历菜单列表并合并
const getMenuTree = (serverArr, localArr) => { const getMenuTree = (serverArr, localArr) => {
var arr = [] var arr = [];
for (const key in serverArr) { for (const key in serverArr) {
arr.push(mergeData(serverArr[key], localArr)); arr.push(mergeData(serverArr[key], localArr));
} }
...@@ -165,36 +259,57 @@ export default { ...@@ -165,36 +259,57 @@ export default {
state.menuList = getNewTree; 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 getBreadCrumb = store.getters.curBreadCrumb;
const breadChildren = getBreadCrumb.children ? getBreadCrumb.children[0] : firstChildren; const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren;
let parentMenuName = getBreadCrumb.parent ? getBreadCrumb.parent.menuName : firstParent.menuName, let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent,
childrenMenuName = breadChildren.menuName, childrenMenuName = getCurChildren.menuName,
childrenPath = breadChildren.path || firstChildren.path || ''; childrenPath = getCurChildren.path || '',
state.curBreadCrumb.parent['menuName'] = parentMenuName; getCurNextChildren = getCurChildren.children;
state.curBreadCrumb.children.push({ state.curBreadCrumb.parent = {
menuName: getCurParent.menuName,
path: getCurParent.path
};
let getCurNextChildrenArr = {
menuName: childrenMenuName, menuName: childrenMenuName,
path: childrenPath, path: childrenPath,
active: true 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) => { 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) => { item.children.forEach((cItem, cIndex) => {
cItem.subItemActive = cItem.origin.menuName === childrenMenuName ? true: false; 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; showEmpty = true;
} }
store.dispatch('app/setCommonData', { showEmpty }); store.dispatch('app/setCommonData', { showEmpty });
let thisPath = childrenPath;
history.pushState(null, childrenPath, childrenPath); if(getCurNextChildren) {
thisPath = getCurNextChildren.path;
}
history.pushState(null, thisPath, thisPath);
store.dispatch('menu/setBreadCrumb', state.curBreadCrumb); store.dispatch('menu/setBreadCrumb', state.curBreadCrumb);
} }
}, err => { }, err => {
...@@ -209,7 +324,8 @@ export default { ...@@ -209,7 +324,8 @@ export default {
return { return {
...toRefs(state), ...toRefs(state),
titleClick, titleClick,
cItemClick cItemClick,
subMenuClicked
} }
} }
......
...@@ -63,23 +63,20 @@ export default { ...@@ -63,23 +63,20 @@ export default {
name: curParent.menuName + ' / ' name: curParent.menuName + ' / '
}); });
} }
if(curChildren && curChildren.length > 0) { if(curChildren) {
curChildren.forEach((item, index, arr) => { const nextChildren = curChildren.children;
if(index === arr.length - 1) {
breadCrumbList.push({ breadCrumbList.push({
name: item.menuName, name: nextChildren ? curChildren.menuName + ' / ': curChildren.menuName,
path: item.path, path: curChildren.path,
active: item.active active: curChildren.active
}); });
} else { if(nextChildren) {
breadCrumbList.push({ breadCrumbList.push({
name: item.menuName + ' / ', name: nextChildren.menuName,
path: item.path, path: nextChildren.path,
active: item.active active: nextChildren.active
}); });
} }
});
} }
return breadCrumbList; return breadCrumbList;
}) })
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
const menuTree = [ const menuTree = [
{ {
origin: { origin: {
parentId: 0,
menuName: "设备管理", menuName: "设备管理",
menuNo: 201, menuNo: 201,
type: 1, type: 1,
...@@ -14,7 +13,6 @@ const menuTree = [ ...@@ -14,7 +13,6 @@ const menuTree = [
children: [ children: [
{ {
origin: { origin: {
parentId: 201,
menuName: "ODB管理", menuName: "ODB管理",
menuNo: 20101, menuNo: 20101,
type: 2, type: 2,
...@@ -25,7 +23,6 @@ const menuTree = [ ...@@ -25,7 +23,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 0,
menuName: "系统管理", menuName: "系统管理",
menuNo: 101, menuNo: 101,
type: 1, type: 1,
...@@ -34,7 +31,6 @@ const menuTree = [ ...@@ -34,7 +31,6 @@ const menuTree = [
children: [ children: [
{ {
origin: { origin: {
parentId: 101,
menuName: "用户管理", menuName: "用户管理",
menuNo: 10101, menuNo: 10101,
type: 2, type: 2,
...@@ -43,16 +39,6 @@ const menuTree = [ ...@@ -43,16 +39,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 101,
menuName: "用户组管理",
menuNo: 10102,
type: 2,
path: '/404'
}
},
{
origin: {
parentId: 101,
menuName: "角色管理", menuName: "角色管理",
menuNo: 10103, menuNo: 10103,
type: 2, type: 2,
...@@ -61,7 +47,6 @@ const menuTree = [ ...@@ -61,7 +47,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 101,
menuName: "菜单管理", menuName: "菜单管理",
menuNo: 10104, menuNo: 10104,
type: 2, type: 2,
...@@ -70,7 +55,6 @@ const menuTree = [ ...@@ -70,7 +55,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 101,
menuName: "组织管理", menuName: "组织管理",
menuNo: 10105, menuNo: 10105,
type: 2, type: 2,
...@@ -79,7 +63,6 @@ const menuTree = [ ...@@ -79,7 +63,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 101,
menuName: "字典管理", menuName: "字典管理",
menuNo: 10106, menuNo: 10106,
type: 2, type: 2,
...@@ -88,7 +71,6 @@ const menuTree = [ ...@@ -88,7 +71,6 @@ const menuTree = [
}, },
{ {
origin: { origin: {
parentId: 101,
menuName: "操作日志", menuName: "操作日志",
menuNo: 10107, menuNo: 10107,
type: 2, type: 2,
......
...@@ -37,34 +37,7 @@ module.exports = { ...@@ -37,34 +37,7 @@ module.exports = {
.set("components", resolve("src/components")) .set("components", resolve("src/components"))
.set("config", resolve("src/config")) .set("config", resolve("src/config"))
.set("utils", resolve("src/utils")) .set("utils", resolve("src/utils"))
.set("services", resolve("src/services")); .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
// }
// }
// })
}, },
css: { css: {
loaderOptions: { loaderOptions: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!