feat:修改学习逻辑
This commit is contained in:
@@ -103,12 +103,12 @@ export function getCurrentStudyWord() {
|
||||
})
|
||||
|
||||
const getList = (startIndex: number, endIndex: number) => {
|
||||
if (startIndex < 0) startIndex = 0
|
||||
return dict.words.slice(startIndex, endIndex)
|
||||
}
|
||||
|
||||
end = start
|
||||
start = start - dict.perDayStudyNumber
|
||||
if (start < 0) start = 0
|
||||
//取上一次学习的单词用于复习
|
||||
let list = getList(start, end)
|
||||
list.map(item => {
|
||||
@@ -117,6 +117,8 @@ export function getCurrentStudyWord() {
|
||||
}
|
||||
})
|
||||
|
||||
console.log(start,end)
|
||||
|
||||
// end = start
|
||||
// start = start - dict.perDayStudyNumber * 3
|
||||
// //在上次学习再往前取前3次学习的单词用于默写
|
||||
@@ -129,44 +131,46 @@ export function getCurrentStudyWord() {
|
||||
|
||||
//write数组放的是上上次之前的单词,总的数量为perDayStudyNumber * 3,取单词的规则为:从后往前取6个perDayStudyNumber的,越靠前的取的单词越多。
|
||||
end = start
|
||||
const totalNeed = perDay * 3;
|
||||
const allWords = dict.words;
|
||||
|
||||
// 上上次更早的单词
|
||||
const candidateWords = allWords.slice(0, end).filter(w => !store.knownWords.includes(w.word));
|
||||
if (end>0){
|
||||
const totalNeed = perDay * 3;
|
||||
const allWords = dict.words;
|
||||
const candidateWords = allWords.slice(0, end).filter(w => !store.knownWords.includes(w.word));
|
||||
|
||||
// 分6组,每组 perDay 个
|
||||
const groupCount = 6;
|
||||
const groupSize = perDay;
|
||||
const groups: Word[][] = [];
|
||||
for (let i = 0; i < groupCount; i++) {
|
||||
const start = candidateWords.length - (i + 1) * groupSize;
|
||||
const end = candidateWords.length - i * groupSize;
|
||||
if (start < 0 && end <= 0) break;
|
||||
groups.unshift(candidateWords.slice(Math.max(0, start), Math.max(0, end)));
|
||||
// 分6组,每组 perDay 个
|
||||
const groupCount = 6;
|
||||
const groupSize = perDay;
|
||||
const groups: Word[][] = [];
|
||||
for (let i = 0; i < groupCount; i++) {
|
||||
const start = candidateWords.length - (i + 1) * groupSize;
|
||||
const end = candidateWords.length - i * groupSize;
|
||||
if (start < 0 && end <= 0) break;
|
||||
groups.unshift(candidateWords.slice(Math.max(0, start), Math.max(0, end)));
|
||||
}
|
||||
|
||||
// 分配数量,靠前组多,靠后组少
|
||||
// 例如分配比例 [1,2,3,4,5,6]
|
||||
const ratio = [1, 2, 3, 4, 5, 6];
|
||||
const ratioSum = ratio.reduce((a, b) => a + b, 0);
|
||||
const realRatio = ratio.map(r => Math.round(r * totalNeed / ratioSum));
|
||||
|
||||
// 按比例从每组取单词
|
||||
let writeWords: Word[] = [];
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
writeWords = writeWords.concat(groups[i].slice(-realRatio[i]));
|
||||
}
|
||||
// 如果数量不够,补足
|
||||
if (writeWords.length < totalNeed) {
|
||||
const extra = candidateWords.filter(w => !writeWords.includes(w)).slice(-(totalNeed - writeWords.length));
|
||||
writeWords = writeWords.concat(extra);
|
||||
}
|
||||
// 最终数量截断
|
||||
writeWords = writeWords.slice(-totalNeed);
|
||||
|
||||
//这里需要反转一下,越靠近今天的单词,越先练习
|
||||
data.write = writeWords.reverse();
|
||||
}
|
||||
|
||||
// 分配数量,靠前组多,靠后组少
|
||||
// 例如分配比例 [1,2,3,4,5,6]
|
||||
const ratio = [1, 2, 3, 4, 5, 6];
|
||||
const ratioSum = ratio.reduce((a, b) => a + b, 0);
|
||||
const realRatio = ratio.map(r => Math.round(r * totalNeed / ratioSum));
|
||||
|
||||
// 按比例从每组取单词
|
||||
let writeWords: Word[] = [];
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
writeWords = writeWords.concat(groups[i].slice(-realRatio[i]));
|
||||
}
|
||||
// 如果数量不够,补足
|
||||
if (writeWords.length < totalNeed) {
|
||||
const extra = candidateWords.filter(w => !writeWords.includes(w)).slice(-(totalNeed - writeWords.length));
|
||||
writeWords = writeWords.concat(extra);
|
||||
}
|
||||
// 最终数量截断
|
||||
writeWords = writeWords.slice(-totalNeed);
|
||||
|
||||
//这里需要反转一下,越靠近今天的单词,越先练习
|
||||
data.write = writeWords.reverse();
|
||||
}
|
||||
|
||||
// console.timeEnd()
|
||||
|
||||
@@ -13,7 +13,6 @@ import {inject, watch} from "vue";
|
||||
|
||||
dayjs.extend(isBetween);
|
||||
|
||||
let dictIsEnd = inject<boolean>('dictIsEnd')
|
||||
|
||||
const store = useBaseStore()
|
||||
const settingStore = useSettingStore()
|
||||
@@ -21,6 +20,9 @@ const statStore = usePracticeStore()
|
||||
const model = defineModel({default: false})
|
||||
let list = $ref([])
|
||||
|
||||
defineProps<{
|
||||
dictIsEnd: boolean;
|
||||
}>()
|
||||
|
||||
function calcWeekList() {
|
||||
// 获取本周的起止时间
|
||||
@@ -61,7 +63,6 @@ watch(model, (newVal) => {
|
||||
requestIdleCallback(() => {
|
||||
store.sdict.lastLearnIndex = store.sdict.lastLearnIndex + statStore.newWordNumber
|
||||
store.sdict.statistics.push(data as any)
|
||||
store.sdict.statistics.sort((a, b) => a.startDate - b.startDate)
|
||||
calcWeekList(); // 新增:计算本周学习记录
|
||||
})
|
||||
}
|
||||
@@ -89,7 +90,7 @@ function options(emitType: string) {
|
||||
:keyboard="false"
|
||||
:show-close="false"
|
||||
v-model="model">
|
||||
<div class="w-120 bg-white color-black p-6 relative flex flex-col gap-6">
|
||||
<div class="w-140 bg-white color-black p-6 relative flex flex-col gap-6">
|
||||
<div class="w-full flex flex-col justify-evenly">
|
||||
<div class="center text-2xl mb-2">已完成今日任务</div>
|
||||
<div class="flex">
|
||||
@@ -160,6 +161,9 @@ function options(emitType: string) {
|
||||
@click="options(EventKey.continueStudy)">
|
||||
{{ dictIsEnd ? '重新练习' : '再来一组' }}
|
||||
</BaseButton>
|
||||
<BaseButton @click="$router.back">
|
||||
返回主页
|
||||
</BaseButton>
|
||||
<BaseButton>
|
||||
分享
|
||||
</BaseButton>
|
||||
|
||||
@@ -71,6 +71,7 @@ watch(() => studyData, () => {
|
||||
data.wrongWords = []
|
||||
allWrongWords = new Set()
|
||||
|
||||
settingStore.dictation = false
|
||||
statStore.step = 0
|
||||
statStore.startDate = Date.now()
|
||||
statStore.inputWordNumber = 0
|
||||
@@ -86,7 +87,6 @@ const dictIsEnd = $computed(() => {
|
||||
})
|
||||
|
||||
provide('studyData', data)
|
||||
provide('dictIsEnd', dictIsEnd)
|
||||
|
||||
const word = $computed(() => {
|
||||
return data.words[data.index] ?? getDefaultWord()
|
||||
@@ -287,7 +287,10 @@ function togglePanel() {
|
||||
|
||||
function continueStudy() {
|
||||
if (dictIsEnd) {
|
||||
|
||||
//todo 不知这样处理是否不妥?
|
||||
store.sdict.lastLearnIndex = 0
|
||||
settingStore.dictation = false
|
||||
studyData = getCurrentStudyWord()
|
||||
} else {
|
||||
settingStore.dictation = false
|
||||
studyData = getCurrentStudyWord()
|
||||
@@ -406,7 +409,7 @@ useEvents([
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
<Statistics v-model="showStatDialog"/>
|
||||
<Statistics v-model="showStatDialog" :dictIsEnd="dictIsEnd"/>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -50,6 +50,10 @@ async function init() {
|
||||
}
|
||||
|
||||
function study() {
|
||||
// getCurrentStudyWord()
|
||||
// store.sdict.lastLearnIndex += 3
|
||||
// return
|
||||
// return store.sdict.lastLearnIndex = store.sdict.length - 1
|
||||
if (store.sdict.id) {
|
||||
if (!store.sdict.words.length) {
|
||||
return ElMessage.warning('没有单词可学习!')
|
||||
@@ -278,7 +282,7 @@ function clickActivityEvent(e) {
|
||||
<div class="center text-sm" :style="{ opacity: tempPerDayStudyNumber === 20 ? 1 : 0 }">
|
||||
推荐
|
||||
</div>
|
||||
<el-slider :min="3" :step="10" show-stops :marks="{ 10: '10', 200: '200' }" size="small" class="my-6"
|
||||
<el-slider :min="10" :step="10" show-stops :marks="{ 10: '10', 200: '200' }" size="small" class="my-6"
|
||||
:max="200" v-model="tempPerDayStudyNumber"/>
|
||||
<div class="flex gap-2 mb-2 mt-10 items-center">
|
||||
<div>预计</div>
|
||||
|
||||
Reference in New Issue
Block a user