<script lang="ts" setup>
|
import type { MesProAiApi } from '#/api/mes/pro/ai';
|
|
import { onUnmounted, ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
import { IconifyIcon } from '@vben/icons';
|
|
import { Alert, Button, Progress, Tag } from 'ant-design-vue';
|
|
import { predictDelivery } from '#/api/mes/pro/ai';
|
|
defineOptions({ name: 'MesProAiPredictDelivery' });
|
|
const props = defineProps<{ workOrderId?: number; mpsId?: number }>();
|
|
const loading = ref(false);
|
const progress = ref(0);
|
const result = ref<MesProAiApi.PredictDeliveryRespVO>();
|
const errorMsg = ref('');
|
|
let progressTimer: ReturnType<typeof setInterval> | null = null;
|
|
function startProgress() {
|
progress.value = 0;
|
progressTimer = setInterval(() => {
|
if (progress.value < 30) {
|
progress.value += 3;
|
} else if (progress.value < 70) {
|
progress.value += 2;
|
} else if (progress.value < 88) {
|
progress.value += 0.5;
|
}
|
}, 100);
|
}
|
|
function stopProgress() {
|
if (progressTimer) {
|
clearInterval(progressTimer);
|
progressTimer = null;
|
}
|
}
|
|
function finishProgress() {
|
stopProgress();
|
progress.value = 100;
|
}
|
|
onUnmounted(() => stopProgress());
|
|
async function handlePredict() {
|
loading.value = true;
|
result.value = undefined;
|
errorMsg.value = '';
|
modalApi.open();
|
startProgress();
|
try {
|
result.value = await predictDelivery(props.workOrderId, props.mpsId);
|
finishProgress();
|
} catch {
|
errorMsg.value = 'AI 分析暂时不可用,请稍后重试';
|
stopProgress();
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
const [ResultModal, modalApi] = useVbenModal({
|
footer: false,
|
onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
stopProgress();
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Button :loading="loading" @click="handlePredict">
|
<template #icon><IconifyIcon icon="ant-design:check-circle-outlined" /></template>
|
AI 交付评估
|
</Button>
|
|
<ResultModal title="AI 按时交付预测" class="w-1/2">
|
<!-- 加载中 -->
|
<div v-if="loading" class="flex flex-col items-center py-10">
|
<div class="relative mb-6">
|
<div class="absolute inset-0 animate-ping rounded-full bg-green-400 opacity-20" style="width: 80px; height: 80px" />
|
<div class="relative flex h-20 w-20 items-center justify-center rounded-full bg-green-50">
|
<IconifyIcon icon="ant-design:check-circle-outlined" class="text-3xl text-green-500" />
|
</div>
|
</div>
|
<div class="mb-3 text-base font-medium text-gray-700">
|
AI 正在评估交付能力...
|
</div>
|
<div class="w-2/3">
|
<Progress
|
:percent="Math.round(progress)"
|
:stroke-color="{ '0%': '#52c41a', '100%': '#b7eb8f' }"
|
:show-info="true"
|
status="active"
|
/>
|
</div>
|
<div class="mt-2 text-sm text-gray-400">正在分析生产进度、剩余工时与交付风险</div>
|
</div>
|
|
<!-- 错误 -->
|
<div v-else-if="errorMsg" class="flex flex-col items-center py-10">
|
<IconifyIcon icon="ant-design:close-circle-filled" class="mb-4 text-5xl text-red-400" />
|
<span class="text-base text-gray-500">{{ errorMsg }}</span>
|
</div>
|
|
<!-- 结果 -->
|
<template v-else-if="result">
|
<div class="mb-4 flex items-center gap-4">
|
<div class="flex items-center gap-2">
|
<span class="text-base font-medium">能否按时交付:</span>
|
<Tag :color="result.onTime ? 'green' : 'red'">
|
{{ result.onTime ? '可按时交付' : '无法按时交付' }}
|
</Tag>
|
</div>
|
<div class="flex items-center gap-2">
|
<span class="text-base">置信度:</span>
|
<span class="font-medium">{{ result.confidence }}%</span>
|
</div>
|
</div>
|
|
<div class="mb-4 flex items-center gap-4">
|
<div class="flex-1">
|
<div class="mb-1 text-sm text-gray-500">
|
生产进度 {{ result.progressPercent }}%
|
</div>
|
<Progress :percent="result.progressPercent" :stroke-color="{ '0%': '#108ee9', '100%': '#87d068' }" />
|
</div>
|
<div class="text-sm text-gray-500">
|
剩余 {{ result.remainingDays }} 天
|
</div>
|
</div>
|
|
<div class="mb-4 rounded bg-gray-50 p-3 text-sm leading-relaxed">
|
{{ result.reasoning }}
|
</div>
|
|
<div v-if="!result.onTime && result.delayFactors?.length">
|
<div class="mb-2 text-base font-medium">延期因素:</div>
|
<Alert
|
v-for="(factor, index) in result.delayFactors"
|
:key="index"
|
type="error"
|
show-icon
|
class="mb-2"
|
:message="factor"
|
/>
|
</div>
|
</template>
|
</ResultModal>
|
</template>
|