Files
iboard/src/api/checkin.js
T
jif2.zhang 9467d4c242 feat(V0.2): 列表拖动修复 + 打卡项组内拖动排序
- 任务列表/看板拖动: 激活后用非 passive touchmove preventDefault 拦截浏览器滚动接管, 修复列表长按抬起后 pointercancel 导致无法真正拖动
- 打卡: 列表按周期分组展示(每天/每周/每月/每年), 长按拖动组内排序(上下落点指示), 新增 POST /checkin/habits/reorder 重写 sortOrder; 新建项排到末尾
- 打卡卡片加 touch-action/user-select 防长按误触; 拖动结束 350ms 内抑制点击余波
2026-10-25 00:06:44 +08:00

43 lines
2.2 KiB
JavaScript

import { api } from './client.js'
const q = (params) => {
const s = new URLSearchParams()
Object.entries(params || {}).forEach(([k, v]) => {
if (v !== undefined && v !== null && v !== '') s.set(k, v)
})
const str = s.toString()
return str ? '?' + str : ''
}
// 打卡 / 日历
export const checkinApi = {
habits: (date) => api('/checkin/habits' + q({ date })),
day: (date) => api('/checkin/day' + q({ date })),
calendar: (month) => api('/checkin/calendar' + q({ month })),
createHabit: (body) => api('/checkin/habits', { method: 'POST', body }),
updateHabit: (id, body) => api(`/checkin/habits/${id}`, { method: 'PUT', body }),
reorderHabits: (ids) => api('/checkin/habits/reorder', { method: 'POST', body: { ids } }),
deleteHabit: (id, hard) => api(`/checkin/habits/${id}${hard ? '?hard=1' : ''}`, { method: 'DELETE' }),
check: (id, date, note) => api(`/checkin/habits/${id}/check`, { method: 'POST', body: { date, note } }),
uncheck: (id, date) => api(`/checkin/habits/${id}/check` + q({ date }), { method: 'DELETE' }),
}
// 检查清单
export const checklistApi = {
lists: (archived) => api('/checklists' + q({ archived: archived ? 1 : 0 })),
list: (id) => api(`/checklists/${id}`),
create: (body) => api('/checklists', { method: 'POST', body }),
update: (id, body) => api(`/checklists/${id}`, { method: 'PUT', body }),
remove: (id) => api(`/checklists/${id}`, { method: 'DELETE' }),
duplicate: (id) => api(`/checklists/${id}/duplicate`, { method: 'POST', body: {} }),
addItem: (id, body) => api(`/checklists/${id}/items`, { method: 'POST', body }),
updateItem: (itemId, body) => api(`/checklists/items/${itemId}`, { method: 'PUT', body }),
removeItem: (itemId) => api(`/checklists/items/${itemId}`, { method: 'DELETE' }),
checkAll: (id, done) => api(`/checklists/${id}/check-all`, { method: 'POST', body: { done } }),
templates: () => api('/checklists/templates'),
template: (id) => api(`/checklists/templates/${id}`),
createTemplate: (body) => api('/checklists/templates', { method: 'POST', body }),
updateTemplate: (id, body) => api(`/checklists/templates/${id}`, { method: 'PUT', body }),
removeTemplate: (id) => api(`/checklists/templates/${id}`, { method: 'DELETE' }),
}