diff --git a/frontend/src/api.js b/frontend/src/api.js index 011dbda..581c0dc 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -85,6 +85,31 @@ export const adminApi = { saveSettings: (body) => request('/api/admin/settings', { method: 'PUT', body }) } +// 读者(评论区)身份。会话是服务端 httpOnly cookie(one_reader), +// 前端只拿 /api/auth/me 的结果做展示,不存 token。 +// 注意 me 在匿名时返回 200 {user:null} 而不是 401 —— request() 对每个 401 +// 都会派发 one:unauthorized,匿名访客每次开页都会刷一遍事件。 +export const readerApi = { + me: () => request('/api/auth/me'), + providers: () => request('/api/auth/providers'), + logout: () => request('/api/auth/logout', { method: 'POST' }), + // Telegram 是 Login Widget:官方脚本回调里直接带着签名字段,没有 code 可换 + telegram: (payload) => request('/api/auth/telegram', { method: 'POST', body: payload }), + + comments: (postId, { sort = 'default', page = 1, size = 10 } = {}) => + request('/api/comments?' + new URLSearchParams({ post_id: postId, sort, page, size })), + thread: (rootId, cursor = '', size = 10) => + request(`/api/comments/${rootId}/thread?` + new URLSearchParams({ cursor, size })), + create: (postId, bodyMd, parentId = 0) => + request('/api/comments', { + method: 'POST', + body: { post_id: postId, parent_id: parentId, body_md: bodyMd } + }), + edit: (id, bodyMd) => + request(`/api/comments/${id}`, { method: 'PUT', body: { body_md: bodyMd } }), + remove: (id) => request(`/api/comments/${id}`, { method: 'DELETE' }) +} + // 后台登录态:cookie 由服务端下发(httpOnly),这里只存一份展示用的用户名 const USER_KEY = 'one.admin.user' diff --git a/frontend/src/components/PostCard.vue b/frontend/src/components/PostCard.vue index bc349ea..82d7111 100644 --- a/frontend/src/components/PostCard.vue +++ b/frontend/src/components/PostCard.vue @@ -71,7 +71,9 @@ const initial = computed(() => (site.author_name || 'O').trim().slice(0, 1).toUp display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px; - padding: 14px 16px; + /* 左右 30 = 16(出血到列边)+ 14(内容离边框的呼吸位)。 + 之前是 16/16,负 margin 正好把内边距抵光,头像贴死在边框上。 */ + padding: 14px 30px; margin: 0 -16px; border-bottom: 1px solid var(--line-soft); transition: background 0.15s ease; diff --git a/frontend/src/components/comments/CommentItem.vue b/frontend/src/components/comments/CommentItem.vue new file mode 100644 index 0000000..a7baabf --- /dev/null +++ b/frontend/src/components/comments/CommentItem.vue @@ -0,0 +1,178 @@ + + +