fix:optimize the article practice
This commit is contained in:
@@ -4,6 +4,7 @@ import nlp from "compromise/one";
|
||||
import {usePlayWordAudio} from "@/hooks/sound.ts";
|
||||
import {getSentenceAllText, getSentenceAllTranslateText} from "@/hooks/translate.ts";
|
||||
import {getDefaultArticleWord} from "@/types/func.ts";
|
||||
import {useSettingStore} from "@/stores/setting.ts";
|
||||
|
||||
interface KeyboardMap {
|
||||
Period: string,
|
||||
@@ -534,6 +535,7 @@ export function getTranslateText(article: Article) {
|
||||
|
||||
export function usePlaySentenceAudio() {
|
||||
const playWordAudio = usePlayWordAudio()
|
||||
const settingStore = useSettingStore()
|
||||
let timer = $ref(0)
|
||||
|
||||
function playSentenceAudio(sentence: Sentence, ref?: HTMLAudioElement, article?: Article) {
|
||||
@@ -543,6 +545,7 @@ export function usePlaySentenceAudio() {
|
||||
ref.pause()
|
||||
}
|
||||
let start = sentence.audioPosition[0];
|
||||
ref.volume = settingStore.wordSoundVolume / 100
|
||||
ref.currentTime = start
|
||||
ref.play()
|
||||
let end = sentence.audioPosition?.[1]
|
||||
|
||||
@@ -149,6 +149,7 @@ function setArticle(val: Article) {
|
||||
articleData.article.sections.map((v, i) => {
|
||||
v.map((w, j) => {
|
||||
w.words.map(s => {
|
||||
s.input = ''
|
||||
if (!ignoreList.includes(s.word.toLowerCase()) && !s.isSymbol) {
|
||||
statisticsStore.total++
|
||||
}
|
||||
@@ -188,6 +189,10 @@ function edit(val: Article = articleData.article) {
|
||||
|
||||
function wrong(word: Word) {
|
||||
let temp = word.word.toLowerCase();
|
||||
//过滤简单词
|
||||
if (settingStore.ignoreSimpleWord) {
|
||||
if (this.simpleWords.includes(temp)) return
|
||||
}
|
||||
if (!allWrongWords.has(word.word.toLowerCase())) {
|
||||
allWrongWords.add(word.word.toLowerCase())
|
||||
statisticsStore.wrong++
|
||||
@@ -277,6 +282,12 @@ onUnmounted(() => {
|
||||
let audioRef = $ref<HTMLAudioElement>()
|
||||
const {playSentenceAudio} = usePlaySentenceAudio()
|
||||
|
||||
function play2(e) {
|
||||
if (settingStore.wordSound || e.handle) {
|
||||
playSentenceAudio(e.sentence, audioRef, articleData.article)
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<PracticeLayout
|
||||
@@ -289,7 +300,7 @@ const {playSentenceAudio} = usePlaySentenceAudio()
|
||||
@wrong="wrong"
|
||||
@next="next"
|
||||
@nextWord="nextWord"
|
||||
@play="e => playSentenceAudio(e,audioRef,articleData.article)"
|
||||
@play="play2"
|
||||
:article="articleData.article"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -35,7 +35,10 @@ const props = withDefaults(defineProps<IProps>(), {
|
||||
const emit = defineEmits<{
|
||||
ignore: [],
|
||||
wrong: [val: Word],
|
||||
play: [val: Sentence],
|
||||
play: [val: {
|
||||
sentence: Sentence,
|
||||
handle: boolean
|
||||
}],
|
||||
nextWord: [val: ArticleWord],
|
||||
complete: [],
|
||||
next: [],
|
||||
@@ -180,10 +183,10 @@ function nextSentence() {
|
||||
isEnd = true
|
||||
emit('complete')
|
||||
} else {
|
||||
emit('play', props.article.sections[sectionIndex][0])
|
||||
emit('play', {sentence: props.article.sections[sectionIndex][0], handle: false})
|
||||
}
|
||||
} else {
|
||||
emit('play', currentSection[sentenceIndex])
|
||||
emit('play', {sentence: currentSection[sentenceIndex], handle: false})
|
||||
}
|
||||
lockNextSentence = false
|
||||
}
|
||||
@@ -224,7 +227,7 @@ function onTyping(e: KeyboardEvent) {
|
||||
playKeyboardAudio()
|
||||
} else {
|
||||
if (sectionIndex === 0 && sentenceIndex === 0 && wordIndex === 0 && stringIndex === 0) {
|
||||
emit('play', currentSection[sentenceIndex])
|
||||
emit('play', {sentence: currentSection[sentenceIndex], handle: false})
|
||||
}
|
||||
let letter = e.key
|
||||
|
||||
@@ -239,7 +242,7 @@ function onTyping(e: KeyboardEvent) {
|
||||
isRight = key === letter
|
||||
}
|
||||
if (!isRight) {
|
||||
if (!currentWord.isSymbol){
|
||||
if (!currentWord.isSymbol) {
|
||||
emit('wrong', currentWord)
|
||||
}
|
||||
playBeep()
|
||||
@@ -273,7 +276,7 @@ function onTyping(e: KeyboardEvent) {
|
||||
|
||||
function play() {
|
||||
let currentSection = props.article.sections[sectionIndex]
|
||||
emit('play', currentSection[sentenceIndex])
|
||||
emit('play', {sentence: currentSection[sentenceIndex], handle: true})
|
||||
}
|
||||
|
||||
function del() {
|
||||
@@ -347,13 +350,13 @@ function onContextMenu(e: MouseEvent, sentence: Sentence, i, j) {
|
||||
sentenceIndex = j
|
||||
wordIndex = 0
|
||||
stringIndex = 0
|
||||
emit('play', sentence)
|
||||
emit('play', {sentence: sentence, handle: false})
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "播放",
|
||||
onClick: () => {
|
||||
emit('play', sentence)
|
||||
emit('play', {sentence: sentence, handle: false})
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user