feat(frontend): add posting compose component suite

新增了发帖相关的完整组件模块:包括顶部导航栏ComposeHeader、正文编辑区ComposeDocument,以及发布设置栏ComposeContextBar,同时添加了vite依赖缓存配置文件。
This commit is contained in:
2026-08-07 17:45:50 +08:00
parent 94f6a9666b
commit 383440ed5b
12 changed files with 725 additions and 181 deletions

View File

@@ -0,0 +1,105 @@
import TagInput from '../TagInput';
import BoardIconDisplay from '../BoardIconDisplay';
import { getBoardThemeIndex } from '../../utils/boardTheme';
import type { Board, ForumLimitsPublic } from '../../api/types';
export type PostType = 'normal' | 'question';
interface Props {
isEdit: boolean;
postType: PostType;
onPostTypeChange: (type: PostType) => void;
boards: Board[];
boardId: string;
onBoardChange: (boardId: string) => void;
tags: string;
onTagsChange: (tags: string) => void;
limits: ForumLimitsPublic;
}
/**
* 发帖页发布设置模块:帖子类型、板块、标签三行配置。
* 受控组件,所有状态由父级持有。
*/
export default function ComposeContextBar({
isEdit,
postType,
onPostTypeChange,
boards,
boardId,
onBoardChange,
tags,
onTagsChange,
limits,
}: Props) {
return (
<section className="compose-context" aria-label="发布设置">
<div className="compose-context-row">
<span className="compose-context-label"></span>
<div className="compose-type-field">
<div className="compose-type-pills" role="radiogroup" aria-label="帖子类型">
<button
type="button"
role="radio"
aria-checked={postType === 'normal'}
className={`compose-type-pill${postType === 'normal' ? ' active' : ''}`}
onClick={() => onPostTypeChange('normal')}
>
</button>
<button
type="button"
role="radio"
aria-checked={postType === 'question'}
className={`compose-type-pill${postType === 'question' ? ' active' : ''}`}
onClick={() => onPostTypeChange('question')}
>
</button>
</div>
{postType === 'question' && (
<span className="compose-type-hint"></span>
)}
</div>
</div>
<div className="compose-context-row">
<span className="compose-context-label"></span>
<div
className="compose-board-pills"
role="listbox"
aria-label={isEdit ? '修改板块' : '选择板块'}
>
{boards.map(b => {
const themeIdx = getBoardThemeIndex(b);
const isActive = String(b.id) === boardId;
return (
<button
key={b.id}
type="button"
role="option"
aria-selected={isActive}
className={`compose-board-pill compose-board-pill--${themeIdx}${isActive ? ' active' : ''}`}
onClick={() => onBoardChange(String(b.id))}
>
<BoardIconDisplay
board={b}
className="compose-board-icon"
/>
<span>{b.name}</span>
</button>
);
})}
</div>
</div>
<div className="compose-context-row compose-context-row--tags">
<span className="compose-context-label"></span>
<TagInput
value={tags}
onChange={onTagsChange}
placeholder="添加标签,回车确认"
maxLength={limits.post_tags_max > 0 ? limits.post_tags_max : undefined}
/>
</div>
</section>
);
}