Skip to content

Commit 561ffb6

Browse files
committed
move the magic key dialog into a component
1 parent be307c5 commit 561ffb6

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

console/atest-ui/src/App.vue

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Guide,
1010
DataAnalysis, Help, Setting
1111
} from '@element-plus/icons-vue'
12-
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
12+
import { ref, watch } from 'vue'
1313
import { API } from './views/net'
1414
import { Cache } from './views/cache'
1515
import TestingPanel from './views/TestingPanel.vue'
@@ -19,6 +19,7 @@ import StoreManager from './views/StoreManager.vue'
1919
import SecretManager from './views/SecretManager.vue'
2020
import WelcomePage from './views/WelcomePage.vue'
2121
import DataManager from './views/DataManager.vue'
22+
import MagicKey from './components/MagicKey.vue'
2223
import { useI18n } from 'vue-i18n'
2324
2425
const { t, locale: i18nLocale } = useI18n()
@@ -98,21 +99,6 @@ const theme = ref(getTheme())
9899
watch(theme, (e) => {
99100
setTheme(e)
100101
})
101-
102-
const keyBindingsDialogVisible = ref(false)
103-
const keyBindings = ref([])
104-
const showKeyBindingsDialog = (keys: any) => {
105-
keyBindingsDialogVisible.value = true
106-
keyBindings.value = keys.detail || []
107-
}
108-
109-
onMounted(() => {
110-
window.addEventListener('show-key-bindings-dialog', showKeyBindingsDialog)
111-
})
112-
113-
onBeforeUnmount(() => {
114-
window.removeEventListener('show-key-bindings-dialog', showKeyBindingsDialog)
115-
})
116102
</script>
117103

118104
<template>
@@ -228,17 +214,7 @@ onBeforeUnmount(() => {
228214
</el-row>
229215
</el-dialog>
230216

231-
<el-drawer v-model="keyBindingsDialogVisible" size="50%">
232-
<template #header>
233-
<h4>{{ t('title.keyBindings') }}</h4>
234-
</template>
235-
<template #default>
236-
<el-table :data="keyBindings">
237-
<el-table-column prop="keys" label="Key" />
238-
<el-table-column prop="description" label="Description" />
239-
</el-table>
240-
</template>
241-
</el-drawer>
217+
<MagicKey />
242218
</template>
243219

244220
<style>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script setup lang="ts">
2+
import { ref, onMounted, onBeforeUnmount } from 'vue'
3+
import { useI18n } from 'vue-i18n'
4+
import { Magic } from '@/views/magicKeys'
5+
6+
const { t } = useI18n()
7+
const keyBindingsDialogVisible = ref(false)
8+
const keyBindings = ref([])
9+
const showKeyBindingsDialog = (keys: any) => {
10+
keyBindingsDialogVisible.value = true
11+
keyBindings.value = keys.detail || []
12+
}
13+
14+
onMounted(() => {
15+
window.addEventListener(Magic.MagicKeyEventName, showKeyBindingsDialog)
16+
})
17+
18+
onBeforeUnmount(() => {
19+
window.removeEventListener(Magic.MagicKeyEventName, showKeyBindingsDialog)
20+
})
21+
</script>
22+
23+
<template>
24+
<el-drawer v-model="keyBindingsDialogVisible" size="50%">
25+
<template #header>
26+
<h4>{{ t('title.keyBindings') }}</h4>
27+
</template>
28+
<template #default>
29+
<el-table :data="keyBindings">
30+
<el-table-column prop="keys" :label="t('field.shortcut')" />
31+
<el-table-column prop="description" :label="t('field.description')" />
32+
</el-table>
33+
</template>
34+
</el-drawer>
35+
</template>

console/atest-ui/src/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
"key": "Key",
8181
"value": "Value",
8282
"proxy": "Proxy",
83+
"shortcut": "Shortcut",
84+
"description": "Description",
8385
"insecure": "Insecure"
8486
},
8587
"proxy": {

console/atest-ui/src/locales/zh.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
"key": "",
7676
"value": "",
7777
"proxy": "代理",
78+
"shortcut": "快捷键",
79+
"description": "描述",
7880
"insecure": "忽略证书验证"
7981
},
8082
"proxy": {

console/atest-ui/src/views/magicKeys.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ interface MagicKey {
3333
Description?: string
3434
}
3535

36+
const MagicKeyEventName = 'show-key-bindings-dialog'
3637
const AdvancedKeys = (keys: MagicKey[]) => {
3738
keys.push({
3839
Keys: ['ctrl+/'],
3940
Func: () => {
40-
const event = new CustomEvent('show-key-bindings-dialog', {
41+
const event = new CustomEvent(MagicKeyEventName, {
4142
detail: keys.map((k) => ({
4243
keys: k.Keys.join(', '),
4344
description: k.Description ?? 'No description',
@@ -54,5 +55,5 @@ const AdvancedKeys = (keys: MagicKey[]) => {
5455
}
5556

5657
export const Magic = {
57-
Keys, AdvancedKeys
58+
Keys, AdvancedKeys, MagicKeyEventName
5859
}

0 commit comments

Comments
 (0)