diff --git a/src/components/Auth/Auth.tsx b/src/components/Auth/Auth.tsx index 0cf815a..517eb56 100644 --- a/src/components/Auth/Auth.tsx +++ b/src/components/Auth/Auth.tsx @@ -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()}; } diff --git a/src/components/Auth/typing.ts b/src/components/Auth/typing.ts index 7ddc927..0f48eae 100644 --- a/src/components/Auth/typing.ts +++ b/src/components/Auth/typing.ts @@ -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; }; @@ -22,7 +25,7 @@ export type AuthDomProps = { export type AuthNoneProps = { // 权限key - permission: string; + permission: Permission; // 国际化key, 如果 text 值存在, 则以text为准 localeKey?: string; // 确认框的标题, 如果此值不为空, 则单击事件会在点击确认后触发 @@ -31,7 +34,7 @@ export type AuthNoneProps = { confirm?: PopconfirmProps; } & AuthDomProps; -export type AuthNoneOptionalProps = { permission?: string } & Omit; +export type AuthNoneOptionalProps = { permission?: Permission } & Omit; export type AuthAProps = AuthNoneProps; diff --git a/src/components/Page/typings.ts b/src/components/Page/typings.ts index 4df2dd3..750ba6d 100644 --- a/src/components/Page/typings.ts +++ b/src/components/Page/typings.ts @@ -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 = { type: 'edit' | 'del' | 'read'; - permission: string; + permission: false | string; // 对 onClick 和 permission 的传递无效 props?: AuthNoneOptionalProps | ((data: T) => AuthNoneOptionalProps); };