refactor(web): 将刷新权限缓存功能移至系统设置
- 新增 PermissionSettings 组件 - 从个人中心页面移除刷新权限缓存功能 - 在系统设置页面添加权限缓存设置卡片 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import { AvatarUpload } from '@/components/forms/AvatarUpload';
|
||||
import { PasswordForm } from '@/components/forms/PasswordForm';
|
||||
import { ProfileForm } from '@/components/forms/ProfileForm';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -15,26 +10,8 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { getUserMenusAndPermissions } from '@/services/permission.service';
|
||||
import { usePermissionStore } from '@/stores';
|
||||
|
||||
export default function ProfilePage() {
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const setPermissionData = usePermissionStore((state) => state.setPermissionData);
|
||||
|
||||
const handleRefreshPermissions = async () => {
|
||||
setIsRefreshing(true);
|
||||
try {
|
||||
const data = await getUserMenusAndPermissions();
|
||||
setPermissionData(data);
|
||||
toast.success('权限缓存已刷新');
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : '刷新失败');
|
||||
} finally {
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
@@ -72,21 +49,6 @@ export default function ProfilePage() {
|
||||
<PasswordForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>刷新权限缓存</CardTitle>
|
||||
<CardDescription>
|
||||
如果您的权限或菜单发生变化,可以手动刷新以获取最新数据。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={handleRefreshPermissions} disabled={isRefreshing}>
|
||||
<RefreshCw className={`mr-2 h-4 w-4 ${isRefreshing ? 'animate-spin' : ''}`} />
|
||||
{isRefreshing ? '刷新中...' : '刷新权限缓存'}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { ThemeSettings, SidebarSettings } from '@/components/settings';
|
||||
import { ThemeSettings, SidebarSettings, PermissionSettings } from '@/components/settings';
|
||||
|
||||
export default function SettingsPage() {
|
||||
return (
|
||||
@@ -13,6 +13,7 @@ export default function SettingsPage() {
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<ThemeSettings />
|
||||
<SidebarSettings />
|
||||
<PermissionSettings />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
51
apps/web/src/components/settings/PermissionSettings.tsx
Normal file
51
apps/web/src/components/settings/PermissionSettings.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
'use client';
|
||||
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { getUserMenusAndPermissions } from '@/services/permission.service';
|
||||
import { usePermissionStore } from '@/stores';
|
||||
|
||||
export function PermissionSettings() {
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const setPermissionData = usePermissionStore((state) => state.setPermissionData);
|
||||
|
||||
const handleRefreshPermissions = async () => {
|
||||
setIsRefreshing(true);
|
||||
try {
|
||||
const data = await getUserMenusAndPermissions();
|
||||
setPermissionData(data);
|
||||
toast.success('权限缓存已刷新');
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : '刷新失败');
|
||||
} finally {
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>权限缓存</CardTitle>
|
||||
<CardDescription>
|
||||
如果您的权限或菜单发生变化,可以手动刷新以获取最新数据。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={handleRefreshPermissions} disabled={isRefreshing}>
|
||||
<RefreshCw className={`mr-2 h-4 w-4 ${isRefreshing ? 'animate-spin' : ''}`} />
|
||||
{isRefreshing ? '刷新中...' : '刷新权限缓存'}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export { ThemeSettings } from './ThemeSettings';
|
||||
export { SidebarSettings } from './SidebarSettings';
|
||||
export { PermissionSettings } from './PermissionSettings';
|
||||
|
||||
Reference in New Issue
Block a user