This commit is contained in:
hansas
2025-09-12 14:44:30 +08:00
6 changed files with 70 additions and 34 deletions

View File

@@ -75,8 +75,8 @@ export function genArticleSectionData(article: Article): number {
nearSymbolPosition = 'end'
} else {
//TODO 可以优化成for+break
section.toReversed().map((sentenceItem, b) => {
sentenceItem.words.toReversed().map((wordItem, c) => {
section.slice().reverse().map((sentenceItem, b) => {
sentenceItem.words.slice().reverse().map((wordItem, c) => {
if (wordItem.symbolPosition !== '' && nearSymbolPosition === null) {
nearSymbolPosition = wordItem.symbolPosition
}
@@ -101,7 +101,7 @@ export function genArticleSectionData(article: Article): number {
word3.nextSpace = true
let addCurrent = false
sentence.words.toReversed().map((wordItem, c) => {
sentence.words.slice().reverse().map((wordItem, c) => {
if (wordItem.symbolPosition === 'start' && !addCurrent) {
addCurrent = true
}
@@ -335,8 +335,8 @@ Its none of your business, the young man said rudely. This is a private conversa
nearSymbolPosition = 'end'
} else {
//TODO 可以优化成for+break
section.toReversed().map((sentenceItem, b) => {
sentenceItem.words.toReversed().map((wordItem, c) => {
section.slice().reverse().map((sentenceItem, b) => {
sentenceItem.words.slice().reverse().map((wordItem, c) => {
if (wordItem.symbolPosition !== '' && nearSymbolPosition === null) {
nearSymbolPosition = wordItem.symbolPosition
}
@@ -361,7 +361,7 @@ Its none of your business, the young man said rudely. This is a private conversa
word3.nextSpace = true
let addCurrent = false
sentence.words.toReversed().map((wordItem, c) => {
sentence.words.slice().reverse().map((wordItem, c) => {
if (wordItem.symbolPosition === 'start' && !addCurrent) {
addCurrent = true
}

View File

@@ -133,7 +133,7 @@ export function getCurrentStudyWord() {
}
//从start往前取perDay个单词作为当前复习单词取到0为止
list = dict.words.slice(0, start).toReversed()
list = dict.words.slice(0, start).reverse()
for (let item of list) {
if (!ignoreList.includes(item.word.toLowerCase())) {
if (data.review.length < perDay) {
@@ -153,9 +153,9 @@ export function getCurrentStudyWord() {
// 上上次更早的单词
//默认只取start之前的单词
let candidateWords = dict.words.slice(0, start).toReversed()
let candidateWords = dict.words.slice(0, start).reverse()
//但如果已完成,则滚动取值
if (complete) candidateWords = candidateWords.concat(dict.words.slice(end).toReversed())
if (complete) candidateWords = candidateWords.concat(dict.words.slice(end).reverse())
candidateWords = candidateWords.filter(w => !ignoreList.includes(w.word.toLowerCase()));
// console.log(candidateWords.map(v => v.word))
//最终要获取的单词数量

View File

@@ -4,7 +4,7 @@ import {onMounted, onUnmounted, watch} from "vue";
import {useBaseStore} from "@/stores/base.ts";
import {emitter, EventKey, useEvents} from "@/utils/eventBus.ts";
import {useSettingStore} from "@/stores/setting.ts";
import {Article, ArticleItem, ArticleWord, Dict, DictType, ShortcutKey, Word} from "@/types/types.ts";
import {Article, ArticleItem, ArticleWord, Dict, DictType, ShortcutKey, Statistics, Word} from "@/types/types.ts";
import {useDisableEventListener, useOnKeyboardEventListener, useStartKeyboardEventListener} from "@/hooks/event.ts";
import useTheme from "@/hooks/theme.ts";
import Toast from '@/pages/pc/components/base/toast/Toast.ts'
@@ -27,16 +27,12 @@ import Switch from "@/pages/pc/components/base/Switch.vue";
const store = useBaseStore()
const settingStore = useSettingStore()
const statisticsStore = usePracticeStore()
const statStore = usePracticeStore()
const {toggleTheme} = useTheme()
let articleData = $ref({
list: [],
article: getDefaultArticle(),
sectionIndex: 0,
sentenceIndex: 0,
wordIndex: 0,
stringIndex: 0,
})
let showEditArticle = $ref(false)
let typingArticleRef = $ref<any>()
@@ -81,6 +77,7 @@ function toggleConciseMode() {
function next() {
if (store.sbook.lastLearnIndex >= articleData.list.length - 1) {
store.sbook.complete = true
store.sbook.lastLearnIndex = 0
//todo 这里应该弹窗
} else store.sbook.lastLearnIndex++
@@ -134,30 +131,51 @@ useStartKeyboardEventListener()
useDisableEventListener(() => loading)
function setArticle(val: Article) {
statisticsStore.inputWordNumber = 0
statisticsStore.wrong = 0
statisticsStore.total = 0
statisticsStore.startDate = Date.now()
statStore.wrong = 0
statStore.total = 0
statStore.startDate = Date.now()
allWrongWords = new Set()
articleData.list[store.sbook.lastLearnIndex] = val
articleData.article = val
articleData.sectionIndex = 0
articleData.sentenceIndex = 0
articleData.wordIndex = 0
articleData.stringIndex = 0
let ignoreList = [store.allIgnoreWords, store.knownWords][settingStore.ignoreSimpleWord ? 0 : 1]
articleData.article.sections.map((v, i) => {
v.map((w) => {
w.words.map(s => {
if (!ignoreList.includes(s.word.toLowerCase()) && !s.isSymbol) {
statisticsStore.total++
statStore.total++
}
})
})
})
}
function complete() {
//todo 有空了改成实时保存
statStore.spend = Date.now() - statStore.startDate
let data: Partial<Statistics> & { title: string, id: string } = {
id: articleData.article.id,
title: articleData.article.title,
spend: statStore.spend,
startDate: statStore.startDate,
total: statStore.total,
wrong: statStore.wrong,
}
let reportData = {
...data,
name: store.sbook.name,
spend: Number(statStore.spend / 1000 / 60).toFixed(1),
custom: store.sdict.custom,
complete: store.sdict.complete,
index: store.sdict.lastLearnIndex,
s: ''
}
reportData.s = `name:${store.sbook.name},title:${store.sbook.lastLearnIndex}.${data.title},spend:${Number(statStore.spend / 1000 / 60).toFixed(1)}`
window.umami?.track('studyWordArticle', reportData)
store.sbook.statistics.push(data as any)
console.log(data, reportData)
}
function getCurrentPractice() {
emitter.emit(EventKey.resetWord)
let currentArticle = articleData.list[store.sbook.lastLearnIndex]
@@ -195,7 +213,7 @@ function wrong(word: Word) {
}
if (!allWrongWords.has(word.word.toLowerCase())) {
allWrongWords.add(word.word.toLowerCase())
statisticsStore.wrong++
statStore.wrong++
}
if (!store.wrong.words.find((v: Word) => v.word.toLowerCase() === temp)) {
@@ -206,7 +224,7 @@ function wrong(word: Word) {
function nextWord(word: ArticleWord) {
if (!store.allIgnoreWords.includes(word.word.toLowerCase()) && !word.isSymbol) {
statisticsStore.inputWordNumber++
statStore.inputWordNumber++
}
}
@@ -271,7 +289,7 @@ let speedMinute = $ref(0)
let timer = $ref(0)
onMounted(() => {
timer = setInterval(() => {
speedMinute = Math.floor((Date.now() - statisticsStore.startDate) / 1000 / 60)
speedMinute = Math.floor((Date.now() - statStore.startDate) / 1000 / 60)
}, 1000)
})
@@ -301,6 +319,7 @@ function play2(e) {
@next="next"
@nextWord="nextWord"
@play="play2"
@complete="complete"
:article="articleData.article"
/>
</template>
@@ -351,7 +370,7 @@ function play2(e) {
</div>
<div class="row">
<div class="num center gap-1">
{{ statisticsStore.total }}
{{ statStore.total }}
<Tooltip>
<IconFluentQuestionCircle20Regular width="18"/>
<template #reference>

View File

@@ -368,7 +368,8 @@ function onContextMenu(e: MouseEvent, sentence: Sentence, i, j, w) {
onClick: () => {
sectionIndex = i
sentenceIndex = j
wordIndex = w
//todo 这里有可能是符号,要处理下
wordIndex = w + 1
stringIndex = 0
input = wrong = ''
isEnd = isSpace = false
@@ -442,6 +443,12 @@ function onContextMenu(e: MouseEvent, sentence: Sentence, i, j, w) {
})
}
},
{
label: "有道词典",
onClick: () => {
window.open(`https://www.youdao.com/result?word=${sentence.text}&lang=en`, '_blank')
}
},
]
});
}