Commit 5c740f5e by 冒粤蓉

improve menu

1 parent 121f9837
...@@ -113,6 +113,11 @@ export default { ...@@ -113,6 +113,11 @@ export default {
return path && path.includes('system') ? path : '/noData'; return path && path.includes('system') ? path : '/noData';
} }
// 存储面包屑
const saveBreadCrumbFunc = (data) => {
store.dispatch('menu/setBreadCrumb', data);
}
// 点击三级菜单做存储 // 点击三级菜单做存储
const subMenuClicked = (thisItem, parentItem, item) => { const subMenuClicked = (thisItem, parentItem, item) => {
let showEmpty = false; let showEmpty = false;
...@@ -140,7 +145,8 @@ export default { ...@@ -140,7 +145,8 @@ export default {
active: true, active: true,
} }
}; };
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
saveBreadCrumbFunc(state.curBreadCrumb);
let path = filterPath(thisOrigin.frontRoute); let path = filterPath(thisOrigin.frontRoute);
if(path === '/noData') { if(path === '/noData') {
...@@ -173,7 +179,7 @@ export default { ...@@ -173,7 +179,7 @@ export default {
active: true active: true
}; };
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb)); saveBreadCrumbFunc(state.curBreadCrumb);
path = filterPath(path); path = filterPath(path);
if(path === '/noData') { if(path === '/noData') {
...@@ -259,68 +265,70 @@ export default { ...@@ -259,68 +265,70 @@ export default {
const resData = res.data; const resData = res.data;
// const getNewTree = getMenuTree(res.data, menuTreeLocalList) // const getNewTree = getMenuTree(res.data, menuTreeLocalList)
state.menuList = resData; state.menuList = resData;
// 初始化操作 // 初始化操作
const firstParent = resData[0].origin, const firstParent = resData[0].origin ? resData[0].origin : {},
firstChildren = resData[0].children[0].origin; firstChildren = resData[0].children.length > 0 ? resData[0].children[0].origin : {};
let showEmpty = false; let showEmpty = false;
// 同步面包屑 // 同步面包屑
const getBreadCrumb = store.getters.curBreadCrumb; const getBreadCrumb = store.getters.curBreadCrumb;
const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren; const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren;
let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent, let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent,
childrenMenuName = getCurChildren.menuName, childrenMenuName = getCurChildren.menuName,
childrenPath = getCurChildren.path || '', childrenPath = getCurChildren.path || '',
getCurNextChildren = getCurChildren.children; getCurNextChildren = getCurChildren.children;
if(isInit) { if(isInit) {
state.curBreadCrumb.parent = { state.curBreadCrumb.parent = {
menuName: getCurParent.menuName, menuName: getCurParent.menuName,
path: getCurParent.path path: getCurParent.path
}; };
let getCurNextChildrenArr = { let getCurNextChildrenArr = {
menuName: childrenMenuName, menuName: childrenMenuName,
path: childrenPath, path: childrenPath,
active: true
};
if(getCurNextChildren) {
getCurNextChildrenArr.active = false;
getCurNextChildrenArr.children = {
menuName: getCurNextChildren.menuName,
path: getCurNextChildren.path,
active: true active: true
}; };
if(getCurNextChildren) {
getCurNextChildrenArr.active = false;
getCurNextChildrenArr.children = {
menuName: getCurNextChildren.menuName,
path: getCurNextChildren.path,
active: true
};
}
state.curBreadCrumb.children = getCurNextChildrenArr;
} }
state.curBreadCrumb.children = getCurNextChildrenArr;
}
// 同步激活样式 // 同步激活样式
resData.forEach((item, index) => { resData.forEach((item, index) => {
item.showSubList = item.origin.menuName == getCurParent.menuName ? 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; cItem.showSubList = cItem.origin.menuName == childrenMenuName ? true: false;
const nextChildren = cItem.children; const nextChildren = cItem.children;
if(nextChildren && getCurNextChildren) { if(nextChildren && getCurNextChildren) {
nextChildren.forEach((nItem) => { nextChildren.forEach((nItem) => {
nItem.subItemActive = nItem.origin.menuName === getCurNextChildren.menuName ? true: false; nItem.subItemActive = nItem.origin.menuName === getCurNextChildren.menuName ? true: false;
}) })
}
})
});
if(isInit) {
if(childrenPath === '/noData' || childrenPath === '/'
|| (getCurNextChildren && getCurNextChildren.path === '/noData')
|| (getCurNextChildren && getCurNextChildren.path === '/')) {
showEmpty = true;
}
store.dispatch('app/setCommonData', { showEmpty });
let thisPath = childrenPath;
if(getCurNextChildren) {
thisPath = getCurNextChildren.path;
} }
history.pushState(null, thisPath, thisPath); })
store.dispatch('menu/setBreadCrumb', state.curBreadCrumb); });
if(isInit) {
let params = null;
if(childrenPath === '/noData' || childrenPath === '/' || childrenPath === ''
|| (getCurNextChildren && getCurNextChildren.path === '/noData')
|| (getCurNextChildren && getCurNextChildren.path === '/')) {
showEmpty = true;
}
store.dispatch('app/setCommonData', { showEmpty });
let thisPath = childrenPath;
if(getCurNextChildren) {
thisPath = getCurNextChildren.path;
params = getCurNextChildren.params ? getCurNextChildren.params : null;
} }
history.pushState(null, thisPath, thisPath);
store.dispatch('menu/setBreadCrumb', state.curBreadCrumb);
}
} }
}, err => { }, err => {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
:class="{active: item.active, pointer: item.path}" :class="{active: item.active, pointer: item.path}"
v-for="(item, index) in breadCrumbList" v-for="(item, index) in breadCrumbList"
:key="index" :key="index"
@click="routerGo(item.path || '')"> @click="routerGo(item, item.path || '/noData')">
{{item.name}} {{item.name}}
</a-breadcrumb-item> </a-breadcrumb-item>
</a-breadcrumb> </a-breadcrumb>
...@@ -50,7 +50,7 @@ export default { ...@@ -50,7 +50,7 @@ export default {
}) })
const showEmpty = computed(() => { const showEmpty = computed(() => {
return !state.el_sub_innerH || store.getters.commonData.showEmpty; return store.getters.commonData.showEmpty || !state.el_sub_innerH;
}) })
const breadCrumbList = computed(() => { const breadCrumbList = computed(() => {
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
let breadCrumbList = []; let breadCrumbList = [];
if(curParent) { if(curParent) {
breadCrumbList.push({ breadCrumbList.push({
name: curParent.menuName + ' / ' name: curChildren.menuName ? curParent.menuName + ' / ' : curParent.menuName
}); });
} }
if(curChildren) { if(curChildren) {
...@@ -68,7 +68,7 @@ export default { ...@@ -68,7 +68,7 @@ export default {
breadCrumbList.push({ breadCrumbList.push({
name: nextChildren ? curChildren.menuName + ' / ': curChildren.menuName, name: nextChildren ? curChildren.menuName + ' / ': curChildren.menuName,
path: curChildren.path, path: curChildren.path,
active: curChildren.active active: nextChildren ? false : true
}); });
if(nextChildren) { if(nextChildren) {
breadCrumbList.push({ breadCrumbList.push({
...@@ -78,18 +78,46 @@ export default { ...@@ -78,18 +78,46 @@ export default {
}); });
} }
} }
return breadCrumbList; return breadCrumbList;
}) })
const routerGo = (path) => {
// history.pushState(null, path, path); const routerGo = (item, path) => {
let saveBreadCrumb = {};
const thisName = item.name.replace(' / ', '');
const curBreadCrumb = store.getters.curBreadCrumb,
curParent = curBreadCrumb['parent'],
curChildren = curBreadCrumb['children'];
if(thisName === curParent.menuName) {
saveBreadCrumb.parent = curParent;
saveBreadCrumb.children = {};
return false;
}
if(curChildren) {
const nextChildren = curChildren.children;
if(thisName === curChildren.menuName) {
saveBreadCrumb.parent = curParent;
if(nextChildren) {
delete curChildren.children;
}
saveBreadCrumb.children = curChildren;
} else {
if(thisName === nextChildren.menuName) {
saveBreadCrumb = curBreadCrumb;
}
}
}
store.dispatch('menu/setBreadCrumb', saveBreadCrumb);
history.pushState(null, path, path);
} }
return { return {
...toRefs(state),
breadCrumbList, breadCrumbList,
elmSubMicro, elmSubMicro,
showEmpty showEmpty,
// routerGo routerGo
} }
} }
} }
......
...@@ -29,6 +29,7 @@ export default { ...@@ -29,6 +29,7 @@ export default {
// 设置面包屑 // 设置面包屑
SET_BREAD_CRUMB(state, data) { SET_BREAD_CRUMB(state, data) {
state.curBreadCrumb = data; state.curBreadCrumb = data;
localStorage.setItem('breadCrumb', JSON.stringify(data));
}, },
// 子系统操作更新菜单 // 子系统操作更新菜单
UPDATE_MENU(state, data) { UPDATE_MENU(state, data) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!