mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
修正字母水滴方向并增加未按下时的浅蓝定位指示
This commit is contained in:
+76
-15
@@ -430,22 +430,21 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
const bodyWebkitUserSelectRef = useRef("")
|
const bodyWebkitUserSelectRef = useRef("")
|
||||||
const [navActiveKey, setNavActiveKey] = useState<string | null>(null)
|
const [navActiveKey, setNavActiveKey] = useState<string | null>(null)
|
||||||
const [navIndicatorY, setNavIndicatorY] = useState(0)
|
const [navIndicatorY, setNavIndicatorY] = useState(0)
|
||||||
const [navIndicatorVisible, setNavIndicatorVisible] = useState(false)
|
const [isNavDraggingState, setIsNavDraggingState] = useState(false)
|
||||||
|
|
||||||
const setNavDraggingState = useCallback((dragging: boolean) => {
|
const setNavDraggingState = useCallback((dragging: boolean) => {
|
||||||
isNavDragging.current = dragging
|
isNavDragging.current = dragging
|
||||||
|
setIsNavDraggingState(dragging)
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
bodyUserSelectRef.current = document.body.style.userSelect
|
bodyUserSelectRef.current = document.body.style.userSelect
|
||||||
bodyWebkitUserSelectRef.current = document.body.style.webkitUserSelect
|
bodyWebkitUserSelectRef.current = document.body.style.webkitUserSelect
|
||||||
document.body.style.userSelect = "none"
|
document.body.style.userSelect = "none"
|
||||||
document.body.style.webkitUserSelect = "none"
|
document.body.style.webkitUserSelect = "none"
|
||||||
setNavIndicatorVisible(true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.style.userSelect = bodyUserSelectRef.current
|
document.body.style.userSelect = bodyUserSelectRef.current
|
||||||
document.body.style.webkitUserSelect = bodyWebkitUserSelectRef.current
|
document.body.style.webkitUserSelect = bodyWebkitUserSelectRef.current
|
||||||
setNavIndicatorVisible(false)
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleNavAction = useCallback(
|
const handleNavAction = useCallback(
|
||||||
@@ -520,6 +519,45 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!groupedStudents.length) {
|
||||||
|
setNavActiveKey(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshActiveByScroll = () => {
|
||||||
|
let currentKey = groupedStudents[0]?.key || null
|
||||||
|
const anchorY = 140
|
||||||
|
|
||||||
|
groupedStudents.forEach((group) => {
|
||||||
|
const el = groupRefs.current[group.key]
|
||||||
|
if (!el) return
|
||||||
|
const top = el.getBoundingClientRect().top
|
||||||
|
if (top <= anchorY) {
|
||||||
|
currentKey = group.key
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (currentKey) {
|
||||||
|
setNavActiveKey(currentKey)
|
||||||
|
const idx = groupedStudents.findIndex((g) => g.key === currentKey)
|
||||||
|
if (idx >= 0 && navContainerRef.current) {
|
||||||
|
const rect = navContainerRef.current.getBoundingClientRect()
|
||||||
|
const itemHeight = rect.height / groupedStudents.length
|
||||||
|
setNavIndicatorY((idx + 0.5) * itemHeight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshActiveByScroll()
|
||||||
|
window.addEventListener("scroll", refreshActiveByScroll, { passive: true })
|
||||||
|
window.addEventListener("resize", refreshActiveByScroll)
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("scroll", refreshActiveByScroll)
|
||||||
|
window.removeEventListener("resize", refreshActiveByScroll)
|
||||||
|
}
|
||||||
|
}, [groupedStudents])
|
||||||
|
|
||||||
const renderQuickNav = () => {
|
const renderQuickNav = () => {
|
||||||
if (
|
if (
|
||||||
groupedStudents.length <= 1 ||
|
groupedStudents.length <= 1 ||
|
||||||
@@ -555,18 +593,23 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
touchAction: "none",
|
touchAction: "none",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{navIndicatorVisible && navActiveKey && (
|
{navActiveKey && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
left: "-14px",
|
left: "-10px",
|
||||||
top: `${navIndicatorY}px`,
|
top: `${navIndicatorY}px`,
|
||||||
width: "34px",
|
width: "34px",
|
||||||
height: "34px",
|
height: "34px",
|
||||||
transform: "translate(-100%, -50%) rotate(-45deg)",
|
transform: "translate(-100%, -50%)",
|
||||||
borderRadius: "50% 50% 50% 4px",
|
borderRadius: "50%",
|
||||||
backgroundColor: "var(--ant-color-primary, #1890ff)",
|
backgroundColor: isNavDraggingState
|
||||||
boxShadow: "0 6px 16px rgba(0,0,0,0.2)",
|
? "var(--ant-color-primary, #1890ff)"
|
||||||
|
: "rgba(24, 144, 255, 0.16)",
|
||||||
|
border: isNavDraggingState
|
||||||
|
? "1px solid transparent"
|
||||||
|
: "1px solid rgba(24, 144, 255, 0.32)",
|
||||||
|
boxShadow: isNavDraggingState ? "0 6px 16px rgba(0,0,0,0.2)" : "none",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
@@ -574,12 +617,26 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
zIndex: 2,
|
zIndex: 2,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
right: "-4px",
|
||||||
|
top: "50%",
|
||||||
|
width: "10px",
|
||||||
|
height: "10px",
|
||||||
|
transform: "translateY(-50%) rotate(45deg)",
|
||||||
|
backgroundColor: isNavDraggingState
|
||||||
|
? "var(--ant-color-primary, #1890ff)"
|
||||||
|
: "rgba(24, 144, 255, 0.16)",
|
||||||
|
borderTop: isNavDraggingState ? "none" : "1px solid rgba(24, 144, 255, 0.32)",
|
||||||
|
borderRight: isNavDraggingState ? "none" : "1px solid rgba(24, 144, 255, 0.32)",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: "#fff",
|
color: isNavDraggingState ? "#fff" : "var(--ant-color-primary, #1890ff)",
|
||||||
fontSize: "13px",
|
fontSize: "13px",
|
||||||
fontWeight: 700,
|
fontWeight: 700,
|
||||||
transform: "rotate(45deg)",
|
|
||||||
lineHeight: 1,
|
lineHeight: 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -599,13 +656,17 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
fontSize: "11px",
|
fontSize: "11px",
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
color:
|
color:
|
||||||
navIndicatorVisible && navActiveKey === group.key
|
navActiveKey === group.key
|
||||||
? "#ffffff"
|
? isNavDraggingState
|
||||||
|
? "#ffffff"
|
||||||
|
: "var(--ant-color-primary, #1890ff)"
|
||||||
: "var(--ant-color-primary, #1890ff)",
|
: "var(--ant-color-primary, #1890ff)",
|
||||||
borderRadius: "50%",
|
borderRadius: "50%",
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
navIndicatorVisible && navActiveKey === group.key
|
navActiveKey === group.key
|
||||||
? "var(--ant-color-primary, #1890ff)"
|
? isNavDraggingState
|
||||||
|
? "var(--ant-color-primary, #1890ff)"
|
||||||
|
: "rgba(24, 144, 255, 0.36)"
|
||||||
: "transparent",
|
: "transparent",
|
||||||
pointerEvents: "none",
|
pointerEvents: "none",
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user