feat(roundtable): 业务链条「发布为公共」+ 我的/公共筛选

后端:roundtable_chains 加 is_public 列;list_chains 支持 scope=mine|public(public=所有已发布,任何账号可查看/选入研讨);get_chain 放开公共可见;响应加 is_public/is_mine;update 支持 is_public(发布/取消,owner 限定,编辑/删除仍仅 owner)。迁移 20260608_03 接在合并 head 20260608_02 之后,保证单一 alembic head(多 head 会让启动自动迁移失败、静默降级 create_all → 列缺失 500)。

前端:listChains(scope) + setChainPublic;BusinessChain 加 isPublic/isMine;列表弹窗与研讨选择器加「我的/公共」筛选 tab;列表卡片发布/取消发布 + 公共徽标(别人的只读);配置页头部加发布按钮(已保存且本人)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-07 22:30:23 +08:00
1 parent 05d14bb364
commit 7affaaf7c0
10 files changed
+373 -44

No files matched your search

@@ -28,6 +28,7 @@ import {
ChevronDown,
ChevronUp,
GitBranch,
Globe,
GripVertical,
Layers,
Loader2,
@@ -70,6 +71,7 @@ import {
createChain,
deleteChain,
listChains,
setChainPublic,
updateChain,
} from "@/roundtable-planning/api/chains";
import {
@@ -130,6 +132,10 @@ export default function BusinessChainEditorPage() {
// ─── 当前编辑中的链条 ─────────────────────────────────────────────────
const [currentChainId, setCurrentChainId] = useState<string | null>(null);
// 当前编辑链条的发布状态 / 是否本人所有(发布按钮 + 只读保护用)。
const [currentChainPublic, setCurrentChainPublic] = useState(false);
const [currentChainMine, setCurrentChainMine] = useState(true);
const [publishing, setPublishing] = useState(false);
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
// 分层编排是唯一数据源;落库时展平为 seats + 折叠为 stages。
@@ -218,6 +224,8 @@ export default function BusinessChainEditorPage() {
// ─── 链条选择 / 新建 ──────────────────────────────────────────────────
const loadChain = useCallback((chain: BusinessChain) => {
setCurrentChainId(chain.id);
setCurrentChainPublic(chain.isPublic ?? false);
setCurrentChainMine(chain.isMine !== false);
setTitle(chain.title);
setDescription(chain.description ?? "");
setStageGroups(chainToStageGroups(chain));
@@ -225,6 +233,8 @@ export default function BusinessChainEditorPage() {
const startNewChain = useCallback(() => {
setCurrentChainId(null);
setCurrentChainPublic(false);
setCurrentChainMine(true);
setTitle("");
setDescription("");
setStageGroups([]);
@@ -462,6 +472,32 @@ export default function BusinessChainEditorPage() {
}
}, [currentChainId, title, startNewChain, refreshChains]);
// 发布 / 取消发布:把当前链条设为公共(所有账号可见 / 选用)或收回。
const handleTogglePublish = useCallback(async () => {
if (!currentChainId) {
toast.warning("请先保存链条再发布");
return;
}
const next = !currentChainPublic;
setPublishing(true);
try {
const updated = await setChainPublic(currentChainId, next);
if (!updated) {
toast.error("链条已不存在,可能被删除");
startNewChain();
await refreshChains();
return;
}
setCurrentChainPublic(updated.isPublic ?? next);
toast.success(next ? "已发布为公共,所有账号都能查看 / 选用" : "已取消发布");
await refreshChains();
} catch (err) {
toast.error(`${next ? "发布" : "取消发布"}失败:${err instanceof Error ? err.message : String(err)}`);
} finally {
setPublishing(false);
}
}, [currentChainId, currentChainPublic, startNewChain, refreshChains]);
// ─── Render ──────────────────────────────────────────────────────────
const triggerLabel = currentChainId ? title || "未命名链条" : "+ 新建链条…";
@@ -587,6 +623,29 @@ export default function BusinessChainEditorPage() {
{/* 右侧操作 */}
<div className="ml-auto flex items-center gap-2">
{/* 发布 / 取消发布:仅已保存且本人所有的链条。发布后所有账号可在「公共」筛选查看 / 选用。 */}
{currentChainId && currentChainMine && (
<button
type="button"
onClick={handleTogglePublish}
disabled={publishing}
title={currentChainPublic ? "已发布为公共,点击收回为私有" : "发布为公共,所有账号都能查看 / 选用"}
className={cn(
"flex items-center gap-1.5 border px-3 py-1.5 text-sm font-medium transition active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-60",
currentChainPublic
? "border-emerald-400/50 bg-emerald-500/10 text-emerald-600 hover:bg-emerald-500/15 dark:text-emerald-400"
: "border-border bg-card text-muted-foreground hover:bg-muted hover:text-foreground",
R_CTRL,
)}
>
{publishing ? (
<Loader2 className="size-4 animate-spin" />
) : (
<Globe className="size-4" />
)}
{currentChainPublic ? "已发布" : "发布"}
</button>
)}
<button
type="button"
onClick={handleDelete}