官网第一版
This commit is contained in:
parent
6a24b3eba3
commit
e5909159fb
873
index.html
Normal file
873
index.html
Normal file
@ -0,0 +1,873 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>计算机协会 - 首页</title>
|
||||
<style>
|
||||
/* 全局样式 - 默认暗黑模式 */
|
||||
:root {
|
||||
--primary-color: #0a192f;
|
||||
--secondary-color: #64ffda;
|
||||
--text-primary: #ccd6f6;
|
||||
--text-secondary: #8892b0;
|
||||
--white: #e6f1ff;
|
||||
--bg-color: #0a192f;
|
||||
--card-bg: rgba(10, 25, 47, 0.8);
|
||||
--footer-bg: #020c1b;
|
||||
--news-bg: rgba(100, 255, 218, 0.03);
|
||||
--link-card-bg: rgba(100, 255, 218, 0.05);
|
||||
--header-bg: rgba(10, 25, 47, 0.9);
|
||||
}
|
||||
|
||||
/* 亮色模式 */
|
||||
[data-theme="light"] {
|
||||
--primary-color: #f8f9fa;
|
||||
--secondary-color: #007bff;
|
||||
--text-primary: #212529;
|
||||
--text-secondary: #495057;
|
||||
--white: #ffffff;
|
||||
--bg-color: #f8f9fa;
|
||||
--card-bg: rgba(255, 255, 255, 0.9);
|
||||
--footer-bg: #e9ecef;
|
||||
--news-bg: rgba(0, 123, 255, 0.03);
|
||||
--link-card-bg: rgba(0, 123, 255, 0.05);
|
||||
--header-bg: rgba(248, 249, 250, 0.9);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: var(--secondary-color);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 12px 28px;
|
||||
background: transparent;
|
||||
color: var(--secondary-color);
|
||||
border: 1px solid var(--secondary-color);
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: rgba(100, 255, 218, 0.1);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
[data-theme="light"] .btn:hover {
|
||||
background: rgba(0, 123, 255, 0.1);
|
||||
}
|
||||
|
||||
/* 导航栏 */
|
||||
header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: var(--header-bg);
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 1000;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-links li {
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
.nav-links a {
|
||||
color: var(--text-primary);
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.nav-links a:hover {
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
/* 汉堡菜单按钮 */
|
||||
.hamburger {
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
width: 30px;
|
||||
height: 21px;
|
||||
position: relative;
|
||||
z-index: 1001;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.hamburger span {
|
||||
display: block;
|
||||
position: absolute;
|
||||
height: 3px;
|
||||
width: 100%;
|
||||
background: var(--text-primary);
|
||||
border-radius: 3px;
|
||||
opacity: 1;
|
||||
left: 0;
|
||||
transform: rotate(0deg);
|
||||
transition: .25s ease-in-out;
|
||||
}
|
||||
|
||||
.hamburger span:nth-child(1) {
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.hamburger span:nth-child(2), .hamburger span:nth-child(3) {
|
||||
top: 9px;
|
||||
}
|
||||
|
||||
.hamburger span:nth-child(4) {
|
||||
top: 18px;
|
||||
}
|
||||
|
||||
.hamburger.open span:nth-child(1) {
|
||||
top: 9px;
|
||||
width: 0%;
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
.hamburger.open span:nth-child(2) {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.hamburger.open span:nth-child(3) {
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.hamburger.open span:nth-child(4) {
|
||||
top: 9px;
|
||||
width: 0%;
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
/* 主题切换开关 */
|
||||
.theme-switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 60px;
|
||||
height: 30px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.theme-switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
transition: .4s;
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 22px;
|
||||
width: 22px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: var(--secondary-color);
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
transform: translateX(30px);
|
||||
}
|
||||
|
||||
.slider .icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 14px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.slider .moon {
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.slider .sun {
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
/* 移动端导航菜单 */
|
||||
.mobile-nav {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: -100%;
|
||||
width: 80%;
|
||||
max-width: 300px;
|
||||
height: 100vh;
|
||||
background: var(--header-bg);
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 1000;
|
||||
padding: 80px 30px 30px;
|
||||
transition: right 0.3s ease;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.mobile-nav.open {
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.mobile-nav-links {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.mobile-nav-links li {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.mobile-nav-links a {
|
||||
color: var(--text-primary);
|
||||
font-size: 18px;
|
||||
display: block;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.mobile-nav-links a:hover {
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.mobile-theme-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--text-secondary);
|
||||
}
|
||||
|
||||
.mobile-theme-toggle span {
|
||||
color: var(--text-primary);
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 英雄区域 */
|
||||
.hero {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-top: 80px;
|
||||
}
|
||||
|
||||
.hero-content {
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.hero-subtitle {
|
||||
color: var(--secondary-color);
|
||||
font-size: 18px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.hero-title {
|
||||
font-size: 60px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 20px;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.hero-description {
|
||||
color: var(--text-secondary);
|
||||
font-size: 18px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 快速链接 */
|
||||
.quick-links {
|
||||
padding: 80px 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
text-align: center;
|
||||
font-size: 36px;
|
||||
margin-bottom: 60px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.section-title::after {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 80px;
|
||||
height: 3px;
|
||||
background: var(--secondary-color);
|
||||
margin: 15px auto 0;
|
||||
}
|
||||
|
||||
.links-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.link-card {
|
||||
background: var(--link-card-bg);
|
||||
border-radius: 8px;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.link-card:hover {
|
||||
transform: translateY(-10px);
|
||||
background: rgba(100, 255, 218, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="light"] .link-card:hover {
|
||||
background: rgba(0, 123, 255, 0.1);
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
font-size: 40px;
|
||||
margin-bottom: 20px;
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.link-title {
|
||||
font-size: 22px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.link-desc {
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 最新动态 */
|
||||
.news {
|
||||
padding: 80px 0;
|
||||
background: var(--news-bg);
|
||||
}
|
||||
|
||||
.news-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.news-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.news-image {
|
||||
height: 200px;
|
||||
background: var(--primary-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.news-content {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.news-date {
|
||||
color: var(--secondary-color);
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.news-title {
|
||||
font-size: 20px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.news-excerpt {
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 页脚 */
|
||||
footer {
|
||||
background: var(--footer-bg);
|
||||
padding: 50px 0 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.footer-links {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
list-style: none;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.footer-links li {
|
||||
margin: 0 15px;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
grid-column: 1 / -1;
|
||||
color: var(--secondary-color);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.loading-spinner i {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.news-card img {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #ff6b6b;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 992px) {
|
||||
.hero-title {
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hamburger {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.hero-title {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
.hero-description {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.links-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.footer-links {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.footer-links li {
|
||||
margin: 10px 15px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.hero-title {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.hero-subtitle {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.theme-switch {
|
||||
width: 50px;
|
||||
height: 25px;
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
bottom: 3.5px;
|
||||
left: 3.5px;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
transform: translateX(25px);
|
||||
}
|
||||
|
||||
.slider .icon {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- 导航栏 -->
|
||||
<header>
|
||||
<div class="container">
|
||||
<nav>
|
||||
<div class="logo">石科信计算机协会</div>
|
||||
<button class="hamburger" id="hamburger">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</button>
|
||||
<ul class="nav-links">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="/about">协会介绍</a></li>
|
||||
<li><a href="/platform">协会平台</a></li>
|
||||
<li><a href="https://news.skxjx.holytreasure.space/">信息中心</a></li>
|
||||
<li><a href="https://git.holytreasure.space/holytreasure/">加入我们</a></li>
|
||||
<li>
|
||||
<label class="theme-switch">
|
||||
<input type="checkbox" id="themeToggle">
|
||||
<span class="slider round">
|
||||
<i class="fas fa-moon icon moon"></i>
|
||||
<i class="fas fa-sun icon sun"></i>
|
||||
</span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 移动端导航菜单 -->
|
||||
<div class="mobile-nav" id="mobileNav">
|
||||
<ul class="mobile-nav-links">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="/about">协会介绍</a></li>
|
||||
<li><a href="/platform">协会平台</a></li>
|
||||
<li><a href="https://news.skxjx.holytreasure.space/">信息中心</a></li>
|
||||
<li><a href="https://git.holytreasure.space/holytreasure/">加入我们</a></li>
|
||||
</ul>
|
||||
<div class="mobile-theme-toggle">
|
||||
<span>暗黑模式</span>
|
||||
<label class="theme-switch">
|
||||
<input type="checkbox" id="mobileThemeToggle">
|
||||
<span class="slider round">
|
||||
<i class="fas fa-moon icon moon"></i>
|
||||
<i class="fas fa-sun icon sun"></i>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 英雄区域 -->
|
||||
<section class="hero">
|
||||
<div class="container">
|
||||
<div class="hero-content">
|
||||
<p class="hero-subtitle">欢迎来到</p>
|
||||
<h1 class="hero-title">石科信计算机协会</h1>
|
||||
<p class="hero-description">
|
||||
我们是一个致力于计算机技术研究、创新和实践的学生组织。
|
||||
在这里,你可以学习前沿技术,参与项目开发,与志同道合的同学一起成长。
|
||||
</p>
|
||||
<a href="/about" class="btn">了解更多</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 快速链接 -->
|
||||
<section class="quick-links">
|
||||
<div class="container">
|
||||
<h2 class="section-title">协会平台</h2>
|
||||
<div class="links-grid">
|
||||
<div class="link-card">
|
||||
<div class="link-icon">📰</div>
|
||||
<h3 class="link-title">信息中心</h3>
|
||||
<p class="link-desc">获取协会最新动态、活动通知和技术分享</p>
|
||||
<a href="https://news.skxjx.holytreasure.space/" class="btn">访问</a>
|
||||
</div>
|
||||
<div class="link-card">
|
||||
<div class="link-icon">💻</div>
|
||||
<h3 class="link-title">代码仓库</h3>
|
||||
<p class="link-desc">查看和参与协会的开源项目</p>
|
||||
<a href="https://git.holytreasure.space/" class="btn">访问</a>
|
||||
</div>
|
||||
<div class="link-card">
|
||||
<div class="link-icon">📂</div>
|
||||
<h3 class="link-title">资源下载</h3>
|
||||
<p class="link-desc">获取学习资料、工具软件和项目文档</p>
|
||||
<a href="https://pan.skxjx.holytreasure.space/1" class="btn">访问</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 最新动态 -->
|
||||
<section class="news">
|
||||
<div class="container">
|
||||
<h2 class="section-title">最新动态</h2>
|
||||
<div class="news-grid" id="newsContainer">
|
||||
<div class="loading-spinner">
|
||||
<i class="fas fa-spinner fa-spin"></i> 加载中...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 页脚 -->
|
||||
<footer>
|
||||
<div class="container">
|
||||
<ul class="footer-links">
|
||||
<li><a href="/about">关于我们</a></li>
|
||||
<li><a href="/contact">联系我们</a></li>
|
||||
<li><a href="https://git.holytreasure.space/">Git仓库</a></li>
|
||||
<li><a href="#">隐私政策</a></li>
|
||||
</ul>
|
||||
<p class="copyright">© 2023 计算机协会. 保留所有权利.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
// 平滑滚动
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
anchor.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
document.querySelector(this.getAttribute('href')).scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 导航栏滚动效果
|
||||
window.addEventListener('scroll', function () {
|
||||
const header = document.querySelector('header');
|
||||
if (window.scrollY > 50) {
|
||||
header.style.boxShadow = '0 5px 20px rgba(0, 0, 0, 0.1)';
|
||||
} else {
|
||||
header.style.boxShadow = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
// 汉堡菜单功能
|
||||
const hamburger = document.getElementById('hamburger');
|
||||
const mobileNav = document.getElementById('mobileNav');
|
||||
|
||||
hamburger.addEventListener('click', function() {
|
||||
this.classList.toggle('open');
|
||||
mobileNav.classList.toggle('open');
|
||||
|
||||
// 切换body的overflow以防止页面滚动
|
||||
if (mobileNav.classList.contains('open')) {
|
||||
document.body.style.overflow = 'hidden';
|
||||
} else {
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
});
|
||||
|
||||
// 关闭移动菜单当点击菜单项
|
||||
document.querySelectorAll('.mobile-nav-links a').forEach(link => {
|
||||
link.addEventListener('click', function() {
|
||||
hamburger.classList.remove('open');
|
||||
mobileNav.classList.remove('open');
|
||||
document.body.style.overflow = '';
|
||||
});
|
||||
});
|
||||
|
||||
// 主题切换功能
|
||||
const themeToggle = document.getElementById('themeToggle');
|
||||
const mobileThemeToggle = document.getElementById('mobileThemeToggle');
|
||||
|
||||
// 检查本地存储中的主题偏好
|
||||
const currentTheme = localStorage.getItem('theme') || 'dark';
|
||||
document.documentElement.setAttribute('data-theme', currentTheme);
|
||||
updateThemeToggle(currentTheme);
|
||||
|
||||
// 切换主题
|
||||
function toggleTheme() {
|
||||
const currentTheme = document.documentElement.getAttribute('data-theme');
|
||||
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
updateThemeToggle(newTheme);
|
||||
}
|
||||
|
||||
// 更新主题切换状态
|
||||
function updateThemeToggle(theme) {
|
||||
const isLight = theme === 'light';
|
||||
themeToggle.checked = isLight;
|
||||
mobileThemeToggle.checked = isLight;
|
||||
}
|
||||
|
||||
// 添加事件监听器
|
||||
themeToggle.addEventListener('change', toggleTheme);
|
||||
mobileThemeToggle.addEventListener('change', toggleTheme);
|
||||
|
||||
// 获取最新文章的函数
|
||||
async function fetchLatestNews() {
|
||||
const newsContainer = document.getElementById('newsContainer');
|
||||
|
||||
try {
|
||||
// 构造API请求URL
|
||||
const apiUrl = new URL('https://news.skxjx.holytreasure.space/');
|
||||
apiUrl.searchParams.append('rest-api', 'article_list');
|
||||
apiUrl.searchParams.append('count', '3'); // 获取3篇文章
|
||||
apiUrl.searchParams.append('sort_id', '2'); // 分类ID为2的文章
|
||||
apiUrl.searchParams.append('order', 'views'); // 按浏览量排序(可选)
|
||||
|
||||
const response = await fetch(apiUrl.toString());
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP错误! 状态码: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
// 检查API返回的数据结构
|
||||
if (result.code !== 0 || !result.data || !result.data.articles) {
|
||||
throw new Error('API返回数据格式不正确');
|
||||
}
|
||||
|
||||
renderNews(result.data.articles);
|
||||
} catch (error) {
|
||||
console.error('获取最新动态失败:', error);
|
||||
newsContainer.innerHTML = `
|
||||
<div class="error-message">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<p>加载动态失败: ${error.message}</p>
|
||||
<p>请稍后刷新页面重试</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染文章列表
|
||||
function renderNews(articles) {
|
||||
const newsContainer = document.getElementById('newsContainer');
|
||||
newsContainer.innerHTML = '';
|
||||
|
||||
if (!articles || articles.length === 0) {
|
||||
newsContainer.innerHTML = '<p class="no-news">暂无最新动态</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
articles.forEach(article => {
|
||||
const newsCard = document.createElement('div');
|
||||
newsCard.className = 'news-card';
|
||||
|
||||
// 格式化日期 (从 "2021-10-11 08:04:11" 转为 "2021年10月11日")
|
||||
const formattedDate = formatDate(article.date);
|
||||
|
||||
// 构造文章卡片
|
||||
newsCard.innerHTML = `
|
||||
<div class="news-image">
|
||||
${article.cover ?
|
||||
`<img src="${article.cover}" alt="${article.title}" loading="lazy">` :
|
||||
'<div class="default-image">文章图片</div>'}
|
||||
</div>
|
||||
<div class="news-content">
|
||||
<p class="news-date">${formattedDate}</p>
|
||||
<h3 class="news-title">${article.title}</h3>
|
||||
<p class="news-excerpt">${article.description || '暂无摘要'}</p>
|
||||
<div class="article-meta">
|
||||
<span><i class="far fa-eye"></i> ${article.views}</span>
|
||||
<span><i class="far fa-comment"></i> ${article.comnum}</span>
|
||||
${article.sort_name ? `<span><i class="fas fa-tag"></i> ${article.sort_name}</span>` : ''}
|
||||
</div>
|
||||
<a href="${article.url}" class="btn" target="_blank">阅读更多</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
newsContainer.appendChild(newsCard);
|
||||
});
|
||||
}
|
||||
|
||||
// 辅助函数:格式化日期
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return '未知日期';
|
||||
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
if (isNaN(date.getTime())) {
|
||||
return dateString; // 如果无法解析,返回原始字符串
|
||||
}
|
||||
|
||||
return `${date.getFullYear()}年${(date.getMonth() + 1).toString().padStart(2, '0')}月${date.getDate().toString().padStart(2, '0')}日`;
|
||||
} catch (e) {
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后获取最新动态
|
||||
document.addEventListener('DOMContentLoaded', fetchLatestNews);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user