修复了数据库中存储的计划时间格式不对的问题
This commit is contained in:
parent
71cf311d7e
commit
bd78b99b0a
Binary file not shown.
@ -153,7 +153,13 @@ class TodoComponent extends HTMLElement {
|
||||
// 设置日期时间选择器的初始值
|
||||
const scheduleInput = modal.querySelector('#schedule');
|
||||
const scheduleDate = new Date(todo.sche_time);
|
||||
scheduleInput.value = scheduleDate.toISOString().slice(0, 16);
|
||||
const year = scheduleDate.getFullYear();
|
||||
const month = String(scheduleDate.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(scheduleDate.getDate()).padStart(2, '0');
|
||||
const hours = String(scheduleDate.getHours()).padStart(2, '0');
|
||||
const minutes = String(scheduleDate.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(scheduleDate.getSeconds()).padStart(2, '0');
|
||||
scheduleInput.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
|
||||
// 添加保存按钮事件
|
||||
const saveButton = modal.querySelector('.save-button');
|
||||
@ -193,7 +199,8 @@ class TodoComponent extends HTMLElement {
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
scheduleInput.value = `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
scheduleInput.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
|
||||
// 获取当前用户等级
|
||||
const currentUserLevel = this.currentUser.access_level || 0;
|
||||
@ -346,8 +353,34 @@ class TodoComponent extends HTMLElement {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 首先根据项目/子项目筛选
|
||||
// 首先根据用户等级进行筛选
|
||||
const userLevel = this.currentUser.level || 0;
|
||||
let filteredTodos = this.todos;
|
||||
|
||||
// 等级4可以看到所有待办事项
|
||||
if (userLevel !== 4) {
|
||||
// 等级3不能看到创建人和执行人都是等级4的待办事项
|
||||
if (userLevel === 3) {
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
const creator = this.users.find(u => u.username === todo.adduser);
|
||||
const executor = this.users.find(u => u.username === todo.exeuser);
|
||||
|
||||
// 如果找不到用户信息,默认显示
|
||||
if (!creator || !executor) return true;
|
||||
|
||||
// 只要创建人或执行人不是等级4,就显示
|
||||
return !(creator.level === 4 && executor.level === 4);
|
||||
});
|
||||
} else {
|
||||
// 等级2或更低只能看到创建人或执行人是自己的待办事项
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
return todo.adduser === this.currentUser.username ||
|
||||
todo.exeuser === this.currentUser.username;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 然后根据项目/子项目筛选
|
||||
if (this.selectedProject) {
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
const matchesProject = todo.project === this.selectedProject;
|
||||
@ -358,40 +391,14 @@ class TodoComponent extends HTMLElement {
|
||||
});
|
||||
}
|
||||
|
||||
// 根据复选框状态筛选
|
||||
// 最后根据复选框状态筛选
|
||||
if (!this.showCompleted) {
|
||||
filteredTodos = filteredTodos.filter(todo => !todo.completed);
|
||||
}
|
||||
|
||||
// 根据用户等级进行筛选
|
||||
const userLevel = this.currentUser.level || 0;
|
||||
|
||||
// 等级4可以看到所有待办事项
|
||||
if (userLevel === 4) {
|
||||
return filteredTodos;
|
||||
}
|
||||
|
||||
// 等级3不能看到创建人和执行人都是等级4的待办事项
|
||||
if (userLevel === 3) {
|
||||
return filteredTodos.filter(todo => {
|
||||
const creator = this.users.find(u => u.username === todo.adduser);
|
||||
const executor = this.users.find(u => u.username === todo.exeuser);
|
||||
|
||||
// 如果找不到用户信息,默认显示
|
||||
if (!creator || !executor) return true;
|
||||
|
||||
// 只要创建人或执行人不是等级4,就显示
|
||||
return !(creator.level === 4 && executor.level === 4);
|
||||
});
|
||||
}
|
||||
|
||||
// 等级2或更低只能看到创建人或执行人是自己的待办事项
|
||||
return filteredTodos.filter(todo => {
|
||||
return todo.adduser === this.currentUser.username ||
|
||||
todo.exeuser === this.currentUser.username;
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.isInitialized) {
|
||||
return;
|
||||
@ -754,8 +761,35 @@ class TodoComponent extends HTMLElement {
|
||||
const container = document.createElement('div');
|
||||
container.className = 'container';
|
||||
|
||||
// 构建并渲染项目树
|
||||
const tree = TodoTree.buildProjectTree(this.todos);
|
||||
// 首先根据用户等级过滤待办事项
|
||||
const userLevel = this.currentUser.level || 0;
|
||||
let filteredTodos = this.todos;
|
||||
|
||||
// 等级4可以看到所有待办事项
|
||||
if (userLevel !== 4) {
|
||||
// 等级3不能看到创建人和执行人都是等级4的待办事项
|
||||
if (userLevel === 3) {
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
const creator = this.users.find(u => u.username === todo.adduser);
|
||||
const executor = this.users.find(u => u.username === todo.exeuser);
|
||||
|
||||
// 如果找不到用户信息,默认显示
|
||||
if (!creator || !executor) return true;
|
||||
|
||||
// 只要创建人或执行人不是等级4,就显示
|
||||
return !(creator.level === 4 && executor.level === 4);
|
||||
});
|
||||
} else {
|
||||
// 等级2或更低只能看到创建人或执行人是自己的待办事项
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
return todo.adduser === this.currentUser.username ||
|
||||
todo.exeuser === this.currentUser.username;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 构建并渲染项目树(使用过滤后的待办事项)
|
||||
const tree = TodoTree.buildProjectTree(filteredTodos);
|
||||
const treeContainer = TodoTree.renderProjectTree(tree, {
|
||||
expandedProjects: this.expandedProjects,
|
||||
selectedProject: this.selectedProject,
|
||||
@ -791,8 +825,23 @@ class TodoComponent extends HTMLElement {
|
||||
onAddTodo: () => this.showNewTodoModal()
|
||||
});
|
||||
|
||||
// 然后根据项目/子项目筛选
|
||||
if (this.selectedProject) {
|
||||
filteredTodos = filteredTodos.filter(todo => {
|
||||
const matchesProject = todo.project === this.selectedProject;
|
||||
if (!this.selectedSubproject) {
|
||||
return matchesProject;
|
||||
}
|
||||
return matchesProject && todo.subproject === this.selectedSubproject;
|
||||
});
|
||||
}
|
||||
|
||||
// 最后根据复选框状态筛选
|
||||
if (!this.showCompleted) {
|
||||
filteredTodos = filteredTodos.filter(todo => !todo.completed);
|
||||
}
|
||||
|
||||
// 渲染过滤后的待办事项
|
||||
const filteredTodos = this.filterTodos();
|
||||
const todosContainer = TodoList.renderTodoList(filteredTodos, {
|
||||
onEditExecutor: (todo) => this.showEditExecutorModal(todo),
|
||||
onEditSchedule: (todo) => this.showEditScheduleModal(todo),
|
||||
|
@ -1257,6 +1257,18 @@ function addTodo(todoData) {
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
const localDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
|
||||
// 处理计划时间
|
||||
let scheTime = todoData.sche_time;
|
||||
if (scheTime) {
|
||||
// 如果sche_time是datetime-local格式(YYYY-MM-DDTHH:mm),转换为数据库格式
|
||||
if (scheTime.includes('T')) {
|
||||
const [datePart, timePart] = scheTime.split('T');
|
||||
scheTime = `${datePart} ${timePart}:00`;
|
||||
}
|
||||
} else {
|
||||
scheTime = localDateTime;
|
||||
}
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO todos (
|
||||
project, subproject, title, text, adduser,
|
||||
@ -1270,7 +1282,7 @@ function addTodo(todoData) {
|
||||
todoData.adduser || '系统',
|
||||
todoData.exeuser || null,
|
||||
localDateTime,
|
||||
todoData.sche_time || localDateTime
|
||||
scheTime
|
||||
);
|
||||
|
||||
db.close();
|
||||
@ -1316,6 +1328,16 @@ function updateTodoStatus(id, completed, exeuser, title, text, sche_time) {
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
const localDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
|
||||
// 处理计划时间
|
||||
let scheTime = sche_time;
|
||||
if (scheTime) {
|
||||
// 如果sche_time是datetime-local格式(YYYY-MM-DDTHH:mm),转换为数据库格式
|
||||
if (scheTime.includes('T')) {
|
||||
const [datePart, timePart] = scheTime.split('T');
|
||||
scheTime = `${datePart} ${timePart}:00`;
|
||||
}
|
||||
}
|
||||
|
||||
const result = db.prepare(`
|
||||
UPDATE todos
|
||||
SET completed = ?,
|
||||
@ -1330,7 +1352,7 @@ function updateTodoStatus(id, completed, exeuser, title, text, sche_time) {
|
||||
exeuser || null,
|
||||
title,
|
||||
text || '',
|
||||
sche_time || null,
|
||||
scheTime || null,
|
||||
completed ? 1 : 0,
|
||||
completed ? localDateTime : null,
|
||||
id
|
||||
|
Loading…
x
Reference in New Issue
Block a user