Skip to content

Commit fa988be

Browse files
committed
fix: cannot input
1 parent 07c3f4a commit fa988be

23 files changed

Lines changed: 192 additions & 153 deletions

File tree

apps/nuxt/app/pages/(articles)/practice-articles/[id].vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { addStat, setUserDictProp } from '@typewords/core/apis'
3-
import { BaseIcon, Tooltip, Toast } from '@typewords/base'
3+
import { BaseIcon, Toast, Tooltip } from '@typewords/base'
44
import ConflictNotice from '@typewords/core/components/dialog/ConflictNotice.vue'
55
import ArticleList from '@typewords/core/components/list/ArticleList.vue'
66
import Panel from '@typewords/core/components/Panel.vue'
@@ -9,11 +9,8 @@ import SettingDialog from '@typewords/core/components/setting/SettingDialog.vue'
99
import { AppEnv, DICT_LIST } from '@typewords/core/config/env.ts'
1010
import { genArticleSectionData, usePlayArticleTextAudio, usePlaySentenceAudio } from '@typewords/core/hooks/article.ts'
1111
import { useArticleOptions } from '@typewords/core/hooks/dict.ts'
12-
import {
13-
useDisableEventListener,
14-
useOnKeyboardEventListener,
15-
useStartKeyboardEventListener,
16-
} from '@typewords/core/hooks/event.ts'
12+
import { useOnKeyboardEventListener, useStartKeyboardEventListener } from '@typewords/core/hooks/event.ts'
13+
import { useDisableEventListener } from '@typewords/utils'
1714
import useTheme from '@typewords/core/hooks/theme.ts'
1815
import ArticleAudio from '@typewords/core/components/article/ArticleAudio.vue'
1916
import EditSingleArticleModal from '@typewords/core/components/article/EditSingleArticleModal.vue'
@@ -35,7 +32,7 @@ import {
3532
} from '@typewords/core/utils'
3633
import { getPracticeArticleCacheLocal } from '@typewords/core/utils/cache.ts'
3734
import { usePracticeArticlePersistence } from '@typewords/core/composables/usePracticePersistence'
38-
import { useEvents, emitter, EventKey } from '@typewords/core/utils/eventBus'
35+
import { emitter, EventKey, useEvents } from '@typewords/core/utils/eventBus'
3936
import { computed, onMounted, onUnmounted, provide, watch } from 'vue'
4037
import { useRoute, useRouter } from 'vue-router'
4138
import { DictType, PracticeArticleWordType, ShortcutKey } from '@typewords/core/types/enum.ts'
@@ -205,9 +202,7 @@ onMounted(() => {
205202
206203
async function unmount() {
207204
document.removeEventListener('visibilitychange', onvisibilitychange)
208-
209205
console.log('onUnmounted')
210-
window.disableEventListener = false
211206
const cache = await getPracticeArticleCacheLocal()
212207
//如果有缓存,则更新花费的时间;因为用户不输入不会保存数据
213208
if (cache) {
@@ -222,8 +217,6 @@ async function unmount() {
222217
223218
onUnmounted(unmount)
224219
225-
onDeactivated(unmount)
226-
227220
useStartKeyboardEventListener()
228221
useDisableEventListener(() => loading)
229222

apps/nuxt/app/pages/(words)/practice-words/[id].vue

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import { emitter, EventKey, useEvents } from '@typewords/core/utils/eventBus.ts'
55
import { useSettingStore } from '@typewords/core/stores/setting.ts'
66
import { useRuntimeStore } from '@typewords/core/stores/runtime.ts'
77
import type { Dict, PracticeData, TaskWords, Word } from '@typewords/core/types/types.ts'
8-
import {
9-
useDisableEventListener,
10-
useOnKeyboardEventListener,
11-
useStartKeyboardEventListener,
12-
} from '@typewords/core/hooks/event.ts'
8+
import { useStartKeyboardEventListener } from '@typewords/core/hooks/event.ts'
9+
import { useDisableEventListener } from '@typewords/utils'
1310
import useTheme from '@typewords/core/hooks/theme.ts'
1411
import { getCurrentStudyWord, useWordOptions } from '@typewords/core/hooks/dict.ts'
1512
import {
@@ -776,20 +773,6 @@ async function savePracticeDataIns(where?) {
776773
777774
const savePracticeData = debounce(savePracticeDataIns, 500)
778775
779-
function onKeyUp(e: KeyboardEvent) {
780-
// console.log('onKeyUp', e)
781-
typingRef.hideWord()
782-
}
783-
784-
function onKeyDown(e: KeyboardEvent) {
785-
// console.log('onKeyDown', e)
786-
switch (e.key) {
787-
case 'Backspace':
788-
typingRef.del()
789-
break
790-
}
791-
}
792-
793776
function repeat() {
794777
console.log('重学一遍')
795778
wordPersistence.clear()
@@ -920,8 +903,7 @@ function randomWrite() {
920903
}
921904
922905
useStartKeyboardEventListener()
923-
useDisableEventListener(() => loading)
924-
useOnKeyboardEventListener(onKeyDown, onKeyUp)
906+
// useDisableEventListener(() => loading)
925907
926908
watch(isIniting, n => {
927909
if (!n) {

apps/nuxt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@typewords/base": "workspace:*",
1818
"@typewords/libs": "workspace:*",
19-
"@typewords/core": "workspace:*"
19+
"@typewords/core": "workspace:*",
20+
"@typewords/utils": "workspace:*"
2021
}
2122
}

apps/vscode-web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@typewords/base": "workspace:*",
1717
"@typewords/libs": "workspace:*",
1818
"@typewords/core": "workspace:*",
19+
"@typewords/utils": "workspace:*",
1920
"jszip": "^3.10.1"
2021
},
2122
"config": {

apps/vscode-web/src/pages/(words)/practice-words/[id].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { useSettingStore } from '@typewords/core/stores/setting.ts'
66
import { useRuntimeStore } from '@typewords/core/stores/runtime.ts'
77
import type { Dict, PracticeData, TaskWords, Word } from '@typewords/core/types/types.ts'
88
import {
9-
useDisableEventListener,
109
useOnKeyboardEventListener,
1110
useStartKeyboardEventListener,
1211
} from '@typewords/core/hooks/event.ts'
12+
import { useDisableEventListener } from '@typewords/utils'
1313
import useTheme from '@typewords/core/hooks/theme.ts'
1414
import { getCurrentStudyWord, useWordOptions } from '@typewords/core/hooks/dict.ts'
1515
import {

packages/base/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"test": "echo \"Error: no test specified\" && exit 1"
1515
},
1616
"keywords": [],
17-
"author": ""
17+
"author": "",
18+
"dependencies": {
19+
"@typewords/utils": "workspace:*"
20+
}
1821
}

packages/base/src/BaseInput.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { ref, useAttrs, watch, computed, onUnmounted } from 'vue'
33
import Close from './icon/Close.vue'
4+
import { useDisableEventListener } from '@typewords/utils'
45
56
const props = defineProps({
67
modelValue: [String, Number],
@@ -36,17 +37,7 @@ let focus = $ref(false)
3637
let inputEl = $ref<HTMLDivElement>()
3738
const passwordVisible = ref(false)
3839
39-
//当聚焦时,禁用输入监听
40-
watch(
41-
() => focus,
42-
(n: any) => {
43-
window.disableEventListener = n
44-
}
45-
)
46-
47-
onUnmounted(() => {
48-
window.disableEventListener = false
49-
})
40+
useDisableEventListener(() => focus)
5041
5142
const inputType = computed(() => {
5243
if (props.type === 'password') {

packages/base/src/Textarea.vue

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
@blur="onBlur"
1616
/>
1717
<!-- 字数统计 -->
18-
<span
19-
v-if="showWordLimit && maxlength"
20-
class="absolute bottom-1 right-2 text-xs text-gray-400 select-none"
21-
>
18+
<span v-if="showWordLimit && maxlength" class="absolute bottom-1 right-2 text-xs text-gray-400 select-none">
2219
{{ innerValue.length }} / {{ maxlength }}
2320
</span>
2421
</div>
2522
</template>
2623

2724
<script setup lang="ts">
2825
import { ref, watch, computed, nextTick, onUnmounted } from 'vue'
26+
import { useDisableEventListener } from '@typewords/utils'
2927
3028
const props = defineProps<{
3129
modelValue: string
@@ -50,9 +48,7 @@ const textareaRef = ref<HTMLTextAreaElement>()
5048
5149
// 聚焦时禁用练习键盘事件监听,参照 BaseInput.vue 的处理方式
5250
const focus = ref(false)
53-
watch(focus, (n: boolean) => {
54-
;(window as any).disableEventListener = n
55-
})
51+
useDisableEventListener(focus)
5652
5753
const onFocus = (e: FocusEvent) => {
5854
focus.value = true
@@ -110,7 +106,6 @@ watch(
110106
{ immediate: true }
111107
)
112108
113-
114109
const vFocus = {
115110
mounted: (el, bind) => {
116111
if (bind.value) {
@@ -119,11 +114,6 @@ const vFocus = {
119114
}
120115
},
121116
}
122-
123-
onUnmounted(() => {
124-
window.disableEventListener = false
125-
})
126-
127117
</script>
128118
<style scoped lang="scss">
129119
.disabled {

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"author": "",
1717
"dependencies": {
1818
"@typewords/base": "workspace:*",
19-
"@typewords/libs": "workspace:*"
19+
"@typewords/libs": "workspace:*",
20+
"@typewords/utils": "workspace:*"
2021
},
2122
"devDependencies": {
2223
"unplugin-vue-macros": "^2.14.5",

packages/core/src/components/article/EditSingleArticleModal.vue

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<script setup lang="ts">
2-
3-
import type {Article} from '../../types';
4-
import {useDisableEventListener} from "../../hooks/event.ts";
5-
import EditArticle from "./EditArticle.vue";
6-
import {getDefaultArticle} from '../../types';
7-
import {defineAsyncComponent} from "vue";
2+
import type { Article } from '../../types'
3+
import { useDisableEventListener } from '@typewords/utils'
4+
import EditArticle from './EditArticle.vue'
5+
import { getDefaultArticle } from '../../types'
6+
import { defineAsyncComponent } from 'vue'
87
98
const Dialog = defineAsyncComponent(() => import('@typewords/base/Dialog'))
109
@@ -15,35 +14,25 @@ interface IProps {
1514
1615
const props = withDefaults(defineProps<IProps>(), {
1716
article: () => getDefaultArticle(),
18-
modelValue: false
17+
modelValue: false,
1918
})
2019
const emit = defineEmits<{
2120
save: [val: Article]
2221
'update:modelValue': [val: boolean]
2322
}>()
2423
2524
useDisableEventListener(() => props.modelValue)
26-
2725
</script>
2826

2927
<template>
30-
<Dialog
31-
:header="false"
32-
:model-value="props.modelValue"
33-
@close="emit('update:modelValue',false)"
34-
:full-screen="true"
35-
>
28+
<Dialog :header="false" :model-value="props.modelValue" @close="emit('update:modelValue', false)" :full-screen="true">
3629
<div class="wrapper">
37-
<EditArticle
38-
:article="article"
39-
@save="val => emit('save',val)"
40-
/>
30+
<EditArticle :article="article" @save="val => emit('save', val)" />
4131
</div>
4232
</Dialog>
4333
</template>
4434

4535
<style scoped lang="scss">
46-
4736
.wrapper {
4837
width: 100%;
4938
height: 100%;

0 commit comments

Comments
 (0)