hn_cloud_web/ldlz-web/src/store/modules/app.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2025-12-19 11:10:30 +08:00
import Cookies from "js-cookie";
2025-11-27 16:55:35 +08:00
const state = {
sidebar: {
2025-12-19 11:10:30 +08:00
opened: Cookies.get("sidebarStatus")
? !!+Cookies.get("sidebarStatus")
: true,
2025-11-27 16:55:35 +08:00
withoutAnimation: false,
2025-12-19 11:10:30 +08:00
hide: false,
isEmbedded: false, // 是否隐藏侧边栏和头部导航栏
2025-11-27 16:55:35 +08:00
},
2025-12-19 11:10:30 +08:00
device: "desktop",
size: Cookies.get("size") || "medium",
};
2025-11-27 16:55:35 +08:00
const mutations = {
2025-12-19 11:10:30 +08:00
TOGGLE_SIDEBAR: (state) => {
2025-11-27 16:55:35 +08:00
if (state.sidebar.hide) {
return false;
}
2025-12-19 11:10:30 +08:00
state.sidebar.opened = !state.sidebar.opened;
state.sidebar.withoutAnimation = false;
2025-11-27 16:55:35 +08:00
if (state.sidebar.opened) {
2025-12-19 11:10:30 +08:00
Cookies.set("sidebarStatus", 1);
2025-11-27 16:55:35 +08:00
} else {
2025-12-19 11:10:30 +08:00
Cookies.set("sidebarStatus", 0);
2025-11-27 16:55:35 +08:00
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
2025-12-19 11:10:30 +08:00
Cookies.set("sidebarStatus", 0);
state.sidebar.opened = false;
state.sidebar.withoutAnimation = withoutAnimation;
2025-11-27 16:55:35 +08:00
},
TOGGLE_DEVICE: (state, device) => {
2025-12-19 11:10:30 +08:00
state.device = device;
2025-11-27 16:55:35 +08:00
},
SET_SIZE: (state, size) => {
2025-12-19 11:10:30 +08:00
state.size = size;
Cookies.set("size", size);
2025-11-27 16:55:35 +08:00
},
SET_SIDEBAR_HIDE: (state, status) => {
2025-12-19 11:10:30 +08:00
state.sidebar.hide = status;
},
SET_SIDEBAR_EMBEDDED: (state, status) => {
console.log("status侧边栏隐藏状态", status);
state.sidebar.isEmbedded = status;
},
};
2025-11-27 16:55:35 +08:00
const actions = {
toggleSideBar({ commit }) {
2025-12-19 11:10:30 +08:00
commit("TOGGLE_SIDEBAR");
2025-11-27 16:55:35 +08:00
},
closeSideBar({ commit }, { withoutAnimation }) {
2025-12-19 11:10:30 +08:00
commit("CLOSE_SIDEBAR", withoutAnimation);
2025-11-27 16:55:35 +08:00
},
toggleDevice({ commit }, device) {
2025-12-19 11:10:30 +08:00
commit("TOGGLE_DEVICE", device);
2025-11-27 16:55:35 +08:00
},
setSize({ commit }, size) {
2025-12-19 11:10:30 +08:00
commit("SET_SIZE", size);
2025-11-27 16:55:35 +08:00
},
toggleSideBarHide({ commit }, status) {
2025-12-19 11:10:30 +08:00
commit("SET_SIDEBAR_HIDE", status);
},
};
2025-11-27 16:55:35 +08:00
export default {
namespaced: true,
state,
mutations,
2025-12-19 11:10:30 +08:00
actions,
};