重构推送历史记录API以使用新端点并更新响应处理。增强PushHistory组件中的错误处理和分页逻辑,以改善用户体验。
This commit is contained in:
@@ -25,41 +25,13 @@ export interface GetPushHistoryResponse {
|
||||
/**
|
||||
* 获取推送历史列表
|
||||
*/
|
||||
export const getPushHistory = async (
|
||||
params: GetPushHistoryParams
|
||||
): Promise<GetPushHistoryResponse> => {
|
||||
try {
|
||||
// TODO: 替换为实际的API接口地址
|
||||
const response = await request.get("/api/push-history", { params });
|
||||
|
||||
// 如果接口返回的数据格式不同,需要在这里进行转换
|
||||
if (response.data && response.data.success !== undefined) {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 兼容不同的响应格式
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
list: response.data?.list || response.data?.data || [],
|
||||
total: response.data?.total || 0,
|
||||
page: response.data?.page || params.page || 1,
|
||||
pageSize: response.data?.pageSize || params.pageSize || 10,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error("获取推送历史失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "获取推送历史失败",
|
||||
};
|
||||
}
|
||||
export interface GetGroupPushHistoryParams {
|
||||
keyword?: string;
|
||||
limit: string;
|
||||
page: string;
|
||||
workbenchId?: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
export const getPushHistory = async (params: GetGroupPushHistoryParams) => {
|
||||
return request("/v1/workbench/group-push-history", { params });
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -76,18 +76,31 @@ const PushHistory: React.FC = () => {
|
||||
}
|
||||
|
||||
const response = await getPushHistory(params);
|
||||
const result = response?.data ?? response ?? {};
|
||||
|
||||
if (response.success) {
|
||||
setDataSource(response.data?.list || []);
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: response.data?.page || page,
|
||||
total: response.data?.total || 0,
|
||||
}));
|
||||
} else {
|
||||
message.error(response.message || "获取推送历史失败");
|
||||
if (!result || typeof result !== "object") {
|
||||
message.error("获取推送历史失败");
|
||||
setDataSource([]);
|
||||
return;
|
||||
}
|
||||
|
||||
const toNumber = (value: unknown, fallback: number) => {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
};
|
||||
|
||||
const list = Array.isArray(result.list) ? result.list : [];
|
||||
const total = toNumber(result.total, pagination.total);
|
||||
const currentPage = toNumber(result.page, page);
|
||||
const pageSize = toNumber(result.pageSize, pagination.pageSize);
|
||||
|
||||
setDataSource(list);
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: currentPage,
|
||||
pageSize,
|
||||
total,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("获取推送历史失败:", error);
|
||||
message.error("获取推送历史失败,请稍后重试");
|
||||
@@ -211,9 +224,7 @@ const PushHistory: React.FC = () => {
|
||||
dataIndex: "pushContent",
|
||||
key: "pushContent",
|
||||
ellipsis: true,
|
||||
render: (text: string) => (
|
||||
<span style={{ color: "#333" }}>{text}</span>
|
||||
),
|
||||
render: (text: string) => <span style={{ color: "#333" }}>{text}</span>,
|
||||
},
|
||||
{
|
||||
title: "目标数量",
|
||||
@@ -287,7 +298,9 @@ const PushHistory: React.FC = () => {
|
||||
subtitle="查看所有推送任务的历史记录"
|
||||
showBackButton={true}
|
||||
backButtonText="返回"
|
||||
onBackClick={() => navigate("/pc/powerCenter/message-push-assistant")}
|
||||
onBackClick={() =>
|
||||
navigate("/pc/powerCenter/message-push-assistant")
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
@@ -369,11 +382,3 @@ const PushHistory: React.FC = () => {
|
||||
};
|
||||
|
||||
export default PushHistory;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -167,27 +167,11 @@ const MessageEnter: React.FC<MessageEnterProps> = ({ contract }) => {
|
||||
// AI 消息处理
|
||||
useEffect(() => {
|
||||
if (quoteMessageContent) {
|
||||
console.log(
|
||||
"🤖 AI消息到达 - aiQuoteMessageContent:",
|
||||
aiQuoteMessageContent,
|
||||
);
|
||||
|
||||
// 检查:如果用户输入框已有内容(且不是之前的AI内容),不覆盖
|
||||
if (inputValue && inputValue !== quoteMessageContent) {
|
||||
console.log("⚠️ 用户正在输入,不覆盖输入内容");
|
||||
updateQuoteMessageContent(""); // 清空AI回复
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAiAssist) {
|
||||
// AI辅助模式:填充到输入框,等待人工确认
|
||||
console.log("✨ AI辅助模式:填充消息到输入框");
|
||||
setInputValue(quoteMessageContent);
|
||||
}
|
||||
|
||||
if (isAiTakeover) {
|
||||
// AI接管模式:直接发送消息(传入内容,避免 state 闭包问题)
|
||||
console.log("🚀 AI接管模式:自动发送消息");
|
||||
handleSend(quoteMessageContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import QuickReplyModal from "./components/QuickReplyModal";
|
||||
import GroupModal from "./components/GroupModal";
|
||||
import { useWeChatStore } from "@/store/module/weChat/weChat";
|
||||
import { useWebSocketStore } from "@/store/module/websocket/websocket";
|
||||
import { ChatRecord } from "@/pages/pc/ckbox/data";
|
||||
|
||||
// 消息类型枚举
|
||||
export enum MessageType {
|
||||
@@ -82,10 +83,12 @@ const QuickWords: React.FC<QuickWordsProps> = ({ onInsert }) => {
|
||||
state => state.updateQuoteMessageContent,
|
||||
);
|
||||
const currentContract = useWeChatStore(state => state.currentContract);
|
||||
const addMessage = useWeChatStore(state => state.addMessage);
|
||||
const { sendCommand } = useWebSocketStore.getState();
|
||||
|
||||
const sendQuickReplyNow = (reply: QuickWordsReply) => {
|
||||
if (!currentContract) return;
|
||||
const messageId = Date.now();
|
||||
const params = {
|
||||
wechatAccountId: currentContract.wechatAccountId,
|
||||
wechatChatroomId: currentContract?.chatroomId ? currentContract.id : 0,
|
||||
@@ -93,7 +96,35 @@ const QuickWords: React.FC<QuickWordsProps> = ({ onInsert }) => {
|
||||
msgSubType: 0,
|
||||
msgType: reply.msgType,
|
||||
content: reply.content,
|
||||
seq: messageId,
|
||||
} as any;
|
||||
|
||||
if (reply.msgType !== MessageType.TEXT) {
|
||||
const localMessage: ChatRecord = {
|
||||
id: messageId,
|
||||
wechatAccountId: params.wechatAccountId,
|
||||
wechatFriendId: params.wechatFriendId,
|
||||
wechatChatroomId: params.wechatChatroomId,
|
||||
tenantId: 0,
|
||||
accountId: 0,
|
||||
synergyAccountId: 0,
|
||||
content: params.content,
|
||||
msgType: reply.msgType,
|
||||
msgSubType: params.msgSubType,
|
||||
msgSvrId: "",
|
||||
isSend: true,
|
||||
createTime: new Date().toISOString(),
|
||||
isDeleted: false,
|
||||
deleteTime: "",
|
||||
sendStatus: 1,
|
||||
wechatTime: Date.now(),
|
||||
origin: 0,
|
||||
msgId: 0,
|
||||
recalled: false,
|
||||
seq: messageId,
|
||||
};
|
||||
addMessage(localMessage);
|
||||
}
|
||||
sendCommand("CmdSendMessage", params);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user