Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: layout 跳外部链接,菜单不选中 #262

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/fes-plugin-layout/src/runtime/views/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<FMenu
v-model:expandedKeys="expandedKeysRef"
:model-value="activePath"
v-model:expanded-keys="expandedKeysRef"
v-model="activeMenu"
:inverted="inverted"
:mode="mode"
:options="transformedMenus"
Expand All @@ -12,9 +12,9 @@
</template>

<script>
import { computed, h, ref, watch } from 'vue';
import { FMenu } from '@fesjs/fes-design';
import { useRoute, useRouter } from '@@/core/coreExports';
import { FMenu } from '@fesjs/fes-design';
import { computed, h, nextTick, ref, watch } from 'vue';
import { transform as transformByAccess } from '../helpers/pluginAccess';
import { transform as transformByLocale } from '../helpers/pluginLocale';
import { flatNodes } from '../helpers/utils';
Expand Down Expand Up @@ -79,6 +79,7 @@ export default {
const router = useRouter();
const transformedMenus = computed(() => transformByLocale(transformByAccess(transform(props.menus))));
const menuArray = computed(() => flatNodes(transformedMenus.value));

const activePath = computed(() => {
const matchMenus = menuArray.value.filter((menu) => {
const match = menu.match;
Expand All @@ -96,6 +97,12 @@ export default {
return matchMenus[0].path;
});

const activeMenu = ref(activePath.value);

watch(activePath, () => {
activeMenu.value = activePath.value;
});

const expandedKeysRef = ref(props.expandedKeys);

watch(
Expand Down Expand Up @@ -132,9 +139,17 @@ export default {
query: currentMenu?.query || {},
params: currentMenu?.params || {},
});
// TODO 有受控模式之后优化
nextTick(() => {
activeMenu.value = activePath.value;
});
window.open(resolved.href, '_blank');
}
else if (/^https?:\/\//.test(path)) {
// TODO 有受控模式之后优化
nextTick(() => {
activeMenu.value = activePath.value;
});
window.open(path, '_blank');
}
else if (/^\//.test(path)) {
Expand All @@ -150,6 +165,7 @@ export default {
};

return {
activeMenu,
activePath,
expandedKeysRef,
transformedMenus,
Expand Down