226 lines
9.4 KiB
PHP
226 lines
9.4 KiB
PHP
@extends('layouts.site')
|
||
|
||
@section('page_class', 'page-tools')
|
||
@section('title', 'AI工具集 - AIWeb')
|
||
@section('meta_description', 'AI工具集首页,按分类分块浏览工具,左侧菜单可定位到对应模块。')
|
||
@section('canonical', route('tools.index'))
|
||
|
||
@section('head')
|
||
@vite('resources/css/tool_index.css')
|
||
@endsection
|
||
|
||
@section('content')
|
||
@php
|
||
$icons = ['bi-stars', 'bi-pencil', 'bi-image', 'bi-camera-video', 'bi-briefcase', 'bi-cpu', 'bi-chat-dots', 'bi-code-slash', 'bi-kanban'];
|
||
$channelModule = $modules['channel_cards'] ?? null;
|
||
$bannerModule = $modules['promo_banners'] ?? null;
|
||
$hotModule = $modules['hot_tools'] ?? null;
|
||
$latestModule = $modules['latest_tools'] ?? null;
|
||
$categoryModule = $modules['category_sections'] ?? null;
|
||
$moduleOrder = collect($modules)->sortBy('sort_order')->pluck('module_key')->values();
|
||
|
||
$channelItems = collect(data_get($channelModule, 'items', []))->take((int) data_get($channelModule, 'limit', 5));
|
||
$bannerItems = collect(data_get($bannerModule, 'items', []))->take((int) data_get($bannerModule, 'limit', 2));
|
||
@endphp
|
||
|
||
<div class="tool-home">
|
||
<aside class="tool-side" aria-label="工具分类侧边栏">
|
||
<div class="tool-side-logo"><span class="tool-side-logo-dot">AI</span>{{ data_get($categoryModule, 'extra.side_title', 'AI工具集') }}</div>
|
||
<nav class="tool-side-links">
|
||
@if(data_get($channelModule, 'enabled', true) === true)
|
||
<a class="tool-side-link" href="#section-channel">
|
||
<i class="bi bi-grid"></i>
|
||
<span>{{ data_get($channelModule, 'title', '频道卡片') }}</span>
|
||
<small>{{ $channelItems->count() }}</small>
|
||
</a>
|
||
@endif
|
||
|
||
@if(data_get($bannerModule, 'enabled', true) === true)
|
||
<a class="tool-side-link" href="#section-banner">
|
||
<i class="bi bi-megaphone"></i>
|
||
<span>{{ data_get($bannerModule, 'title', '横幅推荐') }}</span>
|
||
<small>{{ $bannerItems->count() }}</small>
|
||
</a>
|
||
@endif
|
||
|
||
@if(data_get($hotModule, 'enabled', true) === true)
|
||
<a class="tool-side-link" href="#section-hot">
|
||
<i class="bi bi-fire"></i>
|
||
<span>{{ data_get($hotModule, 'title', '热门工具') }}</span>
|
||
<small>{{ $hotTools->count() }}</small>
|
||
</a>
|
||
@endif
|
||
|
||
@if(data_get($latestModule, 'enabled', true) === true)
|
||
<a class="tool-side-link" href="#section-latest">
|
||
<i class="bi bi-clock-history"></i>
|
||
<span>{{ data_get($latestModule, 'title', '最新收录') }}</span>
|
||
<small>{{ $latestTools->count() }}</small>
|
||
</a>
|
||
@endif
|
||
|
||
@if(data_get($categoryModule, 'enabled', true) === true)
|
||
@foreach($categorySections as $index => $section)
|
||
<a class="tool-side-link" href="#section-{{ $section['slug'] }}">
|
||
<i class="bi {{ $icons[$index % count($icons)] }}"></i>
|
||
<span>{{ $section['name'] }}</span>
|
||
<small>{{ $section['count'] }}</small>
|
||
</a>
|
||
@endforeach
|
||
@endif
|
||
</nav>
|
||
</aside>
|
||
|
||
<section class="tool-main">
|
||
<section class="tool-hero">
|
||
<span class="tool-chip">AIBASE.CN</span>
|
||
<h1 class="tool-title">AI工具集</h1>
|
||
<p class="tool-sub">10000+精选AI工具集合,涵盖写作、图像、视频、编程等多个领域</p>
|
||
|
||
<form class="tool-search" method="get" action="{{ route('tools.list') }}" role="search" aria-label="站内 AI 工具搜索">
|
||
<input type="hidden" name="tab" value="{{ $activeTab }}">
|
||
<input type="search" name="q" value="{{ $filters['q'] ?? '' }}" placeholder="输入关键词搜索AI工具,如:写作、图像、自动化" autocomplete="off" spellcheck="false">
|
||
<button class="btn btn-primary" type="submit"><i class="bi bi-search"></i> 搜索</button>
|
||
</form>
|
||
|
||
<nav class="channel-tabs justify-content-center" aria-label="筛选模式">
|
||
@foreach($tabOptions as $tab)
|
||
<a class="channel-tab @if($activeTab === $tab['key']) active @endif" href="{{ route('tools.index', array_filter(array_merge($filters, ['tab' => $tab['key']]))) }}">{{ $tab['label'] }}</a>
|
||
@endforeach
|
||
</nav>
|
||
</section>
|
||
|
||
@foreach($moduleOrder as $moduleKey)
|
||
|
||
@if($moduleKey === 'hot_tools' && data_get($hotModule, 'enabled', true) === true)
|
||
<section id="section-hot" class="tool-section" aria-label="热门工具">
|
||
<header class="tool-section-head">
|
||
<h2><i class="bi bi-fire text-danger"></i> {{ data_get($hotModule, 'title', '热门工具') }}</h2>
|
||
@php($hotMore = data_get($hotModule, 'more_url') ?: route('tools.list', ['tab' => 'recommended']))
|
||
<a href="{{ $hotMore }}">查看更多</a>
|
||
</header>
|
||
<x-portal.tool-grid :tools="$hotTools" :show-meta="false" :show-footer="false" />
|
||
</section>
|
||
@endif
|
||
|
||
@if($moduleKey === 'latest_tools' && data_get($latestModule, 'enabled', true) === true)
|
||
<section id="section-latest" class="tool-section" aria-label="最新收录">
|
||
<header class="tool-section-head">
|
||
<h2><i class="bi bi-clock-history text-primary"></i> {{ data_get($latestModule, 'title', '最新收录') }}</h2>
|
||
@php($latestMore = data_get($latestModule, 'more_url') ?: route('tools.list', ['tab' => 'latest']))
|
||
<a href="{{ $latestMore }}">查看更多</a>
|
||
</header>
|
||
<x-portal.tool-grid :tools="$latestTools" :show-meta="false" :show-footer="false" />
|
||
</section>
|
||
@endif
|
||
|
||
@if($moduleKey === 'category_sections' && data_get($categoryModule, 'enabled', true) === true)
|
||
@foreach($categorySections as $section)
|
||
<section id="section-{{ $section['slug'] }}" class="tool-section" aria-label="{{ $section['name'] }}工具">
|
||
<header class="tool-section-head">
|
||
<h2><i class="bi bi-grid-3x3-gap text-primary"></i> {{ $section['name'] }}</h2>
|
||
<a href="{{ route('tools.list', ['category' => $section['slug']]) }}">查看更多</a>
|
||
</header>
|
||
|
||
@if($section['tools']->isNotEmpty())
|
||
<x-portal.tool-grid :tools="$section['tools']" :show-meta="false" :show-footer="false" />
|
||
@else
|
||
<p class="text-muted-soft mb-0">该分类暂未收录工具</p>
|
||
@endif
|
||
</section>
|
||
@endforeach
|
||
@endif
|
||
@endforeach
|
||
</section>
|
||
</div>
|
||
@endsection
|
||
|
||
@section('scripts')
|
||
<script>
|
||
(() => {
|
||
const links = Array.from(document.querySelectorAll('.tool-side-link[href^="#section-"]'));
|
||
const sections = Array.from(document.querySelectorAll('[id^="section-"]'));
|
||
|
||
if (!links.length || !sections.length || !('IntersectionObserver' in window)) {
|
||
return;
|
||
}
|
||
|
||
const setActive = (activeId) => {
|
||
links.forEach((link) => {
|
||
const id = link.getAttribute('href')?.replace('#', '') || '';
|
||
link.classList.toggle('is-active', id === activeId);
|
||
});
|
||
};
|
||
|
||
const syncHash = (id) => {
|
||
const hash = `#${id}`;
|
||
if (window.location.hash !== hash) {
|
||
history.replaceState(null, '', hash);
|
||
}
|
||
};
|
||
|
||
links.forEach((link) => {
|
||
link.addEventListener('click', (event) => {
|
||
const id = link.getAttribute('href')?.replace('#', '');
|
||
if (!id) {
|
||
return;
|
||
}
|
||
|
||
const target = document.getElementById(id);
|
||
if (!target) {
|
||
return;
|
||
}
|
||
|
||
event.preventDefault();
|
||
setActive(id);
|
||
syncHash(id);
|
||
target.scrollIntoView({
|
||
behavior: 'smooth',
|
||
block: 'start'
|
||
});
|
||
});
|
||
});
|
||
|
||
const observer = new IntersectionObserver((entries) => {
|
||
const visible = entries
|
||
.filter((entry) => entry.isIntersecting)
|
||
.sort((a, b) => b.intersectionRatio - a.intersectionRatio);
|
||
|
||
if (!visible.length) {
|
||
return;
|
||
}
|
||
|
||
const top = visible[0].target;
|
||
if (top instanceof HTMLElement) {
|
||
setActive(top.id);
|
||
syncHash(top.id);
|
||
}
|
||
}, {
|
||
rootMargin: '-18% 0px -64% 0px',
|
||
threshold: [0.2, 0.45, 0.7],
|
||
});
|
||
|
||
sections.forEach((section) => observer.observe(section));
|
||
|
||
if (window.location.hash) {
|
||
const hashId = window.location.hash.replace('#', '');
|
||
const target = document.getElementById(hashId);
|
||
if (target) {
|
||
setActive(hashId);
|
||
window.requestAnimationFrame(() => {
|
||
target.scrollIntoView({
|
||
behavior: 'auto',
|
||
block: 'start'
|
||
});
|
||
});
|
||
} else {
|
||
setActive(sections[0].id);
|
||
syncHash(sections[0].id);
|
||
}
|
||
} else {
|
||
setActive(sections[0].id);
|
||
syncHash(sections[0].id);
|
||
}
|
||
})();
|
||
</script>
|
||
@endsection |