Skip to content

Commit

Permalink
add complete time
Browse files Browse the repository at this point in the history
  • Loading branch information
storyxc committed Aug 17, 2023
1 parent d597463 commit 76deae5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions electron/ipcMainHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
for (const todoItemEntity of todoItemEntities) {
if (todoItemEntity.id === id) {
todoItemEntity.completed = true;
todoItemEntity.completedAt = formatDate(new Date())
// 更新本地数据
fs.writeFileSync(todoFilePath, JSON.stringify(todoItemEntities));
return true;
Expand Down Expand Up @@ -157,3 +158,13 @@ function fetchTodoDataFromLocal(todoFilePath: string) {
return dataList.filter((item) => !item.completed);
}

function formatDate(date: Date): string {
const year: number = date.getFullYear();
const month: string = String(date.getMonth() + 1).padStart(2, '0');
const day: string = String(date.getDate()).padStart(2, '0');
const hours: string = String(date.getHours()).padStart(2, '0');
const minutes: string = String(date.getMinutes()).padStart(2, '0');
const seconds: string = String(date.getSeconds()).padStart(2, '0');

return `${ year }-${ month }-${ day } ${ hours }:${ minutes }:${ seconds }`;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ido",
"private": true,
"version": "1.0.4",
"version": "1.0.5",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build && electron-builder",
Expand Down
3 changes: 2 additions & 1 deletion src/universal/todo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ interface TodoItemEntity {
remark: string;
tags: string[];
flag: boolean;
completed: boolean;
completed: boolean,
completedAt: string;
}

interface TodoList {
Expand Down
6 changes: 4 additions & 2 deletions src/views/TodoBodyView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const todoItemForm: TodoItemEntity = reactive<TodoItemEntity>({
remark: '',
tags: [],
flag: false,
completed: false
completed: false,
completedAt: ''
});

const handleRemoveTodoItem = async (id: number) => {
Expand Down Expand Up @@ -90,7 +91,8 @@ const childTodoForm = reactive<TodoItemEntity>({
remark: '',
tags: [],
flag: false,
completed: false
completed: false,
completedAt: ''
});
const handleUpdateAddTodoItemForm = async (item: TodoItemEntity) => {
childTodoForm.id = item.id;
Expand Down

0 comments on commit 76deae5

Please sign in to comment.