-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-manager.js
More file actions
98 lines (84 loc) · 2.42 KB
/
Copy pathtask-manager.js
File metadata and controls
98 lines (84 loc) · 2.42 KB
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
import * as dataManager from './data.js';
// 创建新任务
export function createTask(taskData) {
const newTask = {
id: Date.now(),
title: taskData.title,
url: taskData.url,
category: taskData.category,
summary: taskData.summary,
priority: taskData.priority,
date: new Date().toISOString(),
completed: false
};
return dataManager.addTask(newTask);
}
// 切换任务完成状态
export function toggleTaskComplete(taskId) {
const tasks = dataManager.getTasks();
const task = tasks.find(t => t.id === taskId);
if (task) {
const updates = {
completed: !task.completed,
updateDate: new Date().toISOString()
};
return dataManager.updateTask(taskId, updates).then(() => {
// 如果任务有飞书记录ID,同步到飞书
if (task.recordId) {
return chrome.runtime.sendMessage({
action: 'updateTaskStatus',
recordId: task.recordId,
completed: updates.completed
});
}
});
}
return Promise.resolve();
}
// 删除任务
export function deleteTask(taskId) {
return dataManager.deleteTask(taskId);
}
// 保存任务到知识库
export function saveToKnowledgeBase(taskId) {
const tasks = dataManager.getTasks();
const task = tasks.find(t => t.id === taskId);
if (task) {
return dataManager.addToKnowledgeBase(task);
}
return Promise.resolve();
}
// 获取今天的任务
export function getTodayTasks() {
const tasks = dataManager.getTasks();
const today = new Date();
today.setHours(0, 0, 0, 0);
return tasks.filter(task => {
const taskDate = new Date(task.date);
taskDate.setHours(0, 0, 0, 0);
return taskDate.getTime() === today.getTime();
});
}
// 按优先级排序任务
export function sortTasksByPriority(tasks) {
const priorityOrder = { 'high': 1, 'medium': 2, 'low': 3 };
return [...tasks].sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
}
// 自动生成摘要(发送到飞书)
export function generateSummary(articleData) {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
{
action: 'addArticleToFeishu',
article: articleData
},
function(response) {
if (response && response.success) {
resolve('已成功提交到飞书,摘要将由飞书处理');
} else {
reject(response?.error || '未知错误');
}
}
);
});
}