This commit is contained in:
zyronon
2024-06-26 02:12:03 +08:00
parent ca9c806457
commit 6cf077bf2f
215 changed files with 898 additions and 694 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1,11 @@
export const GITHUB = 'https://github.com/zyronon/bbword'
export const GITHUB = 'https://github.com/zyronon/bbword'
const common = {
word_dict_list_version: 1
}
const map = {
dev: {
api: 'http://localhost/index.php',
}
}
export const env = Object.assign(map['dev'], common)

View File

@@ -8,11 +8,10 @@ import enFlag from "@/assets/img/flags/en.png";
import jaFlag from "@/assets/img/flags/ja.png";
import deFlag from "@/assets/img/flags/de.png";
import codeFlag from "@/assets/img/flags/code.png";
import {useNav} from "@/utils";
import {getWordDictList, useNav} from "@/utils";
import {getDefaultDict, Sort} from "@/types.ts";
import {onMounted} from "vue";
import {groupBy, uniq} from "lodash-es";
import dict from "@/assets/dict.json";
const base = useBaseStore()
const router = useRouter()
@@ -45,8 +44,9 @@ const currentTranDictList = $computed(() => {
return currentLangDictList[currentTranslateLanguage2] ?? {}
})
onMounted(() => {
let d: any = groupBy(dict.data, 'langType')
onMounted(async () => {
let res = await getWordDictList()
let d: any = groupBy(res, 'langType')
for (let dKey in d) {
d[dKey] = groupBy(d[dKey], 'tranType')
for (const dKey2 in d[dKey]) {

View File

@@ -139,29 +139,22 @@ export const DefaultBaseState = (): BaseState => ({
wordDictList: [
{
...getDefaultDict(),
id: 'nce-new-2',
name: '新概念英语(新版)-2',
description: '新概念英语新版第二册',
category: '青少年英语',
tags: ['新概念英语'],
url: 'nce-new-2.json',
length: 862,
translateLanguage: 'common',
language: 'en',
type: DictType.word
},
{
...getDefaultDict(),
id: 'cet4',
name: 'CET-4',
description: '大学英语四级词库',
category: '中国考试',
tags: ['大学英语'],
url: 'CET4_T.json',
length: 2607,
translateLanguage: 'common',
language: 'en',
type: DictType.word,
"id": 137,
"name": "新概念英语(新版)-2",
"description": "新概念英语新版第二册",
"length": 862,
"version": 1,
"fileName": "nce-new-2",
"category": "青少年英语",
"langType": 0,
"tranType": 1,
"userId": null,
"tags": [
"新概念英语"
],
"langTypeStr": "en",
"tranTypeStr": "zh",
"dictType": DictType.word,
statistics: []
},
],
@@ -312,6 +305,7 @@ export const useBaseStore = defineStore('base', {
},
actions: {
setState(obj: any) {
return
//这样不会丢失watch的值的引用
merge(this, obj)
},
@@ -330,25 +324,17 @@ export const useBaseStore = defineStore('base', {
console.error('读取本地dict数据失败', e)
}
//自定义的词典文章只删除了sections单词并未做删除所以这里不需要处理
if (this.currentDict.isCustom) {
} else {
}
if (this.currentStudy.word.dictIndex >= 0) {
await _checkDictWords(this.currentStudyWordDict)
let current = this.articleDictList[this.currentStudy.article.dictIndex]
let dictResourceUrl = `./dicts/${current.language}/${current.type}/${current.translateLanguage}/${current.url}`;
if (!current.articles.length) {
let s = await getDictFile(dictResourceUrl)
current.articles = cloneDeep(s.map(v => {
v.id = nanoid(6)
return v
}))
}
// let current = this.articleDictList[this.currentStudy.article.dictIndex]
// let dictResourceUrl = `./dicts/${current.language}/${current.type}/${current.translateLanguage}/${current.url}`;
// if (!current.articles.length) {
// let s = await getDictFile(dictResourceUrl)
// current.articles = cloneDeep(s.map(v => {
// v.id = nanoid(6)
// return v
// }))
// }
// console.log('this.wordDictList', this.wordDictList[0].words[0])
}
emitter.emit(EventKey.changeDict)

View File

@@ -251,7 +251,7 @@ export function getDefaultDict(val = {}): Dict {
}
export interface Dict {
id: string,
id: any,
name: string,
lastLearnIndex: number,
perDayStudyNumber: number,

View File

@@ -8,6 +8,8 @@ import {useRouter} from "vue-router";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {nanoid} from "nanoid";
import dayjs from 'dayjs'
import axios from "axios";
import {env} from "@/config/ENV.ts";
export function getRandom(a: number, b: number): number {
return Math.random() * (b - a) + a;
@@ -185,44 +187,27 @@ export async function _checkDictWords(dict: Dict) {
//TODO 需要和其他需要下载的地方统一
//如果不是自定义词典并且有url地址才去下载
if (!dict.isCustom && dict.fileName) {
let res: any = await _fetch(`http://localhost/index.php/v1/support/getDictVersion?id=${dict.id}`)
// let rrr = await axios('http://localhost/static/dict/en/zh/Top50Prepositions-v1.json')
// console.log('r', rrr)
// return
let url = `http://localhost/index.php/v1/support/getDictFile?id=${dict.id}&v=${dict.version}`
let res: any = await axios(url)
// let res: any = await axios(`http://localhost/index.php/v1/support/getDictFile?id=2`)
console.log('res', res)
//说明重定向了
let r
let dictLocalUrl = `./dicts/${dict.langTypeStr}/${dict.dictType}/${dict.tranTypeStr}/${dict.fileName}-${dict.version}`;
let dictServeUrl = `http://localhost/index.php/v1/support/getDictDetail?id=${dict.id}`;
if (res.success) {
if (res.version > dict.version) {
let r2: any = await _fetch(dictServeUrl)
if (r2.success) {
r = r2.data
} else {
let r3 = await fetch(dictLocalUrl)
try {
r = await r3.json()
} catch (e) {
}
}
} else {
if (!dict.words.length) {
let r3 = await fetch(dictLocalUrl)
try {
r = await r3.json()
} catch (e) {
let r2: any = await _fetch(dictServeUrl)
if (r2.success) {
r = r2.data
}
}
}
}
if (res.request.responseURL !== url) {
r = res.data
} else {
let dictLocalUrl = `./dicts/${dict.langTypeStr}/${dict.dictType}/${dict.tranTypeStr}/${dict.fileName}-v${dict.version}.json`;
let r3 = await fetch(dictLocalUrl)
try {
r = await r3.json()
} catch (e) {
}
console.log('r', r)
}
console.log('v', r)
// // dict.words = Object.freeze(v)
// dict.words = v
dict = Object.assign(dict, r)
@@ -230,6 +215,28 @@ export async function _checkDictWords(dict: Dict) {
}
}
export async function getWordDictList() {
let url = `${env.api}/v1/support/getWordDictListFile?v=${env.word_dict_list_version}`
let res: any = await axios(url)
// let res: any = await axios(`http://localhost/index.php/v1/support/getDictFile?id=2`)
console.log('res', res)
//说明重定向了
let r
if (res.request.responseURL !== url) {
r = res.data
} else {
let dictLocalUrl = `./word_dict_list.json`;
let r3 = await fetch(dictLocalUrl)
try {
let r1 = await r3.json()
r = r1.data
} catch (e) {
}
}
return r
}
//获取完成天数
export function _getAccomplishDays(total: number, dayNumber: number) {
return Math.ceil(total / dayNumber)