fix: 移除SecureLS依赖并使用localStorage替代

由于vite8报错找不到SecureLS构造器,移除对SecureLS的依赖
在开发和生产环境统一使用localStorage作为存储方案
This commit is contained in:
dap
2025-12-25 20:22:54 +08:00
parent b10ce02e2b
commit fbbef8b314

View File

@@ -3,7 +3,8 @@ import type { Pinia } from 'pinia';
import type { App } from 'vue';
import { createPinia } from 'pinia';
import SecureLS from 'secure-ls';
// vite8报错找不到构造器?
// import SecureLS from 'secure-ls';
let pinia: Pinia;
@@ -21,27 +22,28 @@ export async function initStores(app: App, options: InitStoreOptions) {
const { createPersistedState } = await import('pinia-plugin-persistedstate');
pinia = createPinia();
const { namespace } = options;
const ls = new SecureLS({
encodingType: 'aes',
encryptionSecret: import.meta.env.VITE_APP_STORE_SECURE_KEY,
isCompression: true,
// @ts-ignore secure-ls does not have a type definition for this
metaKey: `${namespace}-secure-meta`,
});
// const ls = new SecureLS({
// encodingType: 'aes',
// encryptionSecret: import.meta.env.VITE_APP_STORE_SECURE_KEY,
// isCompression: true,
// // @ts-ignore secure-ls does not have a type definition for this
// metaKey: `${namespace}-secure-meta`,
// });
pinia.use(
createPersistedState({
// key $appName-$store.id
key: (storeKey) => `${namespace}-${storeKey}`,
storage: import.meta.env.DEV
? localStorage
: {
getItem(key) {
return ls.get(key);
},
setItem(key, value) {
ls.set(key, value);
},
},
storage: localStorage,
// storage: import.meta.env.DEV
// ? localStorage
// : {
// getItem(key) {
// return ls.get(key);
// },
// setItem(key, value) {
// ls.set(key, value);
// },
// },
}),
);
app.use(pinia);