Skip to content
Closed

Dev #265

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions apps/nuxt/app/pages/(articles)/articles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ useHead({
title: APP_NAME + ' 文章',
})

const { nav } = useNav()
const {nav} = useNav()
const base = useBaseStore()
const store = useBaseStore()
const settingStore = useSettingStore()
Expand All @@ -50,7 +50,7 @@ watch(
init()
}
},
{ immediate: true }
{immediate: true}
)

async function onvisibilitychange() {
Expand All @@ -72,14 +72,38 @@ async function init() {
document.addEventListener('visibilitychange', onvisibilitychange)

if (AppEnv.CAN_REQUEST) {
let res = await myDictList({ type: 'article' })
let res = await myDictList({type: 'article'})
if (res.success) {
store.setState(Object.assign(store.$state, res.data))
}
}
if (store.article.studyIndex >= 1) {
let studyIndex = store.article.studyIndex
if (studyIndex >= 1) {
if (!store.sbook.custom && !store.sbook.articles.length) {
store.article.bookList[store.article.studyIndex] = await _getDictDataByUrl(store.sbook, DictType.article)
let dictList = await fetch(resourceWrap(DICT_LIST.ARTICLE.ALL)).then(r => r.json())
let dict = await _getDictDataByUrl(store.sbook, DictType.article)
let r = dictList.find(v => [v.enName, v.id].includes(store.sbook.id))
if (r) {
store.article.bookList[studyIndex].articles = dict.articles
store.article.bookList[studyIndex].id = r.id
store.article.bookList[studyIndex].enName = r.enName
store.article.bookList[studyIndex].cover = r.cover
store.article.bookList[studyIndex].category = r.category
store.article.bookList[studyIndex].tags = r.tags
store.article.bookList[studyIndex].url = r.url
store.article.bookList[studyIndex].description = r.description
store.article.bookList[studyIndex].name = r.name
} else {
store.article.bookList[studyIndex] = dict
}
store.article.bookList[studyIndex].length = dict.articles.length
let s = store.article.bookList[studyIndex]
if (s.lastLearnIndex > s.length) {
store.article.bookList[studyIndex].lastLearnIndex = s.length
store.article.bookList[studyIndex].complete = true
//todo 后续加上
// await resetCacheData()
}
}
}
const d = await articlePersistence.load()
Expand Down Expand Up @@ -110,7 +134,7 @@ watch(
text: `下一步(7/${TourConfig.total})`,
action() {
tour.next()
nav('/practice-articles/article_nce2', { guide: 1 })
nav('/practice-articles/article_nce2', {guide: 1})
},
},
],
Expand All @@ -123,7 +147,7 @@ watch(
}, 500)
}
},
{ immediate: true }
{immediate: true}
)

