fix(V0.2): 二轮评审 6 项 —— BUILD_ID 格式 / 菜单与详情精简 / 拖动重做 / 键盘统一方案
Docker Build and Push / build-image (push) Successful in 4m5s
Docker Build and Push / build-image (push) Successful in 4m5s
1. BUILD_ID 改为 yyyyMMddHHmmss (去掉中间点), 仍 UTC+8
2. 任务 ⋯ 菜单去掉顶部任务名标题
3. 任务详情去掉底部「拷贝到其他项目」「删除任务」按钮 (⋯ 菜单已有)
4+6. 键盘遮挡统一方案 (重点设计 §7.2):
- index.html 加 interactive-widget=resizes-content
- App 级 useKeyboardInsetWatcher 写 --kb-inset (visualViewport+window 双源)
- 底部弹层统一 .kb-safe 类 (安全区+20px+键盘插入量, dvh 收缩+内部滚动)
- TaskDetail/UserPicker/CopyTaskPopup/信息块弹层全部迁移, 删除 per-component hook
- 信息块 textarea 补 focus scrollIntoView 兜底
5. 拖动方案重做 (重点设计 §7.1):
- 新 useColumnDrag: Pointer Events + setPointerCapture, 长按400ms原位抬起,
elementFromPoint 高亮目标列, 边缘 rAF 自动横滚; 移除手指跟随浮层(任务名)
- 列表行长按 500ms → 「移动到列」ActionSheet (不做自由拖动)
- 移除「拖到卡片转子任务」误触路径, 统一走详情页层级区
- 删除旧 useLongPressDrag
已验证: 99 文件语法 0 错误、导入 0 缺失
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
// 看板卡片列拖动 (重点设计 §7.1, 2026-10-24 重做)
|
||||
// 方案要点 (替代旧版"手指跟随浮层 + 落点即子任务"的不可靠实现):
|
||||
// 1. Pointer Events + setPointerCapture —— 触摸/鼠标统一, 捕获后不丢事件
|
||||
// 2. 长按 400ms 激活 (先给滚动让路: 激活前移动 >10px 视为滚动并取消)
|
||||
// 3. 激活后卡片原位抬起 (不跟随手指, 无浮层/无任务名), touch-action 由捕获保证
|
||||
// 4. 拖动中持续 elementFromPoint 命中 [data-column-id] 高亮目标列;
|
||||
// 指针靠近容器左右边缘时自动横向滚动, 可拖到屏幕外的列
|
||||
// 5. 松手/取消(pointercancel 也要处理) → 落到目标列(≠原列)才提交;
|
||||
// 拖到卡片上不再转子任务 —— 统一走详情页「转为子任务」
|
||||
export default function useColumnDrag({ onDrop, scrollSelector = '.board-wrap' } = {}) {
|
||||
const [dragTask, setDragTask] = useState(null) // 拖动中的任务 (视觉态)
|
||||
const [overCol, setOverCol] = useState(null) // 高亮的目标列 id
|
||||
const st = useRef({ timer: null, active: false, startX: 0, startY: 0, task: null, autoScroll: 0, raf: 0 })
|
||||
|
||||
const stopAutoScroll = () => {
|
||||
st.current.autoScroll = 0
|
||||
if (st.current.raf) { cancelAnimationFrame(st.current.raf); st.current.raf = 0 }
|
||||
}
|
||||
|
||||
const cleanup = useCallback(() => {
|
||||
if (st.current.timer) { clearTimeout(st.current.timer); st.current.timer = null }
|
||||
st.current.active = false
|
||||
stopAutoScroll()
|
||||
setDragTask(null)
|
||||
setOverCol(null)
|
||||
}, [])
|
||||
|
||||
useEffect(() => () => cleanup(), [cleanup])
|
||||
|
||||
const hitColumn = (x, y) => {
|
||||
const el = document.elementFromPoint(x, y)
|
||||
const colEl = el?.closest?.('[data-column-id]')
|
||||
return colEl ? Number(colEl.dataset.columnId) : null
|
||||
}
|
||||
|
||||
// 边缘自动滚动 (±36px 触发, 每帧 10px)
|
||||
const autoScroll = (container, clientX) => {
|
||||
if (!container) { stopAutoScroll(); return }
|
||||
const r = container.getBoundingClientRect()
|
||||
const edge = 36
|
||||
let dir = 0
|
||||
if (clientX < r.left + edge) dir = -1
|
||||
else if (clientX > r.right - edge) dir = 1
|
||||
st.current.autoScroll = dir
|
||||
if (!dir) { stopAutoScroll(); return }
|
||||
if (st.current.raf) return
|
||||
const step = () => {
|
||||
if (!st.current.autoScroll) return
|
||||
container.scrollLeft += st.current.autoScroll * 10
|
||||
st.current.raf = requestAnimationFrame(step)
|
||||
}
|
||||
st.current.raf = requestAnimationFrame(step)
|
||||
}
|
||||
|
||||
const onPointerDown = (task) => (ev) => {
|
||||
if (ev.button !== undefined && ev.button !== 0) return
|
||||
st.current = { ...st.current, startX: ev.clientX, startY: ev.clientY, task, active: false }
|
||||
// 长按计时: 期间移动超容差(用户在滚动)则取消
|
||||
st.current.timer = setTimeout(() => {
|
||||
st.current.active = true
|
||||
setDragTask(task)
|
||||
if (navigator.vibrate) navigator.vibrate(15)
|
||||
}, 400)
|
||||
}
|
||||
|
||||
const onPointerMove = (ev) => {
|
||||
const s = st.current
|
||||
if (!s.active) {
|
||||
if (s.timer && (Math.abs(ev.clientX - s.startX) > 10 || Math.abs(ev.clientY - s.startY) > 10)) {
|
||||
clearTimeout(s.timer); s.timer = null
|
||||
}
|
||||
return
|
||||
}
|
||||
ev.preventDefault()
|
||||
const col = hitColumn(ev.clientX, ev.clientY)
|
||||
setOverCol(col)
|
||||
autoScroll(document.querySelector(scrollSelector), ev.clientX)
|
||||
}
|
||||
|
||||
const onPointerUp = (ev) => {
|
||||
const s = st.current
|
||||
if (s.active) {
|
||||
const col = hitColumn(ev.clientX, ev.clientY)
|
||||
if (col && s.task && col !== s.task.columnId) onDrop?.(s.task, col)
|
||||
}
|
||||
cleanup()
|
||||
}
|
||||
|
||||
/** 绑定到卡片: 需要卡片元素设置 touch-action: pan-y */
|
||||
const bind = useCallback((task) => ({
|
||||
onPointerDown: (ev) => {
|
||||
// 捕获前先让事件正常冒泡(点击等); 只做长按计时
|
||||
onPointerDown(task)(ev)
|
||||
// 捕获: 后续 move/up 都派发给该元素, 不丢
|
||||
try { ev.currentTarget.setPointerCapture(ev.pointerId) } catch { /* ignore */ }
|
||||
const el = ev.currentTarget
|
||||
const move = (e2) => onPointerMove(e2)
|
||||
const up = (e2) => {
|
||||
onPointerUp(e2)
|
||||
el.removeEventListener('pointermove', move)
|
||||
el.removeEventListener('pointerup', up)
|
||||
el.removeEventListener('pointercancel', up)
|
||||
}
|
||||
el.addEventListener('pointermove', move)
|
||||
el.addEventListener('pointerup', up)
|
||||
el.addEventListener('pointercancel', up)
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}), [])
|
||||
|
||||
return { dragTask, overCol, bind, cancel: cleanup }
|
||||
}
|
||||
Reference in New Issue
Block a user