|
@@ -1,6 +1,6 @@
|
|
|
import { useIntl } from '@umijs/max';
|
|
import { useIntl } from '@umijs/max';
|
|
|
import { Checkbox, Input, Tabs } from 'antd';
|
|
import { Checkbox, Input, Tabs } from 'antd';
|
|
|
-import { useState } from 'react';
|
|
|
|
|
|
|
+import { useMemo, useState } from 'react';
|
|
|
import { TabContent } from './components/TabContent';
|
|
import { TabContent } from './components/TabContent';
|
|
|
import { usePermTree } from './hooks/usePermTree';
|
|
import { usePermTree } from './hooks/usePermTree';
|
|
|
|
|
|
|
@@ -11,6 +11,8 @@ export interface PermTreeProps {
|
|
|
onChange?: (ids: number[]) => void;
|
|
onChange?: (ids: number[]) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const TAB_KEYS = ['api', 'data'] as const;
|
|
|
|
|
+
|
|
|
export const PermTree = ({ mode, allPerms, checkedPermIds = [], onChange }: PermTreeProps) => {
|
|
export const PermTree = ({ mode, allPerms, checkedPermIds = [], onChange }: PermTreeProps) => {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
const {
|
|
const {
|
|
@@ -28,10 +30,24 @@ export const PermTree = ({ mode, allPerms, checkedPermIds = [], onChange }: Perm
|
|
|
|
|
|
|
|
const [activeTab, setActiveTab] = useState<'api' | 'data'>('api');
|
|
const [activeTab, setActiveTab] = useState<'api' | 'data'>('api');
|
|
|
|
|
|
|
|
- const tabItems = [
|
|
|
|
|
- { key: 'api', label: intl.formatMessage({ id: 'admin.permTree.apiTab' }) },
|
|
|
|
|
- { key: 'data', label: intl.formatMessage({ id: 'admin.permTree.dataTab' }) },
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ const tabItems = useMemo(
|
|
|
|
|
+ () =>
|
|
|
|
|
+ TAB_KEYS.map((key) => ({
|
|
|
|
|
+ key,
|
|
|
|
|
+ label: intl.formatMessage({ id: `admin.permTree.${key}Tab` }),
|
|
|
|
|
+ children: (
|
|
|
|
|
+ <TabContent
|
|
|
|
|
+ tab={key}
|
|
|
|
|
+ filteredGroups={filteredGroups}
|
|
|
|
|
+ allGroups={allGroups}
|
|
|
|
|
+ checkedIds={checkedIds}
|
|
|
|
|
+ mode={mode}
|
|
|
|
|
+ onToggle={toggle}
|
|
|
|
|
+ />
|
|
|
|
|
+ ),
|
|
|
|
|
+ })),
|
|
|
|
|
+ [intl, filteredGroups, allGroups, checkedIds, mode, toggle],
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex flex-col gap-2">
|
|
@@ -59,20 +75,7 @@ export const PermTree = ({ mode, allPerms, checkedPermIds = [], onChange }: Perm
|
|
|
<Tabs
|
|
<Tabs
|
|
|
activeKey={activeTab}
|
|
activeKey={activeTab}
|
|
|
onChange={(k) => setActiveTab(k as 'api' | 'data')}
|
|
onChange={(k) => setActiveTab(k as 'api' | 'data')}
|
|
|
- items={tabItems.map((t) => ({
|
|
|
|
|
- key: t.key,
|
|
|
|
|
- label: t.label,
|
|
|
|
|
- children: (
|
|
|
|
|
- <TabContent
|
|
|
|
|
- tab={t.key as 'api' | 'data'}
|
|
|
|
|
- filteredGroups={filteredGroups}
|
|
|
|
|
- allGroups={allGroups}
|
|
|
|
|
- checkedIds={checkedIds}
|
|
|
|
|
- mode={mode}
|
|
|
|
|
- onToggle={toggle}
|
|
|
|
|
- />
|
|
|
|
|
- ),
|
|
|
|
|
- }))}
|
|
|
|
|
|
|
+ items={tabItems}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|