diff --git a/src/api/task.js b/src/api/task.js index 70fdbb4..8ff0789 100644 --- a/src/api/task.js +++ b/src/api/task.js @@ -708,14 +708,16 @@ export const taskApi = { archive: async (id) => { const task = await db().getOptional('SELECT * FROM Task WHERE id = ?', [String(id)]) if (!task) throw new Error('任务不存在或无权限') - const now = now() + // 不能写 const now = now(): 同名 const 会遮蔽模块级 now, 右侧求值落入 TDZ, + // 压缩后报 "Cannot access 'a' before initialization" + const ts = now() await db().writeTransaction(async (tx) => { const kids = await tx.getAll('SELECT id FROM Task WHERE parentId = ?', [String(task.id)]) const ids = [String(task.id), ...kids.map((k) => String(k.id))] const ph = ids.map(() => '?').join(',') await tx.execute( `UPDATE Task SET archived = 1, archivedAt = ?, archiveSource = 'manual', updatedAt = ? WHERE id IN (${ph})`, - [now, now, ...ids], + [ts, ts, ...ids], ) }) return { ok: true, count: 1 } @@ -725,14 +727,14 @@ export const taskApi = { unarchive: async (id) => { const task = await db().getOptional('SELECT * FROM Task WHERE id = ?', [String(id)]) if (!task) throw new Error('任务不存在或无权限') - const now = now() + const ts = now() await db().writeTransaction(async (tx) => { const kids = await tx.getAll('SELECT id FROM Task WHERE parentId = ?', [String(task.id)]) const ids = [String(task.id), ...kids.map((k) => String(k.id))] const ph = ids.map(() => '?').join(',') await tx.execute( `UPDATE Task SET archived = 0, archivedAt = NULL, archiveSource = NULL, updatedAt = ? WHERE id IN (${ph})`, - [now, ...ids], + [ts, ...ids], ) }) return { ok: true, count: 1 }