function startStudy() {
Expand Down Expand Up @@ -231,7 +255,7 @@ const weekList = $computed(() => {
return list
})

const { data: recommendBookList, isFetching } = useFetch(resourceWrap(DICT_LIST.ARTICLE.RECOMMENDED)).json()
const {data: recommendBookList, isFetching} = useFetch(resourceWrap(DICT_LIST.ARTICLE.RECOMMENDED)).json()

let isOldHost = $ref(false)
onMounted(() => {
Expand All @@ -257,7 +281,7 @@ onMounted(() => {
:show-progress="false"
@click="goBookDetail(base.sbook)"
/>
<Book v-else :is-add="true" @click="router.push('/book-list')" />
<Book v-else :is-add="true" @click="router.push('/book-list')"/>
</div>
<div class="flex-1">
<div class="flex justify-between items-start">
Expand Down Expand Up @@ -310,7 +334,7 @@ onMounted(() => {
<BaseButton size="large" class="w-full md:w-auto" @click="startStudy" :disabled="!base.sbook.name">
<div class="flex items-center gap-2 justify-center w-full">
<span class="line-height-[2]">{{ isSaveData ? $t('continue_learning') : $t('start_learning') }}</span>
<IconFluentArrowCircleRight16Regular class="text-xl" />
<IconFluentArrowCircleRight16Regular class="text-xl"/>
</div>
</BaseButton>
</div>
Expand All @@ -323,7 +347,7 @@ onMounted(() => {
<div class="flex gap-4 items-center">
<PopConfirm title="确认删除所有选中书籍?" @confirm="handleBatchDel" v-if="selectIds.length">
<BaseIcon class="del" :title="$t('delete')">
<DeleteIcon />
<DeleteIcon/>
</BaseIcon>
</PopConfirm>

Expand Down Expand Up @@ -356,7 +380,7 @@ onMounted(() => {
v-for="(item, j) in base.article.bookList"
@click="goBookDetail(item)"
/>
<Book :is-add="true" @click="router.push('/book-list')" />
<Book :is-add="true" @click="router.push('/book-list')"/>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion apps/nuxt/app/pages/(words)/dict-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const groupedByCategoryAndTag = $computed(() => {
for (const [key, value] of Object.entries(groupByCategory)) {
data.push([key, groupByDictTags(value)])
}
;[data[2], data[3]] = [data[3], data[2]]
// ;[data[2], data[3]] = [data[3], data[2]]
// console.log('data', data)
return data
})
Expand Down
73 changes: 49 additions & 24 deletions apps/nuxt/app/pages/(words)/words.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
useNav,
} from '@typewords/core/utils'
import type { DictResource, Statistics } from '@typewords/core/types/types.ts'
import { watch } from 'vue'
import { shallowReactive, watch } from 'vue'
import { getCurrentStudyWord } from '@typewords/core/hooks/dict.ts'
import { useRuntimeStore } from '@typewords/core/stores/runtime.ts'
import Book from '@typewords/core/components/Book.vue'
Expand Down Expand Up @@ -62,7 +62,7 @@ const settingStore = useSettingStore()
const wordPersistence = usePracticeWordPersistence()
const dataSync = useDataSyncPersistence()
const router = useRouter()
const { nav } = useNav()
const {nav} = useNav()
const runtimeStore = useRuntimeStore()
let loading = $ref(true)
let isSaveData = $ref(false)
Expand Down Expand Up @@ -125,7 +125,7 @@ watch(
}, 500)
}
}),
{ immediate: true }
{immediate: true}
)

async function onvisibilitychange() {
Expand All @@ -141,7 +141,7 @@ async function onvisibilitychange() {

async function init() {
if (AppEnv.CAN_REQUEST) {
let res = await myDictList({ type: 'word' })
let res = await myDictList({type: 'word'})
if (res.success) {
store.setState(Object.assign(store.$state, res.data))
}
Expand All @@ -150,9 +150,32 @@ async function init() {
document.removeEventListener('visibilitychange', onvisibilitychange)
document.addEventListener('visibilitychange', onvisibilitychange)

if (store.word.studyIndex >= 3) {
let studyIndex = store.word.studyIndex;
if (studyIndex >= 3) {
if (!store.sdict.custom && !store.sdict.words.length) {
store.word.bookList[store.word.studyIndex] = await _getDictDataByUrl(store.sdict)
let dictList = await fetch(resourceWrap(DICT_LIST.WORD.ALL)).then(r => r.json())
let dict = await _getDictDataByUrl(store.sdict)
let r = dictList.find(v => [v.enName, v.id].includes(store.sdict.id))
if (r) {
store.word.bookList[studyIndex].words = dict.words
store.word.bookList[studyIndex].id = r.id
store.word.bookList[studyIndex].enName = r.enName
store.word.bookList[studyIndex].cover = r.cover
store.word.bookList[studyIndex].category = r.category
store.word.bookList[studyIndex].tags = r.tags
store.word.bookList[studyIndex].url = r.url
store.word.bookList[studyIndex].description = r.description
store.word.bookList[studyIndex].name = r.name
} else {
store.word.bookList[studyIndex] = dict
}
store.word.bookList[studyIndex].length = dict.words.length
let s = store.word.bookList[studyIndex]
if (s.lastLearnIndex > s.length) {
store.word.bookList[studyIndex].lastLearnIndex = s.length
store.word.bookList[studyIndex].complete = true
await resetCacheData()
}
}
}

Expand Down Expand Up @@ -205,6 +228,7 @@ async function startPractice(practiceMode: WordPracticeMode, resetCache: boolean
function freePractice() {
startPractice(WordPracticeMode.Free, settingStore.wordPracticeMode !== WordPracticeMode.Free)
}

function systemPractice() {
startPractice(
settingStore.wordPracticeMode === WordPracticeMode.Free ? WordPracticeMode.System : settingStore.wordPracticeMode,
Expand Down Expand Up @@ -308,7 +332,7 @@ function onSelectCalendarDate(dateKey: string) {
for (const book of store.word.bookList) {
for (const stat of book.statistics ?? []) {
if (dayjs(stat.startDate).format('YYYY-MM-DD') === dateKey) {
rows.push({ ...stat, dictName: book.name })
rows.push({...stat, dictName: book.name})
}
}
}
Expand Down Expand Up @@ -450,7 +474,7 @@ async function saveLastPracticeIndex(e) {
Toast.success('修改成功')
}

const { data: recommendDictList, isFetching } = useFetch(resourceWrap(DICT_LIST.WORD.RECOMMENDED)).json()
const {data: recommendDictList, isFetching} = useFetch(resourceWrap(DICT_LIST.WORD.RECOMMENDED)).json()

const systemPracticeText = $computed(() => {
if (settingStore.wordPracticeMode === WordPracticeMode.Free) {
Expand Down Expand Up @@ -484,7 +508,7 @@ onUnmounted(() => {
<div class="flex-1 flex flex-col justify-between">
<div class="flex gap-3">
<div class="p-1 center rounded-full bg-white">
<IconFluentBookNumber20Filled class="text-xl color-link" />
<IconFluentBookNumber20Filled class="text-xl color-link"/>
</div>
<div @click="goDictDetail(store.sdict)" class="text-2xl font-bold cursor-pointer">
{{ store.sdict.name || $t('no_dict_selected') }}
Expand Down Expand Up @@ -513,7 +537,7 @@ onUnmounted(() => {
<div class="flex items-center mt-4 gap-4">
<BaseButton type="info" size="small" @click="router.push('/dict-list')">
<div class="center gap-1">
<IconFluentArrowSwap20Regular />
<IconFluentArrowSwap20Regular/>
<span>{{ $t('select_dict') }}</span>
</div>
</BaseButton>
Expand All @@ -524,21 +548,21 @@ onUnmounted(() => {
>
<BaseButton type="info" size="small" v-if="store.sdict.id">
<div class="center gap-1">
<IconFluentSlideTextTitleEdit20Regular />
<IconFluentSlideTextTitleEdit20Regular/>
<span>{{ $t('change_progress') }}</span>
</div>
</BaseButton>
</PopConfirm>

<BaseButton type="info" size="small" @click="router.push('/fsrs')"> 学习记录 </BaseButton>
<BaseButton type="info" size="small" @click="router.push('/fsrs')"> 学习记录</BaseButton>
</div>
</template>

<div class="flex items-center gap-4 mt-2 flex-1" v-else>
<div class="title">{{ $t('select_dict_to_start') }}</div>
<BaseButton id="step1" type="primary" size="large" @click="router.push('/dict-list')">
<div class="center gap-1">
<IconFluentAdd16Regular />
<IconFluentAdd16Regular/>
<span>{{ $t('select_dict') }}</span>
</div>
</BaseButton>
Expand All @@ -548,14 +572,14 @@ onUnmounted(() => {
<div class="flex justify-between">
<div class="flex items-center gap-2">
<div class="p-2 center rounded-full bg-white">
<IconFluentStar20Filled class="text-lg color-amber" />
<IconFluentStar20Filled class="text-lg color-amber"/>
</div>
<div class="text-xl font-bold">
{{ isSaveData ? $t('last_task') : $t('today_task') }}
</div>
<span class="color-link cursor-pointer" v-if="store.sdict.id" @click="showPracticeWordListDialog = true">{{
$t('word_list')
}}</span>
$t('word_list')
}}</span>
</div>
<div class="flex gap-1 items-center" v-if="store.sdict.id">
{{ $t('daily_goal') }}
Expand All @@ -568,7 +592,7 @@ onUnmounted(() => {
title="当前存在未完成的学习任务,修改会重新生成学习任务,是否继续?"
@confirm="check(() => (showPracticeSettingDialog = true))"
>
<BaseButton type="info" size="small">{{ $t('change') }} </BaseButton>
<BaseButton type="info" size="small">{{ $t('change') }}</BaseButton>
</PopConfirm>
</div>
</div>
Expand All @@ -595,7 +619,7 @@ onUnmounted(() => {
>
<div class="flex items-center gap-2">
<span class="line-height-[2]">{{ systemPracticeText }}</span>
<IconFluentArrowCircleRight16Regular class="text-xl" />
<IconFluentArrowCircleRight16Regular class="text-xl"/>
</div>
</BaseButton>
<template #options>
Expand Down Expand Up @@ -682,7 +706,7 @@ onUnmounted(() => {
: $t('free_practice')
}}
</span>
<IconStreamlineColorPenDrawFlat class="text-xl" />
<IconStreamlineColorPenDrawFlat class="text-xl"/>
</div>
</BaseButton>
</div>
Expand Down Expand Up @@ -723,7 +747,7 @@ onUnmounted(() => {
<div class="flex gap-4 items-center">
<PopConfirm title="确认删除所有选中词典?" @confirm="handleBatchDel" v-if="selectIds.length">
<BaseIcon class="del" :title="$t('delete')">
<DeleteIcon />
<DeleteIcon/>
</BaseIcon>
</PopConfirm>

Expand Down Expand Up @@ -755,7 +779,7 @@ onUnmounted(() => {
v-for="(item, j) in store.word.bookList"
@click="goDictDetail(item)"
/>
<Book :is-add="true" @click="router.push('/dict-list')" />
<Book :is-add="true" @click="router.push('/dict-list')"/>
</div>
</div>

Expand Down Expand Up @@ -785,9 +809,9 @@ onUnmounted(() => {
:onConfirm="savePracticeSetting"
/>

<ChangeLastPracticeIndexDialog v-model="showChangeLastPracticeIndexDialog" @ok="saveLastPracticeIndex" />
<ChangeLastPracticeIndexDialog v-model="showChangeLastPracticeIndexDialog" @ok="saveLastPracticeIndex"/>

<PracticeWordListDialog :data="practiceData?.taskWords" v-model="showPracticeWordListDialog" />
<PracticeWordListDialog :data="practiceData?.taskWords" v-model="showPracticeWordListDialog"/>

<ShufflePracticeSettingDialog
v-model="showShufflePracticeSettingDialog"
Expand Down Expand Up @@ -815,7 +839,7 @@ onUnmounted(() => {
'bg-orange-100 text-orange-700': row.sessionRole === 'end',
}"
>
{{ { start: '学习开始', middle: '学习中', end: '学习结束' }[row.sessionRole] }}
{{ {start: '学习开始', middle: '学习中', end: '学习结束'}[row.sessionRole] }}
</span>
</div>
<div class="text-sm text-gray-600 mt-1">
Expand Down Expand Up @@ -845,6 +869,7 @@ onUnmounted(() => {
@extend .stat;
@apply py-4 flex-1;
width: unset;

.num {
@apply text-2xl break-keep;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export interface Dict extends DictResource {
custom: boolean //是否是自定义词典
complete: boolean //是否学习完成,学完了设为true,然后lastLearnIndex重置
//后端字段
en_name?: string
enName?: string
createdBy?: string
category_id?: number
is_default?: boolean
Expand Down
Loading