From a240985ee711d3056d0bdbb2262070f562249606 Mon Sep 17 00:00:00 2001 From: zhangchuanlong Date: Tue, 15 Feb 2022 14:29:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BE=A7=E8=BE=B9=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=A0=8F=E5=A2=9E=E5=8A=A0=E5=A4=96=E9=93=BE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/sidebar/SideMenu.vue | 13 ++++++++--- src/router/routes/index.js | 25 ++++++++++++++++++++++ src/utils/is.js | 8 +++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/layout/components/sidebar/SideMenu.vue b/src/layout/components/sidebar/SideMenu.vue index 3903c53..ed74ccd 100644 --- a/src/layout/components/sidebar/SideMenu.vue +++ b/src/layout/components/sidebar/SideMenu.vue @@ -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({ diff --git a/src/router/routes/index.js b/src/router/routes/index.js index dd91c7e..a557d7b 100644 --- a/src/router/routes/index.js +++ b/src/router/routes/index.js @@ -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 = { diff --git a/src/utils/is.js b/src/utils/is.js index 8035194..2df0009 100644 --- a/src/utils/is.js +++ b/src/utils/is.js @@ -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