Skip to content

Commit

Permalink
feat: blank and frame page init
Browse files Browse the repository at this point in the history
  • Loading branch information
d3george committed Oct 17, 2023
1 parent 2687511 commit 90af273
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/assets/icons/ic_blank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/icons/ic_external.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/locales/lang/en_US/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@
"menulevel_2a": "Menu Level 2a",
"menulevel_2b": "Menu Level 2b",
"menulevel_3a": "Menu Level 3a",
"menulevel_3b": "Menu Level 3b"
"menulevel_3b": "Menu Level 3b",
"frame": "External",
"external_link": "External Link",
"iframe": "Iframe",
"blank": "Blank"
}
}
}
6 changes: 5 additions & 1 deletion src/locales/lang/zh_CN/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@
"menulevel_2a": "菜单 2a",
"menulevel_2b": "菜单 2b",
"menulevel_3a": "菜单 3a",
"menulevel_3b": "菜单 3b"
"menulevel_3b": "菜单 3b",
"frame": "外部链接",
"external_link": "外链",
"iframe": "内嵌",
"blank": "空白"
}
}
}
15 changes: 15 additions & 0 deletions src/pages/sys/iframe/external-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useLayoutEffect } from 'react';

import { useRouter } from '@/router/hooks';

type Props = {
to: string;
};
export default function ExternalLink({ to }: Props) {
const { back } = useRouter();
useLayoutEffect(() => {
window.open(to, '_black');
back();
});
return <div />;
}
10 changes: 10 additions & 0 deletions src/pages/sys/iframe/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Props = {
src: string;
};
export default function Iframe({ src = '' }: Props) {
return (
<div className="h-full w-full">
<iframe src={src} title="iframe-page" className="h-full w-full" />
</div>
);
}
49 changes: 49 additions & 0 deletions src/router/routes/modules/others.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { lazy } from 'react';

import Card from '@/components/card';
import { SvgIcon } from '@/components/icon';

import { AppRouteObject } from '#/router';

const ExternalLink = lazy(() => import('@/pages/sys/iframe/external-link'));
const Iframe = lazy(() => import('@/pages/sys/iframe'));

const others: AppRouteObject[] = [
{
path: 'frame',
meta: {
title: 'sys.menu.frame',
icon: <SvgIcon icon="ic_external" className="ant-menu-item-icon" size="24" />,
key: '/frame',
},
children: [
{
path: 'external_link',
element: <ExternalLink to="https://ant.design/index-cn" />,
meta: {
title: 'sys.menu.external_link',
key: '/frame/external_link',
},
},
{
path: 'iframe',
element: <Iframe src="https://ant.design/index-cn" />,
meta: {
title: 'sys.menu.iframe',
key: '/frame/iframe',
},
},
],
},
{
path: 'blank',
element: <Card />,
meta: {
title: 'sys.menu.blank',
icon: <SvgIcon icon="ic_blank" className="ant-menu-item-icon" size="24" />,
key: '/blank',
},
},
];

export default others;
2 changes: 1 addition & 1 deletion src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppRouteObject, RouteMeta } from '#/router';
export const menuFilter = (items: AppRouteObject[]) => {
return items
.filter((item) => {
const show = !item.meta?.hideMenu && item.path;
const show = !item.meta?.hideMenu && item.meta?.key;
if (show && item.children) {
item.children = menuFilter(item.children);
}
Expand Down
11 changes: 4 additions & 7 deletions types/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode } from 'react';
import { RouteObject } from 'react-router-dom';

export interface RouteMeta {
// unique
// antd menu selectedKeys
key: string;
title: string;
icon?: ReactNode;
Expand All @@ -14,10 +14,7 @@ export interface RouteMeta {
auth?: boolean;
}
export type AppRouteObject = {
index?: boolean;
path?: RouteObject['path'];
element?: RouteObject['element'];
children?: AppRouteObject[];
meta?: RouteMeta;
order?: number;
};
meta?: RouteMeta;
children?: AppRouteObject[];
} & Omit<RouteObject, 'children'>;

0 comments on commit 90af273

Please sign in to comment.