Skip to content

Commit

Permalink
feat(projects): 增加项目文档外链
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbowe committed Dec 20, 2021
1 parent 041012b commit 1901a0b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/interface/common/route.ts
Expand Up @@ -18,6 +18,7 @@ export type RouteKey =
| 'document_vue'
| 'document_vite'
| 'document_naive'
| 'document_project'
| 'plugin'
| 'plugin_map'
| 'plugin_video'
Expand Down
7 changes: 6 additions & 1 deletion src/layouts/common/GlobalMenu/index.vue
Expand Up @@ -22,6 +22,7 @@ import type { MenuOption } from 'naive-ui';
import { useThemeStore, useAppStore } from '@/store';
import { menus } from '@/router';
import { GlobalMenuOption } from '@/interface';
import { isUrl } from '@/utils';
const theme = useThemeStore();
const app = useAppStore();
Expand Down Expand Up @@ -49,7 +50,11 @@ function getActiveKeysInMenus(menu: GlobalMenuOption) {
function handleUpdateMenu(_key: string, item: MenuOption) {
const menuItem = item as GlobalMenuOption;
router.push(menuItem.routePath);
if (isUrl(menuItem.routePath)) {
window.open(menuItem.routePath, '__blank');
} else {
router.push(menuItem.routePath);
}
}
function handleUpdateExpandedKeys(keys: string[]) {
Expand Down
8 changes: 8 additions & 0 deletions src/router/constant/index.ts
Expand Up @@ -107,6 +107,14 @@ const routeConstMap = new Map<RouteKey, RouteConst>([
title: 'naive文档'
}
],
[
'document_project',
{
name: 'document_project',
path: 'https://docs.soybean.pro/',
title: '项目文档(外链)'
}
],
[
'plugin',
{
Expand Down
12 changes: 11 additions & 1 deletion src/router/modules/document.ts
@@ -1,5 +1,5 @@
import type { RouteRecordRaw } from 'vue-router';
import { BasicLayout } from '@/layouts';
import { BasicLayout, BlankLayout } from '@/layouts';
import { DocumentVue, DocumentVite, DocumentNaive } from '@/views';
import { routeName, routePath, routeTitle } from '../constant';

Expand Down Expand Up @@ -45,6 +45,16 @@ const document: RouteRecordRaw = {
title: routeTitle('document_naive'),
fullPage: true
}
},
{
name: routeName('document_project'),
path: routePath('document_project'),
component: BlankLayout,
meta: {
requiresAuth: true,
title: routeTitle('document_project'),
fullPage: true
}
}
]
};
Expand Down
7 changes: 7 additions & 0 deletions src/utils/router/menus.ts
Expand Up @@ -47,3 +47,10 @@ export function transformRouteToMenu(routes: RouteRecordRaw[]) {
});
return globalMenu;
}

/** 判断路由是否为Url链接 */
export function isUrl(path: string): boolean {
const reg =
/(((^https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
return reg.test(path);
}

0 comments on commit 1901a0b

Please sign in to comment.