Skip to content

Commit

Permalink
feat(Auth): 优化Auth. 允许不进行鉴权
Browse files Browse the repository at this point in the history
  • Loading branch information
lingting committed Dec 7, 2021
1 parent a97d823 commit 23e5350
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/Auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const Auth = ({ permission, render }: AuthProps): JSX.Element => {
const { initialState } = useModel('@@initialState');

// 有权限
if (hasPermission(initialState, permission)) {
if (permission === false || hasPermission(initialState, permission)) {
return <>{render()}</>;
}

Expand Down
9 changes: 6 additions & 3 deletions src/components/Auth/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import type { MouseEvent, CSSProperties } from 'react';
import type { PopconfirmProps } from 'antd';
import type { ButtonType } from 'antd/lib/button';

// 值为false表示不鉴权
type Permission = false | string;

export type AuthProps = {
// 权限key
permission: string;
permission: Permission;
// dom
render: () => React.ReactNode;
};
Expand All @@ -22,7 +25,7 @@ export type AuthDomProps = {

export type AuthNoneProps = {
// 权限key
permission: string;
permission: Permission;
// 国际化key, 如果 text 值存在, 则以text为准
localeKey?: string;
// 确认框的标题, 如果此值不为空, 则单击事件会在点击确认后触发
Expand All @@ -31,7 +34,7 @@ export type AuthNoneProps = {
confirm?: PopconfirmProps;
} & AuthDomProps;

export type AuthNoneOptionalProps = { permission?: string } & Omit<AuthNoneProps, 'permission'>;
export type AuthNoneOptionalProps = { permission?: Permission } & Omit<AuthNoneProps, 'permission'>;

export type AuthAProps = AuthNoneProps;

Expand Down
4 changes: 2 additions & 2 deletions src/components/Page/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { AuthNoneOptionalProps } from '../Auth';
import type { TableProps } from '../Table/typings';
import type { ModalFormProps } from '@/components/Form';

export type PageToolBarActions = { type: 'create'; permission: string } | JSX.Element;
export type PageToolBarActions = { type: 'create'; permission: false | string } | JSX.Element;

export type PageOperateBarPreset<T> = {
type: 'edit' | 'del' | 'read';
permission: string;
permission: false | string;
// 对 onClick 和 permission 的传递无效
props?: AuthNoneOptionalProps | ((data: T) => AuthNoneOptionalProps);
};
Expand Down

0 comments on commit 23e5350

Please sign in to comment.