Files
Kanban/src/views/TodayView.vue
T
chenshoulin 5133bf768c
CI / verify (push) Successful in 1m41s
CI / 部署到服务器 (push) Successful in 26s
feat: 更新统计卡片描述,优化可读性
2026-10-24 18:58:06 +08:00

164 lines
6.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import dayjs from 'dayjs'
import { storeToRefs } from 'pinia'
import { computed, ref } from 'vue'
import TaskCard from '@/components/TaskCard.vue'
import TaskDetailDrawer from '@/components/TaskDetailDrawer.vue'
import { useTaskStore } from '@/stores/tasks'
import type { MoveDirection } from '@/types/task'
import { computeStats } from '@/utils/stats'
import { buildTodayBuckets, countTodayTasks } from '@/utils/today'
const WEEKDAYS = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'] as const
/**
* 用完整类名字符串,避免 Tailwind 扫描不到动态拼接的类。
* 只保留色点:分组计数已经降为纯文字,彩色徽章会把权重抬到标题之上,
* 而且和上方统计带说的还是同一个数字。
*/
const TONES = {
rose: { dot: 'bg-rose-500' },
amber: { dot: 'bg-amber-500' },
sky: { dot: 'bg-sky-500' },
slate: { dot: 'bg-slate-400' },
} as const
const store = useTaskStore()
const { activeTasks } = storeToRefs(store)
const todayLabel = computed(() => {
const now = dayjs()
return `${now.format('YYYY年M月D日')} ${WEEKDAYS[now.day()]}`
})
const buckets = computed(() => buildTodayBuckets(activeTasks.value))
const stats = computed(() => computeStats(activeTasks.value))
const todayCount = computed(() => countTodayTasks(buckets.value))
/**
* 统计卡片与下方分组一一对应:四个数字就是四组任务量。
* 「本周完成」下方没有对应分组,属于回顾性指标,放页头日期后面。
*/
const statCards = computed(() => [
{ label: '逾期', value: buckets.value.overdue.length, dot: 'bg-rose-500' },
{ label: '今天到期', value: buckets.value.dueToday.length, dot: 'bg-amber-500' },
{ label: '进行中', value: buckets.value.inProgress.length, dot: 'bg-sky-500' },
{ label: '待办', value: buckets.value.pending.length, dot: 'bg-slate-400' },
])
/**
* 空分组直接过滤掉。
* 不能把 v-if 和 v-for 写在同一元素上 —— Vue 3 里 v-if 优先级更高,
* 拿不到 v-for 的作用域变量,组件会直接渲染失败。
*/
const sections = computed(() =>
[
{ key: 'overdue', title: '已逾期', tone: 'rose' as const, items: buckets.value.overdue },
{ key: 'dueToday', title: '今天到期', tone: 'amber' as const, items: buckets.value.dueToday },
{ key: 'inProgress', title: '进行中', tone: 'sky' as const, items: buckets.value.inProgress },
{ key: 'pending', title: '待办', tone: 'slate' as const, items: buckets.value.pending },
].filter((section) => section.items.length > 0),
)
const editingId = ref<string | null>(null)
const editingTask = computed(
() => store.activeTasks.find((task) => task.id === editingId.value) ?? null,
)
function toggleTask(id: string): void {
const task = store.activeTasks.find((item) => item.id === id)
if (!task) return
store.updateTask(id, { status: task.status === 'done' ? 'todo' : 'done' })
}
/** 今日视图没有列概念,左右方向键不适用;上下仍可调 order */
function handleKeyMove(payload: { id: string; direction: MoveDirection }): void {
if (payload.direction === 'left' || payload.direction === 'right') return
const task = store.activeTasks.find((item) => item.id === payload.id)
if (!task) return
const column = store.byColumn[task.status]
const currentIndex = column.findIndex((item) => item.id === payload.id)
const nextIndex = currentIndex + (payload.direction === 'up' ? -1 : 1)
if (nextIndex < 0 || nextIndex >= column.length) return
store.moveTask(task.id, task.status, nextIndex)
}
</script>
<template>
<div class="flex min-h-0 flex-1 flex-col overflow-y-auto">
<!-- 限宽居中:否则 1440px 下卡片会被拉满整屏,标题与元信息之间出现大片空白 -->
<div class="mx-auto flex w-full max-w-3xl flex-col gap-5 p-4 md:p-6">
<header class="flex flex-col gap-0.5">
<h1 class="text-xl font-semibold tracking-tight text-slate-900 md:text-2xl dark:text-zinc-100">
今日
</h1>
<!-- 「本周完成」在下方没有对应分组,属于回顾性指标,跟在日期后面而不是占一格统计 -->
<p class="text-sm text-slate-500 dark:text-zinc-400">
{{ todayLabel }} · 本周完成
<span
data-role="completed-this-week"
class="font-medium tabular-nums text-slate-600 dark:text-zinc-300"
>{{ stats.completedThisWeek }}</span
>
个
</p>
</header>
<!-- 四张独立卡片:圆点 + 灰色标签,下方大号数字 -->
<dl class="grid grid-cols-2 gap-3 md:grid-cols-4">
<div
v-for="card in statCards"
:key="card.label"
class="rounded-xl border border-slate-200 bg-white px-4 py-3.5 shadow-card dark:border-zinc-800 dark:bg-zinc-900"
>
<dt class="flex items-center gap-1.5 text-xs text-slate-500 dark:text-zinc-400">
<span class="size-1.5 rounded-full" :class="card.dot" aria-hidden="true" />
{{ card.label }}
</dt>
<dd
class="mt-1.5 text-2xl font-bold tracking-tight tabular-nums text-slate-900 dark:text-zinc-100"
>
{{ card.value }}
</dd>
</div>
</dl>
<p
v-if="todayCount === 0"
class="rounded-xl border border-dashed border-slate-300 bg-white/60 px-4 py-16 text-center text-sm text-slate-400 dark:border-zinc-700 dark:bg-zinc-900/40 dark:text-zinc-500"
>
今天没有待办事项
</p>
<section v-for="section in sections" :key="section.key" class="flex flex-col gap-2">
<h2
class="flex flex-wrap items-center gap-2 text-sm font-medium text-slate-700 dark:text-zinc-300"
>
<span class="size-1.5 rounded-full" :class="TONES[section.tone].dot" aria-hidden="true" />
{{ section.title }}
<span
data-role="section-count"
class="text-xs font-normal tabular-nums text-slate-500 dark:text-zinc-400"
>
{{ section.items.length }} 项
</span>
</h2>
<div class="flex flex-col gap-2">
<TaskCard
v-for="task in section.items"
:key="task.id"
:task="task"
@toggle="toggleTask"
@open="editingId = $event"
@keymove="handleKeyMove"
/>
</div>
</section>
</div>
<TaskDetailDrawer :task="editingTask" @close="editingId = null" />
</div>
</template>