feat(xdfx): 行动历史查询与删除(与 rwfx 共用 dropSixOrSevenData 删除接口)

- 删除接口统一为 dropSixOrSevenData:rwfx 传 ?taskId=、xdfx 传 ?actionId=,另一参数直接不出现在 URL
- xdfx 工作区新增「清除记录」按钮(按行动id 删除),删除前预检「行动历史是否存在」
- action_history_url 配置位(地址待提供,留空则不查询/不阻断删除)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
吉鑫升andClaude Opus 4.8 committed 2026-06-23 19:14:16 +08:00
1 parent 5aa66fc07d
commit a1fbfaf864
7 files changed
+182 -12

No files matched your search

@@ -29,7 +29,12 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { deleteTaskPurpose, readTaskContext } from "@/core/auth/task-purpose";
import {
deleteTaskPurpose,
fetchActionHistoryExists,
readTaskContext,
type ActionHistoryResult,
} from "@/core/auth/task-purpose";
import {
fetchActionDetail,
readCopTaskDetail,
@@ -195,6 +200,8 @@ function TaskConversationsList({
<PlusSquare className="h-4 w-4" /> 新建对话
</Button>
{!lite && <TaskClearButton taskId={taskId} />}
{/* xdfx:按「行动id」清除行动记录(删除前查历史是否存在;与 rwfx 共用同一删除接口)。 */}
{business === "xdfx" && actionId && <ActionClearButton actionId={actionId} />}
</div>
<div className="min-h-0 flex-1 overflow-y-auto p-2">
@@ -292,6 +299,103 @@ function TaskClearButton({ taskId }: { taskId: string }) {
);
}
/**
* 「清除记录」按钮(xdfx 行动分析):放在「新建对话」下面,按「行动id」清除该行动在 B 系统里的
* 策划数据(聊天对话保留),与 rwfx 共用同一个删除接口(仅传 ``actionId``、不传 taskId)。
*
* 打开弹框时先「查询历史是否存在」(``fetchActionHistoryExists``):
* - 接口未就绪(地址未配置)→ ``known=false``:当作未知,仍可删除(不拦截);
* - 查到「无历史」(``known && !exists``)→ 禁用「确认清除」(没有可删的数据)。
*/
function ActionClearButton({ actionId }: { actionId: string }) {
const [open, setOpen] = useState(false);
const [clearing, setClearing] = useState(false);
const [checking, setChecking] = useState(false);
const [history, setHistory] = useState<ActionHistoryResult | null>(null);
// 打开弹框时查历史是否存在(接口未配置 → known=false,不影响删除)。
useEffect(() => {
if (!open) return;
let alive = true;
setChecking(true);
setHistory(null);
void fetchActionHistoryExists(actionId)
.then((r) => {
if (alive) setHistory(r);
})
.finally(() => {
if (alive) setChecking(false);
});
return () => {
alive = false;
};
}, [open, actionId]);
const handleClear = async () => {
setClearing(true);
try {
const r = await deleteTaskPurpose(actionId, { idKind: "action" });
if (r.success) toast.success("已清除行动记录");
else toast.error(r.message || "清除失败");
} catch {
toast.error("清除失败,请稍后再试");
} finally {
setClearing(false);
setOpen(false);
}
};
// 仅当「明确查到无历史」时禁用删除;接口未就绪(known=false)仍允许删除。
const noHistory = history?.known === true && history.exists === false;
return (
<>
<Button
size="sm"
variant="ghost"
className="text-muted-foreground hover:bg-destructive/10 hover:text-destructive dark:text-[#ccd2da] dark:hover:bg-[#5c0011]/35 mt-2 h-9 w-full"
onClick={() => setOpen(true)}
disabled={!actionId}
title="清除行动记录"
>
<Trash2 className="h-3.5 w-3.5" /> 清除记录
</Button>
<Dialog open={open} onOpenChange={(o) => !clearing && setOpen(o)}>
<DialogContent>
<DialogHeader>
<DialogTitle>清除行动记录</DialogTitle>
<DialogDescription>
将清除该行动在 B 系统中的策划数据(聊天对话保留),是否确认?
</DialogDescription>
</DialogHeader>
{checking ? (
<div className="text-muted-foreground flex items-center gap-1.5 text-xs">
<Loader2 className="h-3.5 w-3.5 animate-spin" /> 正在查询历史…
</div>
) : history?.known === true ? (
<div className="text-muted-foreground text-xs">
{history.exists ? "检测到该行动的历史记录。" : "未检测到该行动的历史记录,无需清除。"}
</div>
) : null}
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)} disabled={clearing}>
取消
</Button>
<Button
variant="destructive"
onClick={handleClear}
disabled={clearing || checking || noHistory}
>
{clearing ? <Loader2 className="h-4 w-4 animate-spin" /> : "确认清除"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}
/**
* 任务工作区布局:左列表 + 右 Outlet。
* ``lite``(3qfx/xdfx)= 精简版:左列表无跳转按钮、无底部任务操作面板。