Skip to content

Commit

Permalink
fix(menu): improve menu logic, fix vbenjs#461
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Apr 8, 2021
1 parent 780a8a6 commit ee1c349
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 🐛 Bug Fixes

- 登录页样式修复
- 修复菜单已知问题

## 2.2.0 (2021-04-06)

Expand Down
33 changes: 16 additions & 17 deletions src/components/Application/src/AppDarkModeToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
v-if="getShowDarkModeToggle"
:class="[
prefixCls,
`${prefixCls}--${size}`,
{
[`${prefixCls}--dark`]: isDark,
},
Expand All @@ -30,13 +29,13 @@
export default defineComponent({
name: 'DarkModeToggle',
components: { SvgIcon },
props: {
size: {
type: String,
default: 'default',
validate: (val) => ['default', 'large'].includes(val),
},
},
// props: {
// size: {
// type: String,
// default: 'default',
// validate: (val) => ['default', 'large'].includes(val),
// },
// },
setup() {
const { prefixCls } = useDesign('dark-mode-toggle');
const { getDarkMode, setDarkMode, getShowDarkModeToggle } = useRootSetting();
Expand Down Expand Up @@ -97,15 +96,15 @@
}
}
&--large {
width: 72px;
height: 34px;
padding: 0 10px;
// &--large {
// width: 70px;
// height: 34px;
// padding: 0 10px;
.@{prefix-cls}-inner {
width: 26px;
height: 26px;
}
}
// .@{prefix-cls}-inner {
// width: 26px;
// height: 26px;
// }
// }
}
</style>
6 changes: 1 addition & 5 deletions src/components/Icon/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import Iconify from '@purge-icons/generated';
import { isString } from '/@/utils/is';
import { propTypes } from '/@/utils/propTypes';
import { useRootSetting } from '/@/hooks/setting/useRootSetting';
import { ThemeEnum } from '/@/enums/appEnum';
const SVG_END_WITH_FLAG = '|svg';
export default defineComponent({
Expand All @@ -46,8 +44,6 @@
setup(props) {
const elRef = ref<ElRef>(null);
const { getDarkMode } = useRootSetting();
const isSvgIcon = computed(() => props.icon?.endsWith(SVG_END_WITH_FLAG));
const getSvgIcon = computed(() => props.icon.replace(SVG_END_WITH_FLAG, ''));
const getIconRef = computed(() => `${props.prefix ? props.prefix + ':' : ''}${props.icon}`);
Expand Down Expand Up @@ -85,7 +81,7 @@
return {
fontSize: `${fs}px`,
color: color || (unref(getDarkMode) === ThemeEnum.DARK ? '#fff' : '#303133'),
color: color,
display: 'inline-flex',
};
}
Expand Down
13 changes: 12 additions & 1 deletion src/components/SimpleMenu/src/SimpleMenu.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<Menu
v-bind="getBindValues"
@select="handleSelect"
:activeName="activeName"
:openNames="getOpenKeys"
:class="prefixCls"
:activeSubMenuNames="activeSubMenuNames"
@select="handleSelect"
@open-change="handleOpenChange"
>
<template v-for="item in items" :key="item.path">
<SimpleSubMenu
Expand Down Expand Up @@ -53,6 +54,7 @@
beforeClickFn: {
type: Function as PropType<(key: string) => Promise<boolean>>,
},
isSplitMenu: propTypes.bool,
},
emits: ['menuClick'],
setup(props, { attrs, emit }) {
Expand Down Expand Up @@ -94,6 +96,9 @@
watch(
() => props.items,
() => {
if (!props.isSplitMenu) {
return;
}
setOpenKeys(currentRoute.value.path);
},
{ flush: 'post' }
Expand Down Expand Up @@ -135,11 +140,17 @@
menuState.activeName = key;
}
function handleOpenChange(v) {
console.log('======================');
console.log(v);
console.log('======================');
}
return {
prefixCls,
getBindValues,
handleSelect,
getOpenKeys,
handleOpenChange,
...toRefs(menuState),
};
},
Expand Down
9 changes: 9 additions & 0 deletions src/components/SimpleMenu/src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@
});
emit('select', name);
});
rootMenuEmitter.on('open-name-change', ({ name, opened }) => {
if (opened && !openedNames.value.includes(name)) {
openedNames.value.push(name);
} else if (!opened) {
const index = openedNames.value.findIndex((item) => item === name);
index !== -1 && openedNames.value.splice(index, 1);
}
});
});
return { getClass, openedNames };
Expand Down
9 changes: 7 additions & 2 deletions src/components/SimpleMenu/src/components/MenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@
function handleClickItem() {
const { disabled } = props;
if (disabled) return;
if (disabled) {
return;
}
rootMenuEmitter.emit('on-menu-item-select', props.name);
if (unref(getCollapse)) return;
if (unref(getCollapse)) {
return;
}
const { uidList } = getParentList();
rootMenuEmitter.emit('on-update-opened', {
opend: false,
parent: instance?.parent,
Expand Down
13 changes: 10 additions & 3 deletions src/components/SimpleMenu/src/components/SubMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
:class="`${prefixCls}-submenu-title-icon`"
/>
</div>
<template #content>
<div v-bind="getEvents(true)" v-show="opened">
<!-- eslint-disable-next-line -->
<template #content v-show="opened">
<div v-bind="getEvents(true)">
<ul :class="[prefixCls, `${prefixCls}-${getTheme}`, `${prefixCls}-popup`]">
<slot></slot>
</ul>
Expand Down Expand Up @@ -78,7 +79,7 @@
import { isBoolean, isObject } from '/@/utils/is';
import Mitt from '/@/utils/mitt';
const DELAY = 250;
const DELAY = 200;
export default defineComponent({
name: 'SubMenu',
components: {
Expand Down Expand Up @@ -189,13 +190,19 @@
const { disabled } = props;
if (disabled || unref(getCollapse)) return;
const opened = state.opened;
if (unref(getAccordion)) {
const { uidList } = getParentList();
rootMenuEmitter.emit('on-update-opened', {
opend: false,
parent: instance?.parent,
uidList: uidList,
});
} else {
rootMenuEmitter.emit('open-name-change', {
name: props.name,
opened: !opened,
});
}
state.opened = !opened;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SimpleMenu/src/useOpenKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { uniq } from 'lodash-es';
import { getAllParentPath } from '/@/router/helper/menuHelper';

import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useDebounce } from '../../../hooks/core/useDebounce';
import { useDebounce } from '/@/hooks/core/useDebounce';

export function useOpenKeys(
menuState: MenuState,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/default/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
getAccordion,
getIsHorizontal,
getIsSidebarType,
getSplit,
} = useMenuSetting();
const { getShowLogo } = useRootSetting();
Expand Down Expand Up @@ -144,7 +145,7 @@
// console.log(menus);
if (!menus || !menus.length) return null;
return !props.isHorizontal ? (
<SimpleMenu {...menuProps} items={menus} />
<SimpleMenu {...menuProps} isSplitMenu={unref(getSplit)} items={menus} />
) : (
<BasicMenu
{...menuProps}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/default/setting/SettingDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export default defineComponent({
wrapClassName="setting-drawer"
>
{unref(getShowDarkModeToggle) && <Divider>{() => t('layout.setting.darkMode')}</Divider>}
{unref(getShowDarkModeToggle) && <AppDarkModeToggle class="mx-auto" size="large" />}
{unref(getShowDarkModeToggle) && <AppDarkModeToggle class="mx-auto" />}
<Divider>{() => t('layout.setting.navMode')}</Divider>
{renderSidebar()}
<Divider>{() => t('layout.setting.sysTheme')}</Divider>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/default/tabs/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ html[data-theme='dark'] {
.ant-tabs-tab-active {
position: relative;
padding-left: 18px;
color: @white;
color: @white !important;
background: @primary-color;
border: 0;
transition: none;
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes/modules/demo/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const charts: AppRouteModule = {
path: '/charts',
name: 'Charts',
component: LAYOUT,
redirect: '/charts/apexChart',
redirect: '/charts/echarts/map',
meta: {
icon: 'ion:bar-chart-outline',
title: t('routes.demo.charts.charts'),
Expand Down
4 changes: 4 additions & 0 deletions src/views/sys/login/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
&-form {
background: transparent !important;
}
.app-iconify {
color: #fff;
}
}
}
Expand Down

0 comments on commit ee1c349

Please sign in to comment.