From 9eeb1938a3b166c25d20b64c1f03b62f6bc8ee70 Mon Sep 17 00:00:00 2001 From: zyronon Date: Sat, 4 Nov 2023 02:39:40 +0800 Subject: [PATCH] Add custom shortcut keys --- components.d.ts | 6 - src/components/Modal/Modal.vue | 14 +- .../Practice/PracticeWord/TypingWord.vue | 61 ++-- src/components/Toolbar/DictModal.vue | 5 +- src/components/Toolbar/SettingModal.vue | 36 +-- src/components/Toolbar/Toolbar.vue | 1 - src/components/WordListModal.vue | 46 +-- src/hooks/event.ts | 91 ++++-- src/stores/setting.ts | 2 +- src/types.ts | 295 +++++++++--------- 10 files changed, 307 insertions(+), 250 deletions(-) diff --git a/components.d.ts b/components.d.ts index 0459c6fb..a61d2f4f 100644 --- a/components.d.ts +++ b/components.d.ts @@ -23,9 +23,6 @@ declare module 'vue' { EditArticle: typeof import('./src/components/Article/EditArticle.vue')['default'] EditBatchArticleModal: typeof import('./src/components/Article/EditBatchArticleModal.vue')['default'] EditSingleArticleModal: typeof import('./src/components/Article/EditSingleArticleModal.vue')['default'] - ElButton: typeof import('element-plus/es')['ElButton'] - ElForm: typeof import('element-plus/es')['ElForm'] - ElFormItem: typeof import('element-plus/es')['ElFormItem'] ElInput: typeof import('element-plus/es')['ElInput'] ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElOption: typeof import('element-plus/es')['ElOption'] @@ -68,7 +65,4 @@ declare module 'vue' { WordListModal: typeof import('./src/components/WordListModal.vue')['default'] WordListModal2: typeof import('./src/components/WordListModal2.vue')['default'] } - export interface ComponentCustomProperties { - vLoading: typeof import('element-plus/es')['ElLoadingDirective'] - } } diff --git a/src/components/Modal/Modal.vue b/src/components/Modal/Modal.vue index 5dd5cc4e..332496c8 100644 --- a/src/components/Modal/Modal.vue +++ b/src/components/Modal/Modal.vue @@ -17,7 +17,8 @@ export interface ModalProps { footer?: boolean header?: boolean confirmButtonText?: string - cancelButtonText?: string + cancelButtonText?: string, + keyboard?: boolean } const props = withDefaults(defineProps(), { @@ -28,6 +29,7 @@ const props = withDefaults(defineProps(), { header: true, confirmButtonText: '确认', cancelButtonText: '取消', + keyboard: true }) const emit = defineEmits([ @@ -67,7 +69,7 @@ function close() { visible = false resolve(true) let rIndex = runtimeStore.modalList.findIndex(item => item.id === id) - if (rIndex > 0) { + if (rIndex > -1) { runtimeStore.modalList.splice(rIndex, 1) } }, closeTime) @@ -79,7 +81,7 @@ watch(() => props.modelValue, n => { if (n) { id = Date.now() runtimeStore.modalList.push({id, close}) - zIndex = zIndex + runtimeStore.modalList.length + zIndex = 999 + runtimeStore.modalList.length visible = true } else { close() @@ -92,7 +94,7 @@ onMounted(() => { visible = true id = Date.now() runtimeStore.modalList.push({id, close}) - zIndex = zIndex + runtimeStore.modalList.length + zIndex = 999 + runtimeStore.modalList.length } }) @@ -100,14 +102,14 @@ onUnmounted(() => { if (props.modelValue === undefined) { visible = false let rIndex = runtimeStore.modalList.findIndex(item => item.id === id) - if (rIndex > 0) { + if (rIndex > -1) { runtimeStore.modalList.splice(rIndex, 1) } } }) useEventListener('keyup', (e: KeyboardEvent) => { - if (e.key === 'Escape') { + if (e.key === 'Escape' && props.keyboard) { let lastItem = runtimeStore.modalList[runtimeStore.modalList.length - 1] if (lastItem?.id === id) { close() diff --git a/src/components/Practice/PracticeWord/TypingWord.vue b/src/components/Practice/PracticeWord/TypingWord.vue index 3edc9dae..f1fca17d 100644 --- a/src/components/Practice/PracticeWord/TypingWord.vue +++ b/src/components/Practice/PracticeWord/TypingWord.vue @@ -1,8 +1,8 @@