feat: update TaskList component to display script execution time range and remove real-time timer

This commit is contained in:
duanshuwen
2026-04-16 18:45:56 +08:00
parent 210e8eb363
commit d233b94b2a
4 changed files with 25 additions and 30 deletions

View File

@@ -7,7 +7,7 @@
`${item.total > 98 && item.total + '+' || item.total}` }}</span></div>
</div>
</div>
<div class="flex justify-between mt-3 mb-3 text-[14px]">
<div v-if="latestTask" class="flex justify-between mt-3 mb-3 text-[14px]">
<div class="text-[#171717] dark:text-gray-100">{{ currentDateLabel }}</div>
<div class="text-[#99A0AE] dark:text-gray-500">{{ currentTime }}</div>
</div>
@@ -31,22 +31,26 @@
<script setup lang="ts">
import Card from './TaskCard.vue'
import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
import { ref, reactive, computed } from 'vue'
import { useTaskStore } from '@stores/task'
import type { Task } from '@lib/task-types'
const taskStore = useTaskStore()
const now = ref(new Date())
let timer: ReturnType<typeof setInterval> | null = null
const currentTasks = computed(() => active.value === 1 ? taskStore.pendingTasks : taskStore.completedTasks)
const latestTask = computed(() => currentTasks.value[0])
const currentDateLabel = computed(() => {
if (!latestTask.value) {
return '执行时段'
}
const current = new Date(latestTask.value.createdAt)
const today = new Date()
const y = today.getFullYear()
const m = today.getMonth()
const d = today.getDate()
const current = now.value
const cy = current.getFullYear()
const cm = current.getMonth()
const cd = current.getDate()
@@ -65,24 +69,11 @@ const currentDateLabel = computed(() => {
})
const currentTime = computed(() => {
const pad = (n: number) => String(n).padStart(2, '0')
const h = pad(now.value.getHours())
const m = pad(now.value.getMinutes())
const s = pad(now.value.getSeconds())
return `${h}:${m}:${s}`
})
onMounted(() => {
timer = setInterval(() => {
now.value = new Date()
}, 1000)
})
onUnmounted(() => {
if (timer) {
clearInterval(timer)
timer = null
if (!latestTask.value) {
return '--'
}
const [start, end] = latestTask.value.dateRange
return `${start} ~ ${end}`
})
const tabs = reactive([

View File

@@ -24,7 +24,8 @@ export const useTaskStore = defineStore('task', () => {
// 持久化 helper用于减少写盘次数可在需要时调用
const persist = async () => {
try {
await window.api.invoke(IPC_EVENTS.SET_CONFIG, CONFIG_KEYS.TASK_LIST, tasks.value);
const payload = JSON.parse(JSON.stringify(tasks.value))
await window.api.invoke(IPC_EVENTS.SET_CONFIG, CONFIG_KEYS.TASK_LIST, payload);
} catch (e) {
console.error('Failed to persist tasks', e);
}