|
|
@@ -98,25 +98,39 @@ const todayStats = computed(() => {
|
|
|
})
|
|
|
|
|
|
const workDuration = ref('0m')
|
|
|
+let workDurationMinutes = 0
|
|
|
+let workDurationTimer: ReturnType<typeof setInterval> | null = null
|
|
|
+
|
|
|
+const activeCodes: StatusCode[] = ['busy', 'reasoning', 'using_tool', 'running', 'pending', 'retry']
|
|
|
+
|
|
|
+function formatWorkDuration(min: number) {
|
|
|
+ if (min < 60) return `${min}m`
|
|
|
+ const hr = Math.floor(min / 60)
|
|
|
+ const m = min % 60
|
|
|
+ return `${hr}h ${m}m`
|
|
|
+}
|
|
|
|
|
|
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`
|
|
|
- }
|
|
|
+ workDurationMinutes = data.data.duration_minutes
|
|
|
+ workDuration.value = formatWorkDuration(workDurationMinutes)
|
|
|
}
|
|
|
} catch {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function startWorkDurationTimer() {
|
|
|
+ workDurationTimer = setInterval(() => {
|
|
|
+ if (activeCodes.includes(currentCode.value)) {
|
|
|
+ workDurationMinutes++
|
|
|
+ workDuration.value = formatWorkDuration(workDurationMinutes)
|
|
|
+ }
|
|
|
+ }, 60000)
|
|
|
+}
|
|
|
+
|
|
|
function getOrCreatePieChart(): echarts.ECharts {
|
|
|
if (!pieChart && pieChartRef.value) {
|
|
|
pieChart = echarts.init(pieChartRef.value)
|
|
|
@@ -264,6 +278,7 @@ onMounted(() => {
|
|
|
fetchHistory()
|
|
|
fetchStatus()
|
|
|
fetchWorkDuration()
|
|
|
+ startWorkDurationTimer()
|
|
|
|
|
|
if (pieChartRef.value) {
|
|
|
pieChart = echarts.init(pieChartRef.value)
|
|
|
@@ -280,6 +295,7 @@ onUnmounted(() => {
|
|
|
removeDisconnectListener()
|
|
|
if (clockTimer) clearInterval(clockTimer)
|
|
|
if (durationTimer) clearInterval(durationTimer)
|
|
|
+ if (workDurationTimer) clearInterval(workDurationTimer)
|
|
|
pieChart?.dispose()
|
|
|
timelineChart?.dispose()
|
|
|
window.removeEventListener('resize', handleResize)
|