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

feat: menu 支持配置 _blank 在新页面打开 #258

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
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
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