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