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: 外部页面 (#50) #58

Closed
wants to merge 7 commits into from
Closed
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
12 changes: 9 additions & 3 deletions src/layouts/default/sidebar/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
</a-menu>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import MenuWithChildren from './MenuWithChildren.vue'
import MenuItem from './MenuItem.vue'
import { useCollapsed } from '~/layouts/default/useCollapsed'
Expand All @@ -36,9 +38,13 @@ const openKeys = ref<string[]>([])
const router = useRouter()
const routeStore = useRouteStore()
const menus = ref<RouteModuleList>([])

const handleClick = (path: string) => {
router.push(path)
const handleClick = (path: string, src: string, name: string) => {
if (src) {
router.push({ name, params: { src } })
}
else {
router.push(path)
}
}

watch(() => routeStore.getRoutes, (routes) => {
Expand Down
19 changes: 15 additions & 4 deletions src/layouts/default/sidebar/components/MenuItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<a-menu-item
:key="parentPath ? `${parentPath}/${menu.path}` : menu.path"
@click="handleClick(menu.path)"
@click="handleClick(menu.path, menu.name, menu.meta.frameSrc, menu.meta.external)"
>
<template #icon>
<component :is="menu.meta?.icon" />
Expand All @@ -13,18 +13,29 @@
import type { RouteModuleList } from '~/router/routes/typings'

interface EmitEvents {
(e: 'handleClick', path: string, currentDepth: number | undefined): void
(e: 'handleClick', path: string, currentDepth: number | undefined, src?: string, name?: string): void
}
interface Props {
menu: GetArrayItemType<RouteModuleList>
parentPath?: string
currentDepth?: number
src?: string
// 是否外链
external?: boolean
}

const props = defineProps<Props>()
const emit = defineEmits<EmitEvents>()

function handleClick(path: string) {
emit('handleClick', path, props.currentDepth)
function handleClick(path: string, name: string, src: string, external: boolean) {
// src 为内链 地址
// 需要判断path是否为外链
if (external) {
// 打开外链
window.open(path)
}
else {
emit('handleClick', path, props.currentDepth, src, name)
}
}
</script>
10 changes: 6 additions & 4 deletions src/layouts/default/sidebar/components/MenuWithChildren.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@
<script setup lang="ts">
import MenuItem from './MenuItem.vue'
import type { RouteModuleList } from '~/router/routes/typings'

interface EmitEvents {
(e: 'handleClick', path: string): void
(e: 'handleClick', path: string, src?: string, name?: string): void
}
interface Props {
menu: GetArrayItemType<RouteModuleList>
parentPath: string
// 当前的深度,用于计算 key
currentDepth: number
// 内链 src
src?: string
name?: string
}

const props = defineProps<Props>()
const emit = defineEmits<EmitEvents>()

function handleClick(path: string, depth = 1) {
emit('handleClick', depth > 1 ? `${props.parentPath}/${path}` : path)
function handleClick(path: string, depth = 1, src: string, name: string) {
emit('handleClick', depth > 1 ? `${props.parentPath}/${path}` : path, src, name)
}
</script>
2 changes: 1 addition & 1 deletion src/router/routes/modules/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const route: RouteRecordRaw = {
title: '关于',
icon: SettingOutlined,
single: true,
sort: 3
sort: 4
},
children: [
{
Expand Down
53 changes: 53 additions & 0 deletions src/router/routes/modules/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { RouteRecordRaw } from 'vue-router'
import {
CompassOutlined
} from '@ant-design/icons-vue'
import { DefaultLayout } from '~/layouts'

const route: RouteRecordRaw = {
path: '/docs',
name: 'docs',
component: DefaultLayout,
redirect: '/docs/project/inline',
meta: {
title: '外部页面',
icon: CompassOutlined,
sort: 3
},
children: [
{
path: 'inline/project',
name: 'projectInline',
component: () => import('~/views/docs/inline/index.vue'),
props: true,
meta: {
title: '项目文档 (内嵌)',
frameSrc: 'https://vue-hbs-admin-docs.netlify.app',
sort: 1
}
},
{
path: 'inline/ant',
name: 'antInline',
component: () => import('~/views/docs/inline/index.vue'),
props: true,
meta: {
title: 'antVue文档 (内嵌)',
frameSrc: 'https://antdv.com/components/overview-cn',
sort: 2
}
},
{
path: 'https://vue-hbs-admin-docs.netlify.app/',
name: 'projectInline',
component: () => import('~/views/demo/excel/import.vue'),
meta: {
title: '项目文档 (外链)',
external: true,
sort: 3
}
}
]
}

export default route
12 changes: 12 additions & 0 deletions src/views/docs/inline/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div class="w-full h-full">
<iframe :src="src" scrolling="auto" frameborder="0" class="w-full h-full" />
</div>
</template>
<script setup lang="ts">
defineProps({
src: { type: String }
})
</script>
<style lang="less" scoped>
</style>
2 changes: 2 additions & 0 deletions types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ declare module 'vue-router' {
icon?: FunctionalComponent
// 是否是单独的菜单
single?: boolean
// 内链地址
frameSrc?: string
}
}