Merge pull request #28 from yanbowe/main

增加项目文档(外链方式)
This commit is contained in:
Soybean 2021-12-20 14:47:36 +08:00 committed by GitHub
commit 186f53f634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 2 deletions

View File

@ -18,6 +18,7 @@ export type RouteKey =
| 'document_vue'
| 'document_vite'
| 'document_naive'
| 'document_project'
| 'plugin'
| 'plugin_map'
| 'plugin_video'

View File

@ -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();
@ -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[]) {

View File

@ -107,6 +107,14 @@ const routeConstMap = new Map<RouteKey, RouteConst>([
title: 'naive文档'
}
],
[
'document_project',
{
name: 'document_project',
path: 'https://docs.soybean.pro/',
title: '项目文档(外链)'
}
],
[
'plugin',
{

View File

@ -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';
@ -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
}
}
]
};

View File

@ -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);
}