增加前端搜索功能

This commit is contained in:
李志强 2025-06-06 10:52:56 +08:00
parent 732a8474a8
commit a81aff626e
7 changed files with 2242 additions and 870 deletions

View File

@ -0,0 +1,102 @@
<?php
namespace app\index\controller;
use think\Db;
use app\index\controller\BaseController;
use app\index\model\Articles\Articles;
use app\index\model\Articles\ArticlesCategory;
use app\index\model\Resources\Resources;
use app\index\model\Resources\ResourcesCategory;
class SearchController extends BaseController
{
public function index()
{
$keyword = input('keyword', '');
$type = input('type', 'article'); // 搜索类型article-文章resource-资源
$page = input('page', 1);
$limit = input('limit', 10);
if (empty($keyword)) {
$this->error('请输入搜索关键词');
}
// 根据类型选择对应的表和分类表
if ($type == 'article') {
$model = new Articles();
$categoryModel = new ArticlesCategory();
$detailUrl = '/index/articles/detail';
$categoryUrl = '/index/articles/category';
$status = 2; // 文章状态为2
$fields = 'id, title, cate, image, author, create_time as publishdate';
} else if ($type == 'resource') {
$model = new Resources();
$categoryModel = new ResourcesCategory();
$detailUrl = '/index/resources/detail';
$categoryUrl = '/index/resources/category';
$status = 1; // 资源状态为1
$fields = 'id, title, cate, icon, author, create_time as publishdate';
} else {
$this->error('无效的搜索类型');
}
// 搜索内容
$items = $model->where('title', 'like', "%{$keyword}%")
->where('status', $status)
->field($fields)
->order('create_time desc')
->page($page, $limit)
->select();
// 获取总数
$count = $model->where('title', 'like', "%{$keyword}%")
->where('status', $status)
->count();
// 获取分类名称和图片
foreach ($items as &$item) {
if ($type == 'article') {
$category = $categoryModel->where('id', $item['cate'])
->field('id, name, image')
->find();
$item['category'] = $category ?: ['id' => 0, 'name' => '未分类', 'image' => ''];
// 如果文章的图片为空,使用分类的图片
if (empty($item['image'])) {
$item['image'] = $item['category']['image'];
}
if (empty($item['image'])) {
$item['image'] = '/static/images/default.jpg';
}
} else {
$category = $categoryModel->where('id', $item['cate'])
->field('id, name, icon')
->find();
$item['category'] = $category ?: ['id' => 0, 'name' => '未分类', 'icon' => ''];
// 如果资源的图片为空,使用分类的图片
if (empty($item['icon'])) {
$item['icon'] = $item['category']['icon'];
}
if (empty($item['icon'])) {
$item['icon'] = '/static/images/default.jpg';
}
}
}
// 准备视图数据
$viewData = [
'keyword' => $keyword,
'type' => $type,
'items' => $items,
'detailUrl' => $detailUrl,
'count' => $count,
'page' => $page,
'limit' => $limit
];
return view('index', $viewData);
}
}

View File

