forked from drone/command-center-dashboard

chenyao
2025-04-15 828f2f412b36e03384d62874d3283f05afa7d4ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<template>
    <div class="pointControl">
        <div class="direction">
            <div class="blackBg directionUp">
                <div v-for="item in upperRowButton" :key="item.text">
                    <el-icon :class="item.icon"></el-icon>
                    <div
                        :class="{ hotkeyBtn: true, activeKey: currentKey === item.text }"
                        @click="() => mousedown(item.text)"
                        v-hold="() => mousedown(item.text)"
                    >
                        {{ item.text }}
                    </div>
                </div>
            </div>
            <div class="blackBg directionDown">
                <div v-for="item in lowerRowButton" :key="item.text">
                    <el-icon :class="item.icon"></el-icon>
                    <div
                        :class="{ hotkeyBtn: true, activeKey: currentKey === item.text }"
                        @click="() => mousedown(item.text)"
                        v-hold="() => mousedown(item.text)"
                    >
                        {{ item.text }}
                    </div>
                </div>
            </div>
        </div>
 
        <ControlComPass />
 
        <div class="height-direction">
            <div class="blackBg height-direction-btn">
                <el-icon class="el-icon-top" />
                <div :class="{ hotkeyBtn: true, activeKey: currentKey === 'C' }" v-hold="() => mousedown('C')">C</div>
            </div>
            <div class="blackBg height-direction-btn">
                <div :class="{ hotkeyBtn: true, activeKey: currentKey === 'Z' }" v-hold="() => mousedown('Z')">Z</div>
                <el-icon class="el-icon-bottom" />
            </div>
        </div>
    </div>
</template>
<script setup>
import vHold from '@/directive/hold'
import ControlComPass from './ControlComPass/ControlComPass.vue'
 
const lowerRowButton = [
    { icon: 'el-icon-arrow-left', text: 'A' },
    { icon: 'el-icon-arrow-down', text: 'S' },
    { icon: 'el-icon-arrow-right', text: 'D' },
]
const upperRowButton = [
    { icon: 'el-icon-refresh-left', text: 'Q' },
    { icon: 'el-icon-arrow-up', text: 'W' },
    { icon: 'el-icon-refresh-right', text: 'E' },
]
let currentKey = ref('')
let keyReset = null
let visible = false
 
function mousedown(key) {
    if (key === 'Q') {
        console.log(6666666666)
    }
}
 
function handleKeydown(e) {
    currentKey.value = e.key.toUpperCase()
    mousedown(e.key.toUpperCase())
}
 
function handleKeyup() {
    currentKey.value = null
}
 
onMounted(() => {
    window.addEventListener('keydown', handleKeydown)
    window.addEventListener('keyup', handleKeyup)
})
onBeforeUnmount(() => {
    window.removeEventListener('keydown', handleKeydown)
    window.removeEventListener('keyup', handleKeyup)
})
</script>
 
<style scoped lang="scss">
.f-c {
    display: flex;
    align-items: center;
}
 
//变量
$FSColor: #00ee8b;
 
.hotkeyBtn {
    background: #3c3c3c;
    border-radius: 2px;
    width: 24px;
    height: 24px;
    font-size: 14px;
    line-height: 24px;
    text-align: center;
    color: #fff;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
 
    &:hover {
        background: $FSColor;
    }
}
 
.pointControl {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    color: white;
    gap: 0 10px;
    pointer-events: all;
    width: 100%;
    height: 200px;
 
    .activeKey {
        background: $FSColor;
    }
 
    .blackBg {
        background: rgba(0, 0, 0, 0.65);
        padding: 5px 5px;
        border-radius: 5px;
    }
 
    .direction {
        display: flex;
        flex-direction: column;
        width: 100px;
 
        .speedBox {
            color: $FSColor;
            font-size: 16px;
            font-weight: 600;
            margin: 5px 0;
            gap: 0 5px;
        }
 
        .editBox {
            display: flex;
            justify-content: end;
            gap: 0 5px;
            margin-bottom: 5px;
 
            .current-point {
                font-size: 20px;
                display: flex;
                align-items: center;
                color: $FSColor;
            }
 
            .editPointBtn {
                &:hover {
                    cursor: pointer;
                    background: $FSColor;
                }
            }
        }
 
        .directionUp,
        .directionDown {
            display: flex;
            justify-content: space-around;
            text-align: center;
            height: 55px;
 
            > div {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
            }
        }
    }
 
    .height-direction {
        width: 100px;
        display: flex;
        flex-direction: column;
        align-items: end;
        gap: 5px 0;
 
        .height-direction-btn {
            width: 35px;
            height: 55px;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }
    }
}
</style>