feat: 确认/取消按钮跟随截图区域,显示在选择区右下角

This commit is contained in:
2026-07-16 09:20:30 +08:00
parent 7226bc3bf6
commit 89cc2e2447
+16 -4
View File
@@ -8,7 +8,7 @@
>
<canvas ref="canvasRef" class="screenshot-canvas"></canvas>
<div v-if="!hasSelection" class="screenshot-tip">拖动选择截图区域 · Esc取消</div>
<div v-else class="screenshot-actions" @mousedown.stop @mouseup.stop>
<div v-else class="screenshot-actions" :style="actionsStyle" @mousedown.stop @mouseup.stop>
<button class="action-btn confirm" @click="confirmCapture"> 确认</button>
<button class="action-btn cancel" @click="cancel"> 取消</button>
</div>
@@ -29,6 +29,21 @@ const state = {
const hasSelection = ref(false)
const isCapturing = ref(false)
const actionsStyle = computed(() => {
if (!hasSelection.value) return {}
const x = Math.min(state.startX, state.endX)
const y = Math.min(state.startY, state.endY)
const w = Math.abs(state.endX - state.startX)
const h = Math.abs(state.endY - state.startY)
const panelW = 160
const gap = 8
let left = x + w - panelW
let top = y + h + gap
if (left < 4) left = 4
if (top + 40 > window.innerHeight) top = y - 40 - gap
return { left: left + 'px', top: top + 'px', transform: 'none', bottom: 'auto' }
})
onMounted(() => {
document.addEventListener('keydown', onKeyDown)
})
@@ -172,9 +187,6 @@ function onKeyDown(e: KeyboardEvent) {
.screenshot-actions {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
pointer-events: auto;