原实现是 Canvas 画笔画板,与「文字白板/记事本」需求不符。重做为纯文本实时协作: - model:strokes JSON -> content TEXT + version INT(乐观锁)+ edit_count; schema/dao/service 同步重构,append_stroke/replace_strokes -> update_content。 - WS 协议:stroke -> edit(发完整文本,debounce 400ms);init 下发 content/version。 update 帧广播给他人,cleared 广播给所有人。 - 前端:canvas -> textarea;收到远端 update 用最长公共前后缀算变更区间, 仅替换该区间并保留光标(区间前不动/后平移/内移末尾);清空/复制文本按钮。 - schema.sql 更新 whiteboard 表 DDL;DB 旧表 DROP 重建(开发环境)。 - 测试脚本与 README 同步更新。
39 lines
916 B
Python
39 lines
916 B
Python
"""白板接口 DTO(文本记事本)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from datetime import datetime
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class WhiteboardOut(BaseModel):
|
||
"""白板完整内容(GET /api/wb/{id} 与 WS init 帧)。"""
|
||
|
||
board_id: str
|
||
content: str = Field("", description="白板文本内容")
|
||
version: int = Field(0, description="乐观锁版本号,每次编辑 +1")
|
||
edit_count: int = Field(0, description="累计编辑次数")
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class WhiteboardListItem(BaseModel):
|
||
"""管理页列表项。"""
|
||
|
||
board_id: str
|
||
edit_count: int
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class WhiteboardListResponse(BaseModel):
|
||
"""管理页列表响应。"""
|
||
|
||
total: int
|
||
items: list[WhiteboardListItem]
|