Files
dafuweng-saiadmin6.x/saiadmin-artd/src/store/index.ts
2026-03-03 09:53:54 +08:00

53 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Pinia Store 配置模块
*
* 提供全局状态管理的初始化和配置
*
* ## 主要功能
*
* - Pinia Store 实例创建
* - 持久化插件配置pinia-plugin-persistedstate
* - 版本化存储键管理
* - 自动数据迁移(跨版本)
* - LocalStorage 序列化配置
* - Store 初始化函数
*
* ## 持久化策略
*
* - 使用 StorageKeyManager 生成版本化的存储键
* - 格式sys-v{version}-{storeId}
* - 自动迁移旧版本数据到当前版本
* - 使用 localStorage 作为存储介质
*
* @module store/index
* @author Art Design Pro Team
*/
import type { App } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'
import { StorageKeyManager } from '@/utils/storage/storage-key-manager'
export const store = createPinia()
// 创建存储键管理器实例
const storageKeyManager = new StorageKeyManager()
// 配置持久化插件
store.use(
createPersistedState({
key: (storeId: string) => storageKeyManager.getStorageKey(storeId),
storage: localStorage,
serializer: {
serialize: JSON.stringify,
deserialize: JSON.parse
}
})
)
/**
* 初始化 Store
*/
export function initStore(app: App<Element>): void {
app.use(store)
}