Commit 5c740f5e by 冒粤蓉

improve menu

1 parent 121f9837
......@@ -113,6 +113,11 @@ export default {
return path && path.includes('system') ? path : '/noData';
}
// 存储面包屑
const saveBreadCrumbFunc = (data) => {
store.dispatch('menu/setBreadCrumb', data);
}
// 点击三级菜单做存储
const subMenuClicked = (thisItem, parentItem, item) => {
let showEmpty = false;
......@@ -140,7 +145,8 @@ export default {
active: true,
}
};
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
saveBreadCrumbFunc(state.curBreadCrumb);
let path = filterPath(thisOrigin.frontRoute);
if(path === '/noData') {
......@@ -173,7 +179,7 @@ export default {
active: true
};
localStorage.setItem('breadCrumb', JSON.stringify(state.curBreadCrumb));
saveBreadCrumbFunc(state.curBreadCrumb);
path = filterPath(path);
if(path === '/noData') {
......@@ -259,68 +265,70 @@ export default {
const resData = res.data;
// const getNewTree = getMenuTree(res.data, menuTreeLocalList)
state.menuList = resData;
// 初始化操作
const firstParent = resData[0].origin,
firstChildren = resData[0].children[0].origin;
let showEmpty = false;
// 同步面包屑
const getBreadCrumb = store.getters.curBreadCrumb;
const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren;
let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent,
childrenMenuName = getCurChildren.menuName,
childrenPath = getCurChildren.path || '',
getCurNextChildren = getCurChildren.children;
if(isInit) {
state.curBreadCrumb.parent = {
menuName: getCurParent.menuName,
path: getCurParent.path
};
let getCurNextChildrenArr = {
menuName: childrenMenuName,
path: childrenPath,
// 初始化操作
const firstParent = resData[0].origin ? resData[0].origin : {},
firstChildren = resData[0].children.length > 0 ? resData[0].children[0].origin : {};
let showEmpty = false;
// 同步面包屑
const getBreadCrumb = store.getters.curBreadCrumb;
const getCurChildren = getBreadCrumb.children ? getBreadCrumb.children : firstChildren;
let getCurParent = getBreadCrumb.parent ? getBreadCrumb.parent : firstParent,
childrenMenuName = getCurChildren.menuName,
childrenPath = getCurChildren.path || '',
getCurNextChildren = getCurChildren.children;
if(isInit) {
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
};
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) => {
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(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;
// 同步激活样式
resData.forEach((item, index) => {
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;
})
}
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 => {
......
......@@ -7,7 +7,7 @@
:class="{active: item.active, pointer: item.path}"
v-for="(item, index) in breadCrumbList"
:key="index"
@click="routerGo(item.path || '')">
@click="routerGo(item, item.path || '/noData')">
{{item.name}}
</a-breadcrumb-item>
</a-breadcrumb>
......@@ -50,7 +50,7 @@ export default {
})
const showEmpty = computed(() => {
return !state.el_sub_innerH || store.getters.commonData.showEmpty;
return store.getters.commonData.showEmpty || !state.el_sub_innerH;
})
const breadCrumbList = computed(() => {
......@@ -60,7 +60,7 @@ export default {
let breadCrumbList = [];
if(curParent) {
breadCrumbList.push({
name: curParent.menuName + ' / '
name: curChildren.menuName ? curParent.menuName + ' / ' : curParent.menuName
});
}
if(curChildren) {
......@@ -68,7 +68,7 @@ export default {
breadCrumbList.push({
name: nextChildren ? curChildren.menuName + ' / ': curChildren.menuName,
path: curChildren.path,
active: curChildren.active
active: nextChildren ? false : true
});
if(nextChildren) {
breadCrumbList.push({
......@@ -78,18 +78,46 @@ export default {
});
}
}
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 {
...toRefs(state),
breadCrumbList,
elmSubMicro,
showEmpty
// routerGo
showEmpty,
routerGo
}
}
}
......
......@@ -29,6 +29,7 @@ export default {
// 设置面包屑
SET_BREAD_CRUMB(state, data) {
state.curBreadCrumb = data;
localStorage.setItem('breadCrumb', JSON.stringify(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!