feat: 自定义仪表板,添加知识库和终端统计组件
- 创建自定义 Dashboard 页面替换默认仪表板 - 新增 KnowledgeBaseStatsWidget 显示知识库统计信息 - 文档总数、转换完成数、转换失败数、处理中数量 - 知识库分组数量 - 转换成功率计算 - 新增 TerminalStatsWidget 显示终端统计信息 - 终端总数和激活状态 - 知识库关联数、提示词配置数 - 今日同步成功/失败统计 - 移除默认的 FilamentInfoWidget - 统计卡片支持点击跳转到相关管理页面
This commit is contained in:
25
app/Filament/Pages/Dashboard.php
Normal file
25
app/Filament/Pages/Dashboard.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
protected static ?string $navigationLabel = '仪表板';
|
||||
|
||||
protected static ?string $title = '仪表板';
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
\App\Filament\Widgets\KnowledgeBaseStatsWidget::class,
|
||||
\App\Filament\Widgets\TerminalStatsWidget::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getColumns(): int | string | array
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
61
app/Filament/Widgets/KnowledgeBaseStatsWidget.php
Normal file
61
app/Filament/Widgets/KnowledgeBaseStatsWidget.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Group;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class KnowledgeBaseStatsWidget extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
// 统计文档数据
|
||||
$totalDocuments = Document::count();
|
||||
$completedDocuments = Document::where('conversion_status', 'completed')->count();
|
||||
$failedDocuments = Document::where('conversion_status', 'failed')->count();
|
||||
$processingDocuments = Document::whereIn('conversion_status', ['pending', 'processing'])->count();
|
||||
|
||||
// 统计分组数据
|
||||
$totalGroups = Group::count();
|
||||
|
||||
// 计算转换成功率
|
||||
$conversionRate = $totalDocuments > 0
|
||||
? round(($completedDocuments / $totalDocuments) * 100, 1)
|
||||
: 0;
|
||||
|
||||
return [
|
||||
Stat::make('文档总数', $totalDocuments)
|
||||
->description('知识库中的文档总数')
|
||||
->descriptionIcon('heroicon-m-document-text')
|
||||
->color('primary')
|
||||
->chart([7, 12, 15, 18, 22, 25, $totalDocuments]),
|
||||
|
||||
Stat::make('转换完成', $completedDocuments)
|
||||
->description("成功率: {$conversionRate}%")
|
||||
->descriptionIcon('heroicon-m-check-circle')
|
||||
->color('success')
|
||||
->chart([5, 10, 12, 15, 18, 20, $completedDocuments]),
|
||||
|
||||
Stat::make('转换失败', $failedDocuments)
|
||||
->description('需要重新处理')
|
||||
->descriptionIcon('heroicon-m-x-circle')
|
||||
->color('danger')
|
||||
->url(route('filament.admin.resources.documents.index', ['tableFilters[conversion_status][value]' => 'failed'])),
|
||||
|
||||
Stat::make('处理中', $processingDocuments)
|
||||
->description('等待转换或转换中')
|
||||
->descriptionIcon('heroicon-m-arrow-path')
|
||||
->color('warning'),
|
||||
|
||||
Stat::make('知识库分组', $totalGroups)
|
||||
->description('专用知识库数量')
|
||||
->descriptionIcon('heroicon-m-folder')
|
||||
->color('info')
|
||||
->url(route('filament.admin.resources.groups.index')),
|
||||
];
|
||||
}
|
||||
}
|
||||
65
app/Filament/Widgets/TerminalStatsWidget.php
Normal file
65
app/Filament/Widgets/TerminalStatsWidget.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Terminal;
|
||||
use App\Models\TerminalKnowledgeBase;
|
||||
use App\Models\TerminalPrompt;
|
||||
use App\Models\TerminalSyncLog;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class TerminalStatsWidget extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
// 统计终端数据
|
||||
$totalTerminals = Terminal::count();
|
||||
$activeTerminals = Terminal::where('is_active', true)->count();
|
||||
|
||||
// 统计知识库关联
|
||||
$totalKnowledgeBases = TerminalKnowledgeBase::count();
|
||||
|
||||
// 统计提示词
|
||||
$totalPrompts = TerminalPrompt::count();
|
||||
|
||||
// 统计最近同步
|
||||
$recentSyncs = TerminalSyncLog::where('created_at', '>=', now()->subDay())
|
||||
->where('status', 'success')
|
||||
->count();
|
||||
|
||||
$failedSyncs = TerminalSyncLog::where('created_at', '>=', now()->subDay())
|
||||
->where('status', 'failed')
|
||||
->count();
|
||||
|
||||
return [
|
||||
Stat::make('终端总数', $totalTerminals)
|
||||
->description("{$activeTerminals} 个激活")
|
||||
->descriptionIcon('heroicon-m-computer-desktop')
|
||||
->color('primary')
|
||||
->url(route('filament.admin.resources.terminals.index')),
|
||||
|
||||
Stat::make('知识库关联', $totalKnowledgeBases)
|
||||
->description('终端知识库配置数')
|
||||
->descriptionIcon('heroicon-m-link')
|
||||
->color('info'),
|
||||
|
||||
Stat::make('提示词配置', $totalPrompts)
|
||||
->description('终端提示词总数')
|
||||
->descriptionIcon('heroicon-m-chat-bubble-left-right')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('今日同步成功', $recentSyncs)
|
||||
->description('最近24小时')
|
||||
->descriptionIcon('heroicon-m-arrow-path')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('今日同步失败', $failedSyncs)
|
||||
->description($failedSyncs > 0 ? '需要检查' : '运行正常')
|
||||
->descriptionIcon($failedSyncs > 0 ? 'heroicon-m-exclamation-triangle' : 'heroicon-m-check-circle')
|
||||
->color($failedSyncs > 0 ? 'danger' : 'success'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,11 @@ class AdminPanelProvider extends PanelProvider
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
|
||||
->pages([
|
||||
Pages\Dashboard::class,
|
||||
\App\Filament\Pages\Dashboard::class,
|
||||
])
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
||||
->widgets([
|
||||
Widgets\AccountWidget::class,
|
||||
Widgets\FilamentInfoWidget::class,
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
|
||||
Reference in New Issue
Block a user