feat:在study-word页面可以直接通过url参数下载词典学习,无需从home页进来
This commit is contained in:
@@ -117,7 +117,7 @@ export function getCurrentStudyWord() {
|
||||
}
|
||||
})
|
||||
|
||||
console.log(start,end)
|
||||
// console.log(start,end)
|
||||
|
||||
// end = start
|
||||
// start = start - dict.perDayStudyNumber * 3
|
||||
@@ -174,6 +174,6 @@ export function getCurrentStudyWord() {
|
||||
}
|
||||
|
||||
// console.timeEnd()
|
||||
console.log('data', data)
|
||||
// console.log('data', data)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import {useBaseStore} from "@/stores/base.ts";
|
||||
import {saveAs} from "file-saver";
|
||||
import {checkAndUpgradeSaveDict, checkAndUpgradeSaveSetting, shakeCommonDict} from "@/utils";
|
||||
import {GITHUB} from "@/config/ENV.ts";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -87,9 +88,7 @@ function exportData() {
|
||||
}
|
||||
}
|
||||
let blob = new Blob([JSON.stringify(data)], {type: "text/plain;charset=utf-8"});
|
||||
let date = new Date()
|
||||
let dateStr = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}`
|
||||
saveAs(blob, `${APP_NAME}-User-Data-${dateStr}.json`);
|
||||
saveAs(blob, `${APP_NAME}-User-Data-${dayjs().format('YYYY-MM-DD HH-mm-ss')}.json`);
|
||||
ElMessage.success('导出成功!')
|
||||
}
|
||||
|
||||
@@ -99,9 +98,20 @@ function importData(e) {
|
||||
// no()
|
||||
let reader = new FileReader();
|
||||
reader.onload = function (v) {
|
||||
let str = v.target.result;
|
||||
let str: any = v.target.result;
|
||||
if (str) {
|
||||
let obj = JSON.parse(str)
|
||||
let obj = {
|
||||
version: -1,
|
||||
val: {
|
||||
setting: {},
|
||||
dict: {},
|
||||
}
|
||||
}
|
||||
try {
|
||||
obj = JSON.parse(str)
|
||||
} catch (err) {
|
||||
ElMessage.error('导入失败!')
|
||||
}
|
||||
if (obj.version === EXPORT_DATA_KEY.version) {
|
||||
|
||||
} else {
|
||||
@@ -496,7 +506,7 @@ function importData(e) {
|
||||
padding: 0 var(--space);
|
||||
|
||||
.row {
|
||||
height: 2.6rem;
|
||||
min-height: 2.6rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
@@ -186,7 +186,6 @@ function syncDictInMyStudyList(study = false) {
|
||||
}, 100)
|
||||
}
|
||||
|
||||
//TODO trans结构变了,
|
||||
async function onSubmitWord() {
|
||||
await wordFormRef.validate((valid) => {
|
||||
if (valid) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {useOnKeyboardEventListener, useStartKeyboardEventListener} from "@/hooks
|
||||
import useTheme from "@/hooks/theme.ts";
|
||||
import {getCurrentStudyWord, useWordOptions} from "@/hooks/dict.ts";
|
||||
import {cloneDeep, shuffle} from "lodash-es";
|
||||
import {useRouter} from "vue-router";
|
||||
import {useRoute, useRouter} from "vue-router";
|
||||
import {Icon} from "@iconify/vue";
|
||||
import Footer from "@/pages/pc/word/components/Footer.vue";
|
||||
import Panel from "@/pages/pc/components/Panel.vue";
|
||||
@@ -22,6 +22,8 @@ import Type from "@/pages/pc/word/components/Type.vue";
|
||||
import Empty from "@/components/Empty.vue";
|
||||
import {useBaseStore} from "@/stores/base.ts";
|
||||
import {usePracticeStore} from "@/stores/practice.ts";
|
||||
import {dictionaryResources} from "@/assets/dictionary.ts";
|
||||
import {_getDictDataByUrl} from "@/utils";
|
||||
|
||||
interface IProps {
|
||||
new: Word[],
|
||||
@@ -39,11 +41,13 @@ const settingStore = useSettingStore()
|
||||
const runtimeStore = useRuntimeStore()
|
||||
const {toggleTheme} = useTheme()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const store = useBaseStore()
|
||||
const statStore = usePracticeStore()
|
||||
const typingRef: any = $ref()
|
||||
let allWrongWords = new Set()
|
||||
let showStatDialog = $ref(false)
|
||||
let loading = $ref(false)
|
||||
let studyData = $ref<IProps>({
|
||||
new: [],
|
||||
review: [],
|
||||
@@ -58,10 +62,28 @@ let data = $ref<StudyData>({
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
if (runtimeStore.routeData) {
|
||||
studyData = runtimeStore.routeData
|
||||
let dictId = route.query.q
|
||||
//如果url里有词典id,那么直接请求词典数据,并加到bookList里面进行学习
|
||||
if (dictId) {
|
||||
let dictResource = dictionaryResources.find(v => v.id === dictId)
|
||||
if (dictResource) {
|
||||
loading = true
|
||||
requestIdleCallback(() => {
|
||||
_getDictDataByUrl(dictResource).then(r => {
|
||||
store.changeDict(r)
|
||||
studyData = getCurrentStudyWord()
|
||||
loading = false
|
||||
})
|
||||
})
|
||||
}else {
|
||||
router.push('/word')
|
||||
}
|
||||
} else {
|
||||
router.push('/word')
|
||||
if (runtimeStore.routeData) {
|
||||
studyData = runtimeStore.routeData
|
||||
} else {
|
||||
router.push('/word')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -81,20 +103,17 @@ watch(() => studyData, () => {
|
||||
statStore.index = 0
|
||||
}, {immediate: true, deep: true})
|
||||
|
||||
provide('studyData', data)
|
||||
|
||||
const dictIsEnd = $computed(() => {
|
||||
return store.sdict.lastLearnIndex === store.sdict.length
|
||||
})
|
||||
|
||||
provide('studyData', data)
|
||||
|
||||
const word = $computed(() => {
|
||||
return data.words[data.index] ?? getDefaultWord()
|
||||
})
|
||||
const prevWord: Word = $computed(() => {
|
||||
return data.words?.[data.index - 1] ?? undefined
|
||||
})
|
||||
|
||||
const nextWord: Word = $computed(() => {
|
||||
return data.words?.[data.index + 1] ?? undefined
|
||||
})
|
||||
@@ -228,7 +247,6 @@ function repeat() {
|
||||
studyData = temp
|
||||
}
|
||||
|
||||
//TODO 略过忽略的单词上
|
||||
function prev() {
|
||||
if (data.index === 0) {
|
||||
ElMessage.warning('已经是第一个了~')
|
||||
@@ -348,7 +366,7 @@ useEvents([
|
||||
</div>
|
||||
</div>
|
||||
<Type
|
||||
v-loading="!store.load"
|
||||
v-loading="loading"
|
||||
ref="typingRef"
|
||||
:word="word"
|
||||
@wrong="onTypeWrong"
|
||||
@@ -366,7 +384,7 @@ useEvents([
|
||||
<Panel>
|
||||
<template v-slot="{active}">
|
||||
<div class="panel-page-item pl-4"
|
||||
v-loading="!store.load"
|
||||
v-loading="loading"
|
||||
>
|
||||
<WordList
|
||||
v-if="data.words.length"
|
||||
|
||||
@@ -42,7 +42,7 @@ async function init() {
|
||||
store.word.bookList[store.word.studyIndex] = await _getDictDataByUrl(store.sdict)
|
||||
}
|
||||
}
|
||||
console.log(store.sdict)
|
||||
// console.log(store.sdict)
|
||||
if (!currentStudy.new.length && store.sdict.words.length) {
|
||||
currentStudy = getCurrentStudyWord()
|
||||
}
|
||||
|
||||
@@ -136,11 +136,10 @@ export const useBaseStore = defineStore('base', {
|
||||
}
|
||||
// console.log('this.currentBook', this.currentBook.articles[0])
|
||||
}
|
||||
emitter.emit(EventKey.changeDict)
|
||||
resolve(true)
|
||||
})
|
||||
},
|
||||
//TODO
|
||||
//改变词典
|
||||
changeDict(val: Dict) {
|
||||
//把其他的词典的单词数据都删掉,全保存在内存里太卡了
|
||||
this.word.bookList.slice(3).map(v => {
|
||||
@@ -148,7 +147,7 @@ export const useBaseStore = defineStore('base', {
|
||||
v.words = []
|
||||
}
|
||||
})
|
||||
let rIndex = this.word.bookList.findIndex(v => v.id === val.id)
|
||||
let rIndex = this.word.bookList.findIndex((v: Dict) => v.id === val.id)
|
||||
if (val.words.length < val.perDayStudyNumber) {
|
||||
val.perDayStudyNumber = val.words.length
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user