2025-08-11 18:28:38 +08:00
|
|
|
export default function useGetAiReviewResult({
|
|
|
|
|
cardInfo,
|
|
|
|
|
updateAiReview,
|
|
|
|
|
startAiReviewFn,
|
|
|
|
|
getAiReviewResultFn,
|
|
|
|
|
}: {
|
|
|
|
|
cardInfo: any;
|
|
|
|
|
updateAiReview: (ai_review: any) => void;
|
|
|
|
|
startAiReviewFn: (params: { id: string; platform: string; content: string }) => Promise<any>;
|
|
|
|
|
getAiReviewResultFn: (id: string, ticket: string) => Promise<any>;
|
|
|
|
|
}) {
|
2025-08-11 12:04:03 +08:00
|
|
|
const statusPollingTimer = ref<number | null>(null);
|
|
|
|
|
const ticket = ref('');
|
|
|
|
|
const checkLoading = ref(false);
|
|
|
|
|
const checkResult = ref<any>({});
|
|
|
|
|
|
|
|
|
|
const handleStartCheck = async () => {
|
|
|
|
|
checkLoading.value = true;
|
|
|
|
|
const { id, platform, content } = cardInfo.value;
|
2025-08-11 18:28:38 +08:00
|
|
|
const { code, data } = await startAiReviewFn({ id, platform, content });
|
2025-08-11 12:04:03 +08:00
|
|
|
if (code === 200) {
|
|
|
|
|
ticket.value = data.ticket;
|
|
|
|
|
startStatusPolling();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const handleAgainCheck = async () => {
|
|
|
|
|
checkResult.value = {};
|
|
|
|
|
ticket.value = '';
|
|
|
|
|
clearStatusPollingTimer();
|
|
|
|
|
handleStartCheck();
|
|
|
|
|
};
|
|
|
|
|
const startStatusPolling = () => {
|
|
|
|
|
clearStatusPollingTimer();
|
|
|
|
|
statusPollingTimer.value = setInterval(async () => {
|
2025-08-11 18:28:38 +08:00
|
|
|
const { code, data } = await getAiReviewResultFn(cardInfo.value.id, ticket.value);
|
2025-08-11 12:04:03 +08:00
|
|
|
if (code === 200 && data.status === 1) {
|
|
|
|
|
checkResult.value = data.ai_review;
|
|
|
|
|
updateAiReview?.(data.ai_review);
|
|
|
|
|
checkLoading.value = false;
|
|
|
|
|
clearStatusPollingTimer();
|
|
|
|
|
}
|
|
|
|
|
}, 3000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const clearStatusPollingTimer = () => {
|
|
|
|
|
if (statusPollingTimer.value) {
|
|
|
|
|
clearInterval(statusPollingTimer.value);
|
|
|
|
|
statusPollingTimer.value = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
clearStatusPollingTimer();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
handleStartCheck,
|
|
|
|
|
handleAgainCheck,
|
|
|
|
|
checkResult,
|
|
|
|
|
checkLoading,
|
|
|
|
|
ticket,
|
|
|
|
|
};
|
|
|
|
|
}
|