Files
vueadmin/src/stores/persist.js
T
2026-01-16 09:37:25 +08:00

51 lines
1014 B
JavaScript

/*
* @Descripttion: Pinia 持久化存储适配器 - 使用 tool.data 封装的 localStorage
* @version: 1.0
*/
import tool from '@/utils/tool'
/**
* 自定义存储适配器
* 使用 tool.data 的 set/get/remove 方法,支持加密和过期时间
*/
export const customStorage = {
/**
* 获取数据
* @param {string} key - 存储键
* @returns {any} - 存储的数据
*/
getItem: (key) => {
return tool.data.get(key)
},
/**
* 设置数据
* @param {string} key - 存储键
* @param {any} value - 要存储的值
*/
setItem: (key, value) => {
tool.data.set(key, value)
},
/**
* 删除数据
* @param {string} key - 存储键
*/
removeItem: (key) => {
tool.data.remove(key)
}
}
/**
* 默认持久化配置
*/
export const defaultPersistConfig = {
storage: customStorage,
// 可以在这里添加其他全局配置,如过期时间等
// serializer: {
// serialize: (state) => JSON.stringify(state),
// deserialize: (value) => JSON.parse(value)
// }
}