Skip to content

Commit

Permalink
feat: menu 支持配置 _blank 在新页面打开
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Nov 15, 2024
1 parent 8530183 commit 96058a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/reference/plugin/plugins/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const layout = {
```

- **children**:子菜单配置。
- **_blank**:是否在新的窗口打开页面,默认 http 开头的链接在新窗口打开

:::tip
函数类型仅在运行时可用,可以实现动态变更菜单。
Expand Down
11 changes: 9 additions & 2 deletions packages/fes-plugin-layout/src/runtime/views/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ export default {
const onMenuClick = (e) => {
const path = e.value;
const currentMenu = menuArray.value.find(item => item.value === path);
if (/^https?:\/\//.test(path)) {
if (currentMenu._blank) {
const resolved = router.resolve({
path,
query: currentMenu?.query || {},
params: currentMenu?.params || {},
});
window.open(resolved.href, '_blank');
}
else if (/^https?:\/\//.test(path)) {
window.open(path, '_blank');
}
else if (/^\//.test(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export default {
const handleCloseTab = async (targetKey) => {
targetKey = targetKey || route.path;
const selectedPage = findPage(targetKey);
if (!selectedPage) {
return;
}
const list = [...pageList.value];
const index = list.indexOf(selectedPage);
if (route.path === selectedPage.path) {
Expand Down
2 changes: 2 additions & 0 deletions packages/fes-template/.fes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default defineBuildConfig({
{
name: 'editor',
icon: '/wine-outline.svg',
_blank: true,
},
{
title: '$externalLink',
Expand All @@ -70,6 +71,7 @@ export default defineBuildConfig({
},
{
name: 'pinia',
_blank: true,
},
],
menuProps: {
Expand Down
6 changes: 5 additions & 1 deletion packages/fes-template/src/pages/pinia.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div>{{ store.counter }}</div>
<FButton class="m-2" @click="store.increment">Button</FButton>
<FButton class="m-2" @click="store.increment">
Button
</FButton>
</template>

<config>
{
"name": "pinia",
Expand All @@ -11,6 +14,7 @@
}
}
</config>

<script>
import { FButton } from '@fesjs/fes-design';
import { useStore } from '@/store/main';
Expand Down

0 comments on commit 96058a3

Please sign in to comment.