flat: 缓存

This commit is contained in:
Apcallover
2025-11-28 19:47:42 +08:00
parent 550173c82d
commit d84fd90a11
10 changed files with 691 additions and 12 deletions

View File

@@ -0,0 +1,35 @@
import {
createPersistedState,
type PersistedStateFactoryOptions,
} from "pinia-plugin-persistedstate";
export * from "pinia-plugin-persistedstate";
export function createUnistorage(
globalOptions: PersistedStateFactoryOptions = {},
) {
const persistedState = createPersistedState({
storage: {
getItem(key) {
// @ts-ignore
return uni.getStorageSync(key);
},
setItem(key, value) {
// @ts-ignore
uni.setStorageSync(key, value);
},
},
serializer: {
deserialize: JSON.parse,
serialize: JSON.stringify,
},
...globalOptions,
});
// @ts-ignore
return (ctx) => {
if (ctx.options.unistorage) {
ctx.options.persist = ctx.options.unistorage;
}
return persistedState(ctx);
};
}