feat: 侧边菜单栏增加外链支持

This commit is contained in:
zhangchuanlong 2022-02-15 14:29:06 +08:00
parent 741524ffac
commit a240985ee7
3 changed files with 43 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import { useRouter } from 'vue-router'
import { computed } from 'vue'
import { usePermissionStore } from '@/store/modules/permission'
import { isExternal } from '@/utils/is'
const router = useRouter()
const permissionStore = usePermissionStore()
@ -14,10 +16,11 @@ const menuOptions = computed(() => {
return generateOptions(routes, '')
})
function resolvePath(...pathes) {
function resolvePath(basePath, path) {
if (isExternal(path)) return path
return (
'/' +
pathes
[basePath, path]
.filter((path) => !!path && path !== '/')
.map((path) => path.replace(/(^\/)|(\/$)/g, ''))
.join('/')
@ -49,7 +52,11 @@ function generateOptions(routes, basePath) {
}
function handleMenuSelect(key, item) {
router.push(item.path)
if (isExternal(item.path)) {
window.open(item.path)
} else {
router.push(item.path)
}
// path
// router.push({

View File

@ -86,6 +86,31 @@ export const basicRoutes = [
},
],
},
{
name: 'EXTERNAL-LINK',
path: '/external-link',
component: Layout,
meta: {
title: '外链',
},
children: [
{
name: 'LINK-GITHUB-SRC',
path: 'https://github.com/zclzone/vue-naive-admin',
meta: {
title: '源码 - github',
},
},
{
name: 'LINK-GITEE-SRC',
path: 'https://gitee.com/zclzone/vue-naive-admin',
meta: {
title: '源码 - gitee',
},
},
],
},
]
export const NOT_FOUND_ROUTE = {

View File

@ -97,6 +97,14 @@ export function isUrl(path) {
return reg.test(path)
}
/**
* @param {string} path
* @returns {Boolean}
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
export const isServer = typeof window === 'undefined'
export const isClient = !isServer