曹睿
2025-04-25 ec1bef3a37e8dcdf22f1bf52e7c272a18306f4b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
  <view :class="['todo-item', { completed: todo.completed }]" @tap="toggleCompleted">
    <view class="status-icon">
      <wd-icon v-if="todo.completed" name="check" color="#67C23A" size="20" />
      <view v-else class="uncompleted-circle"></view>
    </view>
    <view class="todo-content">
      <view class="todo-title">{{ todo.title }}</view>
      <view v-if="todo.description" class="todo-description">
        {{ todo.description }}
      </view>
      <view v-if="todo.deadline" class="todo-deadline">
        <wd-icon name="time" size="14" color="#999999" style="margin-right: 4rpx" />
        {{ formatDate(todo.deadline) }}
      </view>
    </view>
    <view class="todo-actions">
      <wd-icon
        name="delete-filling"
        color="#F56C6C"
        size="18"
        @tap.stop="$emit('delete', todo.id)"
      />
    </view>
  </view>
</template>
 
<script lang="ts" setup>
import { defineProps, defineEmits } from "vue";
import { Todo } from "@/types/todo";
 
const props = defineProps({
  todo: {
    type: Object as () => Todo,
    required: true,
  },
});
 
const emit = defineEmits(["update", "delete"]);
 
// 切换完成状态
const toggleCompleted = () => {
  emit("update", {
    ...props.todo,
    completed: !props.todo.completed,
  });
};
 
// 格式化日期
const formatDate = (date: string) => {
  const d = new Date(date);
  const year = d.getFullYear();
  const month = String(d.getMonth() + 1).padStart(2, "0");
  const day = String(d.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
};
</script>
 
<style lang="scss" scoped>
.todo-item {
  display: flex;
  align-items: flex-start;
  padding: 24rpx;
  margin-bottom: 16rpx;
  background-color: #fff;
  border-radius: 12rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
 
  &.completed {
    opacity: 0.7;
 
    .todo-title {
      color: #909399;
      text-decoration: line-through;
    }
  }
 
  .status-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40rpx;
    height: 40rpx;
    margin-right: 20rpx;
 
    .uncompleted-circle {
      width: 36rpx;
      height: 36rpx;
      border: 2rpx solid #dcdfe6;
      border-radius: 50%;
    }
  }
 
  .todo-content {
    flex: 1;
 
    .todo-title {
      margin-bottom: 8rpx;
      font-size: 30rpx;
      font-weight: 500;
      color: #303133;
    }
 
    .todo-description {
      margin-bottom: 8rpx;
      font-size: 26rpx;
      color: #606266;
    }
 
    .todo-deadline {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #909399;
    }
  }
 
  .todo-actions {
    padding: 6rpx;
  }
}
</style>