import { defineStore, createPinia } from "pinia"; import { GlobalState, ThemeConfigProps, AssemblySizeType } from "./interface"; import { DEFAULT_PRIMARY } from "@/config/config"; import piniaPersistConfig from "@/config/piniaPersist"; import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; // defineStore 调用后返回一个函数,调用该函数获得 Store 实体 export const GlobalStore = defineStore({ // id: 必须的,在所有 Store 中唯一 id: "GlobalState", // state: 返回对象的函数 state: (): GlobalState => ({ // token token: "", // userInfo userInfo: "", account: "", moduleId: "", //模块id accountType: undefined, //登录账号类型 moduleName: "", //登录账号类型 // 都是控制退出或者修改密码的时候遮挡视频的问题 editPassword: false, openDropdown: false, Message: null, // 点击跳转的时候存的数据 projectDateAuth: null, //是否拥有所属工程的必填 isManager: "", // element组件大小 assemblySize: "default", // language language: "", path: null, // 工程Sn engineeringSn: "", // 系统配置名称 systemConfigName: "", // 系统配置登录页背景 systemConfigBg: "", // 系统配置登录页子背景 systemConfigSubBg: "", // 系统配置Logo systemConfigLogo: "", // 右侧抽屉选择类别 activeType: "eng", // 右侧抽屉选择的Sn值 activeSn: "", // 右侧抽屉选择的Id值 activeId: "", // 视角书签 viewBookmarkArr: "", // themeConfig themeConfig: { // 当前页面是否全屏 maximize: false, // 布局切换 ==> 纵向:vertical | 经典:classic | 横向:transverse | 分栏:columns layout: "classic", // 默认 primary 主题颜色 primary: DEFAULT_PRIMARY, // 深色模式 isDark: false, // 灰色模式 isGrey: false, // 色弱模式 isWeak: false, // 折叠菜单 isCollapse: false, // 面包屑导航 breadcrumb: false, // 面包屑导航图标 breadcrumbIcon: false, // 标签页 tabs: false, // 标签页图标 tabsIcon: false, // 页脚 footer: false } }), getters: {}, actions: { // setToken setToken(token: string | null) { this.token = token; }, setModultId(moduleId: string | null) { this.moduleId = moduleId; }, setAccountType(accountType: number | undefined) { this.accountType = accountType; }, setAccount(account: string | null) { this.account = account; }, // 判断所属工程有没有校验 setProjectDateAuth(projectDateAuth: number | null) { this.projectDateAuth = projectDateAuth; }, // 判断所属工程有没有校验 setIsManager(isManager: string | null) { this.isManager = isManager; }, // 都是解决视频组件遮挡修改密码或者退出的时候 seteditPassword(editPassword: boolean | null) { this.editPassword = editPassword; }, setopenDropdown(openDropdown: boolean | null) { this.openDropdown = openDropdown; }, setmodultTitle(moduleName: string | null) { this.moduleName = moduleName; }, setPath(path: string | null) { this.path = path; }, // setUserInfo setUserInfo(userInfo: any) { this.userInfo = userInfo; }, // setAssemblySizeSize setAssemblySizeSize(assemblySize: AssemblySizeType | "") { this.assemblySize = assemblySize; }, // updateLanguage updateLanguage(language: string | null) { this.language = language; }, // setThemeConfig setThemeConfig(themeConfig: ThemeConfigProps) { this.themeConfig = themeConfig; }, resetStore() { this.token = null; this.moduleId = null; this.accountType = undefined; this.account = null; this.userInfo = null; this.projectDateAuth = null; this.moduleName = null; this.editPassword = null; this.openDropdown = null; this.path = null; this.Message = null; this.isManager = null; } }, persist: piniaPersistConfig("GlobalState") }); // piniaPersist(持久化) const pinia = createPinia(); pinia.use(piniaPluginPersistedstate); export default pinia;