-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/web/src/components/Setting/components/KeyboardShortcuts/KeyRow.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<SettingRow :title="props.title"> | ||
<a-input v-model="modelValue" class="!w-200px" @keydown="keydown" @keyup="keyup" /> | ||
</SettingRow> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import SettingRow from '../SettingRow/index.vue'; | ||
const modelValue = defineModel<string>(); | ||
const props = defineProps<{ | ||
title: string; | ||
keyText: string; | ||
}>(); | ||
let isWatch = false; | ||
watch( | ||
() => props.keyText, | ||
(v) => { | ||
if (isWatch) { | ||
modelValue.value = v; | ||
} | ||
} | ||
); | ||
function keydown() { | ||
isWatch = true; | ||
} | ||
function keyup() { | ||
isWatch = false; | ||
} | ||
</script> |
23 changes: 23 additions & 0 deletions
23
packages/web/src/components/Setting/components/KeyboardShortcuts/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<template> | ||
<div> | ||
<KeyRow v-model="settingStore.data.keyboardShortcuts.prevChapter" title="上一章" :key-text="keyText" /> | ||
<KeyRow v-model="settingStore.data.keyboardShortcuts.nextChapter" title="下一章" :key-text="keyText" /> | ||
<KeyRow v-model="settingStore.data.keyboardShortcuts.pageUp" title="上一屏" :key-text="keyText" /> | ||
<KeyRow v-model="settingStore.data.keyboardShortcuts.pageDown" title="下一屏" :key-text="keyText" /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useMagicKeys } from '@/hooks/useMagicKeys'; | ||
import { useSettingStore } from '@/stores/setting'; | ||
import KeyRow from './KeyRow.vue'; | ||
const { keyText } = useMagicKeys({ | ||
passive: false, | ||
onEventFired(e) { | ||
e.preventDefault(); | ||
} | ||
}); | ||
const settingStore = useSettingStore(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useMagicKeys as _useMagicKeys, type UseMagicKeysOptions } from '@vueuse/core'; | ||
|
||
export function useMagicKeys(option?: UseMagicKeysOptions<false> | undefined) { | ||
const aliasMap = { | ||
arrowup: '↑', | ||
arrowdown: '↓', | ||
arrowleft: '←', | ||
arrowright: '→', | ||
control: 'ctrl' | ||
}; | ||
|
||
const { current } = _useMagicKeys(option); | ||
|
||
// @ts-ignore | ||
const keyText = computed(() => [...current].map((key) => aliasMap[key] ?? key).join('+')); | ||
|
||
return { | ||
keyText | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { UseMagicKeysOptions } from '@vueuse/core'; | ||
import { useMagicKeys } from '@/hooks/useMagicKeys'; | ||
import { useSettingStore } from '@/stores/setting'; | ||
|
||
type KeyboardEvent = 'prevChapter' | 'nextChapter' | 'pageUp' | 'pageDown'; | ||
|
||
// 监听热键 | ||
export function useKeyboard(options: UseMagicKeysOptions<false> | undefined, cb: (arg: KeyboardEvent) => {}) { | ||
const settingStore = useSettingStore(); | ||
const { keyText } = useMagicKeys(options); | ||
|
||
const settingKeys = Object.keys(settingStore.data.keyboardShortcuts) as KeyboardEvent[]; | ||
watch(keyText, (text) => { | ||
for (const settingKey of settingKeys) { | ||
if (settingStore.data.keyboardShortcuts[settingKey] === text) { | ||
cb(settingKey); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.