feat: 对接ai审核接口

This commit is contained in:
rd
2025-08-11 12:04:03 +08:00
parent f1f9338e58
commit 0b0caf6b64
10 changed files with 197 additions and 104 deletions

View File

@ -0,0 +1,54 @@
import { postWorkAuditsAiReview, getWorkAuditsAiReviewResult } from '@/api/all/generationWorkshop';
export default function useGetAiReviewResult({ cardInfo, updateAiReview }: { cardInfo: any; updateAiReview: (ai_review: any) => void }) {
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;
const { code, data } = await postWorkAuditsAiReview({ id, platform, content });
if (code === 200) {
ticket.value = data.ticket;
startStatusPolling();
}
};
const handleAgainCheck = async () => {
checkResult.value = {};
ticket.value = '';
clearStatusPollingTimer();
handleStartCheck();
};
const startStatusPolling = () => {
clearStatusPollingTimer();
statusPollingTimer.value = setInterval(async () => {
const { code, data } = await getWorkAuditsAiReviewResult(cardInfo.value.id, ticket.value);
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,
};
}