feat: add provider analytics summary
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { BoltIcon, ClockIcon } from '@heroicons/vue/24/outline'
|
||||
import { api } from '../api/client'
|
||||
import LoadingSpinner from './ui/LoadingSpinner.vue'
|
||||
@@ -64,12 +64,18 @@ const activeJob = ref<GenerationJobDetail | null>(null)
|
||||
const providerStats = ref<GenerationProviderStats | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
let refreshTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const isDark = computed(() => props.tone === 'dark')
|
||||
const latestJob = computed(() => jobs.value[0] ?? null)
|
||||
const activeEvents = computed(() => activeJob.value?.events.slice(-10) ?? [])
|
||||
const activeProgress = computed(() => activeJob.value?.progress_percent ?? latestJob.value?.progress_percent ?? 0)
|
||||
const activeProgressLabel = computed(() => activeJob.value?.progress_label ?? latestJob.value?.progress_label ?? '暂无进度')
|
||||
const shouldAutoRefresh = computed(() => {
|
||||
if (activeJob.value) return !activeJob.value.is_terminal
|
||||
if (latestJob.value) return !latestJob.value.is_terminal
|
||||
return false
|
||||
})
|
||||
const providerSuccessRate = computed(() => {
|
||||
if (!providerStats.value?.total_calls) return null
|
||||
return Math.round((providerStats.value.successful_calls / providerStats.value.total_calls) * 100)
|
||||
@@ -206,6 +212,13 @@ async function refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
function stopAutoRefresh() {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer)
|
||||
refreshTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.storyId,
|
||||
() => {
|
||||
@@ -214,6 +227,19 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(shouldAutoRefresh, (enabled) => {
|
||||
stopAutoRefresh()
|
||||
if (enabled) {
|
||||
refreshTimer = setInterval(() => {
|
||||
if (!loading.value) {
|
||||
void refresh()
|
||||
}
|
||||
}, 2500)
|
||||
}
|
||||
})
|
||||
|
||||
onBeforeUnmount(stopAutoRefresh)
|
||||
|
||||
defineExpose({ refresh })
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user