fix:remove localforage

This commit is contained in:
zyronon
2025-08-17 02:42:41 +08:00
parent 82b8ed8039
commit 41a72dfb28
7 changed files with 27 additions and 274 deletions

View File

@@ -4,14 +4,13 @@ import {BaseState, useBaseStore} from "@/stores/base.ts";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {useSettingStore} from "@/stores/setting.ts";
import useTheme from "@/hooks/theme.ts";
import * as localforage from "localforage";
import CollectNotice from "@/pages/pc/components/CollectNotice.vue";
import {SAVE_DICT_KEY, SAVE_SETTING_KEY} from "@/utils/const.ts";
import {isMobile, shakeCommonDict} from "@/utils";
import router, {routes} from "@/router.ts";
import {set} from 'idb-keyval'
import {useRoute} from "vue-router";
import ConflictNotice from "@/pages/pc/components/ConflictNotice.vue";
const store = useBaseStore()
const runtimeStore = useRuntimeStore()
@@ -19,11 +18,11 @@ const settingStore = useSettingStore()
const {setTheme} = useTheme()
watch(store.$state, (n: BaseState) => {
localforage.setItem(SAVE_DICT_KEY.key, JSON.stringify({val: shakeCommonDict(n), version: SAVE_DICT_KEY.version}))
set(SAVE_DICT_KEY.key, JSON.stringify({val: shakeCommonDict(n), version: SAVE_DICT_KEY.version}))
})
watch(settingStore.$state, (n) => {
localStorage.setItem(SAVE_SETTING_KEY.key, JSON.stringify({val: n, version: SAVE_SETTING_KEY.version}))
set(SAVE_SETTING_KEY.key, JSON.stringify({val: n, version: SAVE_SETTING_KEY.version}))
})
async function init() {

View File

@@ -2,22 +2,22 @@
// import origin from './data.json'
import BaseButton from "@/components/BaseButton.vue";
import {checkAndUpgradeSaveDict} from "@/utils";
import localforage from "localforage";
import {SAVE_DICT_KEY} from "@/utils/const.ts";
import str from './data.json'
import {get} from 'idb-keyval'
let data = {}
let origin = {}
async function look() {
let configStr: string = await localforage.getItem(SAVE_DICT_KEY.key)
let configStr: string = await get(SAVE_DICT_KEY.key)
let obj = JSON.parse(configStr)
console.log('local', obj)
}
function set() {
function set1() {
// localforage.setItem(SAVE_DICT_KEY.key, JSON.stringify({val: shakeCommonDict(origin.val as any), version: 3}))
}

View File

@@ -1,12 +1,10 @@
import {defineStore} from 'pinia'
import {Dict, DictId, Word} from "../types/types.ts"
import {cloneDeep} from "@/utils";
import * as localforage from "localforage";
import {nanoid} from "nanoid";
import {_getStudyProgress, checkAndUpgradeSaveDict} from "@/utils";
import {SAVE_DICT_KEY} from "@/utils/const.ts";
import {_getStudyProgress, checkAndUpgradeSaveDict, getDictFile} from "@/utils";
import {markRaw, shallowReactive} from "vue";
import {shallowReactive} from "vue";
import {getDefaultDict} from "@/types/func.ts";
import {get, set} from 'idb-keyval'
export interface BaseState {
simpleWords: string[],
@@ -130,11 +128,11 @@ export const useBaseStore = defineStore('base', {
if (outData) {
this.setState(outData)
} else {
let configStr: string = await localforage.getItem(SAVE_DICT_KEY.key)
let configStr: string = await get(SAVE_DICT_KEY.key)
let data = checkAndUpgradeSaveDict(configStr)
this.setState(data)
}
localforage.setItem(SAVE_DICT_KEY.key, JSON.stringify({val: this.$state, version: SAVE_DICT_KEY.version}))
set(SAVE_DICT_KEY.key, JSON.stringify({val: this.$state, version: SAVE_DICT_KEY.version}))
} catch (e) {
console.error('读取本地dict数据失败', e)
}