Skip to content

Commit ea4c0d4

Browse files
authored
feat: add more shortcuts (#508)
Co-authored-by: rick <[email protected]>
1 parent 03a614a commit ea4c0d4

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

console/atest-ui/src/views/TestCase.vue

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import { Cache } from './cache'
99
import { API } from './net'
1010
import { UIAPI } from './net-vue'
1111
import type { TestCaseResponse } from './cache'
12+
import { Magic } from './magicKeys'
1213
import { useI18n } from 'vue-i18n'
1314
import { JSONPath } from 'jsonpath-plus'
1415
import { Codemirror } from 'vue-codemirror'
1516
import jsonlint from 'jsonlint-mod'
16-
import { useMagicKeys } from '@vueuse/core'
1717
18-
const keys = useMagicKeys()
19-
const keyAltS = keys['Alt+S']
2018
const { t } = useI18n()
2119
2220
const props = defineProps({
@@ -30,12 +28,6 @@ let querySuggestedAPIs = NewSuggestedAPIsQuery(Cache.GetCurrentStore().name!, pr
3028
const testResultActiveTab = ref(Cache.GetPreference().responseActiveTab)
3129
watch(testResultActiveTab, Cache.WatchResponseActiveTab)
3230
33-
watch(keyAltS, (v) => {
34-
if (v) {
35-
sendRequest()
36-
}
37-
})
38-
3931
const parameters = ref([] as Pair[])
4032
const requestLoading = ref(false)
4133
const testResult = ref({ header: [] as Pair[] } as TestResult)
@@ -47,6 +39,7 @@ const sendRequest = async () => {
4739
runTestCase()
4840
}
4941
}
42+
Magic.Keys(sendRequest, ['Alt+S', 'Alt+ß'])
5043
5144
const runTestCase = () => {
5245
requestLoading.value = true

console/atest-ui/src/views/TestSuite.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { NewSuggestedAPIsQuery, GetHTTPMethods } from './types'
88
import { Cache } from './cache'
99
import { useI18n } from 'vue-i18n'
1010
import { API } from './net'
11+
import { Magic } from './magicKeys'
1112
import { Codemirror } from 'vue-codemirror'
1213
import yaml from 'js-yaml'
1314
@@ -58,7 +59,7 @@ watch(props, () => {
5859
load()
5960
})
6061
61-
function save() {
62+
const save = () => {
6263
let oldImportPath = ''
6364
let hasImport = false
6465
if (suite.value.spec && suite.value.spec.rpc) {
@@ -94,6 +95,7 @@ function save() {
9495
}
9596
)
9697
}
98+
Magic.Keys(save, ['Alt+S', 'Alt+ß'])
9799
98100
const isFullScreen = ref(false)
99101
const dialogVisible = ref(false)
@@ -112,6 +114,7 @@ function openNewTestCaseDialog() {
112114
dialogVisible.value = true
113115
querySuggestedAPIs = NewSuggestedAPIsQuery(Cache.GetCurrentStore().name!, props.name!)
114116
}
117+
Magic.Keys(openNewTestCaseDialog, ['Alt+N', 'Alt+dead'])
115118
116119
const submitForm = async (formEl: FormInstance | undefined) => {
117120
if (!formEl) return
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2024 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { watch } from 'vue'
18+
import { useMagicKeys } from '@vueuse/core'
19+
20+
function Keys(func: () => void, keys: string[]) {
21+
const magicKeys = useMagicKeys()
22+
keys.forEach(k => {
23+
watch(magicKeys[k], (v) => {
24+
if (v) func()
25+
})
26+
})
27+
}
28+
29+
export const Magic = {
30+
Keys
31+
}

0 commit comments

Comments
 (0)