feat:修改复习时没有新词导致无法开始的bug;添加complete字段标记是否学完

This commit is contained in:
zyronon
2025-07-29 01:18:36 +08:00
parent bf34b055ce
commit f7dc9f207e
4 changed files with 47 additions and 15 deletions

View File

@@ -15,8 +15,14 @@ defineEmits<{
}>()
const progress = $computed(() => {
if (props.item.complete) return 100
return Number(((props.item?.lastLearnIndex / props.item?.length) * 100).toFixed())
})
const studyProgress = $computed(() => {
if (props.item.complete) return props.item?.length + '/'
return props.item?.lastLearnIndex ? props.item?.lastLearnIndex + '/' : ''
})
</script>
<template>
@@ -27,10 +33,10 @@ const progress = $computed(() => {
<div class="text-sm line-clamp-3" v-opacity="item.name !== item.description">{{ item?.description }}</div>
</div>
<div class="absolute bottom-4 right-4">
<div>{{ item?.lastLearnIndex ? item?.lastLearnIndex + '/' : '' }}{{ item?.length }}{{ quantifier }}</div>
<div>{{ studyProgress }}{{ item?.length }}{{ quantifier }}</div>
</div>
<div class="absolute bottom-2 left-4 right-4">
<el-progress v-if="item?.lastLearnIndex" class="mt-1"
<el-progress v-if="item?.lastLearnIndex || item.complete" class="mt-1"
:percentage="progress"
:show-text="false"></el-progress>
</div>

View File

@@ -19,10 +19,7 @@ const settingStore = useSettingStore()
const statStore = usePracticeStore()
const model = defineModel({default: false})
let list = $ref([])
defineProps<{
dictIsEnd: boolean;
}>()
let dictIsEnd = $ref(false)
function calcWeekList() {
// 获取本周的起止时间
@@ -62,6 +59,11 @@ watch(model, (newVal) => {
//这里不知为啥会卡,打开有延迟
requestIdleCallback(() => {
store.sdict.lastLearnIndex = store.sdict.lastLearnIndex + statStore.newWordNumber
if (store.sdict.lastLearnIndex >= store.sdict.length) {
dictIsEnd = true;
store.sdict.complete = true
store.sdict.lastLearnIndex = 0
}
store.sdict.statistics.push(data as any)
calcWeekList(); // 新增:计算本周学习记录
})

View File

@@ -75,7 +75,7 @@ onMounted(() => {
loading = false
})
})
}else {
} else {
router.push('/word')
}
} else {
@@ -88,20 +88,37 @@ onMounted(() => {
})
watch(() => studyData, () => {
data.words = studyData.new
if (studyData.new.length === 0) {
if (studyData.review.length) {
settingStore.dictation = false
statStore.step = 2
data.words = studyData.review
} else {
if (studyData.write.length) {
settingStore.dictation = true
data.words = studyData.write
statStore.step = 4
} else {
ElMessage.warning('没有可学习的单词!')
router.push('/word')
}
}
} else {
settingStore.dictation = false
data.words = studyData.new
statStore.step = 0
}
data.index = 0
data.wrongWords = []
allWrongWords = new Set()
settingStore.dictation = false
statStore.step = 0
statStore.startDate = Date.now()
statStore.inputWordNumber = 0
statStore.wrong = 0
statStore.total = studyData.review.concat(studyData.new).concat(studyData.write).length
statStore.total = studyData.review.length + studyData.new.length + studyData.write.length
statStore.newWordNumber = studyData.new.length
statStore.index = 0
}, {immediate: true, deep: true})
})
provide('studyData', data)
@@ -236,8 +253,14 @@ useOnKeyboardEventListener(onKeyDown, onKeyUp)
function repeat() {
console.log('重学一遍')
settingStore.dictation = false
//将学习进度减回去
store.sdict.lastLearnIndex = store.sdict.lastLearnIndex - statStore.newWordNumber
if (store.sdict.lastLearnIndex === 0 && store.sdict.complete) {
//如果是刚刚完成那么学习进度要从length减回去因为lastLearnIndex为0了同时改complete为false
store.sdict.lastLearnIndex = store.sdict.length - statStore.newWordNumber
store.sdict.complete = false
} else {
//将学习进度减回去
store.sdict.lastLearnIndex = store.sdict.lastLearnIndex - statStore.newWordNumber
}
emitter.emit(EventKey.resetWord)
let temp = cloneDeep(studyData)
//排除已掌握单词

View File

@@ -272,7 +272,8 @@ export interface Dict extends DictResource {
words: Word[],
articles: Article[],
statistics: Statistics[],
custom: boolean,
custom: boolean,//是否是自定义词典
complete: boolean,//是否学习完成学完了设为true然后lastLearnIndex重置
}
export interface ArticleItem {