From 1a5e9f7064898c27444ffed8b4795a0ac286635c Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Sat, 1 Aug 2026 12:34:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(static):=20=E9=A6=96=E9=A1=B5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=99=BB=E5=BD=95=E6=80=81=E6=A3=80=E6=B5=8B=E4=B8=8E?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=AC=94=E8=AE=B0=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - index.html: lang 改为 zh-CN,新增"关于本站"介绍段落,按钮改为有 id 的登录/注册/进入/退出四按钮(默认隐藏进入/退出) - 新增 index.js: POST /whoami 检测登录态(HttpOnly Cookie 自动携带),已登录则显示用户名+进入笔记/退出按钮,未登录显示登录/注册 - 退出按钮调用 POST /logout 后刷新页面 --- static/public/index.html | 24 +++++++++++++++++----- static/public/js/index.js | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/static/public/index.html b/static/public/index.html index 608b0f5..d86131d 100644 --- a/static/public/index.html +++ b/static/public/index.html @@ -1,5 +1,5 @@ - + @@ -24,6 +24,13 @@ margin-left: 5px; margin-right: 5px; } + .site-intro { + max-width: 640px; + margin: 0 auto; + font-size: 0.95rem; + line-height: 1.9; + color: var(--fg-secondary); + } DNFS 欢迎来到树状笔记 @@ -33,16 +40,23 @@
头像加载失败 DNFS - - + + + +
-

推荐节点

- +

关于本站

+

+ DNFS 树状笔记是一个以树状结构组织内容的笔记社区:每个节点都可以生长出子节点, + 像树枝一样层层延展,让知识自然成体系。支持 Markdown 文本、链接卡片、图片与文件分享, + 注册登录后即可创建属于你自己的知识树。 +

+ \ No newline at end of file diff --git a/static/public/js/index.js b/static/public/js/index.js index e69de29..15c6706 100644 --- a/static/public/js/index.js +++ b/static/public/js/index.js @@ -0,0 +1,42 @@ +/* index.js — 社区首页逻辑 + * + * 登录态检测:POST /whoami(HttpOnly q4_token Cookie 自动携带,JS 不经手 Token) + * 已登录:显示用户名与"进入笔记/退出"按钮;未登录:显示"登录/注册" + */ +(function () { + 'use strict'; + + const nameEl = document.getElementById('name'); + const enterBtn = document.getElementById('enterBtn'); + const logoutBtn = document.getElementById('logoutBtn'); + const loginBtn = document.getElementById('loginBtn'); + const registerBtn = document.getElementById('registerBtn'); + + async function checkLogin() { + try { + const res = await fetch('/whoami', { method: 'POST' }); + if (!res.ok) return; + const data = await res.json(); + if (data && data.login && data.user) { + nameEl.textContent = String(data.user); + enterBtn.style.display = ''; + logoutBtn.style.display = ''; + loginBtn.style.display = 'none'; + registerBtn.style.display = 'none'; + } + } catch (e) { + console.warn('index: 登录态检测失败', e.message); + } + } + + logoutBtn.addEventListener('click', async function () { + try { + await fetch('/logout', { method: 'POST' }); + } catch (e) { + console.warn('index: 退出登录请求异常', e.message); + } + location.reload(); + }); + + checkLogin(); +})();