This commit is contained in:
Zyronon
2025-10-12 03:37:34 +08:00
parent b36aaf2370
commit eac6fd6748
13 changed files with 123 additions and 57 deletions

View File

@@ -155,6 +155,8 @@ const weekList = $computed(() => {
const {data: recommendBookList, isFetching} = useFetch(resourceWrap(DICT_LIST.ARTICLE.RECOMMENDED)).json()
</script>
<template>

View File

@@ -20,7 +20,9 @@ import ArticleAudio from "@/pages/article/components/ArticleAudio.vue";
import { MessageBox } from "@/utils/MessageBox.tsx";
import { useSettingStore } from "@/stores/setting.ts";
import { useFetch } from "@vueuse/core";
import { DICT_LIST } from "@/config/env.ts";
import { CAN_REQUEST, DICT_LIST } from "@/config/env.ts";
import { detail } from "@/apis";
import { run } from "vue-tsc";
const runtimeStore = useRuntimeStore()
const settingStore = useSettingStore()
@@ -57,7 +59,7 @@ async function addMyStudyList() {
}
studyLoading = true
base.changeBook(sbook)
await base.changeBook(sbook)
studyLoading = false
window.umami?.track('startStudyArticle', {
@@ -83,17 +85,28 @@ async function init() {
} else {
if (!runtimeStore.editDict?.articles?.length
&& !runtimeStore.editDict?.custom
&& ![DictId.articleCollect].includes(runtimeStore.editDict.id)
&& ![DictId.articleCollect].includes(runtimeStore.editDict.en_name || runtimeStore.editDict.id)
) {
loading = true
let r = await _getDictDataByUrl(runtimeStore.editDict, DictType.article)
loading = false
runtimeStore.editDict = r
}
if (base.article.bookList.find(book => book.id === runtimeStore.editDict.id)) {
if (CAN_REQUEST) {
let res = await detail({id: runtimeStore.editDict.id})
if (res.success) {
runtimeStore.editDict.statistics = res.data.statistics
if (res.data.articles.length){
runtimeStore.editDict.articles = res.data.articles
}
}
}
}
if (runtimeStore.editDict.articles.length) {
selectArticle = runtimeStore.editDict.articles[0]
}
console.log('runtimeStore.editDict', runtimeStore.editDict)
}
}
}

View File

@@ -34,9 +34,12 @@ import { useRoute, useRouter } from "vue-router";
import PracticeLayout from "@/components/PracticeLayout.vue";
import ArticleAudio from "@/pages/article/components/ArticleAudio.vue";
import VolumeSetting from "@/pages/article/components/VolumeSetting.vue";
import { DICT_LIST, PracticeSaveArticleKey } from "@/config/env.ts";
import { CAN_REQUEST, DICT_LIST, PracticeSaveArticleKey } from "@/config/env.ts";
import { addStat, setDictProp } from "@/apis";
import { useRuntimeStore } from "@/stores/runtime.ts";
const store = useBaseStore()
const runtimeStore = useRuntimeStore()
const settingStore = useSettingStore()
const statStore = usePracticeStore()
const {toggleTheme} = useTheme()
@@ -106,10 +109,10 @@ async function init() {
let dictId = route.params.id
if (dictId) {
//先在自己的词典列表里面找,如果没有再在资源列表里面找
dict = store.article.bookList.find(v => v.id === dictId)
dict = store.article.bookList.find(v => v.id == dictId)
let r = await fetch(resourceWrap(DICT_LIST.ARTICLE.ALL))
let book_list = await r.json()
if (!dict) dict = book_list.flat().find(v => v.id === dictId) as Dict
if (!dict) dict = book_list.find(v => v.id === dictId) as Dict
if (dict && dict.id) {
//如果是不是自定义词典,就请求数据
if (!dict.custom) dict = await _getDictDataByUrl(dict, DictType.article)
@@ -117,7 +120,7 @@ async function init() {
router.push('/articles')
return Toast.warning('没有文章可学习!')
}
store.changeBook(dict)
await store.changeBook(dict)
articleData.list = cloneDeep(store.sbook.articles)
getCurrentPractice()
loading = false
@@ -143,6 +146,7 @@ onMounted(() => {
})
onUnmounted(() => {
runtimeStore.disableEventListener = false
clearInterval(timer)
savePracticeData(true, false)
})
@@ -234,21 +238,29 @@ function setArticle(val: Article) {
})
}
function complete() {
async function complete() {
clearInterval(timer)
setTimeout(() => {
localStorage.removeItem(PracticeSaveArticleKey.key)
}, 1500)
//todo 有空了改成实时保存
let data: Partial<Statistics> & { title: string, id: string } = {
id: articleData.article.id,
let data: Partial<Statistics> & { title: string, articleId: number } = {
articleId: articleData.article.id,
title: articleData.article.title,
spend: statStore.spend,
startDate: statStore.startDate,
total: statStore.total,
wrong: statStore.wrong,
}
if (CAN_REQUEST) {
let res = await addStat({...data, type: 'article'})
if (!res.success) {
Toast.error(res.msg)
}
}
let reportData = {
name: store.sbook.name,
index: store.sbook.lastLearnIndex,
@@ -271,7 +283,6 @@ function getCurrentPractice() {
emitter.emit(EventKey.resetWord)
let currentArticle = articleData.list[store.sbook.lastLearnIndex]
let article = getDefaultArticle(currentArticle)
// console.log('article', article)
if (article.sections.length) {
setArticle(article)
} else {
@@ -320,11 +331,18 @@ function nextWord(word: ArticleWord) {
}
}
function changeArticle(val: ArticleItem) {
async function changeArticle(val: ArticleItem) {
let rIndex = articleData.list.findIndex(v => v.id === val.item.id)
if (rIndex > -1) {
store.sbook.lastLearnIndex = rIndex
getCurrentPractice()
if (CAN_REQUEST) {
let res = await setDictProp(null, store.sbook)
if (!res.success) {
Toast.error(res.msg)
}
}
}
}

View File

@@ -51,11 +51,12 @@ const {data: dict_list, isFetching} = useFetch(resourceWrap(DICT_LIST.WORD.ALL))
const groupedByCategoryAndTag = $computed(() => {
let data = []
if (!dict_list.value) return data
const groupByCategory = groupBy(dict_list.value.flat(), 'category')
const groupByCategory = groupBy(dict_list.value, 'category')
for (const [key, value] of Object.entries(groupByCategory)) {
data.push([key, groupByDictTags(value)])
}
[data[2], data[3]] = [data[3], data[2]];
console.log('data',data)
return data
})
@@ -65,7 +66,7 @@ let searchKey = $ref('')
const searchList = computed<any[]>(() => {
if (searchKey) {
let s = searchKey.toLowerCase()
return dict_list.value.flat().filter((item) => {
return dict_list.value.filter((item) => {
return item.id.toLowerCase().includes(s)
|| item.name.toLowerCase().includes(s)
|| item.category.toLowerCase().includes(s)