Files
yitao-ren-gallery/gallery/templates/gallery/search.html
2026-02-25 16:47:17 +08:00

191 lines
10 KiB
HTML
Executable File

{% extends 'gallery/base.html' %}
{% block content %}
<div class="container mx-auto px-4 py-8">
<!-- 面包屑导航 -->
<nav class="mb-8">
<ol class="flex items-center space-x-2 text-sm text-gray-400">
<li>
<a href="{% url 'index' %}" class="hover:text-blue-400 transition-colors">Gallery</a>
</li>
<li>
<span class="mx-2">/</span>
</li>
<li class="text-gray-300">搜索</li>
</ol>
</nav>
<!-- 搜索框 -->
<div class="max-w-2xl mx-auto mb-12">
<form method="get" action="{% url 'search' %}" class="relative">
<div class="relative">
<input
type="text"
name="q"
value="{{ query }}"
placeholder="搜索作品标题、描述或分类..."
class="w-full px-6 py-4 pl-14 bg-dark-card border border-gray-800 rounded-xl text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all"
autocomplete="off"
>
<div class="absolute left-5 top-1/2 transform -translate-y-1/2">
<svg class="w-5 h-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</div>
<button
type="submit"
class="absolute right-3 top-1/2 transform -translate-y-1/2 px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors"
>
搜索
</button>
</div>
</form>
{% if query %}
<div class="mt-4 text-center">
<p class="text-gray-400">
搜索 "<span class="text-blue-400 font-medium">{{ query }}</span>" 的结果
<span class="text-gray-300">({{ artworks.count }} 个作品)</span>
</p>
</div>
{% endif %}
</div>
<!-- 搜索结果 -->
{% if query %}
{% if artworks %}
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
{% for artwork in artworks %}
<a href="{% url 'artwork_detail' artwork.slug %}" class="group">
<div class="relative overflow-hidden rounded-xl bg-dark-card transition-all duration-300 hover:scale-[1.02] hover:shadow-2xl">
<!-- 图片 -->
<div class="aspect-square overflow-hidden">
<img
data-src="{{ artwork.thumbnail.url|default:artwork.image.url }}"
alt="{{ artwork.title }}"
class="lazy-image w-full h-full object-cover transition-transform duration-500 group-hover:scale-110"
loading="lazy"
>
</div>
<!-- 遮罩层 -->
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
<!-- 作品信息 -->
<div class="absolute bottom-0 left-0 right-0 p-4 transform translate-y-full group-hover:translate-y-0 transition-transform duration-300">
<div class="bg-black/80 backdrop-blur-sm rounded-lg p-4">
<h3 class="text-lg font-semibold text-white mb-2 truncate">{{ artwork.title }}</h3>
{% if artwork.description %}
<p class="text-gray-300 text-sm line-clamp-2 mb-3">
{{ artwork.description|truncatechars:80 }}
</p>
{% endif %}
{% if artwork.category %}
<div class="mb-3">
<a href="{% url 'category' artwork.category.slug %}" class="inline-flex items-center px-3 py-1 bg-blue-600/20 text-blue-400 rounded-full text-xs hover:bg-blue-600/30 transition-colors">
{{ artwork.category.name }}
</a>
</div>
{% endif %}
<div class="flex items-center justify-between text-xs text-gray-400">
<span>{{ artwork.created_at|date:"Y年m月d日" }}</span>
{% if artwork.view_count %}
<span>{{ artwork.view_count }} 次浏览</span>
{% endif %}
</div>
</div>
</div>
<!-- 高亮匹配 -->
{% if query in artwork.title or query in artwork.description %}
<div class="absolute top-4 left-4">
<span class="px-3 py-1 bg-yellow-600/90 text-white text-xs font-medium rounded-full backdrop-blur-sm">
匹配
</span>
</div>
{% endif %}
</div>
</a>
{% endfor %}
</div>
{% else %}
<!-- 无结果 -->
<div class="text-center py-20">
<div class="inline-flex items-center justify-center w-24 h-24 rounded-full bg-gray-800/50 mb-6">
<svg class="w-12 h-12 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<h3 class="text-xl font-semibold text-gray-300 mb-2">未找到相关作品</h3>
<p class="text-gray-500 max-w-md mx-auto mb-8">
没有找到与 "<span class="text-blue-400">{{ query }}</span>" 相关的作品。
请尝试其他关键词或浏览所有作品。
</p>
<div class="flex flex-col sm:flex-row gap-4 justify-center">
<a href="{% url 'index' %}" class="inline-flex items-center justify-center px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
</svg>
浏览所有作品
</a>
<button onclick="history.back()" class="inline-flex items-center justify-center px-6 py-3 bg-gray-800 hover:bg-gray-700 text-gray-300 rounded-lg transition-colors">
返回上一页
</button>
</div>
</div>
{% endif %}
{% else %}
<!-- 搜索提示 -->
<div class="text-center py-20">
<div class="inline-flex items-center justify-center w-24 h-24 rounded-full bg-gray-800/50 mb-6">
<svg class="w-12 h-12 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</div>
<h3 class="text-xl font-semibold text-gray-300 mb-2">搜索作品</h3>
<p class="text-gray-500 max-w-md mx-auto mb-8">
输入关键词搜索作品标题、描述或分类。
支持中文和英文搜索。
</p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 max-w-3xl mx-auto">
<div class="bg-dark-card rounded-xl p-6 border border-gray-800">
<div class="w-12 h-12 rounded-lg bg-blue-600/20 flex items-center justify-center mb-4">
<svg class="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14"></path>
</svg>
</div>
<h4 class="text-lg font-medium text-gray-300 mb-2">标题搜索</h4>
<p class="text-gray-500 text-sm">
按作品标题关键词搜索,支持模糊匹配。
</p>
</div>
<div class="bg-dark-card rounded-xl p-6 border border-gray-800">
<div class="w-12 h-12 rounded-lg bg-green-600/20 flex items-center justify-center mb-4">
<svg class="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
</svg>
</div>
<h4 class="text-lg font-medium text-gray-300 mb-2">描述搜索</h4>
<p class="text-gray-500 text-sm">
搜索作品描述中的关键词,了解作品背后的故事。
</p>
</div>
<div class="bg-dark-card rounded-xl p-6 border border-gray-800">
<div class="w-12 h-12 rounded-lg bg-purple-600/20 flex items-center justify-center mb-4">
<svg class="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path>
</svg>
</div>
<h4 class="text-lg font-medium text-gray-300 mb-2">分类搜索</h4>
<p class="text-gray-500 text-sm">
按分类名称搜索,快速找到特定类型的作品。
</p>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}