zhgdlarge/src/stores/index.ts

142 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-07-12 09:56:31 +08:00
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 => ({
2024-03-28 11:30:42 +08:00
globalScale: 1,
2023-07-12 09:56:31 +08:00
sn: "",
// token
token: "",
// userInfo
userInfo: "",
account: "",
moduleId: "", //模块id
accountType: undefined, //登录账号类型
moduleName: "", //登录账号类型
// 都是控制退出或者修改密码的时候遮挡视频的问题
editPassword: false,
openDropdown: false,
Message: null, // 点击跳转的时候存的数据
projectDateAuth: null, //动态路由
2023-07-12 09:56:31 +08:00
isManager: "",
// element组件大小
assemblySize: "default",
// language
language: "",
path: null,
// 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: {
//项目sn
setSN(sn: string | null) {
this.sn = sn;
},
// 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;
},
// 动态路由
2023-07-12 09:56:31 +08:00
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.sn = null;
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;