Skip to content

Commit

Permalink
fix(menu): top submenu disappeared problem #214
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 25, 2021
1 parent 783e658 commit 0ec1a62
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 352 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- 修复 form 表单初始化值为 0 问题
- 修复表格换行问题
- 修复菜单外链不跳转
- 修复菜单顶部显示问题

## 2.0.0-rc.17 (2020-01-18)

Expand Down
3 changes: 2 additions & 1 deletion build/config/lessModifyVars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* less global variable
*/
const primaryColor = '#018ffb';
const primaryColor = '#0084f4';
// const primaryColor = '#018ffb';
// const primaryColor = '#0065cc';
//{
const modifyVars = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"@vitejs/plugin-legacy": "^1.2.1",
"@vitejs/plugin-vue": "^1.1.2",
"@vitejs/plugin-vue": "1.1.0",
"@vitejs/plugin-vue-jsx": "^1.0.2",
"@vue/compiler-sfc": "^3.0.5",
"@vuedx/typecheck": "^0.6.0",
Expand Down
23 changes: 8 additions & 15 deletions src/components/Menu/src/BasicMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
v-bind="getInlineCollapseOptions"
>
<template v-for="item in items" :key="item.path">
<BasicSubMenuItem
:item="item"
:theme="theme"
:level="1"
:showTitle="showTitle"
:isHorizontal="isHorizontal"
/>
<BasicSubMenuItem :item="item" :theme="theme" :isHorizontal="isHorizontal" />
</template>
</Menu>
</template>
Expand All @@ -46,6 +40,7 @@
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
import { listenerLastChangeTab } from '/@/logics/mitt/tabChange';
import { getAllParentPath } from '/@/router/helper/menuHelper';
export default defineComponent({
name: 'BasicMenu',
Expand Down Expand Up @@ -96,16 +91,12 @@
prefixCls,
`justify-${align}`,
{
[`${prefixCls}--hide-title`]: !unref(showTitle),
[`${prefixCls}--collapsed-show-title`]: props.collapsedShowTitle,
[`${prefixCls}__second`]: !props.isHorizontal && unref(getSplit),
[`${prefixCls}__sidebar-hor`]: unref(getIsTopMenu),
},
];
});
const showTitle = computed(() => props.collapsedShowTitle && unref(getCollapsed));
const getInlineCollapseOptions = computed(() => {
const isInline = props.mode === MenuModeEnum.INLINE;
Expand Down Expand Up @@ -135,7 +126,7 @@
}
);
async function handleMenuClick({ key, keyPath }: { key: string; keyPath: string[] }) {
async function handleMenuClick({ key }: { key: string; keyPath: string[] }) {
const { beforeClickFn } = props;
if (beforeClickFn && isFunction(beforeClickFn)) {
const flag = await beforeClickFn(key);
Expand All @@ -144,7 +135,9 @@
emit('menuClick', key);
isClickGo.value = true;
menuState.openKeys = keyPath;
// const parentPath = await getCurrentParentPath(key);
// menuState.openKeys = [parentPath];
menuState.selectedKeys = [key];
}
Expand All @@ -160,7 +153,8 @@
const parentPath = await getCurrentParentPath(path);
menuState.selectedKeys = [parentPath];
} else {
menuState.selectedKeys = [path];
const parentPaths = await getAllParentPath(props.items, path);
menuState.selectedKeys = parentPaths;
}
}
Expand All @@ -172,7 +166,6 @@
getMenuClass,
handleOpenChange,
getOpenKeys,
showTitle,
...toRefs(menuState),
};
},
Expand Down
20 changes: 11 additions & 9 deletions src/components/Menu/src/components/BasicMenuItem.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<template>
<MenuItem :class="getLevelClass">
<MenuItem>
<!-- <MenuItem :class="getLevelClass"> -->
<MenuItemContent v-bind="$props" :item="item" />
</MenuItem>
</template>
<script lang="ts">
import { defineComponent, computed } from 'vue';
import { defineComponent } from 'vue';
import { Menu } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { itemProps } from '../props';
Expand All @@ -14,18 +15,19 @@
name: 'BasicMenuItem',
components: { MenuItem: Menu.Item, MenuItemContent },
props: itemProps,
setup(props) {
setup() // props
{
const { prefixCls } = useDesign('basic-menu-item');
const getLevelClass = computed(() => {
const { level, theme } = props;
// const getLevelClass = computed(() => {
// const { level, theme } = props;
const levelCls = [`${prefixCls}__level${level}`, theme];
return levelCls;
});
// const levelCls = [`${prefixCls}__level${level}`, theme];
// return levelCls;
// });
return {
prefixCls,
getLevelClass,
// getLevelClass,
};
},
});
Expand Down
10 changes: 3 additions & 7 deletions src/components/Menu/src/components/BasicSubMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
<BasicMenuItem v-if="!menuHasChildren(item) && getShowMenu" v-bind="$props" />
<SubMenu
v-if="menuHasChildren(item) && getShowMenu"
:class="[`${prefixCls}__level${level}`, theme]"
:class="[theme]"
popupClassName="app-top-menu-popup"
>
<template #title>
<MenuItemContent v-bind="$props" :item="item" />
</template>
<!-- <template #expandIcon="{ key }">
<ExpandIcon :key="key" />
</template> -->

<template v-for="childrenItem in item.children || []" :key="childrenItem.path">
<BasicSubMenuItem v-bind="$props" :item="childrenItem" :level="level + 1" />
<BasicSubMenuItem v-bind="$props" :item="childrenItem" />
</template>
</SubMenu>
</template>
Expand All @@ -26,7 +24,6 @@
import BasicMenuItem from './BasicMenuItem.vue';
import MenuItemContent from './MenuItemContent.vue';
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
export default defineComponent({
name: 'BasicSubMenuItem',
isSubMenu: true,
Expand All @@ -35,7 +32,6 @@
SubMenu: Menu.SubMenu,
MenuItem: Menu.Item,
MenuItemContent,
// ExpandIcon: createAsyncComponent(() => import('./ExpandIcon.vue')),
},
props: itemProps,
setup(props) {
Expand Down
15 changes: 4 additions & 11 deletions src/components/Menu/src/components/MenuItemContent.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<template>
<span :class="`${prefixCls}-wrapper`">
<Icon v-if="getIcon" :icon="getIcon" :size="18" :class="`${prefixCls}-wrapper__icon`" />
<span :class="getNameClass">
{{ getI18nName }}
<MenuItemTag v-bind="$props" />
</span>
{{ getI18nName }}
</span>
</template>
<script lang="ts">
Expand All @@ -14,25 +11,21 @@
import { useI18n } from '/@/hooks/web/useI18n';
import { useDesign } from '/@/hooks/web/useDesign';
import { contentProps } from '../props';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
const { t } = useI18n();
export default defineComponent({
name: 'MenuItemContent',
components: { Icon, MenuItemTag: createAsyncComponent(() => import('./MenuItemTag.vue')) },
components: {
Icon,
},
props: contentProps,
setup(props) {
const { prefixCls } = useDesign('basic-menu-item-content');
const getI18nName = computed(() => t(props.item?.name));
const getIcon = computed(() => props.item?.icon);
const getNameClass = computed(() => {
const { showTitle } = props;
return { [`${prefixCls}--show-title`]: showTitle, [`${prefixCls}__name`]: !showTitle };
});
return {
prefixCls,
getNameClass,
getI18nName,
getIcon,
};
Expand Down
Loading

0 comments on commit 0ec1a62

Please sign in to comment.