|
|
@@ -1,6 +1,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue'
|
|
|
import { ptzControl } from '@/api/camera'
|
|
|
+import type { PTZAction } from '@/types'
|
|
|
|
|
|
const props = withDefaults(
|
|
|
defineProps<{
|
|
|
@@ -16,24 +17,28 @@ const isMoving = ref(false)
|
|
|
const currentDirection = ref<string | null>(null)
|
|
|
|
|
|
// 方向映射
|
|
|
-const directionToCommand: Record<string, string> = {
|
|
|
- UP: 'up',
|
|
|
- DOWN: 'down',
|
|
|
- LEFT: 'left',
|
|
|
- RIGHT: 'right',
|
|
|
- STOP: 'stop'
|
|
|
+const directionToAction: Record<string, PTZAction> = {
|
|
|
+ up: 'up',
|
|
|
+ down: 'down',
|
|
|
+ left: 'left',
|
|
|
+ right: 'right',
|
|
|
+ up_left: 'up_left',
|
|
|
+ up_right: 'up_right',
|
|
|
+ down_left: 'down_left',
|
|
|
+ down_right: 'down_right',
|
|
|
+ zoom_in: 'zoom_in',
|
|
|
+ zoom_out: 'zoom_out',
|
|
|
+ stop: 'stop'
|
|
|
}
|
|
|
|
|
|
// 开始移动
|
|
|
-async function handleStart(
|
|
|
- direction: 'UP' | 'DOWN' | 'LEFT' | 'RIGHT' | 'UP_LEFT' | 'UP_RIGHT' | 'DOWN_LEFT' | 'DOWN_RIGHT'
|
|
|
-) {
|
|
|
+async function handleStart(direction: PTZAction) {
|
|
|
if (isMoving.value || !props.cameraId) return
|
|
|
isMoving.value = true
|
|
|
currentDirection.value = direction
|
|
|
|
|
|
- const command = directionToCommand[direction] || 'stop'
|
|
|
- const result = await ptzControl({ cameraId: props.cameraId, command })
|
|
|
+ const command = directionToAction[direction]
|
|
|
+ const result = await ptzControl({ cameraId: props.cameraId, action: command })
|
|
|
if (!result.success) {
|
|
|
console.error('PTZ 控制失败:', result.errMsg)
|
|
|
}
|
|
|
@@ -43,7 +48,7 @@ async function handleStart(
|
|
|
async function handleStop() {
|
|
|
if (!isMoving.value || !props.cameraId) return
|
|
|
|
|
|
- const result = await ptzControl({ cameraId: props.cameraId, command: 'stop' })
|
|
|
+ const result = await ptzControl({ cameraId: props.cameraId, action: 'stop' })
|
|
|
if (!result.success) {
|
|
|
console.error('PTZ 停止失败:', result.errMsg)
|
|
|
}
|
|
|
@@ -57,15 +62,15 @@ async function handleStop() {
|
|
|
<div class="ptz-controller">
|
|
|
<div class="ptz-grid">
|
|
|
<!-- 第一行 -->
|
|
|
- <button class="ptz-btn corner" @mousedown="handleStart('UP_LEFT')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
+ <button class="ptz-btn corner" @mousedown="handleStart('up_left')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
<el-icon><i-ep-top-left /></el-icon>
|
|
|
</button>
|
|
|
- <button class="ptz-btn" @mousedown="handleStart('UP')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
+ <button class="ptz-btn" @mousedown="handleStart('up')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
<el-icon><i-ep-arrow-up /></el-icon>
|
|
|
</button>
|
|
|
<button
|
|
|
class="ptz-btn corner"
|
|
|
- @mousedown="handleStart('UP_RIGHT')"
|
|
|
+ @mousedown="handleStart('up_right')"
|
|
|
@mouseup="handleStop"
|
|
|
@mouseleave="handleStop"
|
|
|
>
|
|
|
@@ -73,32 +78,32 @@ async function handleStop() {
|
|
|
</button>
|
|
|
|
|
|
<!-- 第二行 -->
|
|
|
- <button class="ptz-btn" @mousedown="handleStart('LEFT')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
+ <button class="ptz-btn" @mousedown="handleStart('left')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
<el-icon><i-ep-arrow-left /></el-icon>
|
|
|
</button>
|
|
|
<div class="ptz-center">
|
|
|
<el-icon v-if="isMoving" class="spinning"><i-ep-loading /></el-icon>
|
|
|
<span v-else>PTZ</span>
|
|
|
</div>
|
|
|
- <button class="ptz-btn" @mousedown="handleStart('RIGHT')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
+ <button class="ptz-btn" @mousedown="handleStart('right')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
<el-icon><i-ep-arrow-right /></el-icon>
|
|
|
</button>
|
|
|
|
|
|
<!-- 第三行 -->
|
|
|
<button
|
|
|
class="ptz-btn corner"
|
|
|
- @mousedown="handleStart('DOWN_LEFT')"
|
|
|
+ @mousedown="handleStart('down_left')"
|
|
|
@mouseup="handleStop"
|
|
|
@mouseleave="handleStop"
|
|
|
>
|
|
|
<el-icon><i-ep-bottom-left /></el-icon>
|
|
|
</button>
|
|
|
- <button class="ptz-btn" @mousedown="handleStart('DOWN')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
+ <button class="ptz-btn" @mousedown="handleStart('down')" @mouseup="handleStop" @mouseleave="handleStop">
|
|
|
<el-icon><i-ep-arrow-down /></el-icon>
|
|
|
</button>
|
|
|
<button
|
|
|
class="ptz-btn corner"
|
|
|
- @mousedown="handleStart('DOWN_RIGHT')"
|
|
|
+ @mousedown="handleStart('down_right')"
|
|
|
@mouseup="handleStop"
|
|
|
@mouseleave="handleStop"
|
|
|
>
|
|
|
@@ -169,6 +174,7 @@ async function handleStop() {
|
|
|
from {
|
|
|
transform: rotate(0deg);
|
|
|
}
|
|
|
+
|
|
|
to {
|
|
|
transform: rotate(360deg);
|
|
|
}
|