diff --git a/src/App.vue b/src/App.vue index ec977447..4ef932cf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,7 +29,7 @@ import BaseButton from "@/components/BaseButton.vue"; let input = $ref('') let wrong = $ref('') let showFullWord = $ref(false) -let isDictation = $ref(true) +let isDictation = $ref(false) let activeIndex = $ref(-1) const store = useBaseStore() @@ -158,9 +158,6 @@ async function onKeyDown(e: KeyboardEvent) { } } -onMounted(() => { - -}) const show = $ref(false) const {appearance, toggle} = useThemeColor() diff --git a/src/components/BaseButton.vue b/src/components/BaseButton.vue index 59a8cf14..bb215ba3 100644 --- a/src/components/BaseButton.vue +++ b/src/components/BaseButton.vue @@ -73,6 +73,7 @@ const props = defineProps<{ align-items: center; justify-content: center; font-size: 12rem; + color: white; //gap: 2rem; .key { diff --git a/src/components/WordList.vue b/src/components/WordList.vue index bcf45fb3..36279d69 100644 --- a/src/components/WordList.vue +++ b/src/components/WordList.vue @@ -84,6 +84,7 @@ watch(() => props.list, () => { display: flex; justify-content: space-between; transition: all .3s; + //color: black; &.active { background: $second; diff --git a/src/stores/base.ts b/src/stores/base.ts index 38e1aa1a..baa4c4ae 100644 --- a/src/stores/base.ts +++ b/src/stores/base.ts @@ -3,138 +3,138 @@ import {Config, Dict, DictType, SaveKey, State, Word} from "../types.ts" import {chunk, cloneDeep} from "lodash"; export const useBaseStore = defineStore('base', { - state: (): State => { - return { - newWordDict: { - type: DictType.newWordDict, - wordList: [], - chapterList: [], - chapterIndex: -1, - wordIndex: -1, - }, - skipWordDict: { - type: DictType.skipWordDict, - wordList: [], - chapterList: [], - chapterIndex: -1, - wordIndex: -1, - }, - dict: { - type: DictType.inner, - name: '新概念英语-2', - description: '新概念英语第二册', - category: '青少年英语', - tags: ['新概念英语'], - url: '/dicts/NCE_2.json', - length: 858, - language: 'en', - languageCategory: 'en', - wordList: [], - chapterList: [], - chapterIndex: 0, - wordIndex: 0, - }, - currentDictType: { - name: DictType.inner, - dictUrl: '/dicts/NCE_2.json' - }, - sideIsOpen: false, - dictModalIsOpen: false, - dictModalIsOpen2: false, - setting: { - showToolbar: true, - show: false, - value1: false, - value2: 50, - value3: 1, - value4: false, - } + state: (): State => { + return { + newWordDict: { + type: DictType.newWordDict, + wordList: [], + chapterList: [], + chapterIndex: -1, + wordIndex: -1, + }, + skipWordDict: { + type: DictType.skipWordDict, + wordList: [], + chapterList: [], + chapterIndex: -1, + wordIndex: -1, + }, + dict: { + type: DictType.inner, + name: '新概念英语-2', + description: '新概念英语第二册', + category: '青少年英语', + tags: ['新概念英语'], + url: '/dicts/NCE_2.json', + length: 858, + language: 'en', + languageCategory: 'en', + wordList: [], + chapterList: [], + chapterIndex: 0, + wordIndex: 0, + }, + currentDictType: { + name: DictType.inner, + dictUrl: '/dicts/NCE_2.json' + }, + sideIsOpen: false, + dictModalIsOpen: false, + dictModalIsOpen2: false, + setting: { + showToolbar: true, + show: false, + value1: false, + value2: 50, + value3: 1, + value4: false, + } + } + }, + getters: { + skipWordNames: (state: State) => { + return state.skipWordDict.wordList.map(v => v.name) + }, + currentDict(state: State): Dict { + switch (state.currentDictType.name) { + case DictType.newWordDict: + return state.newWordDict + case DictType.skipWordDict: + return state.skipWordDict + case DictType.inner: + case DictType.custom: + return state.dict + } + }, + chapter(): Word[] { + return this.currentDict.chapterList[this.currentDict.chapterIndex] ?? [] + }, + word(): Word { + return this.chapter[this.currentDict.wordIndex] ?? { + trans: [], + name: '' + } + }, + }, + actions: { + setState(obj: any) { + for (const [key, value] of Object.entries(obj)) { + this[key] = value + } + console.log('this/', this) + }, + async init() { + let configStr = localStorage.getItem(SaveKey) + if (configStr) { + let obj: Config = JSON.parse(configStr) + this.setState(obj) + } + if (this.currentDictType.name === DictType.inner) { + let r = await fetch(`/public/${this.currentDictType.dictUrl}`) + r.json().then(v => { + this.dict.wordList = v + this.dict.chapterList = chunk(this.dict.wordList, 15) + }) + } + if (this.currentDictType.name === DictType.custom) { + let r = await fetch(`/public/${this.currentDictType.dictUrl}`) + r.json().then(v => { + this.dict.wordList = v + this.dict.chapterList = chunk(this.dict.wordList, 15) + }) + } + this.dictModalIsOpen = false + this.dictModalIsOpen2 = false + }, + async changeDict(dict: Dict, chapterIndex: number = -1, wordIndex: number = -1) { + console.log('changeDict') + if ([DictType.newWordDict, DictType.skipWordDict].includes(dict.type)) { + this.currentDictType.name = dict.type + this.currentDictType.dictUrl = '' + this[dict.type].chapterList = [this[dict.type].wordList] + this[dict.type].chapterIndex = chapterIndex === -1 ? 0 : chapterIndex + this[dict.type].wordIndex = wordIndex === -1 ? 0 : wordIndex + } else { + if (dict.name === this.dict.name) { + this.currentDictType.name = dict.type + this.currentDictType.dictUrl = dict.url + if (wordIndex !== -1) this.dict.wordIndex = wordIndex + if (chapterIndex !== -1) this.dict.chapterIndex = chapterIndex + } else { + // let r = await fetch(`/public/${dict.url}`) + // r.json().then(v => { + // this.currentDictType.name === dict.type + // this.currentDictType.dictUrl = dict.url + // + // }) + this.dict = cloneDeep(dict) + this.dict.chapterList = chunk(this.dict.wordList, 15) + this.dict.chapterIndex = chapterIndex === -1 ? 0 : chapterIndex + this.dict.wordIndex = wordIndex === -1 ? 0 : wordIndex } - }, - getters: { - skipWordNames: (state: State) => { - return state.skipWordDict.wordList.map(v => v.name) - }, - currentDict(state: State): Dict { - switch (state.currentDictType.name) { - case DictType.newWordDict: - return state.newWordDict - case DictType.skipWordDict: - return state.skipWordDict - case DictType.inner: - case DictType.custom: - return state.dict - } - }, - chapter(): Word[] { - return this.currentDict.chapterList[this.currentDict.chapterIndex] ?? [] - }, - word(): Word { - return this.chapter[this.currentDict.wordIndex] ?? { - trans: [], - name: '' - } - }, - }, - actions: { - setState(obj: any) { - for (const [key, value] of Object.entries(obj)) { - this[key] = value - } - console.log('this/', this) - }, - async init() { - let configStr = localStorage.getItem(SaveKey) - if (configStr) { - let obj: Config = JSON.parse(configStr) - this.setState(obj) - } - if (this.currentDictType.name === DictType.inner) { - let r = await fetch(`/public/${this.currentDictType.dictUrl}`) - r.json().then(v => { - this.dict.wordList = v - this.dict.chapterList = chunk(this.dict.wordList, 15) - }) - } - if (this.currentDictType.name === DictType.custom) { - let r = await fetch(`/public/${this.currentDictType.dictUrl}`) - r.json().then(v => { - this.dict.wordList = v - this.dict.chapterList = chunk(this.dict.wordList, 15) - }) - } - this.dictModalIsOpen = false - this.dictModalIsOpen2 = false - }, - async changeDict(dict: Dict, chapterIndex: number = -1, wordIndex: number = -1) { - console.log('changeDict') - if ([DictType.newWordDict, DictType.skipWordDict].includes(dict.type)) { - this.currentDictType.name = dict.type - this.currentDictType.dictUrl = '' - this[dict.type].chapterList = [this[dict.type].wordList] - this[dict.type].chapterIndex = chapterIndex === -1 ? 0 : chapterIndex - this[dict.type].wordIndex = wordIndex === -1 ? 0 : wordIndex - } else { - if (dict.name === this.dict.name) { - this.currentDictType.name = dict.type - this.currentDictType.dictUrl = dict.url - if (wordIndex !== -1) this.dict.wordIndex = wordIndex - if (chapterIndex !== -1) this.dict.chapterIndex = chapterIndex - } else { - // let r = await fetch(`/public/${dict.url}`) - // r.json().then(v => { - // this.currentDictType.name === dict.type - // this.currentDictType.dictUrl = dict.url - // - // }) - this.dict = cloneDeep(dict) - this.dict.chapterList = chunk(this.dict.wordList, 15) - this.dict.chapterIndex = chapterIndex === -1 ? 0 : chapterIndex - this.dict.wordIndex = wordIndex === -1 ? 0 : wordIndex - } - } + } - } - }, + } + }, }) \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 5c1870c2..684ad194 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,22 +1,22 @@ export type Config = { - newWords: Word[], - skipWords: Word[], - skipWordNames: string[], - dict: string, - currentDict: { - wordList: Word[], - chapterList: Word[][], - name: string, - desc: string - } - chapterIndex: number, - wordIndex: number, + newWords: Word[], + skipWords: Word[], + skipWordNames: string[], + dict: string, + currentDict: { + wordList: Word[], + chapterList: Word[][], + name: string, + desc: string + } + chapterIndex: number, + wordIndex: number, } export type Word = { - "name": string, - "usphone": string, - "ukphone": string, - "trans": string[] + "name": string, + "usphone": string, + "ukphone": string, + "trans": string[] } export const SaveKey = 'bb-word-config' @@ -30,122 +30,121 @@ export type LanguageCategoryType = 'en' | 'ja' | 'de' | 'code' export type DictionaryResource = { - id: string - name: string - description: string - category: string - tags: string[] - url: string - length: number - language: LanguageType - languageCategory: LanguageCategoryType - //override default pronunciation when not undefined - defaultPronIndex?: number + id: string + name: string + description: string + category: string + tags: string[] + url: string + length: number + language: LanguageType + languageCategory: LanguageCategoryType + //override default pronunciation when not undefined + defaultPronIndex?: number } export type Dictionary = { - id: string - name: string - description: string - category: string - tags: string[] - url: string - length: number - language: LanguageType - languageCategory: LanguageCategoryType - // calculated in the store - chapterCount: number - //override default pronunciation when not undefined - defaultPronIndex?: number + id: string + name: string + description: string + category: string + tags: string[] + url: string + length: number + language: LanguageType + languageCategory: LanguageCategoryType + // calculated in the store + chapterCount: number + //override default pronunciation when not undefined + defaultPronIndex?: number } export type PronunciationConfig = { - name: string - pron: PronunciationType + name: string + pron: PronunciationType } export type LanguagePronunciationMapConfig = { - defaultPronIndex: number - pronunciation: PronunciationConfig[] + defaultPronIndex: number + pronunciation: PronunciationConfig[] } export type LanguagePronunciationMap = { - [key in LanguageType]: LanguagePronunciationMapConfig + [key in LanguageType]: LanguagePronunciationMapConfig } export type SoundResource = { - key: string - name: string - filename: string + key: string + name: string + filename: string } export interface DictJson { - name: string, - description: string, - category: string, - tags: string[], - url: string, - length: number, - language: string, - languageCategory: string, + name: string, + description: string, + category: string, + tags: string[], + url: string, + length: number, + language: string, + languageCategory: string, } export enum DictType { - newWordDict = 'newWordDict', - skipWordDict = 'skipWordDict', - inner = 'inner', - custom = 'custom', + newWordDict = 'newWordDict', + skipWordDict = 'skipWordDict', + inner = 'inner', + custom = 'custom', } export interface Dict extends DictJson { - type: DictType, - wordList: Word[], - chapterList: Word[][], - chapterIndex: number, - wordIndex: number, + type: DictType, + wordList: Word[], + chapterList: Word[][], + chapterIndex: number, + wordIndex: number, } interface DictLog { - startDate: number,//开始日期 - endDate: number//结束日期 - chapterWordNumber: number//章节单词数量 - chapterLog: { - startDate: number,//开始日期 - endDate: number//结束日期 - correctRate: number//正确率 - } + startDate: number,//开始日期 + endDate: number//结束日期 + chapterWordNumber: number//章节单词数量 + statistics: Array +} + +interface ChapterStatistics { + startDate: number,//开始日期 + endDate: number//结束日期 + correctRate: number//正确率 + correctNumber: number//正确数 } export interface State { - newWordDict: { - type: DictType, - wordList: Word[], - chapterList: Word[][], - chapterIndex: number, - wordIndex: number, - }, - skipWordDict: { - type: DictType, - wordList: Word[], - chapterList: Word[][], - chapterIndex: number, - wordIndex: number, - }, - dict: Dict, - currentDictType: { - name: DictType, - dictUrl: string - } - sideIsOpen: boolean, - dictModalIsOpen: boolean, - dictModalIsOpen2: boolean, - setting: { - showToolbar: boolean, - show: boolean, - value1: boolean, - value2: number, - value3: number, - value4: boolean, - } + newWordDict: { + wordList: Word[], + wordIndex: number, + statistics: Array + }, + skipWordDict: { + wordList: Word[], + wordIndex: number, + statistics: Array + }, + dict: Dict, + currentDictType: { + name: DictType, + dictUrl: string + } + sideIsOpen: boolean, + dictModalIsOpen: boolean, + dictModalIsOpen2: boolean, + setting: { + showToolbar: boolean, + show: boolean, + value1: boolean, + value2: number, + value3: number, + value4: boolean, + } } \ No newline at end of file