feat: 优化首页帖子列表并新增右侧栏最新注册组件
首页列表精简 meta 与统计展示,板块色标前移并淡化;有回复时显示最后回复人。右侧栏新增最新注册(4 列头像网格),友链改为标签块并排换行。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { User, UserPublic, UserActivityStats, Board, PostItem, Comment, RecentComment, ForumStats, TagCount, AdminDashboard, AdminSettings, ForumLimits, ForumLimitsPublic, PostDetailResponse, PostRevision, CommentRevision, MailConfig, OIDCConfig, OAuthClient, OAuthClientInput, GiteaProject, GiteaSyncConfig, StorageConfig, MediaListResult, SiteBranding, RegisterConfig, PrivateMessage, MessageConversation, PostReport, ReportReason, ReportStatus, BadgeDef, PointLedger, CheckInStatus, LotteryStatus, SitePage, SitePageSummary, PollView, PostLotteryView, FriendLinkApply } from './types';
|
import type { User, UserPublic, UserActivityStats, Board, PostItem, Comment, RecentComment, RecentUser, ForumStats, TagCount, AdminDashboard, AdminSettings, ForumLimits, ForumLimitsPublic, PostDetailResponse, PostRevision, CommentRevision, MailConfig, OIDCConfig, OAuthClient, OAuthClientInput, GiteaProject, GiteaSyncConfig, StorageConfig, MediaListResult, SiteBranding, RegisterConfig, PrivateMessage, MessageConversation, PostReport, ReportReason, ReportStatus, BadgeDef, PointLedger, CheckInStatus, LotteryStatus, SitePage, SitePageSummary, PollView, PostLotteryView, FriendLinkApply } from './types';
|
||||||
|
|
||||||
const BASE = '';
|
const BASE = '';
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ export const api = {
|
|||||||
return request<{ comments: Comment[]; total: number }>(`/api/posts/${id}/comments${q}`);
|
return request<{ comments: Comment[]; total: number }>(`/api/posts/${id}/comments${q}`);
|
||||||
},
|
},
|
||||||
recentComments: () => request<{ comments: RecentComment[] }>('/api/comments/recent'),
|
recentComments: () => request<{ comments: RecentComment[] }>('/api/comments/recent'),
|
||||||
|
recentUsers: () => request<{ users: RecentUser[] }>('/api/users/recent'),
|
||||||
favorites: () => request<{ favorites: unknown[]; total: number }>('/api/favorites'),
|
favorites: () => request<{ favorites: unknown[]; total: number }>('/api/favorites'),
|
||||||
createBoard: (body: { name: string; description: string; sort_order: number; icon?: string; color_index?: number }) =>
|
createBoard: (body: { name: string; description: string; sort_order: number; icon?: string; color_index?: number }) =>
|
||||||
request<{ board: Board }>('/api/admin/boards', { method: 'POST', body: JSON.stringify(body) }),
|
request<{ board: Board }>('/api/admin/boards', { method: 'POST', body: JSON.stringify(body) }),
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ export interface PostItem {
|
|||||||
view_count: number;
|
view_count: number;
|
||||||
comment_count: number;
|
comment_count: number;
|
||||||
last_reply_at?: string;
|
last_reply_at?: string;
|
||||||
|
/** 最后回复用户(登录用户);与 last_reply_guest_nick 二选一 */
|
||||||
|
last_reply_user?: User;
|
||||||
|
/** 最后回复游客昵称 */
|
||||||
|
last_reply_guest_nick?: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at?: string;
|
updated_at?: string;
|
||||||
board?: Board;
|
board?: Board;
|
||||||
@@ -187,7 +191,7 @@ export interface AdminDashboard {
|
|||||||
recent_posts: PostItem[];
|
recent_posts: PostItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AsideWidgetId = 'tag_cloud' | 'recent_comments' | 'friend_links';
|
export type AsideWidgetId = 'tag_cloud' | 'recent_comments' | 'recent_users' | 'friend_links';
|
||||||
|
|
||||||
export interface AsideWidget {
|
export interface AsideWidget {
|
||||||
id: AsideWidgetId;
|
id: AsideWidgetId;
|
||||||
@@ -197,6 +201,7 @@ export interface AsideWidget {
|
|||||||
export const DEFAULT_ASIDE_WIDGETS: AsideWidget[] = [
|
export const DEFAULT_ASIDE_WIDGETS: AsideWidget[] = [
|
||||||
{ id: 'tag_cloud', enabled: false },
|
{ id: 'tag_cloud', enabled: false },
|
||||||
{ id: 'recent_comments', enabled: false },
|
{ id: 'recent_comments', enabled: false },
|
||||||
|
{ id: 'recent_users', enabled: false },
|
||||||
{ id: 'friend_links', enabled: true },
|
{ id: 'friend_links', enabled: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -500,6 +505,14 @@ export interface RecentComment {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 右栏「最新注册」用户 */
|
||||||
|
export interface RecentUser {
|
||||||
|
id: number;
|
||||||
|
nickname: string;
|
||||||
|
avatar: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
/** 站内私信 */
|
/** 站内私信 */
|
||||||
export interface PrivateMessage {
|
export interface PrivateMessage {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -1,45 +1,48 @@
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Eye, Image as ImageIcon, MessageCircle, ThumbsUp } from 'lucide-react';
|
import { MessageCircle } from 'lucide-react';
|
||||||
|
import BoardBadge from '@/components/BoardBadge';
|
||||||
import FeaturedIcon from '@/components/FeaturedIcon';
|
import FeaturedIcon from '@/components/FeaturedIcon';
|
||||||
import UserLink from '@/components/UserLink';
|
import UserLink from '@/components/UserLink';
|
||||||
import type { PostItem } from '../api/types';
|
import type { PostItem } from '../api/types';
|
||||||
import type { FeedSort } from './FeedSortBar';
|
import type { FeedSort } from './FeedSortBar';
|
||||||
import { useForumLimits } from '../hooks/useForumLimits';
|
import { useForumLimits } from '../hooks/useForumLimits';
|
||||||
import { formatTime } from '../utils/content';
|
import { formatTime } from '../utils/content';
|
||||||
import { postPath } from '../utils/permalink';
|
import { boardPath, postPath } from '../utils/permalink';
|
||||||
import { toPostImageThumbSrc } from '../utils/postContent';
|
import { toPostImageThumbSrc } from '../utils/postContent';
|
||||||
import { excerptFromHTML, firstImageFromHTML } from '../utils/seoText';
|
import { excerptFromHTML, firstImageFromHTML } from '../utils/seoText';
|
||||||
import { parseTags } from './TagInput';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
post: PostItem;
|
post: PostItem;
|
||||||
sort?: FeedSort;
|
sort?: FeedSort;
|
||||||
|
/** 当前板块 id,>0 时隐藏行内板块色标(避免板块页重复) */
|
||||||
|
boardId?: number;
|
||||||
onSelect: (id: number) => void;
|
onSelect: (id: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function PostListItem({ post, sort = 'latest', onSelect }: Props) {
|
function PostListItem({ post, sort = 'latest', boardId = 0, onSelect }: Props) {
|
||||||
const nav = useNavigate();
|
const nav = useNavigate();
|
||||||
const { limits } = useForumLimits();
|
const { limits } = useForumLimits();
|
||||||
const feedStyle = limits.feed_list_style ?? 'title';
|
const feedStyle = limits.feed_list_style ?? 'title';
|
||||||
const showExcerpt = feedStyle === 'excerpt' || feedStyle === 'thumbnail';
|
const showExcerpt = feedStyle === 'excerpt' || feedStyle === 'thumbnail';
|
||||||
const showThumb = feedStyle === 'thumbnail';
|
const showThumb = feedStyle === 'thumbnail';
|
||||||
|
const titleOnly = feedStyle === 'title';
|
||||||
|
|
||||||
const initial = post.user?.nickname?.[0] || '?';
|
const initial = post.user?.nickname?.[0] || '?';
|
||||||
const timeLabel = sort === 'reply'
|
const timeLabel = sort === 'reply' && !post.last_reply_at
|
||||||
? (post.last_reply_at
|
? '暂无回复'
|
||||||
? `${formatTime(post.last_reply_at)} 回复`
|
|
||||||
: '暂无回复')
|
|
||||||
: formatTime(post.created_at);
|
: formatTime(post.created_at);
|
||||||
|
const lastReplyName = post.last_reply_user?.nickname?.trim()
|
||||||
|
|| post.last_reply_user?.username?.trim()
|
||||||
|
|| post.last_reply_guest_nick?.trim()
|
||||||
|
|| '';
|
||||||
|
const showLastReply = !!post.last_reply_at && (!!post.last_reply_user || !!lastReplyName);
|
||||||
const commentCount = post.comment_count ?? 0;
|
const commentCount = post.comment_count ?? 0;
|
||||||
const likeCount = post.like_count ?? 0;
|
|
||||||
const viewCount = post.view_count ?? 0;
|
|
||||||
const href = postPath(post.id);
|
const href = postPath(post.id);
|
||||||
const firstImage = firstImageFromHTML(post.content || '');
|
const firstImage = firstImageFromHTML(post.content || '');
|
||||||
const thumbSrc = showThumb && firstImage ? toPostImageThumbSrc(firstImage) : null;
|
const thumbSrc = showThumb && firstImage ? toPostImageThumbSrc(firstImage) : null;
|
||||||
const excerpt = showExcerpt ? excerptFromHTML(post.content || '', 60) : '';
|
const excerpt = showExcerpt ? excerptFromHTML(post.content || '', 60) : '';
|
||||||
const showImageIcon = !!firstImage && !thumbSrc;
|
const showBoardBadge = !!post.board && boardId !== post.board.id;
|
||||||
const tagList = parseTags(post.tags || '').slice(0, 3);
|
|
||||||
|
|
||||||
const openPost = () => onSelect(post.id);
|
const openPost = () => onSelect(post.id);
|
||||||
const onKeyDown = (e: React.KeyboardEvent) => {
|
const onKeyDown = (e: React.KeyboardEvent) => {
|
||||||
@@ -108,57 +111,53 @@ function PostListItem({ post, sort = 'latest', onSelect }: Props) {
|
|||||||
|
|
||||||
const metaLeft = (
|
const metaLeft = (
|
||||||
<div className="post-meta-left">
|
<div className="post-meta-left">
|
||||||
<UserLink user={post.user} stopPropagation className="post-meta-author" showBadges={false} />
|
{showBoardBadge && post.board && (
|
||||||
<span className="post-meta-sep" aria-hidden>·</span>
|
|
||||||
<span className="post-meta-time">{timeLabel}</span>
|
|
||||||
{post.board && (
|
|
||||||
<>
|
|
||||||
<span className="post-meta-sep" aria-hidden>·</span>
|
|
||||||
<span className="post-meta-board">{post.board.name}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{tagList.map(t => (
|
|
||||||
<button
|
<button
|
||||||
key={t}
|
|
||||||
type="button"
|
type="button"
|
||||||
className="post-list-tag"
|
className="post-list-board-btn"
|
||||||
title={`筛选标签:${t}`}
|
title={`进入板块:${post.board.name}`}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
nav(`/?tag=${encodeURIComponent(t)}`);
|
nav(boardPath(post.board!.id, limits));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
#{t}
|
<BoardBadge board={post.board} className="post-list-board-badge" />
|
||||||
</button>
|
</button>
|
||||||
))}
|
)}
|
||||||
|
<UserLink user={post.user} stopPropagation className="post-meta-author" showBadges={false} />
|
||||||
|
<span className="post-meta-sep post-meta-sep--before-time" aria-hidden>·</span>
|
||||||
|
<span className="post-meta-time post-meta-time--created">{timeLabel}</span>
|
||||||
|
{showLastReply && (
|
||||||
|
<span className="post-meta-last-reply">
|
||||||
|
<span className="post-meta-last-reply-arrow" aria-hidden>←</span>
|
||||||
|
{post.last_reply_user ? (
|
||||||
|
<UserLink
|
||||||
|
user={post.last_reply_user}
|
||||||
|
stopPropagation
|
||||||
|
className="post-meta-last-reply-user"
|
||||||
|
showBadges={false}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="post-meta-last-reply-user">{lastReplyName}</span>
|
||||||
|
)}
|
||||||
|
<span className="post-meta-last-reply-time">{formatTime(post.last_reply_at!)}</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const stats = (
|
const stats = (
|
||||||
<div className="post-stats">
|
<div className="post-stats">
|
||||||
{showImageIcon && (
|
|
||||||
<span className="post-stat post-stat--media" title="含图片">
|
|
||||||
<ImageIcon aria-hidden />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<span className={`post-stat${commentCount === 0 ? ' post-stat--zero' : ''}`} title="评论">
|
<span className={`post-stat${commentCount === 0 ? ' post-stat--zero' : ''}`} title="评论">
|
||||||
<MessageCircle aria-hidden />
|
<MessageCircle aria-hidden />
|
||||||
{commentCount}
|
{commentCount}
|
||||||
</span>
|
</span>
|
||||||
<span className={`post-stat${likeCount === 0 ? ' post-stat--zero' : ''}`} title="点赞">
|
|
||||||
<ThumbsUp aria-hidden />
|
|
||||||
{likeCount}
|
|
||||||
</span>
|
|
||||||
<span className={`post-stat${viewCount === 0 ? ' post-stat--zero' : ''}`} title="浏览">
|
|
||||||
<Eye aria-hidden />
|
|
||||||
{viewCount}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`post-row post-row--v2${thumbSrc ? ' post-row--has-thumb' : ''}`}
|
className={`post-row post-row--v2${titleOnly ? ' post-row--title-only' : ''}${thumbSrc ? ' post-row--has-thumb' : ''}`}
|
||||||
role="link"
|
role="link"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onClick={openPost}
|
onClick={openPost}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function feedListRowEstimate(style: FeedListStyle): number {
|
|||||||
switch (style) {
|
switch (style) {
|
||||||
case 'excerpt': return 68;
|
case 'excerpt': return 68;
|
||||||
case 'thumbnail': return 72;
|
case 'thumbnail': return 72;
|
||||||
default: return 52;
|
default: return 64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,13 +21,17 @@ interface Props {
|
|||||||
export default function PostListSkeleton({ count = 8, listStyle = 'title' }: Props) {
|
export default function PostListSkeleton({ count = 8, listStyle = 'title' }: Props) {
|
||||||
const showExcerpt = listStyle === 'excerpt' || listStyle === 'thumbnail';
|
const showExcerpt = listStyle === 'excerpt' || listStyle === 'thumbnail';
|
||||||
const showThumb = listStyle === 'thumbnail';
|
const showThumb = listStyle === 'thumbnail';
|
||||||
|
const titleOnly = listStyle === 'title';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="post-list-skeleton" aria-busy="true" aria-label="加载中">
|
<div className="post-list-skeleton" aria-busy="true" aria-label="加载中">
|
||||||
{Array.from({ length: count }, (_, i) => {
|
{Array.from({ length: count }, (_, i) => {
|
||||||
const hasThumb = showThumb && i % 3 === 0;
|
const hasThumb = showThumb && i % 3 === 0;
|
||||||
return (
|
return (
|
||||||
<div key={i} className={`post-row post-row--v2 post-row--skeleton${hasThumb ? ' post-row--has-thumb' : ''}`}>
|
<div
|
||||||
|
key={i}
|
||||||
|
className={`post-row post-row--v2 post-row--skeleton${titleOnly ? ' post-row--title-only' : ''}${hasThumb ? ' post-row--has-thumb' : ''}`}
|
||||||
|
>
|
||||||
<Skeleton className="skeleton--avatar skeleton--avatar-v2" />
|
<Skeleton className="skeleton--avatar skeleton--avatar-v2" />
|
||||||
{hasThumb ? (
|
{hasThumb ? (
|
||||||
<div className="post-main post-main--with-thumb">
|
<div className="post-main post-main--with-thumb">
|
||||||
@@ -36,14 +40,15 @@ export default function PostListSkeleton({ count = 8, listStyle = 'title' }: Pro
|
|||||||
{showExcerpt && (
|
{showExcerpt && (
|
||||||
<Skeleton className="skeleton--excerpt skeleton--excerpt-v2" style={{ width: `${72 + (i % 3) * 8}%` }} />
|
<Skeleton className="skeleton--excerpt skeleton--excerpt-v2" style={{ width: `${72 + (i % 3) * 8}%` }} />
|
||||||
)}
|
)}
|
||||||
<Skeleton className="skeleton--meta-line" style={{ width: `${45 + (i % 3) * 10}%` }} />
|
<div className="post-meta-left post-meta-left--skeleton">
|
||||||
|
<Skeleton className="skeleton--board-badge" />
|
||||||
|
<Skeleton className="skeleton--meta-line" style={{ width: `${45 + (i % 3) * 10}%` }} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="post-aside">
|
<div className="post-aside">
|
||||||
<Skeleton className="skeleton--thumb skeleton--thumb-tall" />
|
<Skeleton className="skeleton--thumb skeleton--thumb-tall" />
|
||||||
<div className="post-stats">
|
<div className="post-stats">
|
||||||
<Skeleton className="skeleton--stat" />
|
<Skeleton className="skeleton--stat" />
|
||||||
<Skeleton className="skeleton--stat" />
|
|
||||||
<Skeleton className="skeleton--stat" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -56,11 +61,12 @@ export default function PostListSkeleton({ count = 8, listStyle = 'title' }: Pro
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="post-meta">
|
<div className="post-meta">
|
||||||
<Skeleton className="skeleton--meta-line" style={{ width: `${45 + (i % 3) * 10}%` }} />
|
<div className="post-meta-left post-meta-left--skeleton">
|
||||||
|
<Skeleton className="skeleton--board-badge" />
|
||||||
|
<Skeleton className="skeleton--meta-line" style={{ width: `${45 + (i % 3) * 10}%` }} />
|
||||||
|
</div>
|
||||||
<div className="post-stats">
|
<div className="post-stats">
|
||||||
<Skeleton className="skeleton--stat" />
|
<Skeleton className="skeleton--stat" />
|
||||||
<Skeleton className="skeleton--stat" />
|
|
||||||
<Skeleton className="skeleton--stat" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { ListTree, MessageCircle, Tags, Link2 } from 'lucide-react';
|
import { ListTree, MessageCircle, Tags, Link2, UserPlus } from 'lucide-react';
|
||||||
import { useLocation, useSearchParams, useNavigate } from 'react-router-dom';
|
import { useLocation, useSearchParams, useNavigate } from 'react-router-dom';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import type { AsideWidget, RecentComment, TagCount, User, ForumStats, FriendLink } from '../api/types';
|
import type { AsideWidget, RecentComment, RecentUser, TagCount, User, ForumStats, FriendLink } from '../api/types';
|
||||||
import type { PostHeading } from '../utils/postHeadings';
|
import type { PostHeading } from '../utils/postHeadings';
|
||||||
import { useSiteBranding } from '../hooks/useSiteBranding';
|
import { useSiteBranding } from '../hooks/useSiteBranding';
|
||||||
import { formatShortDateTime, formatTime } from '../utils/content';
|
import { formatShortDateTime, formatTime } from '../utils/content';
|
||||||
@@ -25,6 +25,7 @@ export type PostDetailAside = {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
recentComments: RecentComment[];
|
recentComments: RecentComment[];
|
||||||
|
recentUsers: RecentUser[];
|
||||||
tags?: TagCount[];
|
tags?: TagCount[];
|
||||||
tagsLoading?: boolean;
|
tagsLoading?: boolean;
|
||||||
stats?: ForumStats | null;
|
stats?: ForumStats | null;
|
||||||
@@ -53,8 +54,22 @@ function CommentSkeleton() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function UserSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="widget-recent-users-grid" aria-busy="true" aria-label="用户加载中">
|
||||||
|
{Array.from({ length: 8 }, (_, i) => (
|
||||||
|
<div key={i} className="widget-recent-user-cell widget-recent-user-cell--skeleton">
|
||||||
|
<Skeleton className="skeleton--recent-user-avatar" />
|
||||||
|
<Skeleton className="skeleton--recent-user-name" style={{ width: `${48 + (i % 3) * 10}%` }} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function RightPanel({
|
export default function RightPanel({
|
||||||
recentComments,
|
recentComments,
|
||||||
|
recentUsers,
|
||||||
tags = [],
|
tags = [],
|
||||||
tagsLoading = false,
|
tagsLoading = false,
|
||||||
stats = null,
|
stats = null,
|
||||||
@@ -69,6 +84,7 @@ export default function RightPanel({
|
|||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const activeTag = params.get('tag') || '';
|
const activeTag = params.get('tag') || '';
|
||||||
const commentList = recentComments?.slice(0, 6) ?? [];
|
const commentList = recentComments?.slice(0, 6) ?? [];
|
||||||
|
const userList = recentUsers?.slice(0, 8) ?? [];
|
||||||
const friendLinks = (branding.friend_links ?? []).filter(
|
const friendLinks = (branding.friend_links ?? []).filter(
|
||||||
(l: FriendLink) => l.name?.trim() && l.url?.trim(),
|
(l: FriendLink) => l.name?.trim() && l.url?.trim(),
|
||||||
);
|
);
|
||||||
@@ -118,7 +134,7 @@ export default function RightPanel({
|
|||||||
申请
|
申请
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="widget-card-body">
|
<div className="widget-card-body widget-card-body--friend-links">
|
||||||
{friendLinks.length === 0 ? (
|
{friendLinks.length === 0 ? (
|
||||||
<div className="widget-empty">暂无友情链接</div>
|
<div className="widget-empty">暂无友情链接</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -126,7 +142,9 @@ export default function RightPanel({
|
|||||||
<ul className="widget-friend-links-list">
|
<ul className="widget-friend-links-list">
|
||||||
{friendLinks.slice(0, 8).map((link: FriendLink) => (
|
{friendLinks.slice(0, 8).map((link: FriendLink) => (
|
||||||
<li key={`${link.name}-${link.url}`}>
|
<li key={`${link.name}-${link.url}`}>
|
||||||
<a href={link.url} target="_blank" rel="noopener noreferrer">{link.name}</a>
|
<a href={link.url} target="_blank" rel="noopener noreferrer" title={link.name}>
|
||||||
|
{link.name}
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -212,6 +230,41 @@ export default function RightPanel({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
case 'recent_users':
|
||||||
|
return (
|
||||||
|
<div key="recent_users" className="widget-card widget-card--users">
|
||||||
|
<div className="widget-card-head">
|
||||||
|
<UserPlus className="widget-card-icon widget-card-icon--users" aria-hidden />
|
||||||
|
最新注册
|
||||||
|
</div>
|
||||||
|
<div className="widget-card-body widget-card-body--users">
|
||||||
|
{loading && userList.length === 0 ? (
|
||||||
|
<UserSkeleton />
|
||||||
|
) : userList.length === 0 ? (
|
||||||
|
<div className="widget-empty">暂无用户</div>
|
||||||
|
) : (
|
||||||
|
<div className="widget-recent-users-grid">
|
||||||
|
{userList.map(item => (
|
||||||
|
<UserLink
|
||||||
|
key={item.id}
|
||||||
|
user={{ id: item.id, nickname: item.nickname, avatar: item.avatar }}
|
||||||
|
className="widget-recent-user-cell"
|
||||||
|
showBadges={false}
|
||||||
|
title={item.nickname}
|
||||||
|
>
|
||||||
|
<span className="widget-recent-user-avatar" aria-hidden>
|
||||||
|
{item.avatar
|
||||||
|
? <img src={item.avatar} alt="" loading="lazy" decoding="async" />
|
||||||
|
: (item.nickname?.[0] || '?')}
|
||||||
|
</span>
|
||||||
|
<span className="widget-recent-user-name">{item.nickname}</span>
|
||||||
|
</UserLink>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ export default function VirtualPostList({
|
|||||||
transform: `translateY(${offsetY}px)`,
|
transform: `translateY(${offsetY}px)`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PostListItem post={post} sort={sort} onSelect={onSelect} />
|
<PostListItem post={post} sort={sort} boardId={boardId} onSelect={onSelect} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ const WIDGET_META: Record<AsideWidgetId, { label: string; hint: string }> = {
|
|||||||
label: '最新评论',
|
label: '最新评论',
|
||||||
hint: '在右侧栏展示最近回复',
|
hint: '在右侧栏展示最近回复',
|
||||||
},
|
},
|
||||||
|
recent_users: {
|
||||||
|
label: '最新注册',
|
||||||
|
hint: '在右侧栏展示最近注册的用户',
|
||||||
|
},
|
||||||
friend_links: {
|
friend_links: {
|
||||||
label: '友情链接',
|
label: '友情链接',
|
||||||
hint: '关闭后不在右侧栏展示,友链仍可在「友情链接」页面查看与申请',
|
hint: '关闭后不在右侧栏展示,友链仍可在「友情链接」页面查看与申请',
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import { useAuth } from '../hooks/useAuth';
|
|||||||
import { useTheme, useMediaQuery } from '../hooks/useTheme';
|
import { useTheme, useMediaQuery } from '../hooks/useTheme';
|
||||||
import { useOverlayA11y, moveTabIndex } from '../hooks/useOverlayA11y';
|
import { useOverlayA11y, moveTabIndex } from '../hooks/useOverlayA11y';
|
||||||
import { api } from '../api/client';
|
import { api } from '../api/client';
|
||||||
import type { Board, RecentComment, ForumStats, TagCount, User } from '../api/types';
|
import type { Board, RecentComment, RecentUser, ForumStats, TagCount, User } from '../api/types';
|
||||||
import type { PostHeading } from '../utils/postHeadings';
|
import type { PostHeading } from '../utils/postHeadings';
|
||||||
import { getCachedBoards, getCachedStats, getCachedRecentComments, getCachedTags, hasCachedAside, setCachedBoards, setCachedStats, setCachedRecentComments, setCachedTags } from '../utils/layoutCache';
|
import { getCachedBoards, getCachedStats, getCachedRecentComments, getCachedRecentUsers, getCachedTags, hasCachedAside, setCachedBoards, setCachedStats, setCachedRecentComments, setCachedRecentUsers, setCachedTags } from '../utils/layoutCache';
|
||||||
import Sidebar, { isNeutralSidebarRoute } from '../components/Sidebar';
|
import Sidebar, { isNeutralSidebarRoute } from '../components/Sidebar';
|
||||||
import RightPanel from '../components/RightPanel';
|
import RightPanel from '../components/RightPanel';
|
||||||
import BackToTop from '../components/BackToTop';
|
import BackToTop from '../components/BackToTop';
|
||||||
@@ -49,6 +49,7 @@ export default function MainLayout() {
|
|||||||
const [boards, setBoards] = useState<Board[]>(() => getCachedBoards());
|
const [boards, setBoards] = useState<Board[]>(() => getCachedBoards());
|
||||||
const [stats, setStats] = useState<ForumStats | null>(() => getCachedStats());
|
const [stats, setStats] = useState<ForumStats | null>(() => getCachedStats());
|
||||||
const [recentComments, setRecentComments] = useState<RecentComment[]>(() => getCachedRecentComments());
|
const [recentComments, setRecentComments] = useState<RecentComment[]>(() => getCachedRecentComments());
|
||||||
|
const [recentUsers, setRecentUsers] = useState<RecentUser[]>(() => getCachedRecentUsers());
|
||||||
const [unreadMessages, setUnreadMessages] = useState(0);
|
const [unreadMessages, setUnreadMessages] = useState(0);
|
||||||
const [tags, setTags] = useState<TagCount[]>(() => getCachedTags());
|
const [tags, setTags] = useState<TagCount[]>(() => getCachedTags());
|
||||||
const [tagsLoading, setTagsLoading] = useState(() => getCachedTags().length === 0);
|
const [tagsLoading, setTagsLoading] = useState(() => getCachedTags().length === 0);
|
||||||
@@ -82,6 +83,7 @@ export default function MainLayout() {
|
|||||||
const asideWidgets = useMemo(() => resolveAsideWidgets(forumLimits), [forumLimits]);
|
const asideWidgets = useMemo(() => resolveAsideWidgets(forumLimits), [forumLimits]);
|
||||||
const showTagCloud = asideWidgets.some(w => w.id === 'tag_cloud' && w.enabled);
|
const showTagCloud = asideWidgets.some(w => w.id === 'tag_cloud' && w.enabled);
|
||||||
const showRecentComments = asideWidgets.some(w => w.id === 'recent_comments' && w.enabled);
|
const showRecentComments = asideWidgets.some(w => w.id === 'recent_comments' && w.enabled);
|
||||||
|
const showRecentUsers = asideWidgets.some(w => w.id === 'recent_users' && w.enabled);
|
||||||
|
|
||||||
const asideDrawerRef = useRef<HTMLElement>(null);
|
const asideDrawerRef = useRef<HTMLElement>(null);
|
||||||
const asideCloseRef = useRef<HTMLButtonElement>(null);
|
const asideCloseRef = useRef<HTMLButtonElement>(null);
|
||||||
@@ -241,6 +243,31 @@ export default function MainLayout() {
|
|||||||
};
|
};
|
||||||
}, [needRecentComments]);
|
}, [needRecentComments]);
|
||||||
|
|
||||||
|
const needRecentUsers = needAsideData && showRecentUsers;
|
||||||
|
useEffect(() => {
|
||||||
|
if (!needRecentUsers) return;
|
||||||
|
let cancelled = false;
|
||||||
|
if (!asideEverLoaded.current && !hasCachedAside()) {
|
||||||
|
setAsideLoading(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
api.recentUsers().then(d => {
|
||||||
|
if (cancelled) return;
|
||||||
|
const next = Array.isArray(d.users) ? d.users : [];
|
||||||
|
setRecentUsers(next);
|
||||||
|
setCachedRecentUsers(next);
|
||||||
|
}).catch(() => {}).finally(() => {
|
||||||
|
if (!cancelled) {
|
||||||
|
asideEverLoaded.current = true;
|
||||||
|
setAsideLoading(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [needRecentUsers]);
|
||||||
|
|
||||||
const doSearch = () => {
|
const doSearch = () => {
|
||||||
const kw = keyword.trim();
|
const kw = keyword.trim();
|
||||||
const author = searchAuthor.trim();
|
const author = searchAuthor.trim();
|
||||||
@@ -642,6 +669,7 @@ export default function MainLayout() {
|
|||||||
<aside className="aside-panel">
|
<aside className="aside-panel">
|
||||||
<RightPanel
|
<RightPanel
|
||||||
recentComments={recentComments}
|
recentComments={recentComments}
|
||||||
|
recentUsers={recentUsers}
|
||||||
tags={tags}
|
tags={tags}
|
||||||
tagsLoading={tagsLoading}
|
tagsLoading={tagsLoading}
|
||||||
stats={stats}
|
stats={stats}
|
||||||
@@ -757,6 +785,7 @@ export default function MainLayout() {
|
|||||||
<div className="aside-drawer-body">
|
<div className="aside-drawer-body">
|
||||||
<RightPanel
|
<RightPanel
|
||||||
recentComments={recentComments}
|
recentComments={recentComments}
|
||||||
|
recentUsers={recentUsers}
|
||||||
tags={tags}
|
tags={tags}
|
||||||
tagsLoading={tagsLoading}
|
tagsLoading={tagsLoading}
|
||||||
stats={stats}
|
stats={stats}
|
||||||
|
|||||||
@@ -2320,6 +2320,15 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 仅标题模式:略增行距,避免帖子贴得过紧 */
|
||||||
|
.post-row--v2.post-row--title-only {
|
||||||
|
padding: 12px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2.post-row--title-only .post-main {
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.post-row--v2 .post-avatar {
|
.post-row--v2 .post-avatar {
|
||||||
width: 36px;
|
width: 36px;
|
||||||
height: 36px;
|
height: 36px;
|
||||||
@@ -2434,6 +2443,7 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
|
|
||||||
.post-row--v2 .post-title {
|
.post-row--v2 .post-title {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
font-weight: 400;
|
||||||
line-height: 1.35;
|
line-height: 1.35;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2447,6 +2457,7 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
flex-wrap: nowrap;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -2456,10 +2467,11 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
.post-row--v2 .post-meta-left {
|
.post-row--v2 .post-meta-left {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-wrap: wrap;
|
flex-wrap: nowrap;
|
||||||
gap: 0;
|
gap: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-row--v2 .post-meta-author {
|
.post-row--v2 .post-meta-author {
|
||||||
@@ -2487,13 +2499,153 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-row--v2 .post-meta-board {
|
.post-row--v2 .post-meta-last-reply {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-shrink: 1;
|
||||||
|
min-width: 0;
|
||||||
|
margin-left: 6px;
|
||||||
|
gap: 4px;
|
||||||
color: var(--color-text-4);
|
color: var(--color-text-4);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-last-reply-arrow {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
opacity: 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-last-reply-user {
|
||||||
|
flex-shrink: 1;
|
||||||
|
min-width: 0;
|
||||||
max-width: 5rem;
|
max-width: 5rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
color: var(--color-text-3);
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 a.post-meta-last-reply-user:hover {
|
||||||
|
color: var(--j13-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-last-reply-time {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 手机端 meta 精简:作者、回复人、一个时间(有回复则用回复时间) */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.post-row--v2 .post-list-board-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-left:has(.post-meta-last-reply) .post-meta-sep--before-time,
|
||||||
|
.post-row--v2 .post-meta-left:has(.post-meta-last-reply) .post-meta-time--created {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-author {
|
||||||
|
max-width: 4.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-meta-last-reply-user {
|
||||||
|
max-width: 4.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 列表内板块色标(meta 行、用户名之前;颜色淡化) */
|
||||||
|
.post-row--v2 .post-list-board-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
max-width: 5rem;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 6px 0 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-list-board-badge {
|
||||||
|
display: inline-block;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1.45;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--0 {
|
||||||
|
color: color-mix(in srgb, var(--board-0-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-0-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--1 {
|
||||||
|
color: color-mix(in srgb, var(--board-1-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-1-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--2 {
|
||||||
|
color: color-mix(in srgb, var(--board-2-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-2-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--3 {
|
||||||
|
color: color-mix(in srgb, var(--board-3-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-3-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--4 {
|
||||||
|
color: color-mix(in srgb, var(--board-4-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-4-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--5 {
|
||||||
|
color: color-mix(in srgb, var(--board-5-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-5-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--6 {
|
||||||
|
color: color-mix(in srgb, var(--board-6-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-6-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-badge.board-badge--7 {
|
||||||
|
color: color-mix(in srgb, var(--board-7-color) 52%, var(--color-text-3, #64748b));
|
||||||
|
background: color-mix(in srgb, var(--board-7-color) 9%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--0 {
|
||||||
|
color: color-mix(in srgb, var(--board-0-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-0-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--1 {
|
||||||
|
color: color-mix(in srgb, var(--board-1-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-1-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--2 {
|
||||||
|
color: color-mix(in srgb, var(--board-2-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-2-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--3 {
|
||||||
|
color: color-mix(in srgb, var(--board-3-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-3-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--4 {
|
||||||
|
color: color-mix(in srgb, var(--board-4-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-4-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--5 {
|
||||||
|
color: color-mix(in srgb, var(--board-5-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-5-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--6 {
|
||||||
|
color: color-mix(in srgb, var(--board-6-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-6-color) 14%, transparent);
|
||||||
|
}
|
||||||
|
.post-row--v2 .post-list-board-btn:hover .post-list-board-badge.board-badge--7 {
|
||||||
|
color: color-mix(in srgb, var(--board-7-color) 72%, var(--color-text-2, #475569));
|
||||||
|
background: color-mix(in srgb, var(--board-7-color) 14%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-row--v2 .post-list-tag {
|
.post-row--v2 .post-list-tag {
|
||||||
@@ -2504,6 +2656,7 @@ body:has(.admin-topbar) .ptr-indicator {
|
|||||||
color: var(--color-text-4);
|
color: var(--color-text-4);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
max-width: 5rem;
|
max-width: 5rem;
|
||||||
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-row--v2 .post-list-tag:hover {
|
.post-row--v2 .post-list-tag:hover {
|
||||||
@@ -3108,6 +3261,26 @@ a.post-title:visited {
|
|||||||
height: 14px;
|
height: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.skeleton--board-badge {
|
||||||
|
width: 2.5rem;
|
||||||
|
height: 14px;
|
||||||
|
border-radius: 3px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta-left--skeleton {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta-left--skeleton .skeleton--meta-line {
|
||||||
|
flex: 1;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
.skeleton--excerpt-v2 {
|
.skeleton--excerpt-v2 {
|
||||||
height: 12px;
|
height: 12px;
|
||||||
}
|
}
|
||||||
@@ -6354,6 +6527,7 @@ a.waline-comment-author:hover {
|
|||||||
.widget-card-icon--hot { color: #e74c3c; }
|
.widget-card-icon--hot { color: #e74c3c; }
|
||||||
.widget-card-icon--notice { color: #3498db; }
|
.widget-card-icon--notice { color: #3498db; }
|
||||||
.widget-card-icon--links { color: #2d6a4f; }
|
.widget-card-icon--links { color: #2d6a4f; }
|
||||||
|
.widget-card-icon--users { color: #8b5cf6; }
|
||||||
|
|
||||||
.widget-card-head--split {
|
.widget-card-head--split {
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -6399,22 +6573,51 @@ a.waline-comment-author:hover {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.widget-card-body--friend-links {
|
||||||
|
padding-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.widget-friend-links-list {
|
.widget-friend-links-list {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: grid;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.widget-friend-links-list li {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.widget-friend-links-list a {
|
.widget-friend-links-list a {
|
||||||
color: var(--j13-link, var(--primary, #2d6a4f));
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 26px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px solid var(--j13-border-light);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--j13-bg-block-muted);
|
||||||
|
color: var(--color-text-2);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
|
line-height: 1.3;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
transition:
|
||||||
|
border-color 0.15s ease,
|
||||||
|
background 0.15s ease,
|
||||||
|
color 0.15s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.widget-friend-links-list a:hover {
|
.widget-friend-links-list a:hover {
|
||||||
text-decoration: underline;
|
border-color: color-mix(in srgb, var(--j13-green) 35%, var(--j13-border-light));
|
||||||
|
background: var(--j13-green-soft);
|
||||||
|
color: var(--j13-green);
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.friend-link-site-info {
|
.friend-link-site-info {
|
||||||
@@ -7454,6 +7657,91 @@ a.user-link--avatar-only:focus-visible {
|
|||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 最新注册:4 列网格,头像在上、昵称在下 */
|
||||||
|
.widget-card-body--users {
|
||||||
|
padding-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-users-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
gap: 10px 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-user-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 4px 2px;
|
||||||
|
border-radius: 6px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
transition: background 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.widget-recent-user-cell:hover,
|
||||||
|
a.widget-recent-user-cell:focus-visible {
|
||||||
|
background: var(--j13-bg-block-accent);
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-user-avatar {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--j13-green);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-user-avatar img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-user-name {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.3;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--color-text-2);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.widget-recent-user-cell:hover .widget-recent-user-name,
|
||||||
|
a.widget-recent-user-cell:focus-visible .widget-recent-user-name {
|
||||||
|
color: var(--j13-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-recent-user-cell--skeleton {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skeleton--recent-user-avatar {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skeleton--recent-user-name {
|
||||||
|
height: 11px;
|
||||||
|
width: 70%;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
a.widget-item-avatar.user-link {
|
a.widget-item-avatar.user-link {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { AsideWidget, AsideWidgetId, ForumLimits, ForumLimitsPublic } from '../api/types';
|
import type { AsideWidget, AsideWidgetId, ForumLimits, ForumLimitsPublic } from '../api/types';
|
||||||
import { DEFAULT_ASIDE_WIDGETS } from '../api/types';
|
import { DEFAULT_ASIDE_WIDGETS } from '../api/types';
|
||||||
|
|
||||||
const ASIDE_WIDGET_IDS: AsideWidgetId[] = ['tag_cloud', 'recent_comments', 'friend_links'];
|
const ASIDE_WIDGET_IDS: AsideWidgetId[] = ['tag_cloud', 'recent_comments', 'recent_users', 'friend_links'];
|
||||||
|
|
||||||
/** 从 limits 解析右侧栏组件列表(兼容仅有布尔开关的旧数据) */
|
/** 从 limits 解析右侧栏组件列表(兼容仅有布尔开关的旧数据) */
|
||||||
export function resolveAsideWidgets(
|
export function resolveAsideWidgets(
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import type { Board, ForumStats, RecentComment, TagCount } from '../api/types';
|
import type { Board, ForumStats, RecentComment, RecentUser, TagCount } from '../api/types';
|
||||||
|
|
||||||
const BOARDS_KEY = 'j13-cache-boards';
|
const BOARDS_KEY = 'j13-cache-boards';
|
||||||
const STATS_KEY = 'j13-cache-stats';
|
const STATS_KEY = 'j13-cache-stats';
|
||||||
const RECENT_COMMENTS_KEY = 'j13-cache-recent-comments';
|
const RECENT_COMMENTS_KEY = 'j13-cache-recent-comments';
|
||||||
|
const RECENT_USERS_KEY = 'j13-cache-recent-users';
|
||||||
const TAGS_KEY = 'j13-cache-tags';
|
const TAGS_KEY = 'j13-cache-tags';
|
||||||
|
|
||||||
function readJson<T>(key: string): T | null {
|
function readJson<T>(key: string): T | null {
|
||||||
@@ -38,6 +39,12 @@ export function getCachedRecentComments(): RecentComment[] {
|
|||||||
return Array.isArray(list) ? list : [];
|
return Array.isArray(list) ? list : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 读取缓存的最新注册用户 */
|
||||||
|
export function getCachedRecentUsers(): RecentUser[] {
|
||||||
|
const list = readJson<RecentUser[]>(RECENT_USERS_KEY);
|
||||||
|
return Array.isArray(list) ? list : [];
|
||||||
|
}
|
||||||
|
|
||||||
/** 读取缓存的标签云 */
|
/** 读取缓存的标签云 */
|
||||||
export function getCachedTags(): TagCount[] {
|
export function getCachedTags(): TagCount[] {
|
||||||
const list = readJson<TagCount[]>(TAGS_KEY);
|
const list = readJson<TagCount[]>(TAGS_KEY);
|
||||||
@@ -47,7 +54,9 @@ export function getCachedTags(): TagCount[] {
|
|||||||
/** 右栏是否已有可展示的 session 缓存(含空列表) */
|
/** 右栏是否已有可展示的 session 缓存(含空列表) */
|
||||||
export function hasCachedAside(): boolean {
|
export function hasCachedAside(): boolean {
|
||||||
try {
|
try {
|
||||||
return sessionStorage.getItem(RECENT_COMMENTS_KEY) != null;
|
return sessionStorage.getItem(RECENT_COMMENTS_KEY) != null
|
||||||
|
|| sessionStorage.getItem(RECENT_USERS_KEY) != null
|
||||||
|
|| sessionStorage.getItem(TAGS_KEY) != null;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -65,6 +74,10 @@ export function setCachedRecentComments(list: RecentComment[]) {
|
|||||||
writeJson(RECENT_COMMENTS_KEY, list);
|
writeJson(RECENT_COMMENTS_KEY, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setCachedRecentUsers(list: RecentUser[]) {
|
||||||
|
writeJson(RECENT_USERS_KEY, list);
|
||||||
|
}
|
||||||
|
|
||||||
export function setCachedTags(tags: TagCount[]) {
|
export function setCachedTags(tags: TagCount[]) {
|
||||||
writeJson(TAGS_KEY, tags);
|
writeJson(TAGS_KEY, tags);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1141,6 +1141,19 @@ func (h *Handlers) APIRecentComments(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"comments": list})
|
c.JSON(http.StatusOK, gin.H{"comments": list})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APIRecentUsers 最新注册用户(右栏)
|
||||||
|
func (h *Handlers) APIRecentUsers(c *gin.Context) {
|
||||||
|
list, err := h.User.ListRecentRegistered(8)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if list == nil {
|
||||||
|
list = []service.RecentUserItem{}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"users": list})
|
||||||
|
}
|
||||||
|
|
||||||
// APIFavorites 我的收藏
|
// APIFavorites 我的收藏
|
||||||
func (h *Handlers) APIFavorites(c *gin.Context) {
|
func (h *Handlers) APIFavorites(c *gin.Context) {
|
||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
|
|||||||
@@ -137,8 +137,9 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
|
|||||||
pubAPI.GET("/posts/hot", h.APIHotPosts)
|
pubAPI.GET("/posts/hot", h.APIHotPosts)
|
||||||
pubAPI.GET("/tags", h.APITags)
|
pubAPI.GET("/tags", h.APITags)
|
||||||
pubAPI.GET("/comments/recent", h.APIRecentComments)
|
pubAPI.GET("/comments/recent", h.APIRecentComments)
|
||||||
// search 须在 :id 之前
|
// search / recent 须在 :id 之前
|
||||||
pubAPI.GET("/users/search", h.APISearchUsers)
|
pubAPI.GET("/users/search", h.APISearchUsers)
|
||||||
|
pubAPI.GET("/users/recent", h.APIRecentUsers)
|
||||||
pubAPI.GET("/users/:id", h.APIUserPublic)
|
pubAPI.GET("/users/:id", h.APIUserPublic)
|
||||||
pubAPI.GET("/posts/:id", h.APIPostDetail)
|
pubAPI.GET("/posts/:id", h.APIPostDetail)
|
||||||
pubAPI.GET("/posts/:id/comments", h.APIPostComments)
|
pubAPI.GET("/posts/:id/comments", h.APIPostComments)
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ func TestNormalizeAsideWidgetsPreservesOrder(t *testing.T) {
|
|||||||
{ID: AsideWidgetRecentComments, Enabled: false},
|
{ID: AsideWidgetRecentComments, Enabled: false},
|
||||||
}
|
}
|
||||||
out := NormalizeAsideWidgets(in)
|
out := NormalizeAsideWidgets(in)
|
||||||
if len(out) != 3 {
|
if len(out) != 4 {
|
||||||
t.Fatalf("want 3 widgets, got %d", len(out))
|
t.Fatalf("want 4 widgets, got %d", len(out))
|
||||||
}
|
}
|
||||||
want := []string{AsideWidgetFriendLinks, AsideWidgetTagCloud, AsideWidgetRecentComments}
|
want := []string{AsideWidgetFriendLinks, AsideWidgetTagCloud, AsideWidgetRecentComments, AsideWidgetRecentUsers}
|
||||||
for i, id := range want {
|
for i, id := range want {
|
||||||
if out[i].ID != id {
|
if out[i].ID != id {
|
||||||
t.Fatalf("index %d: want %s, got %s", i, id, out[i].ID)
|
t.Fatalf("index %d: want %s, got %s", i, id, out[i].ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !out[0].Enabled || !out[1].Enabled || out[2].Enabled {
|
if !out[0].Enabled || !out[1].Enabled || out[2].Enabled || out[3].Enabled {
|
||||||
t.Fatalf("enabled flags mismatch: %+v", out)
|
t.Fatalf("enabled flags mismatch: %+v", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@ func TestAsideBoolsFromWidgets(t *testing.T) {
|
|||||||
{ID: AsideWidgetRecentComments, Enabled: true},
|
{ID: AsideWidgetRecentComments, Enabled: true},
|
||||||
{ID: AsideWidgetFriendLinks, Enabled: false},
|
{ID: AsideWidgetFriendLinks, Enabled: false},
|
||||||
{ID: AsideWidgetTagCloud, Enabled: true},
|
{ID: AsideWidgetTagCloud, Enabled: true},
|
||||||
|
{ID: AsideWidgetRecentUsers, Enabled: true},
|
||||||
}
|
}
|
||||||
bools := asideBoolsFromWidgets(widgets)
|
bools := asideBoolsFromWidgets(widgets)
|
||||||
if !bools.tagCloud || !bools.recentComments || bools.friendLinks {
|
if !bools.tagCloud || !bools.recentComments || bools.friendLinks {
|
||||||
|
|||||||
@@ -56,8 +56,16 @@ type PostListQuery struct {
|
|||||||
// PostListItem 帖子列表项(含评论数等扩展字段)
|
// PostListItem 帖子列表项(含评论数等扩展字段)
|
||||||
type PostListItem struct {
|
type PostListItem struct {
|
||||||
model.Post
|
model.Post
|
||||||
CommentCount int `json:"comment_count"`
|
CommentCount int `json:"comment_count"`
|
||||||
LastReplyAt *time.Time `json:"last_reply_at,omitempty"`
|
LastReplyAt *time.Time `json:"last_reply_at,omitempty"`
|
||||||
|
LastReplyUser *model.User `json:"last_reply_user,omitempty"`
|
||||||
|
LastReplyGuestNick string `json:"last_reply_guest_nick,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type lastReplyInfo struct {
|
||||||
|
At *time.Time
|
||||||
|
User *model.User
|
||||||
|
GuestNick string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostService) ListItems(q PostListQuery) ([]PostListItem, int64, error) {
|
func (s *PostService) ListItems(q PostListQuery) ([]PostListItem, int64, error) {
|
||||||
@@ -73,13 +81,16 @@ func (s *PostService) ListItems(q PostListQuery) ([]PostListItem, int64, error)
|
|||||||
ids[i] = p.ID
|
ids[i] = p.ID
|
||||||
}
|
}
|
||||||
countMap := s.commentCountMap(ids)
|
countMap := s.commentCountMap(ids)
|
||||||
replyMap := s.lastReplyMap(ids)
|
replyMap := s.lastReplyInfoMap(ids)
|
||||||
items := make([]PostListItem, len(posts))
|
items := make([]PostListItem, len(posts))
|
||||||
for i, p := range posts {
|
for i, p := range posts {
|
||||||
|
info := replyMap[p.ID]
|
||||||
items[i] = PostListItem{
|
items[i] = PostListItem{
|
||||||
Post: p,
|
Post: p,
|
||||||
CommentCount: countMap[p.ID],
|
CommentCount: countMap[p.ID],
|
||||||
LastReplyAt: replyMap[p.ID],
|
LastReplyAt: info.At,
|
||||||
|
LastReplyUser: info.User,
|
||||||
|
LastReplyGuestNick: info.GuestNick,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items, total, nil
|
return items, total, nil
|
||||||
@@ -101,44 +112,50 @@ func (s *PostService) commentCountMap(postIDs []uint) map[uint]int {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostService) lastReplyMap(postIDs []uint) map[uint]*time.Time {
|
func (s *PostService) lastReplyInfoMap(postIDs []uint) map[uint]lastReplyInfo {
|
||||||
type row struct {
|
m := make(map[uint]lastReplyInfo, len(postIDs))
|
||||||
PostID uint
|
if len(postIDs) == 0 {
|
||||||
LastReply string
|
return m
|
||||||
}
|
}
|
||||||
var rows []row
|
type idRow struct {
|
||||||
|
PostID uint
|
||||||
|
MaxID uint
|
||||||
|
}
|
||||||
|
var idRows []idRow
|
||||||
model.DB.Model(&model.Comment{}).
|
model.DB.Model(&model.Comment{}).
|
||||||
Select("post_id, MAX(created_at) as last_reply").
|
Select("post_id, MAX(id) as max_id").
|
||||||
Where("post_id IN ? AND status = ?", postIDs, model.ContentStatusPublished).
|
Where("post_id IN ? AND status = ?", postIDs, model.ContentStatusPublished).
|
||||||
Group("post_id").
|
Group("post_id").
|
||||||
Scan(&rows)
|
Scan(&idRows)
|
||||||
m := make(map[uint]*time.Time, len(rows))
|
if len(idRows) == 0 {
|
||||||
for _, r := range rows {
|
return m
|
||||||
if t, ok := parseSQLiteTime(r.LastReply); ok {
|
}
|
||||||
m[r.PostID] = &t
|
commentIDs := make([]uint, len(idRows))
|
||||||
|
for i, r := range idRows {
|
||||||
|
commentIDs[i] = r.MaxID
|
||||||
|
}
|
||||||
|
var comments []model.Comment
|
||||||
|
if err := model.DB.Preload("User").Where("id IN ?", commentIDs).Find(&comments).Error; err != nil {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
for i := range comments {
|
||||||
|
c := &comments[i]
|
||||||
|
info := lastReplyInfo{At: &c.CreatedAt}
|
||||||
|
if c.UserID > 0 && c.User.ID > 0 {
|
||||||
|
u := c.User
|
||||||
|
info.User = &u
|
||||||
|
} else {
|
||||||
|
nick := strings.TrimSpace(c.GuestNick)
|
||||||
|
if nick == "" {
|
||||||
|
nick = "游客"
|
||||||
|
}
|
||||||
|
info.GuestNick = nick
|
||||||
}
|
}
|
||||||
|
m[c.PostID] = info
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseSQLiteTime 解析 SQLite 聚合查询返回的时间字符串
|
|
||||||
func parseSQLiteTime(s string) (time.Time, bool) {
|
|
||||||
if s == "" {
|
|
||||||
return time.Time{}, false
|
|
||||||
}
|
|
||||||
for _, layout := range []string{
|
|
||||||
"2006-01-02 15:04:05.999999999-07:00",
|
|
||||||
time.RFC3339Nano,
|
|
||||||
time.RFC3339,
|
|
||||||
"2006-01-02 15:04:05",
|
|
||||||
} {
|
|
||||||
if t, err := time.Parse(layout, s); err == nil {
|
|
||||||
return t, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return time.Time{}, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// HotPosts 近期活跃讨论(近 7 日有公开回复,按最后回复时间倒序)
|
// HotPosts 近期活跃讨论(近 7 日有公开回复,按最后回复时间倒序)
|
||||||
func (s *PostService) HotPosts(limit int) ([]PostListItem, error) {
|
func (s *PostService) HotPosts(limit int) ([]PostListItem, error) {
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
@@ -170,13 +187,16 @@ func (s *PostService) HotPosts(limit int) ([]PostListItem, error) {
|
|||||||
ids[i] = p.ID
|
ids[i] = p.ID
|
||||||
}
|
}
|
||||||
countMap := s.commentCountMap(ids)
|
countMap := s.commentCountMap(ids)
|
||||||
replyMap := s.lastReplyMap(ids)
|
replyMap := s.lastReplyInfoMap(ids)
|
||||||
items := make([]PostListItem, len(posts))
|
items := make([]PostListItem, len(posts))
|
||||||
for i, p := range posts {
|
for i, p := range posts {
|
||||||
|
info := replyMap[p.ID]
|
||||||
items[i] = PostListItem{
|
items[i] = PostListItem{
|
||||||
Post: p,
|
Post: p,
|
||||||
CommentCount: countMap[p.ID],
|
CommentCount: countMap[p.ID],
|
||||||
LastReplyAt: replyMap[p.ID],
|
LastReplyAt: info.At,
|
||||||
|
LastReplyUser: info.User,
|
||||||
|
LastReplyGuestNick: info.GuestNick,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
|
|||||||
@@ -144,12 +144,14 @@ type AsideWidget struct {
|
|||||||
const (
|
const (
|
||||||
AsideWidgetTagCloud = "tag_cloud"
|
AsideWidgetTagCloud = "tag_cloud"
|
||||||
AsideWidgetRecentComments = "recent_comments"
|
AsideWidgetRecentComments = "recent_comments"
|
||||||
|
AsideWidgetRecentUsers = "recent_users"
|
||||||
AsideWidgetFriendLinks = "friend_links"
|
AsideWidgetFriendLinks = "friend_links"
|
||||||
)
|
)
|
||||||
|
|
||||||
var asideWidgetDefaultOrder = []string{
|
var asideWidgetDefaultOrder = []string{
|
||||||
AsideWidgetTagCloud,
|
AsideWidgetTagCloud,
|
||||||
AsideWidgetRecentComments,
|
AsideWidgetRecentComments,
|
||||||
|
AsideWidgetRecentUsers,
|
||||||
AsideWidgetFriendLinks,
|
AsideWidgetFriendLinks,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +744,7 @@ func asideBoolsFromWidgets(widgets []AsideWidget) asideWidgetBools {
|
|||||||
|
|
||||||
func isValidAsideWidgetID(id string) bool {
|
func isValidAsideWidgetID(id string) bool {
|
||||||
switch id {
|
switch id {
|
||||||
case AsideWidgetTagCloud, AsideWidgetRecentComments, AsideWidgetFriendLinks:
|
case AsideWidgetTagCloud, AsideWidgetRecentComments, AsideWidgetRecentUsers, AsideWidgetFriendLinks:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -123,6 +123,44 @@ func (s *UserService) SearchUsersBrief(keyword string, limit int) ([]model.User,
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecentUserItem 右栏「最新注册」条目
|
||||||
|
type RecentUserItem struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRecentRegistered 前台最新注册用户(排除封禁)
|
||||||
|
func (s *UserService) ListRecentRegistered(limit int) ([]RecentUserItem, error) {
|
||||||
|
if limit < 1 {
|
||||||
|
limit = 8
|
||||||
|
}
|
||||||
|
var users []model.User
|
||||||
|
err := model.DB.Select("id", "username", "nickname", "avatar", "created_at").
|
||||||
|
Where("banned = ?", false).
|
||||||
|
Order("created_at DESC, id DESC").
|
||||||
|
Limit(limit).
|
||||||
|
Find(&users).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := make([]RecentUserItem, 0, len(users))
|
||||||
|
for _, u := range users {
|
||||||
|
nick := strings.TrimSpace(u.Nickname)
|
||||||
|
if nick == "" {
|
||||||
|
nick = u.Username
|
||||||
|
}
|
||||||
|
out = append(out, RecentUserItem{
|
||||||
|
ID: u.ID,
|
||||||
|
Nickname: nick,
|
||||||
|
Avatar: u.Avatar,
|
||||||
|
CreatedAt: u.CreatedAt.UTC().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateNickname 修改昵称
|
// UpdateNickname 修改昵称
|
||||||
func (s *UserService) UpdateNickname(userID uint, nickname string) error {
|
func (s *UserService) UpdateNickname(userID uint, nickname string) error {
|
||||||
nickname = strings.TrimSpace(nickname)
|
nickname = strings.TrimSpace(nickname)
|
||||||
|
|||||||
Reference in New Issue
Block a user