700 lines
23 KiB
HTML
700 lines
23 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>合作伙伴 - Chookoo</title>
|
|
<style>
|
|
:root {
|
|
color-scheme: light;
|
|
--bg: #f5f7fb;
|
|
--text: #0f172a;
|
|
--muted: #5b6472;
|
|
--primary: #2f6bff;
|
|
--primary-weak: #e8f1ff;
|
|
--card: #ffffff;
|
|
--line: #e5e7eb;
|
|
--shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
|
|
}
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
html { overflow-y: scroll; }
|
|
body {
|
|
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
min-width: 1280px;
|
|
line-height: 1.6;
|
|
transform-origin: top left;
|
|
}
|
|
a { color: inherit; text-decoration: none; }
|
|
|
|
/* 导航栏 */
|
|
.navbar {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 1000;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
backdrop-filter: blur(20px);
|
|
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
|
|
}
|
|
.navbar-inner {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
height: 64px;
|
|
padding: 0 32px;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
.navbar-logo img { height: 40px; }
|
|
.navbar-back {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
transition: color 0.2s;
|
|
}
|
|
.navbar-back:hover { color: var(--text); }
|
|
|
|
/* 主内容区 */
|
|
.main-content {
|
|
padding-top: 100px;
|
|
padding-bottom: 80px;
|
|
min-height: 100vh;
|
|
}
|
|
.container {
|
|
width: 1000px;
|
|
max-width: 1000px;
|
|
margin: 0 auto;
|
|
padding: 0 24px;
|
|
}
|
|
|
|
/* 搜索区域 */
|
|
.search-section {
|
|
text-align: center;
|
|
margin-bottom: 48px;
|
|
}
|
|
.search-title {
|
|
font-size: 32px;
|
|
font-weight: 700;
|
|
margin-bottom: 8px;
|
|
color: var(--text);
|
|
}
|
|
.search-subtitle {
|
|
font-size: 16px;
|
|
color: var(--muted);
|
|
margin-bottom: 32px;
|
|
}
|
|
.search-box {
|
|
position: relative;
|
|
max-width: 560px;
|
|
margin: 0 auto;
|
|
}
|
|
.search-input {
|
|
width: 100%;
|
|
padding: 16px 24px 16px 52px;
|
|
font-size: 16px;
|
|
border: 2px solid var(--line);
|
|
border-radius: 16px;
|
|
background: var(--card);
|
|
outline: none;
|
|
transition: all 0.3s;
|
|
}
|
|
.search-input:focus {
|
|
border-color: var(--primary);
|
|
box-shadow: 0 0 0 4px rgba(47, 107, 255, 0.1);
|
|
}
|
|
.search-icon {
|
|
position: absolute;
|
|
left: 20px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
color: var(--muted);
|
|
}
|
|
.search-results {
|
|
position: absolute;
|
|
top: calc(100% + 8px);
|
|
left: 0;
|
|
right: 0;
|
|
background: var(--card);
|
|
border-radius: 12px;
|
|
box-shadow: 0 8px 32px rgba(0,0,0,0.12);
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
display: none;
|
|
z-index: 100;
|
|
}
|
|
.search-results.active { display: block; }
|
|
.search-result-item {
|
|
padding: 14px 20px;
|
|
cursor: pointer;
|
|
border-bottom: 1px solid var(--line);
|
|
transition: background 0.2s;
|
|
}
|
|
.search-result-item:last-child { border-bottom: none; }
|
|
.search-result-item:hover { background: var(--primary-weak); }
|
|
.search-result-title {
|
|
font-size: 15px;
|
|
font-weight: 500;
|
|
margin-bottom: 4px;
|
|
}
|
|
.search-result-category {
|
|
font-size: 12px;
|
|
color: var(--muted);
|
|
}
|
|
.search-no-result {
|
|
padding: 24px;
|
|
text-align: center;
|
|
color: var(--muted);
|
|
}
|
|
|
|
/* 分类标签 */
|
|
.category-tabs {
|
|
display: flex;
|
|
gap: 12px;
|
|
justify-content: center;
|
|
flex-wrap: wrap;
|
|
margin-bottom: 40px;
|
|
}
|
|
.category-tab {
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
border-radius: 999px;
|
|
background: var(--card);
|
|
border: 1px solid var(--line);
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
.category-tab:hover {
|
|
border-color: var(--primary);
|
|
color: var(--primary);
|
|
}
|
|
.category-tab.active {
|
|
background: var(--primary);
|
|
border-color: var(--primary);
|
|
color: #fff;
|
|
}
|
|
|
|
/* 文章分类区块 */
|
|
.articles-section {
|
|
margin-bottom: 48px;
|
|
}
|
|
.section-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
margin-bottom: 20px;
|
|
cursor: pointer;
|
|
}
|
|
.section-icon {
|
|
width: 44px;
|
|
height: 44px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 12px;
|
|
font-size: 20px;
|
|
}
|
|
.section-icon.dealer { background: linear-gradient(135deg, #dbeafe, #bfdbfe); }
|
|
.section-icon.affiliate { background: linear-gradient(135deg, #fef3c7, #fde68a); }
|
|
.section-icon.business { background: linear-gradient(135deg, #d1fae5, #a7f3d0); }
|
|
.section-icon.tech { background: linear-gradient(135deg, #e0e7ff, #c7d2fe); }
|
|
.section-title {
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
flex: 1;
|
|
}
|
|
.section-count {
|
|
font-size: 13px;
|
|
color: var(--muted);
|
|
background: var(--bg);
|
|
padding: 4px 12px;
|
|
border-radius: 999px;
|
|
}
|
|
.section-toggle {
|
|
color: var(--muted);
|
|
transition: transform 0.3s;
|
|
}
|
|
.section-header.collapsed .section-toggle {
|
|
transform: rotate(-90deg);
|
|
}
|
|
|
|
/* 文章列表 */
|
|
.article-list {
|
|
display: grid;
|
|
gap: 12px;
|
|
padding-left: 56px;
|
|
}
|
|
.article-list.hidden { display: none; }
|
|
.article-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 16px 20px;
|
|
background: var(--card);
|
|
border-radius: 12px;
|
|
border: 1px solid var(--line);
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
.article-item:hover {
|
|
border-color: var(--primary);
|
|
box-shadow: 0 4px 12px rgba(47, 107, 255, 0.1);
|
|
transform: translateX(4px);
|
|
}
|
|
.article-item svg {
|
|
color: var(--primary);
|
|
flex-shrink: 0;
|
|
}
|
|
.article-title {
|
|
font-size: 15px;
|
|
font-weight: 500;
|
|
flex: 1;
|
|
}
|
|
.article-arrow {
|
|
color: var(--muted);
|
|
opacity: 0;
|
|
transition: opacity 0.2s;
|
|
}
|
|
.article-item:hover .article-arrow {
|
|
opacity: 1;
|
|
}
|
|
|
|
/* 文章详情页 */
|
|
.article-detail {
|
|
display: none;
|
|
}
|
|
.article-detail.active {
|
|
display: block;
|
|
}
|
|
.article-breadcrumb {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
margin-bottom: 24px;
|
|
}
|
|
.article-breadcrumb a:hover { color: var(--primary); }
|
|
.article-detail-title {
|
|
font-size: 28px;
|
|
font-weight: 700;
|
|
margin-bottom: 16px;
|
|
line-height: 1.4;
|
|
}
|
|
.article-meta {
|
|
display: flex;
|
|
gap: 16px;
|
|
font-size: 13px;
|
|
color: var(--muted);
|
|
margin-bottom: 32px;
|
|
padding-bottom: 24px;
|
|
border-bottom: 1px solid var(--line);
|
|
}
|
|
.article-content {
|
|
font-size: 16px;
|
|
line-height: 1.8;
|
|
color: #374151;
|
|
}
|
|
.article-content h3 {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
margin: 32px 0 16px;
|
|
color: var(--text);
|
|
}
|
|
.article-content p {
|
|
margin-bottom: 16px;
|
|
}
|
|
.article-content ul, .article-content ol {
|
|
margin-bottom: 16px;
|
|
padding-left: 24px;
|
|
}
|
|
.article-content li {
|
|
margin-bottom: 8px;
|
|
}
|
|
.article-content img {
|
|
max-width: 100%;
|
|
border-radius: 12px;
|
|
margin: 20px 0;
|
|
}
|
|
.article-tip {
|
|
background: var(--primary-weak);
|
|
border-left: 4px solid var(--primary);
|
|
padding: 16px 20px;
|
|
border-radius: 0 12px 12px 0;
|
|
margin: 24px 0;
|
|
}
|
|
.article-tip-title {
|
|
font-weight: 600;
|
|
color: var(--primary);
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
/* 返回按钮 */
|
|
.back-btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 10px 16px;
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
background: var(--card);
|
|
border: 1px solid var(--line);
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
margin-bottom: 24px;
|
|
}
|
|
.back-btn:hover {
|
|
border-color: var(--primary);
|
|
color: var(--primary);
|
|
}
|
|
|
|
/* 相关文章 */
|
|
.related-articles {
|
|
margin-top: 48px;
|
|
padding-top: 32px;
|
|
border-top: 1px solid var(--line);
|
|
}
|
|
.related-title {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
margin-bottom: 16px;
|
|
}
|
|
.related-list {
|
|
display: grid;
|
|
gap: 8px;
|
|
}
|
|
.related-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 12px 16px;
|
|
background: var(--card);
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
.related-item:hover {
|
|
background: var(--primary-weak);
|
|
}
|
|
.related-item svg {
|
|
color: var(--primary);
|
|
font-size: 14px;
|
|
}
|
|
|
|
/* 页脚 */
|
|
.footer {
|
|
background: #1a1f2e;
|
|
color: #9ca3af;
|
|
padding: 40px 24px;
|
|
text-align: center;
|
|
}
|
|
.footer-logo {
|
|
height: 32px;
|
|
margin-bottom: 16px;
|
|
filter: brightness(0) invert(1);
|
|
opacity: 0.8;
|
|
}
|
|
.footer-text {
|
|
font-size: 13px;
|
|
}
|
|
|
|
/* 响应式 */
|
|
@media (max-width: 768px) {
|
|
.search-title { font-size: 24px; }
|
|
.search-input { padding: 14px 20px 14px 48px; font-size: 15px; }
|
|
.article-list { padding-left: 0; margin-top: 16px; }
|
|
.section-header { padding: 12px 16px; background: var(--card); border-radius: 12px; }
|
|
.article-detail-title { font-size: 22px; }
|
|
}
|
|
|
|
/* 列表页隐藏/显示 */
|
|
.articles-list-view { display: block; }
|
|
.articles-list-view.hidden { display: none; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- 导航栏 -->
|
|
<nav class="navbar">
|
|
<div class="navbar-inner">
|
|
<a href="index.html" class="navbar-logo">
|
|
<img src="logo.png" alt="Chookoo" />
|
|
</a>
|
|
<a href="index.html" class="navbar-back">
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
|
|
返回首页
|
|
</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- 主内容 -->
|
|
<main class="main-content">
|
|
<div class="container">
|
|
<!-- 文章列表视图 -->
|
|
<div class="articles-list-view" id="articlesListView">
|
|
<!-- 搜索区域 -->
|
|
<section class="search-section">
|
|
<h1 class="search-title">合作伙伴</h1>
|
|
<p class="search-subtitle">搜索您想了解的合作伙伴信息</p>
|
|
<div class="search-box">
|
|
<svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>
|
|
<input type="text" class="search-input" id="searchInput" placeholder="搜索..." />
|
|
<div class="search-results" id="searchResults"></div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- 分类标签 -->
|
|
<div class="category-tabs" id="categoryTabs">
|
|
<div class="category-tab active" data-category="all">全部</div>
|
|
<div class="category-tab" data-category="dealer">经销商入驻</div>
|
|
<div class="category-tab" data-category="affiliate">联盟推广</div>
|
|
<div class="category-tab" data-category="business">企业采购</div>
|
|
<div class="category-tab" data-category="tech">技术合作</div>
|
|
</div>
|
|
|
|
<!-- 文章分类列表 -->
|
|
<div id="articlesContainer"></div>
|
|
</div>
|
|
|
|
<!-- 文章详情视图 -->
|
|
<div class="article-detail" id="articleDetail">
|
|
<button class="back-btn" id="backToList">
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
|
|
返回列表
|
|
</button>
|
|
<div id="articleContent"></div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- 页脚 -->
|
|
<footer class="footer">
|
|
<img src="logo.png" alt="Chookoo" class="footer-logo" />
|
|
<p class="footer-text">© 2025 宠科智能科技(苏州)有限公司 保留所有权利</p>
|
|
</footer>
|
|
|
|
<script>
|
|
// 视口缩放 - 基于1920px设计稿
|
|
(() => {
|
|
const designWidth = 1920;
|
|
const minWidth = 1280;
|
|
const maxWidth = 2560;
|
|
|
|
function scale() {
|
|
const vw = window.innerWidth;
|
|
let scale = 1;
|
|
|
|
if (vw < minWidth) {
|
|
scale = vw / minWidth;
|
|
} else if (vw > maxWidth) {
|
|
scale = vw / maxWidth;
|
|
} else {
|
|
scale = vw / designWidth;
|
|
}
|
|
|
|
document.body.style.transform = `scale(${scale})`;
|
|
document.body.style.width = `${designWidth}px`;
|
|
}
|
|
|
|
scale();
|
|
window.addEventListener('resize', scale);
|
|
})();
|
|
</script>
|
|
<script>
|
|
// 页面类型
|
|
const PAGE_TYPE = 'partner';
|
|
|
|
// 分类配置
|
|
const categories = {
|
|
all: { name: '全部', icon: '📋' },
|
|
dealer: { name: '经销商入驻', icon: '🏪' },
|
|
affiliate: { name: '联盟推广', icon: '🔗' },
|
|
business: { name: '企业采购', icon: '🏢' },
|
|
tech: { name: '技术合作', icon: '🔬' }
|
|
};
|
|
|
|
// 默认文章数据(合作伙伴)
|
|
const defaultArticles = [
|
|
{ id: 301, pageType: 'partner', category: 'dealer', categoryName: '经销商入驻', title: '经销商入驻条件', content: '<h2>入驻条件</h2><ul><li>具有合法经营资质</li><li>有宠物行业经验优先</li><li>具备一定的资金实力</li><li>认同品牌理念</li></ul>', views: 654, date: '2025-01-15' },
|
|
{ id: 302, pageType: 'partner', category: 'dealer', categoryName: '经销商入驻', title: '经销商政策', content: '<h2>合作政策</h2><ul><li>区域独家保护</li><li>市场费用支持</li><li>培训支持</li><li>售后支持</li></ul>', views: 543, date: '2025-01-14' },
|
|
{ id: 303, pageType: 'partner', category: 'affiliate', categoryName: '联盟推广', title: '推广联盟计划', content: '<h2>推广联盟</h2><p>加入Chookoo推广联盟,通过分享获得收益。</p><ul><li>佣金比例:10%-15%</li><li>结算周期:月结</li><li>支持素材丰富</li></ul>', views: 432, date: '2025-01-13' },
|
|
{ id: 304, pageType: 'partner', category: 'business', categoryName: '企业采购', title: '企业采购服务', content: '<h2>企业采购</h2><p>为企业客户提供定制化采购服务:</p><ul><li>批量优惠</li><li>定制包装</li><li>专属客服</li><li>发票支持</li></ul>', views: 321, date: '2025-01-12' },
|
|
{ id: 305, pageType: 'partner', category: 'tech', categoryName: '技术合作', title: '技术合作', content: '<h2>技术合作</h2><p>我们欢迎各类技术合作:</p><ul><li>智能家居平台对接</li><li>Pet IoT生态合作</li><li>技术授权</li></ul>', views: 234, date: '2025-01-11' }
|
|
];
|
|
|
|
// 文章数据
|
|
let articles = [...defaultArticles];
|
|
|
|
// 当前状态
|
|
let currentCategory = 'all';
|
|
let collapsedSections = {};
|
|
|
|
// 初始化
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const savedArticles = localStorage.getItem('chookoo_help_articles');
|
|
if (savedArticles) {
|
|
try {
|
|
const parsed = JSON.parse(savedArticles);
|
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
const customArticles = parsed.filter(a => (a.pageType || 'help') === 'partner');
|
|
articles.push(...customArticles);
|
|
}
|
|
} catch (e) {
|
|
console.error('加载文章数据失败:', e);
|
|
}
|
|
}
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const category = urlParams.get('category');
|
|
const articleId = urlParams.get('article');
|
|
|
|
if (articleId) {
|
|
showArticle(parseInt(articleId));
|
|
} else if (category && categories[category]) {
|
|
currentCategory = category;
|
|
document.querySelectorAll('.category-tab').forEach(tab => {
|
|
tab.classList.toggle('active', tab.dataset.category === category);
|
|
});
|
|
}
|
|
|
|
renderArticles();
|
|
initSearch();
|
|
initCategoryTabs();
|
|
initBackButton();
|
|
});
|
|
|
|
function renderArticles() {
|
|
const container = document.getElementById('articlesContainer');
|
|
let html = '';
|
|
const categoryOrder = ['dealer', 'affiliate', 'business', 'tech'];
|
|
|
|
categoryOrder.forEach(cat => {
|
|
if (currentCategory !== 'all' && currentCategory !== cat) return;
|
|
const catArticles = articles.filter(a => a.category === cat && (!a.pageType || a.pageType === PAGE_TYPE));
|
|
if (catArticles.length === 0) return;
|
|
|
|
const isCollapsed = collapsedSections[cat];
|
|
const catInfo = categories[cat];
|
|
|
|
html += `
|
|
<section class="articles-section" data-category="${cat}">
|
|
<div class="section-header ${isCollapsed ? 'collapsed' : ''}" onclick="toggleSection('${cat}')">
|
|
<div class="section-icon ${cat}">${catInfo.icon}</div>
|
|
<h2 class="section-title">${catInfo.name}</h2>
|
|
<span class="section-count">${catArticles.length} 篇文章</span>
|
|
<svg class="section-toggle" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M6 9l6 6 6-6"/></svg>
|
|
</div>
|
|
<div class="article-list ${isCollapsed ? 'hidden' : ''}">
|
|
${catArticles.map(article => `
|
|
<div class="article-item" onclick="showArticle(${article.id})">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
|
|
<span class="article-title">${article.title}</span>
|
|
<svg class="article-arrow" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
</section>
|
|
`;
|
|
});
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
function toggleSection(cat) {
|
|
collapsedSections[cat] = !collapsedSections[cat];
|
|
renderArticles();
|
|
}
|
|
|
|
function showArticle(id) {
|
|
const article = articles.find(a => a.id === id);
|
|
if (!article) return;
|
|
|
|
const content = document.getElementById('articleContent');
|
|
content.innerHTML = `
|
|
<div class="article-breadcrumb">
|
|
<a href="#" onclick="backToList(); return false;">合作伙伴</a>
|
|
<span>/</span>
|
|
<span>${article.categoryName}</span>
|
|
</div>
|
|
<div class="article-detail">
|
|
<h1 class="article-title">${article.title}</h1>
|
|
<div class="article-meta">
|
|
<span class="article-date">${article.date}</span>
|
|
<span class="article-views">${article.views} 次阅读</span>
|
|
</div>
|
|
<div class="article-body">${article.content}</div>
|
|
</div>
|
|
`;
|
|
|
|
document.getElementById('articlesContainer').style.display = 'none';
|
|
document.getElementById('articlesListView').style.display = 'none';
|
|
document.getElementById('articleDetail').style.display = 'block';
|
|
document.getElementById('articleDetail').classList.add('active');
|
|
history.pushState({ articleId: id }, '', `?article=${id}`);
|
|
}
|
|
|
|
function backToList() {
|
|
document.getElementById('articlesContainer').style.display = 'block';
|
|
document.getElementById('articlesListView').style.display = 'block';
|
|
document.getElementById('articleDetail').style.display = 'none';
|
|
document.getElementById('articleDetail').classList.remove('active');
|
|
history.pushState({}, '', window.location.pathname);
|
|
}
|
|
|
|
function initBackButton() {
|
|
document.getElementById('backToList').addEventListener('click', backToList);
|
|
}
|
|
|
|
function initCategoryTabs() {
|
|
document.querySelectorAll('.category-tab').forEach(tab => {
|
|
tab.addEventListener('click', function() {
|
|
document.querySelectorAll('.category-tab').forEach(t => t.classList.remove('active'));
|
|
this.classList.add('active');
|
|
currentCategory = this.dataset.category;
|
|
renderArticles();
|
|
});
|
|
});
|
|
}
|
|
|
|
function initSearch() {
|
|
const searchInput = document.getElementById('searchInput');
|
|
const results = document.getElementById('searchResults');
|
|
|
|
searchInput.addEventListener('input', function() {
|
|
const query = this.value.toLowerCase().trim();
|
|
if (query.length < 2) {
|
|
results.classList.remove('active');
|
|
return;
|
|
}
|
|
|
|
const matched = articles.filter(a =>
|
|
(!a.pageType || a.pageType === PAGE_TYPE) &&
|
|
(a.title.toLowerCase().includes(query) || a.content.toLowerCase().includes(query))
|
|
);
|
|
|
|
if (matched.length === 0) {
|
|
results.innerHTML = '<div class="search-no-result">未找到相关文章</div>';
|
|
} else {
|
|
results.innerHTML = matched.slice(0, 8).map(a => `
|
|
<div class="search-result-item" onclick="showArticle(${a.id})">
|
|
<div class="search-result-title">${a.title}</div>
|
|
<div class="search-result-category">${a.categoryName}</div>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
results.classList.add('active');
|
|
});
|
|
|
|
document.addEventListener('click', function(e) {
|
|
if (!searchInput.contains(e.target) && !results.contains(e.target)) {
|
|
results.classList.remove('active');
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |