feat(标签管理): 添加标签删除功能并优化界面样式

- 在后端添加删除标签的API端点,包含权限检查和级联删除
- 在前端添加标签删除按钮和确认对话框
- 优化标签管理界面的样式和交互体验
- 改进导航标签栏的设计
This commit is contained in:
sudomarcma
2025-06-26 17:57:20 +08:00
parent 1b85bd8011
commit 2ec03705d1
3 changed files with 98 additions and 22 deletions
+26 -1
View File
@@ -296,6 +296,32 @@ async function startServer() {
}
})
// NEW: DELETE a tag
app.delete('/api/managers/tags/:id', authenticateJWT, async (req, res) => {
try {
const { id } = req.params
// Optional: Check if the user is a manager before allowing deletion
if (req.user.role !== 'manager') {
return res.status(403).json({ message: 'Forbidden: Only managers can delete tags.' })
}
// Delete the tag from the 'tags' table.
// If 'worker_tags' table has ON DELETE CASCADE for tag_id,
// related entries in 'worker_tags' will automatically be removed.
const [result] = await db.execute('DELETE FROM tags WHERE id = ?', [id])
if (result.affectedRows === 0) {
return res.status(404).json({ message: 'Tag not found.' })
}
res.status(204).send() // 204 No Content for successful deletion
} catch (error) {
console.error('Delete tag error:', error)
res.status(500).json({ message: 'Database error deleting tag.' })
}
})
// POST to assign a tag to a worker
app.post('/api/managers/workers/:workerId/tags', authenticateJWT, async (req, res) => {
try {
@@ -484,7 +510,6 @@ async function startServer() {
return res.status(409).json({ message: `Worker is already clocked ${status}.` })
}
// --- THIS IS THE FIX ---
// Sanitize the timestamp from "YYYY-MM-DDTHH:mm" to "YYYY-MM-DD HH:mm"
const sanitizedTimestamp = timestamp.replace('T', ' ')
await db.execute(