优化界面
This commit is contained in:
@@ -6,7 +6,6 @@ namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\Guide;
|
||||
use App\Models\Tool;
|
||||
use App\Support\MarkdownRenderer;
|
||||
@@ -32,9 +31,29 @@ class GuideController extends Controller
|
||||
$builder->where('difficulty', (string) $request->string('difficulty'));
|
||||
}
|
||||
|
||||
$difficultyCounts = Guide::query()
|
||||
->published()
|
||||
->selectRaw('difficulty, COUNT(*) as aggregate')
|
||||
->groupBy('difficulty')
|
||||
->pluck('aggregate', 'difficulty');
|
||||
|
||||
$difficultyOptions = [
|
||||
['value' => 'beginner', 'label' => '入门', 'count' => (int) ($difficultyCounts['beginner'] ?? 0)],
|
||||
['value' => 'intermediate', 'label' => '进阶', 'count' => (int) ($difficultyCounts['intermediate'] ?? 0)],
|
||||
['value' => 'advanced', 'label' => '高级', 'count' => (int) ($difficultyCounts['advanced'] ?? 0)],
|
||||
];
|
||||
|
||||
$guideStats = [
|
||||
'total' => Guide::query()->published()->count(),
|
||||
'beginner' => Guide::query()->published()->where('difficulty', 'beginner')->count(),
|
||||
'advanced' => Guide::query()->published()->where('difficulty', 'advanced')->count(),
|
||||
'updated_7d' => Guide::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(),
|
||||
];
|
||||
|
||||
return view('public.guides.index', [
|
||||
'items' => $builder->latest('published_at')->paginate(15)->withQueryString(),
|
||||
'categories' => Category::query()->where('type', 'guide')->where('is_active', true)->orderBy('name')->get(),
|
||||
'difficultyOptions' => $difficultyOptions,
|
||||
'guideStats' => $guideStats,
|
||||
'filters' => $request->only(['q', 'difficulty']),
|
||||
'sidebarTools' => Tool::published()->latest('published_at')->limit(6)->get(),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
@@ -60,6 +79,8 @@ class GuideController extends Controller
|
||||
return view('public.guides.show', [
|
||||
'item' => $guide,
|
||||
'bodyHtml' => $this->markdownRenderer->render($guide->body),
|
||||
'sidebarTools' => Tool::published()->latest('published_at')->limit(6)->get(),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace App\Http\Controllers\Site;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiModel;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -30,9 +29,30 @@ class ModelController extends Controller
|
||||
$builder->where('deployment_mode', (string) $request->string('deployment'));
|
||||
}
|
||||
|
||||
$modalityCounts = AiModel::query()
|
||||
->published()
|
||||
->selectRaw('modality, COUNT(*) as aggregate')
|
||||
->groupBy('modality')
|
||||
->pluck('aggregate', 'modality');
|
||||
|
||||
$modalityOptions = [
|
||||
['value' => 'text', 'label' => '文本', 'count' => (int) ($modalityCounts['text'] ?? 0)],
|
||||
['value' => 'multimodal', 'label' => '多模态', 'count' => (int) ($modalityCounts['multimodal'] ?? 0)],
|
||||
['value' => 'image', 'label' => '图像', 'count' => (int) ($modalityCounts['image'] ?? 0)],
|
||||
['value' => 'audio', 'label' => '音频', 'count' => (int) ($modalityCounts['audio'] ?? 0)],
|
||||
];
|
||||
|
||||
$modelStats = [
|
||||
'total' => AiModel::query()->published()->count(),
|
||||
'multimodal' => AiModel::query()->published()->where('modality', 'multimodal')->count(),
|
||||
'api' => AiModel::query()->published()->where('deployment_mode', 'api')->count(),
|
||||
'updated_7d' => AiModel::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(),
|
||||
];
|
||||
|
||||
return view('public.models.index', [
|
||||
'items' => $builder->orderByDesc('total_score')->paginate(18)->withQueryString(),
|
||||
'categories' => Category::query()->where('type', 'model')->where('is_active', true)->orderBy('name')->get(),
|
||||
'modalityOptions' => $modalityOptions,
|
||||
'modelStats' => $modelStats,
|
||||
'filters' => $request->only(['q', 'modality', 'deployment']),
|
||||
'sidebarTools' => \App\Models\Tool::published()->latest('published_at')->limit(6)->get(),
|
||||
'sidebarNews' => Article::published()->latest('published_at')->limit(6)->get(),
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Models\Category;
|
||||
use App\Models\Guide;
|
||||
use App\Support\MarkdownRenderer;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NewsController extends Controller
|
||||
@@ -34,9 +35,27 @@ class NewsController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$categories = Category::query()
|
||||
->where('type', 'news')
|
||||
->where('is_active', true)
|
||||
->withCount([
|
||||
'articles as published_articles_count' => fn (Builder $query): Builder => $query->published(),
|
||||
])
|
||||
->orderByDesc('published_articles_count')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$newsStats = [
|
||||
'total' => Article::query()->published()->count(),
|
||||
'today' => Article::query()->published()->whereDate('published_at', today())->count(),
|
||||
'high_source' => Article::query()->published()->where('source_level', 'high')->count(),
|
||||
'updated_7d' => Article::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(),
|
||||
];
|
||||
|
||||
return view('public.news.index', [
|
||||
'items' => $builder->latest('published_at')->paginate(15)->withQueryString(),
|
||||
'categories' => Category::query()->where('type', 'news')->where('is_active', true)->orderBy('name')->get(),
|
||||
'categories' => $categories,
|
||||
'newsStats' => $newsStats,
|
||||
'filters' => $request->only(['q', 'category']),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(),
|
||||
@@ -56,6 +75,8 @@ class NewsController extends Controller
|
||||
'item' => $article,
|
||||
'bodyHtml' => $this->markdownRenderer->render($article->body),
|
||||
'showRiskNotice' => $this->containsRiskKeyword($article->title.' '.$article->body),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user