feat:修改在学完状态下,单词任务的返回值
This commit is contained in:
@@ -93,32 +93,48 @@ export function getCurrentStudyWord() {
|
||||
let data = {new: [], review: [], write: []}
|
||||
let dict = store.sdict;
|
||||
if (dict.words?.length) {
|
||||
const getList = (startIndex: number, endIndex: number) => dict.words.slice(startIndex, endIndex)
|
||||
|
||||
const perDay = store.sdict.perDayStudyNumber;
|
||||
const totalNeed = perDay * 3;
|
||||
let start = dict.lastLearnIndex;
|
||||
let end = start + dict.perDayStudyNumber
|
||||
dict.words.slice(start, end).map(item => {
|
||||
if (!store.knownWords.includes(item.word)) {
|
||||
data.new.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
const getList = (startIndex: number, endIndex: number) => {
|
||||
return dict.words.slice(startIndex, endIndex)
|
||||
if (dict.complete) {
|
||||
//如果是已完成,那么把应该学的新词放到复习词组里面
|
||||
dict.words.slice(start, end).map(item => {
|
||||
if (!store.knownWords.includes(item.word)) {
|
||||
data.review.push(item)
|
||||
}
|
||||
})
|
||||
//如果起点index 减去总默写不足的话,那就直接从最后面取
|
||||
//todo 这里有空了,优化成往前滚动取值
|
||||
if (start - totalNeed < 0) {
|
||||
end = dict.length
|
||||
} else {
|
||||
end = start
|
||||
}
|
||||
} else {
|
||||
dict.words.slice(start, end).map(item => {
|
||||
if (!store.knownWords.includes(item.word)) {
|
||||
data.new.push(item)
|
||||
}
|
||||
})
|
||||
end = start
|
||||
start = start - dict.perDayStudyNumber
|
||||
if (start < 0) start = 0
|
||||
//取上一次学习的单词用于复习
|
||||
let list = getList(start, end)
|
||||
list.map(item => {
|
||||
if (!store.knownWords.includes(item.word)) {
|
||||
data.review.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
end = start
|
||||
}
|
||||
|
||||
end = start
|
||||
start = start - dict.perDayStudyNumber
|
||||
if (start < 0) start = 0
|
||||
//取上一次学习的单词用于复习
|
||||
let list = getList(start, end)
|
||||
list.map(item => {
|
||||
if (!store.knownWords.includes(item.word)) {
|
||||
data.review.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
// console.log(start,end)
|
||||
|
||||
// end = start
|
||||
// start = start - dict.perDayStudyNumber * 3
|
||||
// //在上次学习再往前取前3次学习的单词用于默写
|
||||
@@ -130,11 +146,9 @@ export function getCurrentStudyWord() {
|
||||
// })
|
||||
|
||||
//write数组放的是上上次之前的单词,总的数量为perDayStudyNumber * 3,取单词的规则为:从后往前取6个perDayStudyNumber的,越靠前的取的单词越多。
|
||||
end = start
|
||||
|
||||
// 上上次更早的单词
|
||||
if (end>0){
|
||||
const totalNeed = perDay * 3;
|
||||
if (end > 0) {
|
||||
const allWords = dict.words;
|
||||
const candidateWords = allWords.slice(0, end).filter(w => !store.knownWords.includes(w.word));
|
||||
|
||||
@@ -172,7 +186,6 @@ export function getCurrentStudyWord() {
|
||||
data.write = writeWords.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
// console.timeEnd()
|
||||
// console.log('data', data)
|
||||
return data
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
import Dialog from "@/pages/pc/components/dialog/Dialog.vue";
|
||||
import {useBaseStore} from "@/stores/base.ts";
|
||||
import BaseButton from "@/components/BaseButton.vue";
|
||||
import {ShortcutKey, Statistics, StudyData} from "@/types.ts";
|
||||
import {ShortcutKey, Statistics} from "@/types.ts";
|
||||
import {emitter, EventKey, useEvents} from "@/utils/eventBus.ts";
|
||||
import {Icon} from '@iconify/vue';
|
||||
import {useSettingStore} from "@/stores/setting.ts";
|
||||
import {usePracticeStore} from "@/stores/practice.ts";
|
||||
import dayjs from "dayjs";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
import {inject, watch} from "vue";
|
||||
import {watch} from "vue";
|
||||
|
||||
dayjs.extend(isBetween);
|
||||
|
||||
|
||||
const store = useBaseStore()
|
||||
const settingStore = useSettingStore()
|
||||
const statStore = usePracticeStore()
|
||||
@@ -49,6 +48,7 @@ function calcWeekList() {
|
||||
// 监听 model 弹窗打开时重新计算
|
||||
watch(model, (newVal) => {
|
||||
if (newVal) {
|
||||
dictIsEnd = false;
|
||||
let data: Statistics = {
|
||||
spend: statStore.spend,
|
||||
startDate: statStore.startDate,
|
||||
@@ -79,7 +79,7 @@ useEvents([
|
||||
])
|
||||
|
||||
function options(emitType: string) {
|
||||
model.value = false
|
||||
close()
|
||||
emitter.emit(EventKey[emitType])
|
||||
}
|
||||
|
||||
@@ -106,19 +106,14 @@ function options(emitType: string) {
|
||||
</div>
|
||||
<div class="flex-1 flex flex-col items-center">
|
||||
<div class="text-sm color-gray">默写数</div>
|
||||
<div class="text-4xl font-bold">{{
|
||||
statStore.newWordNumber
|
||||
}}
|
||||
</div>
|
||||
<div class="text-4xl font-bold">{{ statStore.newWordNumber }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xl text-center flex flex-col justify-around">
|
||||
<div>非常棒! 坚持了 <span class="color-green font-bold text-2xl">{{
|
||||
dayjs().diff(statStore.startDate, 'm')
|
||||
}}</span>
|
||||
分钟
|
||||
<div>非常棒! 坚持了 <span class="color-green font-bold text-2xl">
|
||||
{{ dayjs().diff(statStore.startDate, 'm') }}</span>分钟
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-center gap-10">
|
||||
|
||||
@@ -116,7 +116,7 @@ watch(() => studyData, () => {
|
||||
statStore.inputWordNumber = 0
|
||||
statStore.wrong = 0
|
||||
statStore.total = studyData.review.length + studyData.new.length + studyData.write.length
|
||||
statStore.newWordNumber = studyData.new.length
|
||||
statStore.newWordNumber = store.sdict.complete ? studyData.review.length : studyData.new.length
|
||||
statStore.index = 0
|
||||
})
|
||||
|
||||
@@ -327,15 +327,8 @@ function togglePanel() {
|
||||
}
|
||||
|
||||
function continueStudy() {
|
||||
if (dictIsEnd) {
|
||||
//todo 不知这样处理是否不妥?
|
||||
store.sdict.lastLearnIndex = 0
|
||||
settingStore.dictation = false
|
||||
studyData = getCurrentStudyWord()
|
||||
} else {
|
||||
settingStore.dictation = false
|
||||
studyData = getCurrentStudyWord()
|
||||
}
|
||||
settingStore.dictation = false
|
||||
studyData = getCurrentStudyWord()
|
||||
}
|
||||
|
||||
useEvents([
|
||||
@@ -450,7 +443,7 @@ useEvents([
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
<Statistics v-model="showStatDialog" :dictIsEnd="dictIsEnd"/>
|
||||
<Statistics v-model="showStatDialog"/>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -49,10 +49,13 @@ async function init() {
|
||||
|
||||
}
|
||||
|
||||
function study() {
|
||||
function startStudy() {
|
||||
// getCurrentStudyWord()
|
||||
// store.sdict.lastLearnIndex += 3
|
||||
// return
|
||||
// return store.sdict.lastLearnIndex = store.sdict.length - 1
|
||||
// store.sdict.complete = true
|
||||
// store.sdict.lastLearnIndex = 20
|
||||
// currentStudy = getCurrentStudyWord()
|
||||
// return
|
||||
// return store.sdict.lastLearnIndex = store.sdict.length - 1
|
||||
if (store.sdict.id) {
|
||||
if (!store.sdict.words.length) {
|
||||
@@ -166,6 +169,15 @@ function clickActivityEvent(e) {
|
||||
}
|
||||
}
|
||||
|
||||
const progressTextLeft = $computed(() => {
|
||||
if (store.sdict.complete) return '已学完,进入总复习阶段'
|
||||
return '已学习' + store.currentStudyProgress + '%'
|
||||
})
|
||||
const progressTextRight = $computed(() => {
|
||||
// if (store.sdict.complete) return store.sdict?.length
|
||||
return store.sdict?.lastLearnIndex
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@@ -183,10 +195,8 @@ function clickActivityEvent(e) {
|
||||
</div>
|
||||
<div class="">
|
||||
<div class="text-sm flex justify-between">
|
||||
已学习{{ store.currentStudyProgress }}%
|
||||
<span>{{ store.sdict.lastLearnIndex }} / {{
|
||||
store.sdict.words.length
|
||||
}}</span>
|
||||
<span>{{ progressTextLeft }}</span>
|
||||
<span>{{ progressTextRight }} / {{ store.sdict.words.length }}</span>
|
||||
</div>
|
||||
<el-progress class="mt-1" :percentage="store.currentStudyProgress" :show-text="false"></el-progress>
|
||||
</div>
|
||||
@@ -224,7 +234,7 @@ function clickActivityEvent(e) {
|
||||
个单词
|
||||
</div>
|
||||
<div class="rounded-xl bg-slate-800 flex items-center gap-2 py-3 px-5 text-white cursor-pointer"
|
||||
:class="store.sdict.name || 'opacity-70 cursor-not-allowed'" @click="study">
|
||||
:class="store.sdict.name || 'opacity-70 cursor-not-allowed'" @click="startStudy">
|
||||
<span>开始学习</span>
|
||||
<Icon icon="icons8:right-round" class="text-2xl"/>
|
||||
</div>
|
||||
|
||||
@@ -94,6 +94,7 @@ export const useBaseStore = defineStore('base', {
|
||||
},
|
||||
currentStudyProgress(): number {
|
||||
if (!this.sdict.words?.length) return 0
|
||||
if (this.sdict.complete) return 100
|
||||
return _getStudyProgress(this.sdict.lastLearnIndex, this.sdict.words?.length)
|
||||
},
|
||||
currentBook(): Dict {
|
||||
|
||||
Reference in New Issue
Block a user