@ -46,6 +46,9 @@ $loginStatus = [
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="main-menu__search">
<i class="layui-icon layui-icon-search search-icon" id="mainSearchIcon"></i>
</div>
<div class="main-menu__right">
<div class="username">
<?php if ($userInfo['is_login']): ?>
@ -103,6 +106,9 @@ $loginStatus = [
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="sticky-nav__search">
<i class="layui-icon layui-icon-search search-icon" id="stickySearchIcon"></i>
</div>
<div class="sticky-nav__right">
<div class="main-menu__right">
<div class="username">
@ -145,216 +151,19 @@ $loginStatus = [
</div>
</div>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
</style>
<!-- 搜索遮罩 -->
<div class="search-mask" id="searchMask">
<div class="search-container">
<div class="search-box">
<select id="searchType" class="search-type">
<option value="article">文章</option>
<option value="resource">资源</option>
</select>
<input type="text" id="searchInput" placeholder="请输入搜索关键词">
<button id="searchBtn">搜索</button>
</div>
</div>
</div>
<script>
// 在页面加载时立即执行
@ -601,4 +410,482 @@ $loginStatus = [
return false;
});
});
</script>
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 执行搜索
function executeSearch() {
var searchInput = document.getElementById('searchInput');
if (!searchInput) {
layer.msg('搜索组件初始化失败');
return;
}
var keyword = searchInput.value.trim();
var type = document.getElementById('searchType').value;
if (!keyword) {
layer.msg('请输入搜索关键词');
return;
}
// 跳转到统一的搜索结果页面
window.location.href = '/index/search/index?keyword=' + encodeURIComponent(keyword) + '&type=' + type;
}
// 绑定事件
$(function() {
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var mainSearchIcon = $('#mainSearchIcon');
var stickySearchIcon = $('#stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
setTimeout(function() {
searchInput.focus();
}, 300);
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('');
}
// 绑定搜索图标点击事件
mainSearchIcon.on('click', showSearch);
stickySearchIcon.on('click', showSearch);
// 绑定搜索按钮点击事件
searchBtn.on('click', function(e) {
e.preventDefault();
executeSearch();
});
// 绑定回车键搜索
searchInput.on('keypress', function(e) {
if (e.which === 13) {
e.preventDefault();
executeSearch();
}
});
// 点击遮罩层关闭搜索框
searchMask.on('click', function(e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 绑定ESC键关闭搜索框
$(document).on('keydown', function(e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时选中所有文本
searchInput.on('focus', function() {
this.select();
});
});
});
</script>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
/* 搜索相关样式 */
.search-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 9999;
display: none;
opacity: 0;
transition: opacity 0.3s ease;
justify-content: center;
align-items: center;
}
.search-mask.show {
display: flex;
opacity: 1;
}
.search-container {
position: relative;
width: 80%;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transform: translateY(-20px);
transition: transform 0.3s ease;
}
.search-mask.show .search-container {
transform: translateY(0);
}
.search-box {
display: flex;
align-items: center;
height: 60px;
background: #fff;
border-radius: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.search-box input {
flex: 1;
height: 100%;
padding: 0 20px;
border: none;
outline: none;
font-size: 16px;
}
.search-box button {
height: 100%;
padding: 0 30px;
border: none;
background: #1E9FFF;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.search-box button:hover {
background: #1a8fe6;
}
.search-icon {
font-size: 20px;
cursor: pointer;
color: #333;
transition: color 0.3s ease;
}
.search-icon:hover {
color: #1e9fff;
}
.search-type {
height: 100%;
padding: 0 15px;
border: none;
border-right: 1px solid #eee;
background: #f8f8f8;
color: #666;
font-size: 14px;
cursor: pointer;
outline: none;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 12px;
padding-right: 30px;
}
.search-type:hover {
background-color: #f0f0f0;
}
.search-type:focus {
background-color: #fff;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.search-results {
padding: 15px;
max-height: 370px;
overflow-y: auto;
}
.search-section {
margin-bottom: 20px;
}
.search-section h3 {
font-size: 16px;
color: #333;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px solid #eee;
}
.search-section ul {
list-style: none;
padding: 0;
margin: 0;
}
.search-section li {
padding: 8px 0;
border-bottom: 1px dashed #eee;
display: flex;
align-items: center;
justify-content: space-between;
}
.search-section li:last-child {
border-bottom: none;
}
.search-section a {
color: #333;
text-decoration: none;
flex: 1;
}
.search-section a:hover {
color: #1E9FFF;
}
.search-section .downloads {
color: #1E9FFF;
font-size: 12px;
margin-left: 10px;
}
/* 自定义滚动条样式 */
.search-results::-webkit-scrollbar {
width: 6px;
}
.search-results::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.search-results::-webkit-scrollbar-thumb {
background: #ccc;
border-radius: 3px;
}
.search-results::-webkit-scrollbar-thumb:hover {
background: #999;
}
</style>

View File

@ -69,6 +69,22 @@ $loginStatus = [
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="main-menu__search">
<i class="layui-icon layui-icon-search search-icon" id="mainSearchIcon"></i>
</div>
<!-- 搜索蒙版 -->
<div class="search-mask" id="searchMask" style="">
<div class="search-container">
<div class="search-box">
<select id="searchType" class="search-type">
<option value="article">文章</option>
<option value="resource">资源</option>
</select>
<input type="text" id="searchInput" placeholder="请输入搜索关键词">
<button class="search-btn" id="searchBtn">搜索</button>
</div>
</div>
</div>
<div class="main-menu__right">
<div class="username">
<?php if ($userInfo['is_login']): ?>
@ -125,14 +141,17 @@ $loginStatus = [
</div>
<div class="sticky-nav__menu">
<ul>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="sticky-nav__search">
<i class="layui-icon layui-icon-search search-icon" id="stickySearchIcon"></i>
</div>
<div class="sticky-nav__right">
<div class="main-menu__right">
<div class="username">
@ -175,217 +194,6 @@ $loginStatus = [
</div>
</div>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
</style>
<script>
// 在页面加载时立即执行
(function () {
@ -417,8 +225,97 @@ $loginStatus = [
}
})();
layui.use(['carousel', 'form', 'layer'], function () {
var carousel = layui.carousel, form = layui.form, layer = layui.layer, $ = layui.$;
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 执行搜索
function executeSearch() {
var searchInput = document.getElementById('searchInput');
if (!searchInput) {
layer.msg('搜索组件初始化失败');
return;
}
var keyword = searchInput.value.trim();
var type = document.getElementById('searchType').value;
if (!keyword) {
layer.msg('请输入搜索关键词');
return;
}
// 跳转到统一的搜索结果页面
window.location.href = '/index/search/index?keyword=' + encodeURIComponent(keyword) + '&type=' + type;
}
// 绑定事件
$(function() {
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var mainSearchIcon = $('#mainSearchIcon');
var stickySearchIcon = $('#stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
setTimeout(function() {
searchInput.focus();
}, 300);
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('');
}
// 绑定搜索图标点击事件
mainSearchIcon.on('click', showSearch);
stickySearchIcon.on('click', showSearch);
// 绑定搜索按钮点击事件
searchBtn.on('click', function(e) {
e.preventDefault();
executeSearch();
});
// 绑定回车键搜索
searchInput.on('keypress', function(e) {
if (e.which === 13) {
e.preventDefault();
executeSearch();
}
});
// 点击遮罩层关闭搜索框
searchMask.on('click', function(e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 绑定ESC键关闭搜索框
$(document).on('keydown', function(e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时选中所有文本
searchInput.on('focus', function() {
this.select();
});
});
});
// 其他功能相关代码
layui.use(['carousel', 'form'], function () {
var carousel = layui.carousel;
var form = layui.form;
var $ = layui.$;
// 检查本地存储并自动登录
function checkAutoLogin() {
@ -671,4 +568,324 @@ $loginStatus = [
return false;
});
});
</script>
</script>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
.search-icon {
font-size: 20px;
cursor: pointer;
color: #333;
transition: color 0.3s ease;
}
.search-icon:hover {
color: #1e9fff;
}
.search-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 9999;
display: none;
opacity: 0;
transition: opacity 0.3s ease;
justify-content: center;
align-items: center;
}
.search-mask.show {
display: flex;
opacity: 1;
}
.search-container {
position: relative;
width: 80%;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transform: translateY(-20px);
transition: transform 0.3s ease;
}
.search-mask.show .search-container {
transform: translateY(0);
}
.search-box {
display: flex;
align-items: center;
height: 60px;
background: #fff;
border-radius: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.search-box input {
flex: 1;
height: 100%;
padding: 0 20px;
border: none;
outline: none;
font-size: 16px;
}
.search-box button {
height: 100%;
padding: 0 30px;
border: none;
background: #1E9FFF;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.search-box button:hover {
background: #1a8fe6;
}
.search-type {
height: 100%;
padding: 0 15px;
border: none;
border-right: 1px solid #eee;
background: #f8f8f8;
color: #666;
font-size: 14px;
cursor: pointer;
outline: none;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 12px;
padding-right: 30px;
}
.search-type:hover {
background-color: #f0f0f0;
}
.search-type:focus {
background-color: #fff;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
</style>

View File

@ -614,6 +614,87 @@
});
}
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 搜索功能相关变量
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var searchIcons = $('#mainSearchIcon, #stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
searchInput.focus();
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('').blur();
}
// 执行搜索
function doSearch() {
var keyword = searchInput.val().trim();
if (keyword) {
window.location.href = '/search?keyword=' + encodeURIComponent(keyword);
} else {
layer.msg('请输入搜索关键词', { icon: 0 });
}
}
// 事件绑定
function bindEvents() {
// 点击搜索图标显示搜索框
searchIcons.on('click', showSearch);
// 点击蒙版背景隐藏搜索框
searchMask.on('click', function (e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 搜索按钮点击事件
searchBtn.on('click', function (e) {
e.preventDefault();
doSearch();
});
// 回车键触发搜索
searchInput.on('keypress', function (e) {
if (e.which === 13) {
e.preventDefault();
doSearch();
}
});
// ESC键关闭搜索框
$(document).on('keydown', function (e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时全选文本
searchInput.on('focus', function () {
this.select();
});
}
// 初始化
function init() {
bindEvents();
}
// 启动
init();
});
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
loadWebArticles();

View File

@ -0,0 +1,88 @@
{include file="component/head" /}
{include file="component/header-simple" /}
<div class="layui-container" style="padding: 20px 0;">
<div class="layui-row">
<div class="layui-col-md12">
<!-- 搜索头部 -->
<div class="layui-card">
<div class="layui-card-header" style="display: flex; align-items: center;">
<h6 class="layui-inline" style="margin-bottom: 0;padding:10px 0;">搜索结果:{$keyword}</h6>
<!-- <div class="layui-inline" style="float: right;">
<a href="/index/search/list?keyword={$keyword}&type=article" class="layui-btn layui-btn-sm {$type == 'article' ? 'layui-btn-normal' : 'layui-btn-primary'}">文章</a>
<a href="/index/search/list?keyword={$keyword}&type=resource" class="layui-btn layui-btn-sm {$type == 'resource' ? 'layui-btn-normal' : 'layui-btn-primary'}">资源</a>
</div> -->
</div>
</div>
<!-- 搜索结果列表 -->
<div class="layui-row layui-col-space20" style="margin-top: 20px;">
{if $items}
{volist name="items" id="item"}
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<div style="display: flex; align-items: center;">
<div style="margin-right: 20px;">
{if $type == 'article'}
<img src="{$item.image}" alt="{$item.title}" style="width: 250px; height: 140px; object-fit: cover;">
{else}
<img src="{$item.icon}" alt="{$item.title}" style="width: 250px; height: 140px; object-fit: cover;">
{/if}
</div>
<div class="layui-col-md8">
<h3 class="layui-text">
<a href="{$detailUrl}?id={$item.id}" class="layui-text" style="color: #333;">{$item.title}</a>
</h3>
<div class="layui-text" style="margin: 10px 0;">
<span class="layui-badge layui-bg-gray">{$item.category.name}</span>
<span class="layui-badge layui-bg-gray">{$item.author}</span>
<span class="layui-badge layui-bg-gray">{$item.publishdate|date="Y-m-d"}</span>
</div>
<div class="layui-text" style="margin-top: 10px;">
<a href="{$detailUrl}?id={$item.id}" class="layui-btn layui-btn-sm layui-btn-normal">查看详情</a>
</div>
</div>
</div>
</div>
</div>
</div>
{/volist}
{else}
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body" style="text-align: center; padding: 50px 0;">
<i class="layui-icon layui-icon-face-surprised" style="font-size: 48px; color: #999;"></i>
<p style="margin-top: 15px; color: #999;">暂无相关{$type == 'article' ? '文章' : '资源'}</p>
</div>
</div>
</div>
{/if}
</div>
<!-- 分页 -->
<div id="pagination" style="text-align: center; margin-top: 20px;"></div>
</div>
</div>
</div>
{include file="component/footer" /}
{include file="component/foot" /}
<script>
layui.use(['laypage'], function(){
var laypage = layui.laypage;
//执行一个laypage实例
laypage.render({
elem: 'pagination',
count: {$count},
limit: {$limit},
curr: {$page},
jump: function(obj, first){
if(!first){
var url = '/index/search/list?keyword={$keyword}&type={$type}&page=' + obj.curr + '&limit=' + obj.limit;
window.location.href = url;
}
}
});
});
</script>

View File

@ -1,4 +1,4 @@
<?php /*a:5:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\articles\detail.php";i:1748423296;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\head.php";i:1747617129;s:71:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header-simple.php";i:1748316508;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747617266;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\foot.php";i:1747616844;}*/ ?>
<?php /*a:5:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\articles\detail.php";i:1748423296;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\head.php";i:1747617129;s:71:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header-simple.php";i:1749174451;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1749170849;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\foot.php";i:1747616844;}*/ ?>
<!DOCTYPE html>
<html>
@ -58,12 +58,17 @@ $loginStatus = [
</div>
<div class="main-menu__nav">
<ul class="main-menu__list">
<li><a href="/index.html">首页</a></li>
<li><a href="/about.html">关于我们</a></li>
<li><a href="/products.html">产品服务</a></li>
<li><a href="/contact.html">联系我们</a></li>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="main-menu__search">
<i class="layui-icon layui-icon-search search-icon" id="mainSearchIcon"></i>
</div>
<div class="main-menu__right">
<div class="username">
<?php if ($userInfo['is_login']): ?>
@ -113,12 +118,17 @@ $loginStatus = [
</div>
<div class="sticky-nav__menu">
<ul>
<li><a href="/index.html">首页</a></li>
<li><a href="/about.html">关于我们</a></li>
<li><a href="/products.html">产品服务</a></li>
<li><a href="/contact.html">联系我们</a></li>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="sticky-nav__search">
<i class="layui-icon layui-icon-search search-icon" id="stickySearchIcon"></i>
</div>
<div class="sticky-nav__right">
<div class="main-menu__right">
<div class="username">
@ -161,216 +171,19 @@ $loginStatus = [
</div>
</div>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
</style>
<!-- 搜索遮罩 -->
<div class="search-mask" id="searchMask">
<div class="search-container">
<div class="search-box">
<select id="searchType" class="search-type">
<option value="article">文章</option>
<option value="resource">资源</option>
</select>
<input type="text" id="searchInput" placeholder="请输入搜索关键词">
<button id="searchBtn">搜索</button>
</div>
</div>
</div>
<script>
// 在页面加载时立即执行
@ -617,7 +430,485 @@ $loginStatus = [
return false;
});
});
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 执行搜索
function executeSearch() {
var searchInput = document.getElementById('searchInput');
if (!searchInput) {
layer.msg('搜索组件初始化失败');
return;
}
var keyword = searchInput.value.trim();
var type = document.getElementById('searchType').value;
if (!keyword) {
layer.msg('请输入搜索关键词');
return;
}
// 跳转到统一的搜索结果页面
window.location.href = '/index/search/index?keyword=' + encodeURIComponent(keyword) + '&type=' + type;
}
// 绑定事件
$(function() {
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var mainSearchIcon = $('#mainSearchIcon');
var stickySearchIcon = $('#stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
setTimeout(function() {
searchInput.focus();
}, 300);
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('');
}
// 绑定搜索图标点击事件
mainSearchIcon.on('click', showSearch);
stickySearchIcon.on('click', showSearch);
// 绑定搜索按钮点击事件
searchBtn.on('click', function(e) {
e.preventDefault();
executeSearch();
});
// 绑定回车键搜索
searchInput.on('keypress', function(e) {
if (e.which === 13) {
e.preventDefault();
executeSearch();
}
});
// 点击遮罩层关闭搜索框
searchMask.on('click', function(e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 绑定ESC键关闭搜索框
$(document).on('keydown', function(e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时选中所有文本
searchInput.on('focus', function() {
this.select();
});
});
});
</script>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
/* 搜索相关样式 */
.search-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 9999;
display: none;
opacity: 0;
transition: opacity 0.3s ease;
justify-content: center;
align-items: center;
}
.search-mask.show {
display: flex;
opacity: 1;
}
.search-container {
position: relative;
width: 80%;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transform: translateY(-20px);
transition: transform 0.3s ease;
}
.search-mask.show .search-container {
transform: translateY(0);
}
.search-box {
display: flex;
align-items: center;
height: 60px;
background: #fff;
border-radius: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.search-box input {
flex: 1;
height: 100%;
padding: 0 20px;
border: none;
outline: none;
font-size: 16px;
}
.search-box button {
height: 100%;
padding: 0 30px;
border: none;
background: #1E9FFF;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.search-box button:hover {
background: #1a8fe6;
}
.search-icon {
font-size: 20px;
cursor: pointer;
color: #333;
transition: color 0.3s ease;
}
.search-icon:hover {
color: #1e9fff;
}
.search-type {
height: 100%;
padding: 0 15px;
border: none;
border-right: 1px solid #eee;
background: #f8f8f8;
color: #666;
font-size: 14px;
cursor: pointer;
outline: none;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 12px;
padding-right: 30px;
}
.search-type:hover {
background-color: #f0f0f0;
}
.search-type:focus {
background-color: #fff;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.search-results {
padding: 15px;
max-height: 370px;
overflow-y: auto;
}
.search-section {
margin-bottom: 20px;
}
.search-section h3 {
font-size: 16px;
color: #333;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px solid #eee;
}
.search-section ul {
list-style: none;
padding: 0;
margin: 0;
}
.search-section li {
padding: 8px 0;
border-bottom: 1px dashed #eee;
display: flex;
align-items: center;
justify-content: space-between;
}
.search-section li:last-child {
border-bottom: none;
}
.search-section a {
color: #333;
text-decoration: none;
flex: 1;
}
.search-section a:hover {
color: #1E9FFF;
}
.search-section .downloads {
color: #1E9FFF;
font-size: 12px;
margin-left: 10px;
}
/* 自定义滚动条样式 */
.search-results::-webkit-scrollbar {
width: 6px;
}
.search-results::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.search-results::-webkit-scrollbar-thumb {
background: #ccc;
border-radius: 3px;
}
.search-results::-webkit-scrollbar-thumb:hover {
background: #999;
}
</style>
<div class="main">
<div class="location">
<div class="container">
@ -820,6 +1111,10 @@ $loginStatus = [
<p class="copyright__text">Copyright <span class="dynamic-year">2025</span> | All Rights By <a
href="http://www.yunzer.cn">Yunzer</a></p>
</div>
<div class="container wow fadeInUp animated" data-wow-delay="400ms"
style="visibility: visible; animation-delay: 400ms; animation-name: fadeInUp;">
<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow"><?php echo htmlentities((string) $config['admin_icp']); ?></a>
</div>
<div class="tongji">
<script id="LA-DATA-WIDGET" crossorigin="anonymous" charset="UTF-8"
src="https://v6-widget.51.la/v6/KoyzaWWEcLvPzkQn/quote.js?theme=#1690FF,#FFFFFF,#999999,#FFFFFF,#FFFFFF,#1690FF,12&f=12"></script>

View File

@ -1,4 +1,4 @@
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746865108;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1748423736;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1748398948;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747617266;}*/ ?>
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746865108;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1749178268;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1749172174;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1749170849;}*/ ?>
<!DOCTYPE html>
<html>
@ -87,6 +87,22 @@ $loginStatus = [
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="main-menu__search">
<i class="layui-icon layui-icon-search search-icon" id="mainSearchIcon"></i>
</div>
<!-- 搜索蒙版 -->
<div class="search-mask" id="searchMask" style="">
<div class="search-container">
<div class="search-box">
<select id="searchType" class="search-type">
<option value="article">文章</option>
<option value="resource">资源</option>
</select>
<input type="text" id="searchInput" placeholder="请输入搜索关键词">
<button class="search-btn" id="searchBtn">搜索</button>
</div>
</div>
</div>
<div class="main-menu__right">
<div class="username">
<?php if ($userInfo['is_login']): ?>
@ -143,14 +159,17 @@ $loginStatus = [
</div>
<div class="sticky-nav__menu">
<ul>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
<li><a href="/">首页</a></li>
<li><a href="/index/articles/index?cateid=1">站点资讯</a></li>
<li><a href="/index/articles/index?cateid=3">技术文章</a></li>
<li><a href="/index/program/index?cateid=2">办公资源</a></li>
<li><a href="/index/program/index?cateid=1">程序下载</a></li>
<li><a href="/index/game/index?cateid=8">游戏下载</a></li>
</ul>
</div>
<div class="sticky-nav__search">
<i class="layui-icon layui-icon-search search-icon" id="stickySearchIcon"></i>
</div>
<div class="sticky-nav__right">
<div class="main-menu__right">
<div class="username">
@ -193,217 +212,6 @@ $loginStatus = [
</div>
</div>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
</style>
<script>
// 在页面加载时立即执行
(function () {
@ -435,8 +243,97 @@ $loginStatus = [
}
})();
layui.use(['carousel', 'form', 'layer'], function () {
var carousel = layui.carousel, form = layui.form, layer = layui.layer, $ = layui.$;
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 执行搜索
function executeSearch() {
var searchInput = document.getElementById('searchInput');
if (!searchInput) {
layer.msg('搜索组件初始化失败');
return;
}
var keyword = searchInput.value.trim();
var type = document.getElementById('searchType').value;
if (!keyword) {
layer.msg('请输入搜索关键词');
return;
}
// 跳转到统一的搜索结果页面
window.location.href = '/index/search/index?keyword=' + encodeURIComponent(keyword) + '&type=' + type;
}
// 绑定事件
$(function() {
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var mainSearchIcon = $('#mainSearchIcon');
var stickySearchIcon = $('#stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
setTimeout(function() {
searchInput.focus();
}, 300);
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('');
}
// 绑定搜索图标点击事件
mainSearchIcon.on('click', showSearch);
stickySearchIcon.on('click', showSearch);
// 绑定搜索按钮点击事件
searchBtn.on('click', function(e) {
e.preventDefault();
executeSearch();
});
// 绑定回车键搜索
searchInput.on('keypress', function(e) {
if (e.which === 13) {
e.preventDefault();
executeSearch();
}
});
// 点击遮罩层关闭搜索框
searchMask.on('click', function(e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 绑定ESC键关闭搜索框
$(document).on('keydown', function(e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时选中所有文本
searchInput.on('focus', function() {
this.select();
});
});
});
// 其他功能相关代码
layui.use(['carousel', 'form'], function () {
var carousel = layui.carousel;
var form = layui.form;
var $ = layui.$;
// 检查本地存储并自动登录
function checkAutoLogin() {
@ -690,6 +587,326 @@ $loginStatus = [
});
});
</script>
<style>
/* 用户头像样式 */
#userAvatar {
width: 40px;
height: 40px;
cursor: pointer;
transition: all 0.3s ease;
}
#userAvatar:hover {
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 下拉菜单容器 */
.user-dropdown {
position: absolute;
top: 50px;
right: 0;
width: 160px;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
z-index: 9999;
}
.user-dropdown.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
/* 下拉菜单列表 */
.user-dropdown ul {
margin: 0;
padding: 5px 0;
list-style: none;
}
/* 下拉菜单项 */
.user-dropdown li {
margin: 0;
padding: 0;
}
/* 下拉菜单链接 */
.user-dropdown li a {
display: flex;
align-items: center;
padding: 10px 15px;
color: #333;
text-decoration: none;
transition: all 0.3s ease;
}
/* 下拉菜单图标 */
.user-dropdown li a i {
margin-right: 10px;
font-size: 16px;
color: #666;
}
/* 下拉菜单文字 */
.user-dropdown li a span {
font-size: 14px;
}
/* 下拉菜单悬停效果 */
.user-dropdown li a:hover {
background: #f5f5f5;
color: #1E9FFF;
}
.user-dropdown li a:hover i {
color: #1E9FFF;
}
/* 分隔线 */
.user-dropdown li:not(:last-child) {
border-bottom: 1px solid #f0f0f0;
}
#userDropdownSticky a {
color: #0d6efd !important;
}
/* Banner样式 */
.banner-content {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.banner-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner-image img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
.banner-text {
position: absolute;
top: 40%;
left: 10%;
z-index: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
color: #fff;
}
.banner-text a {
text-decoration: none;
margin-top: 30px;
}
.banner-title {
font-size: 4em;
font-weight: 600;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.banner-desc {
font-size: 2em;
font-weight: 400;
max-width: 800px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}
.banner-btn {
background: #fff;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.banner-btn:hover {
background: #000;
color: #fff;
}
.banner-slider {
width: 100%;
height: 86vh;
overflow: hidden;
position: relative;
}
.banner-container {
width: 100%;
height: 100%;
}
.banner-slide {
display: block;
width: 100%;
height: 100%;
}
.banner-slide img {
width: 100%;
height: 100%;
object-fit: cover;
/* 关键:等比缩放并铺满 */
display: block;
}
.layui-carousel {
background: #f8f8f8;
margin: 0;
padding: 0;
}
/* 确保轮播容器和项目的高度正确 */
#test10,
#test10 [carousel-item],
#test10 [carousel-item]>* {
height: 86vh !important;
}
#test10 [carousel-item]>* {
background: none !important;
}
.main-menu__right {
display: flex;
align-items: center;
}
.username {
display: flex;
align-items: center;
}
.search-icon {
font-size: 20px;
cursor: pointer;
color: #333;
transition: color 0.3s ease;
}
.search-icon:hover {
color: #1e9fff;
}
.search-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 9999;
display: none;
opacity: 0;
transition: opacity 0.3s ease;
justify-content: center;
align-items: center;
}
.search-mask.show {
display: flex;
opacity: 1;
}
.search-container {
position: relative;
width: 80%;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transform: translateY(-20px);
transition: transform 0.3s ease;
}
.search-mask.show .search-container {
transform: translateY(0);
}
.search-box {
display: flex;
align-items: center;
height: 60px;
background: #fff;
border-radius: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.search-box input {
flex: 1;
height: 100%;
padding: 0 20px;
border: none;
outline: none;
font-size: 16px;
}
.search-box button {
height: 100%;
padding: 0 30px;
border: none;
background: #1E9FFF;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.search-box button:hover {
background: #1a8fe6;
}
.search-type {
height: 100%;
padding: 0 15px;
border: none;
border-right: 1px solid #eee;
background: #f8f8f8;
color: #666;
font-size: 14px;
cursor: pointer;
outline: none;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 12px;
padding-right: 30px;
}
.search-type:hover {
background-color: #f0f0f0;
}
.search-type:focus {
background-color: #fff;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
</style>
<main class="main-content">
<div class="container">
<!-- 站点资讯模块 -->
@ -1306,6 +1523,87 @@ $loginStatus = [
});
}
// 搜索功能相关代码
layui.use(['layer'], function () {
var layer = layui.layer;
var $ = layui.jquery;
// 搜索功能相关变量
var searchMask = $('#searchMask');
var searchInput = $('#searchInput');
var searchBtn = $('#searchBtn');
var searchIcons = $('#mainSearchIcon, #stickySearchIcon');
// 显示搜索框
function showSearch() {
searchMask.addClass('show');
searchInput.focus();
}
// 隐藏搜索框
function hideSearch() {
searchMask.removeClass('show');
searchInput.val('').blur();
}
// 执行搜索
function doSearch() {
var keyword = searchInput.val().trim();
if (keyword) {
window.location.href = '/search?keyword=' + encodeURIComponent(keyword);
} else {
layer.msg('请输入搜索关键词', { icon: 0 });
}
}
// 事件绑定
function bindEvents() {
// 点击搜索图标显示搜索框
searchIcons.on('click', showSearch);
// 点击蒙版背景隐藏搜索框
searchMask.on('click', function (e) {
if ($(e.target).hasClass('search-mask')) {
hideSearch();
}
});
// 搜索按钮点击事件
searchBtn.on('click', function (e) {
e.preventDefault();
doSearch();
});
// 回车键触发搜索
searchInput.on('keypress', function (e) {
if (e.which === 13) {
e.preventDefault();
doSearch();
}
});
// ESC键关闭搜索框
$(document).on('keydown', function (e) {
if (e.keyCode === 27 && searchMask.hasClass('show')) {
hideSearch();
}
});
// 输入框获得焦点时全选文本
searchInput.on('focus', function () {
this.select();
});
}
// 初始化
function init() {
bindEvents();
}
// 启动
init();
});
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
loadWebArticles();
@ -1366,6 +1664,10 @@ $loginStatus = [
<p class="copyright__text">Copyright <span class="dynamic-year">2025</span> | All Rights By <a
href="http://www.yunzer.cn">Yunzer</a></p>
</div>
<div class="container wow fadeInUp animated" data-wow-delay="400ms"
style="visibility: visible; animation-delay: 400ms; animation-name: fadeInUp;">
<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow"><?php echo htmlentities((string) $config['admin_icp']); ?></a>
</div>
<div class="tongji">
<script id="LA-DATA-WIDGET" crossorigin="anonymous" charset="UTF-8"
src="https://v6-widget.51.la/v6/KoyzaWWEcLvPzkQn/quote.js?theme=#1690FF,#FFFFFF,#999999,#FFFFFF,#FFFFFF,#1690FF,12&f=12"></script>