save
This commit is contained in:
@@ -8,7 +8,7 @@ import {useRuntimeStore} from "@/stores/runtime.ts";
|
||||
import {useSettingStore} from "@/stores/setting.ts";
|
||||
import {cloneDeep} from "lodash-es";
|
||||
import Backgorund from "@/components/Backgorund.vue";
|
||||
import useTheme from "@/hooks/useTheme.ts";
|
||||
import useTheme from "@/hooks/theme.ts";
|
||||
import * as localforage from "localforage";
|
||||
import SettingDialog from "@/components/dialog/SettingDialog.vue";
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ async function selectDict(val: { dict: DictResource | Dict, index: number }) {
|
||||
runtimeStore.editDict.originWords = cloneDeep(v)
|
||||
changeSort(runtimeStore.editDict.sort)
|
||||
} else {
|
||||
runtimeStore.editDict.length = runtimeStore.editDict.words.length + runtimeStore.editDict.residueWords.length
|
||||
runtimeStore.editDict.length = runtimeStore.editDict.words.length
|
||||
}
|
||||
}
|
||||
if (runtimeStore.editDict.type === DictType.article) {
|
||||
@@ -456,7 +456,7 @@ $header-height: 60rem;
|
||||
|
||||
.left-column {
|
||||
overflow: auto;
|
||||
flex: 4;
|
||||
flex: 6;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10rem;
|
||||
@@ -464,7 +464,6 @@ $header-height: 60rem;
|
||||
position: relative;
|
||||
color: var(--color-font-1);
|
||||
font-size: 14rem;
|
||||
position: relative;
|
||||
padding-right: var(--space);
|
||||
|
||||
.name {
|
||||
@@ -515,7 +514,7 @@ $header-height: 60rem;
|
||||
}
|
||||
|
||||
.right-column {
|
||||
flex: 8;
|
||||
flex: 7;
|
||||
border-radius: 10rem;
|
||||
background: var(--color-second-bg);
|
||||
color: var(--color-font-1);
|
||||
@@ -570,6 +569,7 @@ $header-height: 60rem;
|
||||
justify-content: flex-end;
|
||||
gap: var(--space);
|
||||
padding-right: var(--space);
|
||||
margin-bottom: 20rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import Tooltip from "@/components/Tooltip.vue"
|
||||
import useTheme from "@/hooks/useTheme.ts"
|
||||
import useTheme from "@/hooks/theme.ts"
|
||||
import {useBaseStore} from "@/stores/base.ts"
|
||||
import FeedbackModal from "@/components/toolbar/FeedbackModal.vue"
|
||||
|
||||
|
||||
@@ -4,157 +4,196 @@ import {useRuntimeStore} from "@/stores/runtime.ts";
|
||||
import {chunk, cloneDeep} from "lodash-es";
|
||||
import {isArticle} from "@/hooks/article.ts";
|
||||
import {nanoid} from "nanoid";
|
||||
import {$ref} from "vue/macros";
|
||||
|
||||
|
||||
export function useWordOptions() {
|
||||
const store = useBaseStore()
|
||||
const store = useBaseStore()
|
||||
|
||||
function isWordCollect(val: Word) {
|
||||
return !!store.collect.originWords.find(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
}
|
||||
function isWordCollect(val: Word) {
|
||||
return !!store.collect.originWords.find(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
}
|
||||
|
||||
function toggleWordCollect(val: Word) {
|
||||
let rIndex = store.collect.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.originWords.splice(rIndex, 1)
|
||||
} else {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
}
|
||||
store.collect.originWords.push(val)
|
||||
}
|
||||
function toggleWordCollect(val: Word) {
|
||||
let rIndex = store.collect.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.originWords.splice(rIndex, 1)
|
||||
} else {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
}
|
||||
store.collect.originWords.push(val)
|
||||
}
|
||||
}
|
||||
|
||||
function isWordSimple(val: Word) {
|
||||
return !!store.simple.originWords.find(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
}
|
||||
function isWordSimple(val: Word) {
|
||||
return !!store.simple.originWords.find(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
}
|
||||
|
||||
function toggleWordSimple(val: Word) {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
} else {
|
||||
let rIndex = store.collect.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.originWords.splice(rIndex, 1)
|
||||
}
|
||||
store.simple.originWords.push(val)
|
||||
}
|
||||
function toggleWordSimple(val: Word) {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
} else {
|
||||
let rIndex = store.collect.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.originWords.splice(rIndex, 1)
|
||||
}
|
||||
store.simple.originWords.push(val)
|
||||
}
|
||||
}
|
||||
|
||||
function delWrongWord(val: Word) {
|
||||
let rIndex = store.wrong.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.wrong.originWords.splice(rIndex, 1)
|
||||
}
|
||||
function delWrongWord(val: Word) {
|
||||
let rIndex = store.wrong.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.wrong.originWords.splice(rIndex, 1)
|
||||
}
|
||||
}
|
||||
|
||||
function delSimpleWord(val: Word) {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
}
|
||||
function delSimpleWord(val: Word) {
|
||||
let rIndex = store.simple.originWords.findIndex(v => v.name.toLowerCase() === val.name.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.simple.originWords.splice(rIndex, 1)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isWordCollect,
|
||||
toggleWordCollect,
|
||||
isWordSimple,
|
||||
toggleWordSimple,
|
||||
delWrongWord,
|
||||
delSimpleWord
|
||||
}
|
||||
return {
|
||||
isWordCollect,
|
||||
toggleWordCollect,
|
||||
isWordSimple,
|
||||
toggleWordSimple,
|
||||
delWrongWord,
|
||||
delSimpleWord
|
||||
}
|
||||
}
|
||||
|
||||
export function useArticleOptions() {
|
||||
const store = useBaseStore()
|
||||
const store = useBaseStore()
|
||||
|
||||
function isArticleCollect(val: Article) {
|
||||
return !!store.collect.articles.find(v => v.title.toLowerCase() === val.title.toLowerCase())
|
||||
}
|
||||
function isArticleCollect(val: Article) {
|
||||
return !!store.collect.articles.find(v => v.title.toLowerCase() === val.title.toLowerCase())
|
||||
}
|
||||
|
||||
function toggleArticleCollect(val: Article) {
|
||||
let rIndex = store.collect.articles.findIndex(v => v.title.toLowerCase() === val.title.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.articles.splice(rIndex, 1)
|
||||
} else {
|
||||
store.collect.articles.push(val)
|
||||
}
|
||||
function toggleArticleCollect(val: Article) {
|
||||
let rIndex = store.collect.articles.findIndex(v => v.title.toLowerCase() === val.title.toLowerCase())
|
||||
if (rIndex > -1) {
|
||||
store.collect.articles.splice(rIndex, 1)
|
||||
} else {
|
||||
store.collect.articles.push(val)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isArticleCollect,
|
||||
toggleArticleCollect,
|
||||
}
|
||||
return {
|
||||
isArticleCollect,
|
||||
toggleArticleCollect,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function checkDictHasTranslate(dict: Dict) {
|
||||
let dictResourceUrl = `./dicts/${dict.language}/${dict.type}/${dict.translateLanguage}/${dict.url}`;
|
||||
if ([
|
||||
DictType.word,
|
||||
DictType.customWord,
|
||||
].includes(dict.type)) {
|
||||
if (!dict.originWords.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
// let r = await fetch(`.${dict.url}`)
|
||||
let v = await r.json()
|
||||
if (dict.translateLanguage === 'common') {
|
||||
const runtimeStore = useRuntimeStore()
|
||||
let r2 = await fetch('./translate/en2zh_CN-min.json')
|
||||
// fetch('http://sc.ttentau.top/en2zh_CN-min.json').then(r2 => {
|
||||
let list: Word[] = await r2.json()
|
||||
let dictResourceUrl = `./dicts/${dict.language}/${dict.type}/${dict.translateLanguage}/${dict.url}`;
|
||||
if ([
|
||||
DictType.word,
|
||||
DictType.customWord,
|
||||
].includes(dict.type)) {
|
||||
if (!dict.originWords.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
// let r = await fetch(`.${dict.url}`)
|
||||
let v = await r.json()
|
||||
if (dict.translateLanguage === 'common') {
|
||||
const runtimeStore = useRuntimeStore()
|
||||
let r2 = await fetch('./translate/en2zh_CN-min.json')
|
||||
// fetch('http://sc.ttentau.top/en2zh_CN-min.json').then(r2 => {
|
||||
let list: Word[] = await r2.json()
|
||||
|
||||
runtimeStore.translateWordList = list
|
||||
runtimeStore.translateWordList = list
|
||||
|
||||
dict.originWords = cloneDeep(v)
|
||||
dict.words = cloneDeep(v)
|
||||
dict.chapterWords = chunk(dict.words, dict.chapterWordNumber)
|
||||
dict.chapterWords[dict.chapterIndex].map((w: Word) => {
|
||||
let res = list.find(a => a.name === w.name)
|
||||
if (res) w = Object.assign(w, res)
|
||||
})
|
||||
} else {
|
||||
dict.originWords = cloneDeep(v)
|
||||
dict.words = cloneDeep(v)
|
||||
dict.chapterWords = chunk(dict.words, dict.chapterWordNumber)
|
||||
}
|
||||
}
|
||||
dict.originWords = cloneDeep(v)
|
||||
dict.words = cloneDeep(v)
|
||||
dict.chapterWords = chunk(dict.words, dict.chapterWordNumber)
|
||||
dict.chapterWords[dict.chapterIndex].map((w: Word) => {
|
||||
let res = list.find(a => a.name === w.name)
|
||||
if (res) w = Object.assign(w, res)
|
||||
})
|
||||
} else {
|
||||
dict.originWords = cloneDeep(v)
|
||||
dict.words = cloneDeep(v)
|
||||
dict.chapterWords = chunk(dict.words, dict.chapterWordNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([
|
||||
DictType.article,
|
||||
DictType.customArticle,
|
||||
].includes(dict.type)) {
|
||||
if (!dict.articles.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
let s: any[] = await r.json()
|
||||
dict.articles = cloneDeep(s.map(v => {
|
||||
v.id = nanoid(6)
|
||||
return v
|
||||
}))
|
||||
}
|
||||
if ([
|
||||
DictType.article,
|
||||
DictType.customArticle,
|
||||
].includes(dict.type)) {
|
||||
if (!dict.articles.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
let s: any[] = await r.json()
|
||||
dict.articles = cloneDeep(s.map(v => {
|
||||
v.id = nanoid(6)
|
||||
return v
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//同步到我的词典列表
|
||||
export function syncMyDictList(dict: Dict) {
|
||||
const store = useBaseStore()
|
||||
//任意修改,都将其变为自定义词典
|
||||
dict.isCustom = true
|
||||
if (isArticle(dict.type)) {
|
||||
dict.length = dict.articles.length
|
||||
} else {
|
||||
dict.length = dict.words.length + dict.residueWords.length
|
||||
}
|
||||
const store = useBaseStore()
|
||||
//任意修改,都将其变为自定义词典
|
||||
dict.isCustom = true
|
||||
if (isArticle(dict.type)) {
|
||||
dict.length = dict.articles.length
|
||||
} else {
|
||||
dict.length = dict.words.length + dict.residueWords.length
|
||||
}
|
||||
|
||||
let rIndex = store.myDictList.findIndex(v => v.id === dict.id)
|
||||
if (rIndex > -1) {
|
||||
store.myDictList[rIndex] = cloneDeep(dict)
|
||||
} else {
|
||||
store.myDictList.push(cloneDeep(dict))
|
||||
}
|
||||
let rIndex = store.myDictList.findIndex(v => v.id === dict.id)
|
||||
if (rIndex > -1) {
|
||||
store.myDictList[rIndex] = cloneDeep(dict)
|
||||
} else {
|
||||
store.myDictList.push(cloneDeep(dict))
|
||||
}
|
||||
}
|
||||
|
||||
export function useTranslateWordList() {
|
||||
let progress = $ref(0)
|
||||
|
||||
function translate(list: Word) {
|
||||
requestIdleCallback(() => {
|
||||
let count = 0
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let w = list[index]
|
||||
if (!w.trans.length) {
|
||||
requestIdleCallback(() => {
|
||||
if (list.length) {
|
||||
let res = runtimeStore.translateWordList.find(a => a.name === w.name)
|
||||
if (res) w = Object.assign(w, res)
|
||||
count++
|
||||
if (count === list.length) {
|
||||
progress = 100
|
||||
} else {
|
||||
if (count % 30 === 0) progress = (count / list.length) * 100
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
count++
|
||||
if (count === list.length) {
|
||||
progress = 100
|
||||
} else {
|
||||
if (count % 30 === 0) progress = (count / list.length) * 100
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
progress,
|
||||
translate
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export default async function (time: number) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, time)
|
||||
})
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function scrollToBottom() {
|
||||
}
|
||||
|
||||
function scrollToItem(index: number) {
|
||||
listRef.scrollToItem(index)
|
||||
nextTick(() => listRef.scrollToItem(index))
|
||||
}
|
||||
|
||||
defineExpose({scrollToBottom, scrollToItem})
|
||||
|
||||
@@ -157,8 +157,17 @@ let residueWordListCheckedTotal = $computed(() => {
|
||||
function handleChangeCurrentChapter(val: {
|
||||
index: number
|
||||
}) {
|
||||
chapterWordList.map(v => v.checked = false)
|
||||
chapterIndex = val.index
|
||||
chapterWordList.map(v => {
|
||||
v.checked = false
|
||||
//TODO 可能会存在卡的问题
|
||||
if (!v.trans.length && runtimeStore.translateWordList.length) {
|
||||
let res = runtimeStore.translateWordList.find(a => a.name === v.name)
|
||||
if (res) v = Object.assign(v, res)
|
||||
}
|
||||
})
|
||||
|
||||
chapterWordListRef?.scrollToItem(0)
|
||||
closeWordForm()
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {MessageBox} from "@/utils/MessageBox.tsx";
|
||||
import PracticeArticle from "@/pages/practice/practice-article/index.vue";
|
||||
import PracticeWord from "@/pages/practice/practice-word/index.vue";
|
||||
import {ShortcutKey} from "@/types.ts";
|
||||
import useTheme from "@/hooks/useTheme.ts";
|
||||
import useTheme from "@/hooks/theme.ts";
|
||||
import SettingDialog from "@/components/dialog/SettingDialog.vue";
|
||||
import DictModal from "@/components/dialog/DictDiglog.vue";
|
||||
|
||||
|
||||
@@ -260,7 +260,6 @@ export const useBaseStore = defineStore('base', {
|
||||
//TODO 保存统计
|
||||
// this.saveStatistics()
|
||||
console.log('changeDict', cloneDeep(dict), chapterIndex, wordIndex)
|
||||
this.currentDict.type = dict.type
|
||||
this.current.practiceType = practiceType
|
||||
if ([DictType.collect,
|
||||
DictType.simple,
|
||||
|
||||
Reference in New Issue
Block a user