Browse Source

feat: 网站样式与交互优化

Xiaogang Liao 4 months ago
parent
commit
7747796c0e
2 changed files with 498 additions and 4 deletions
  1. 394 4
      web/css/style.css
  2. 104 0
      web/js/main.js

+ 394 - 4
web/css/style.css

@@ -83,13 +83,12 @@ html {
   scroll-behavior: smooth;
   -webkit-text-size-adjust: 100%;
   scroll-padding-top: var(--header-height);
-  scroll-snap-type: y mandatory;
+  scroll-snap-type: y proximity;
 }
 
-/* All major sections snap to top when scrolling stops */
+/* Sections gently align when scrolling stops */
 section[id] {
   scroll-snap-align: start;
-  scroll-snap-stop: always;
 }
 
 body {
@@ -1793,7 +1792,7 @@ ul { list-style: none; }
     top: var(--header-height);
     left: 0;
     right: 0;
-    background: rgba(255, 249, 240, .98);
+    background: rgba(245, 250, 254, .97);
     backdrop-filter: blur(16px);
     -webkit-backdrop-filter: blur(16px);
     border-bottom: 1px solid var(--color-border-light);
@@ -2204,6 +2203,397 @@ ul { list-style: none; }
   white-space: nowrap;
 }
 
+/* ----------------------------------------------------------
+    22. Product Feature Bullet Lists
+    ---------------------------------------------------------- */
+.product-summary {
+  font-size: var(--font-size-small);
+  color: var(--color-text-secondary);
+  line-height: 1.6;
+  margin-bottom: var(--space-sm);
+}
+
+.product-features {
+  list-style: none;
+  padding: 0;
+  margin: 0 0 var(--space-md);
+}
+
+.product-features li {
+  position: relative;
+  padding-left: 1.25em;
+  font-size: var(--font-size-small);
+  color: var(--color-text-secondary);
+  line-height: 1.8;
+}
+
+.product-features li::before {
+  content: '·';
+  position: absolute;
+  left: .35em;
+  color: var(--product-color, var(--color-primary));
+  font-weight: 700;
+  font-size: 1.1em;
+}
+
+/* ----------------------------------------------------------
+    23. Floating CTA Button
+    ---------------------------------------------------------- */
+.float-cta {
+  position: fixed;
+  bottom: 2rem;
+  right: 2rem;
+  z-index: 999;
+  display: flex;
+  flex-direction: column;
+  align-items: flex-end;
+  gap: var(--space-sm);
+}
+
+.float-cta-btn {
+  width: 52px;
+  height: 52px;
+  border-radius: 50%;
+  border: none;
+  background: var(--color-primary);
+  color: #fff;
+  cursor: pointer;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  box-shadow: 0 4px 16px rgba(74, 155, 215, .35);
+  transition: all var(--transition-fast);
+  position: relative;
+}
+
+.float-cta-btn:hover {
+  background: var(--color-primary-hover);
+  transform: scale(1.08);
+  box-shadow: 0 6px 24px rgba(74, 155, 215, .45);
+}
+
+.float-cta-btn:active {
+  transform: scale(.95);
+}
+
+.float-cta-popup {
+  position: absolute;
+  bottom: 64px;
+  right: 0;
+  opacity: 0;
+  visibility: hidden;
+  transform: translateY(8px) scale(.95);
+  transition: all var(--transition-normal);
+  transform-origin: bottom right;
+}
+
+.float-cta-popup.open {
+  opacity: 1;
+  visibility: visible;
+  transform: translateY(0) scale(1);
+}
+
+.float-cta-popup-inner {
+  background: var(--bg-surface);
+  border-radius: var(--radius-lg);
+  box-shadow: var(--shadow-xl);
+  padding: var(--space-lg);
+  text-align: center;
+  min-width: 200px;
+  position: relative;
+}
+
+.float-cta-close {
+  position: absolute;
+  top: 6px;
+  right: 10px;
+  border: none;
+  background: none;
+  font-size: 1.4rem;
+  color: var(--color-text-muted);
+  cursor: pointer;
+  line-height: 1;
+  padding: 4px;
+}
+
+.float-cta-close:hover {
+  color: var(--color-text-primary);
+}
+
+.float-cta-title {
+  font-size: var(--font-size-small);
+  font-weight: 600;
+  color: var(--color-text-primary);
+  margin-bottom: var(--space-sm);
+}
+
+.float-cta-qr {
+  margin: 0 auto var(--space-sm);
+  width: 72px;
+  height: 72px;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  background: var(--bg-body);
+  border-radius: var(--radius-sm);
+}
+
+.float-cta-tip {
+  font-size: var(--font-size-tiny);
+  color: var(--color-text-muted);
+}
+
+/* ----------------------------------------------------------
+    24. Cookie Consent Banner
+    ---------------------------------------------------------- */
+.cookie-consent {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  right: 0;
+  background: var(--color-text-primary);
+  color: #fff;
+  padding: var(--space-md) var(--space-xl);
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  gap: var(--space-lg);
+  z-index: 1000;
+  transform: translateY(100%);
+  transition: transform var(--transition-normal);
+  flex-wrap: wrap;
+}
+
+.cookie-consent.visible {
+  transform: translateY(0);
+}
+
+.cookie-consent-text {
+  font-size: var(--font-size-small);
+  color: rgba(255, 255, 255, .85);
+  line-height: 1.5;
+}
+
+.cookie-consent-text a {
+  color: var(--color-accent);
+  text-decoration: underline;
+}
+
+.cookie-consent-btn {
+  background: var(--color-primary);
+  color: #fff;
+  border: none;
+  border-radius: var(--radius-full);
+  padding: .5em 1.5em;
+  font-size: var(--font-size-small);
+  cursor: pointer;
+  white-space: nowrap;
+  transition: background var(--transition-fast);
+  flex-shrink: 0;
+}
+
+.cookie-consent-btn:hover {
+  background: var(--color-primary-hover);
+}
+
+/* ----------------------------------------------------------
+    25. Footer Enhancements
+    ---------------------------------------------------------- */
+.footer-contact li {
+  font-size: var(--font-size-small);
+  color: var(--color-text-secondary);
+  line-height: 1.8;
+}
+
+.footer-legal {
+  margin-top: var(--space-xs);
+  font-size: var(--font-size-tiny);
+  color: var(--color-text-muted);
+  display: flex;
+  gap: var(--space-md);
+  justify-content: center;
+  flex-wrap: wrap;
+}
+
+.footer-legal a {
+  color: var(--color-text-muted);
+  text-decoration: underline;
+}
+
+.footer-legal a:hover {
+  color: var(--color-primary);
+}
+
+/* Responsive footer bottom on small screens */
+@media (max-width: 480px) {
+  .footer-legal {
+    flex-direction: column;
+    gap: var(--space-xs);
+    align-items: center;
+  }
+
+  .float-cta {
+    bottom: 1rem;
+    right: 1rem;
+  }
+
+  .float-cta-btn {
+    width: 46px;
+    height: 46px;
+  }
+
+  .cookie-consent {
+    padding: var(--space-sm) var(--space-md);
+    flex-direction: column;
+    text-align: center;
+  }
+}
+
+/* ----------------------------------------------------------
+    26. Knowledge Base Section
+    ---------------------------------------------------------- */
+.section-knowledge {
+  background: var(--bg-section-alt);
+}
+
+.knowledge-grid {
+  display: grid;
+  grid-template-columns: repeat(2, 1fr);
+  gap: var(--space-xl);
+  margin-top: var(--space-xl);
+}
+
+.knowledge-card {
+  background: var(--bg-surface);
+  border-radius: var(--radius-lg);
+  overflow: hidden;
+  box-shadow: var(--shadow-sm);
+  transition: all var(--transition-normal);
+  display: flex;
+  flex-direction: column;
+}
+
+.knowledge-card:hover {
+  box-shadow: var(--shadow-md);
+  transform: translateY(-3px);
+}
+
+.knowledge-card-cover {
+  width: 100%;
+  height: 180px;
+  object-fit: cover;
+  background: var(--color-primary-light);
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  color: var(--color-primary);
+  font-size: 2.5rem;
+}
+
+.knowledge-card-body {
+  padding: var(--space-lg);
+  flex: 1;
+  display: flex;
+  flex-direction: column;
+}
+
+.knowledge-card-category {
+  display: inline-block;
+  font-size: var(--font-size-tiny);
+  font-weight: 600;
+  color: var(--color-primary);
+  background: var(--color-primary-light);
+  padding: .2em .8em;
+  border-radius: var(--radius-full);
+  margin-bottom: var(--space-sm);
+  align-self: flex-start;
+}
+
+.knowledge-card-title {
+  font-size: 1.05rem;
+  font-weight: 700;
+  color: var(--color-text-primary);
+  line-height: 1.5;
+  margin-bottom: var(--space-sm);
+  display: -webkit-box;
+  -webkit-line-clamp: 2;
+  -webkit-box-orient: vertical;
+  overflow: hidden;
+}
+
+.knowledge-card-summary {
+  font-size: var(--font-size-small);
+  color: var(--color-text-secondary);
+  line-height: 1.7;
+  flex: 1;
+  display: -webkit-box;
+  -webkit-line-clamp: 3;
+  -webkit-box-orient: vertical;
+  overflow: hidden;
+  margin-bottom: var(--space-md);
+}
+
+.knowledge-card-meta {
+  font-size: var(--font-size-tiny);
+  color: var(--color-text-muted);
+  display: flex;
+  align-items: center;
+  gap: var(--space-md);
+  padding-top: var(--space-sm);
+  border-top: 1px solid var(--color-border-light);
+}
+
+.knowledge-card-meta .dimension-tag {
+  display: inline-block;
+  font-size: 10px;
+  font-weight: 600;
+  padding: .15em .5em;
+  border-radius: var(--radius-full);
+  color: #fff;
+}
+
+.knowledge-footer {
+  text-align: center;
+  margin-top: var(--space-2xl);
+}
+
+.knowledge-tip {
+  font-size: var(--font-size-small);
+  color: var(--color-text-muted);
+}
+
+.knowledge-tip strong {
+  color: var(--color-primary);
+}
+
+.knowledge-loading {
+  grid-column: 1 / -1;
+  text-align: center;
+  padding: var(--space-3xl) 0;
+}
+
+.knowledge-loading-text {
+  font-size: var(--font-size-small);
+  color: var(--color-text-muted);
+}
+
+.knowledge-error {
+  grid-column: 1 / -1;
+  text-align: center;
+  padding: var(--space-xl) 0;
+  color: var(--color-text-muted);
+  font-size: var(--font-size-small);
+}
+
+@media (max-width: 600px) {
+  .knowledge-grid {
+    grid-template-columns: 1fr;
+  }
+  .knowledge-card-cover {
+    height: 140px;
+  }
+}
+
 /* Responsive: Wuxing diagram — handled by aspect-ratio and Canvas redraw */
 @media (max-width: 600px) {
   .wuxing-diagram {

+ 104 - 0
web/js/main.js

@@ -423,6 +423,110 @@ document.addEventListener('DOMContentLoaded', () => {
     // (The center emblem is replaced by the .taiji-center SVG overlay.)
   }
 
+  // --------------------------------------------------------
+  // 8. Knowledge Base — fetch featured articles from API
+  // --------------------------------------------------------
+  const API_BASE = 'https://cfc.etotem.com.cn';
+
+  (function loadFeaturedArticles() {
+    const grid = document.getElementById('knowledgeGrid');
+    const loading = document.getElementById('knowledgeLoading');
+    if (!grid) return;
+
+    fetch(API_BASE + '/api/articles/featured', {
+      method: 'POST',
+      headers: { 'Content-Type': 'application/json' },
+      body: JSON.stringify({ size: 4 })
+    })
+    .then(function (res) { return res.json(); })
+    .then(function (result) {
+      if (loading) loading.style.display = 'none';
+      if (!result.data || !result.data.length) {
+        grid.innerHTML = '<p class="knowledge-error">暂无内容,敬请期待</p>';
+        return;
+      }
+      var html = '';
+      var dimColors = {
+        '身': '#FF8C42', '智': '#6366F1', '富': '#F59E0B',
+        '行': '#10B981', '心': '#FF6B9D'
+      };
+      result.data.forEach(function (article) {
+        var relatedDim = article.relatedDimensions || '';
+        var dimTag = '';
+        if (relatedDim && dimColors[relatedDim]) {
+          dimTag = '<span class="dimension-tag" style="background:' + dimColors[relatedDim] + '">' + relatedDim + '</span>';
+        } else if (relatedDim) {
+          dimTag = '<span class="dimension-tag" style="background:#4A9BD7">' + relatedDim + '</span>';
+        }
+        var coverHtml = article.coverImage
+          ? '<img class="knowledge-card-cover" src="' + API_BASE + article.coverImage + '" alt="' + article.title + '" loading="lazy">'
+          : '<div class="knowledge-card-cover"><svg viewBox="0 0 24 24" width="40" height="40" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M4 19.5A2.5 2.5 0 016.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 014 19.5v-15A2.5 2.5 0 016.5 2z"/><path d="M8 7h6M8 11h8M8 15h4"/></svg></div>';
+        var catName = article.categoryName || '';
+        html += '<div class="knowledge-card">'
+          + coverHtml
+          + '<div class="knowledge-card-body">'
+          + (catName ? '<span class="knowledge-card-category">' + catName + '</span>' : '')
+          + '<h3 class="knowledge-card-title">' + article.title + '</h3>'
+          + (article.summary ? '<p class="knowledge-card-summary">' + article.summary + '</p>' : '')
+          + '<div class="knowledge-card-meta">'
+          + dimTag
+          + (article.readTime ? '<span>阅读约 ' + article.readTime + ' 分钟</span>' : '')
+          + '</div></div></div>';
+      });
+      grid.innerHTML = html;
+    })
+    .catch(function () {
+      if (loading) loading.style.display = 'none';
+      grid.innerHTML = '<p class="knowledge-error">暂时无法加载,请稍后再试</p>';
+    });
+  })();
+
+  // --------------------------------------------------------
+  // 9. Floating CTA toggle
+  // --------------------------------------------------------
+  const floatCtaBtn = document.getElementById('floatCtaBtn');
+  const floatCtaPopup = document.getElementById('floatCtaPopup');
+  const floatCtaClose = document.getElementById('floatCtaClose');
+
+  if (floatCtaBtn && floatCtaPopup) {
+    floatCtaBtn.addEventListener('click', (e) => {
+      e.stopPropagation();
+      floatCtaPopup.classList.toggle('open');
+    });
+
+    if (floatCtaClose) {
+      floatCtaClose.addEventListener('click', (e) => {
+        e.stopPropagation();
+        floatCtaPopup.classList.remove('open');
+      });
+    }
+
+    document.addEventListener('click', () => {
+      floatCtaPopup.classList.remove('open');
+    });
+
+    floatCtaPopup.addEventListener('click', (e) => {
+      e.stopPropagation();
+    });
+  }
+
+  // --------------------------------------------------------
+  // 9. Cookie consent banner
+  // --------------------------------------------------------
+  const cookieConsent = document.getElementById('cookieConsent');
+  const cookieConsentBtn = document.getElementById('cookieConsentBtn');
+
+  if (cookieConsent && cookieConsentBtn) {
+    if (!localStorage.getItem('cookieConsent')) {
+      setTimeout(() => cookieConsent.classList.add('visible'), 600);
+    }
+
+    cookieConsentBtn.addEventListener('click', () => {
+      cookieConsent.classList.remove('visible');
+      localStorage.setItem('cookieConsent', 'true');
+    });
+  }
+
   // Initial draw
   drawWuxingDiagram();