|
|
@@ -9,6 +9,7 @@ import StatusCard from '@/components/StatusCard.vue'
|
|
|
import http from '@/api/index'
|
|
|
import {getHistory} from '@/api/history'
|
|
|
import {getStatus} from '@/api/status'
|
|
|
+import {getWorkDuration} from '@/api/work-duration'
|
|
|
|
|
|
const {connected, onMessage, onDisconnect} = useSSE('/api/events')
|
|
|
const {theme} = useTheme()
|
|
|
@@ -96,26 +97,25 @@ const todayStats = computed(() => {
|
|
|
}))
|
|
|
})
|
|
|
|
|
|
-const activeStatusCodes: StatusCode[] = ['busy', 'reasoning', 'using_tool', 'running', 'pending', 'retry']
|
|
|
+const workDuration = ref('0m')
|
|
|
|
|
|
-const workDuration = computed(() => {
|
|
|
- const items = eventLog.value.slice().reverse()
|
|
|
- if (items.length === 0) return '0m'
|
|
|
-
|
|
|
- let totalMs = 0
|
|
|
- for (let i = 0; i < items.length; i++) {
|
|
|
- if (activeStatusCodes.includes(items[i].code)) {
|
|
|
- const end = i + 1 < items.length ? items[i + 1].ts : Date.now()
|
|
|
- totalMs += end - items[i].ts
|
|
|
+async function fetchWorkDuration() {
|
|
|
+ try {
|
|
|
+ const res = await getWorkDuration()
|
|
|
+ const data = res.data
|
|
|
+ if (data.code === 0 && data.data) {
|
|
|
+ const min = data.data.duration_minutes
|
|
|
+ if (min < 60) {
|
|
|
+ workDuration.value = `${min}m`
|
|
|
+ } else {
|
|
|
+ const hr = Math.floor(min / 60)
|
|
|
+ const m = min % 60
|
|
|
+ workDuration.value = `${hr}h ${m}m`
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch {
|
|
|
}
|
|
|
-
|
|
|
- const totalMin = Math.floor(totalMs / 60000)
|
|
|
- if (totalMin < 60) return `${totalMin}m`
|
|
|
- const hr = Math.floor(totalMin / 60)
|
|
|
- const min = totalMin % 60
|
|
|
- return `${hr}h ${min}m`
|
|
|
-})
|
|
|
+}
|
|
|
|
|
|
function getOrCreatePieChart(): echarts.ECharts {
|
|
|
if (!pieChart && pieChartRef.value) {
|
|
|
@@ -238,6 +238,7 @@ const removeListener = onMessage((msg: SseMessage) => {
|
|
|
ts: Date.now(),
|
|
|
})
|
|
|
if (eventLog.value.length > 50) eventLog.value.pop()
|
|
|
+ fetchWorkDuration()
|
|
|
})
|
|
|
|
|
|
watch(connected, (val) => {
|
|
|
@@ -262,6 +263,7 @@ onMounted(() => {
|
|
|
|
|
|
fetchHistory()
|
|
|
fetchStatus()
|
|
|
+ fetchWorkDuration()
|
|
|
|
|
|
if (pieChartRef.value) {
|
|
|
pieChart = echarts.init(pieChartRef.value)
|