添加store

This commit is contained in:
zyronon
2023-08-04 18:47:16 +08:00
parent 4d72b95ece
commit 8a18bb53fd
6 changed files with 625 additions and 11 deletions

View File

@@ -14,18 +14,11 @@ import correct from './assets/sound/correct.wav'
import {chunk} from "lodash"
import {$ref} from "vue/macros"
import {useSound} from "@/hooks/useSound.ts"
import {useBaseStore} from "@/stores/base.ts"
import {Config, Word} from "@/types.ts"
// import {$ref, $computed} from 'vue/macros'
// import MCE_3 from './assets/dicts/NCE_3.json'
type Config = {
newWords: Word[],
skipWords: Word[],
skipWordNames: string[],
dict: string,
chapterIndex: number,
wordIndex: number,
}
type Word = {"name": string, "usphone": string, "ukphone": string, "trans": string[]}
let wordList: Word[][] = $ref([])
let input = $ref('')
let wrong = $ref('')
@@ -39,6 +32,8 @@ let config: Config = $ref({
wordIndex: 0,
})
const store = useBaseStore()
// const [play, setAudio] = useSound([机械0, 机械1, 机械2, 机械3], 1)
const [play, setAudio] = useSound([老式机械], 3)
// const [play, setAudio] = useSound([电话打字的声音Mp3], 3)

View File

@@ -1,5 +1,10 @@
import { createApp } from 'vue'
import {createApp} from 'vue'
import './style.css'
import App from './App.vue'
import {createPinia} from "pinia"
createApp(App).mount('#app')
const pinia = createPinia()
const app = createApp(App)
app.use(pinia)
app.mount('#app')

26
src/stores/base.ts Normal file
View File

@@ -0,0 +1,26 @@
import {defineStore} from 'pinia'
import {Config, Word} from "../types.ts"
export const useBaseStore = defineStore('base', {
state: () => ({
newWords: [],
skipWords: [],
skipWordNames: [],
dict: 'nce2',
chapterIndex: 0,
wordIndex: 0,
}
),
getters: {
word: (state): Word => {
return state.wordList?.[state.chapterIndex]?.[state.wordIndex] ?? {
trans: [],
name: ''
}
},
},
actions: {
init(config: Config) {
},
},
})

9
src/types.ts Normal file
View File

@@ -0,0 +1,9 @@
export type Config = {
newWords: Word[],
skipWords: Word[],
skipWordNames: string[],
dict: string,
chapterIndex: number,
wordIndex: number,
}
export type Word = {"name": string, "usphone": string, "ukphone": string, "trans": string[]}