Browse Source

fix: bug修复3

master
guoapeng 2 months ago
parent
commit
ab2d62fe2e
  1. 7
      src/index.css
  2. 61
      src/pages/Measure.tsx

7
src/index.css

@ -22,10 +22,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-color: var(--primaryColor); background-color: var(--primaryColor);
padding-left: 1rem;
padding-right: 1rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
padding: 0.25rem 1rem;
color: #fff; color: #fff;
cursor: pointer; cursor: pointer;
} }
@ -94,7 +91,7 @@ code {
opacity: 1; opacity: 1;
} }
.icon-button:active {
.active-icon-button {
opacity: 0.6; /* 按下变暗 */ opacity: 0.6; /* 按下变暗 */
transform: scale(0.9); /* 轻微缩小 */ transform: scale(0.9); /* 轻微缩小 */
} }

61
src/pages/Measure.tsx

@ -408,10 +408,18 @@ export default function Measure() {
} }
} }
} }
const [style, setStyle] = useState({
left: 'none',
right: 'none',
up: 'none',
down: 'none',
left_rotation:'none',
right_rotation:'none',
});
//上下移动 //上下移动
let timerRef = useRef<any>(null); let timerRef = useRef<any>(null);
const handlePressStart = (type: string) => { const handlePressStart = (type: string) => {
setStyle({...style, [type]: 'active'})
console.log('你进行了长按操作!'); console.log('你进行了长按操作!');
if (timerRef.current) { if (timerRef.current) {
return return
@ -424,6 +432,14 @@ export default function Measure() {
}; };
const handlePressEnd = () => { const handlePressEnd = () => {
setStyle({
left: 'none',
right: 'none',
up: 'none',
down: 'none',
left_rotation:'none',
right_rotation:'none',
})
clearInterval(timerRef.current); clearInterval(timerRef.current);
timerRef.current = null; timerRef.current = null;
}; };
@ -458,6 +474,7 @@ export default function Measure() {
}; };
const handleRotationPressStart = (type: string) => { const handleRotationPressStart = (type: string) => {
setStyle({...style, [type === 'left' ? 'left_rotation' : 'right_rotation']: 'active'})
timerRef.current = setInterval(() => { timerRef.current = setInterval(() => {
onRotationLine(type); onRotationLine(type);
}, 500); }, 500);
@ -575,8 +592,13 @@ export default function Measure() {
onClick={() => onMoveLine('left')} onClick={() => onMoveLine('left')}
onTouchStart={() => handlePressStart('left')} onTouchStart={() => handlePressStart('left')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.left === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="左移" alt="左移"
/> />
@ -586,8 +608,13 @@ export default function Measure() {
onClick={() => onMoveLine('right')} onClick={() => onMoveLine('right')}
onTouchStart={() => handlePressStart('right')} onTouchStart={() => handlePressStart('right')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.right === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="右移" alt="右移"
/> />
@ -597,8 +624,13 @@ export default function Measure() {
onClick={() => onMoveLine('up')} onClick={() => onMoveLine('up')}
onTouchStart={() => handlePressStart('up')} onTouchStart={() => handlePressStart('up')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.up === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="上移" alt="上移"
/> />
@ -608,8 +640,13 @@ export default function Measure() {
onClick={() => onMoveLine('down')} onClick={() => onMoveLine('down')}
onTouchStart={() => handlePressStart('down')} onTouchStart={() => handlePressStart('down')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.down === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="下移" alt="下移"
/> />
@ -619,8 +656,13 @@ export default function Measure() {
onClick={() => onRotationLine('left')} onClick={() => onRotationLine('left')}
onTouchStart={() => handleRotationPressStart('left')} onTouchStart={() => handleRotationPressStart('left')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.left_rotation === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="逆时针旋转" alt="逆时针旋转"
/> />
@ -630,8 +672,13 @@ export default function Measure() {
onClick={() => onRotationLine('right')} onClick={() => onRotationLine('right')}
onTouchStart={() => handleRotationPressStart('right')} onTouchStart={() => handleRotationPressStart('right')}
onTouchEnd={handlePressEnd} onTouchEnd={handlePressEnd}
onTouchCancel={handlePressEnd}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className="text-[20px] ml-[5px] icon-button"
className={
style.right_rotation === 'active'
? 'text-[20px] ml-[5px] icon-button active-icon-button'
: 'text-[20px] ml-[5px] icon-button'
}
alt="顺时针旋转" alt="顺时针旋转"
/> />
</section> </section>

Loading…
Cancel
Save