You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.2 KiB
97 lines
2.2 KiB
import Cookies from "js-cookie";
|
|
import { Message } from "element-ui";
|
|
import { show, save } from "@/api/system/expand";
|
|
import store from "@/store";
|
|
const state = {
|
|
sidebar: {
|
|
opened: Cookies.get("sidebarStatus")
|
|
? !!+Cookies.get("sidebarStatus")
|
|
: true,
|
|
withoutAnimation: false,
|
|
},
|
|
device: "desktop",
|
|
workerLayout: {},
|
|
};
|
|
const getter = {
|
|
layout: (state) => {
|
|
return state["app/workerLayout"]?.config || [];
|
|
},
|
|
};
|
|
const mutations = {
|
|
TOGGLE_SIDEBAR: (state) => {
|
|
state.sidebar.opened = !state.sidebar.opened;
|
|
state.sidebar.withoutAnimation = false;
|
|
if (state.sidebar.opened) {
|
|
Cookies.set("sidebarStatus", 1);
|
|
} else {
|
|
Cookies.set("sidebarStatus", 0);
|
|
}
|
|
},
|
|
CLOSE_SIDEBAR: (state, withoutAnimation) => {
|
|
Cookies.set("sidebarStatus", 0);
|
|
state.sidebar.opened = false;
|
|
state.sidebar.withoutAnimation = withoutAnimation;
|
|
},
|
|
TOGGLE_DEVICE: (state, device) => {
|
|
state.device = device;
|
|
},
|
|
SET_LAYOUT: (state, layout) => {
|
|
state.workerLayout = layout;
|
|
},
|
|
};
|
|
|
|
const actions = {
|
|
toggleSideBar({ commit }) {
|
|
commit("TOGGLE_SIDEBAR");
|
|
},
|
|
closeSideBar({ commit }, { withoutAnimation }) {
|
|
commit("CLOSE_SIDEBAR", withoutAnimation);
|
|
},
|
|
toggleDevice({ commit }, device) {
|
|
commit("TOGGLE_DEVICE", device);
|
|
},
|
|
getLayout({ commit, state }) {
|
|
return state.workerLayout.config
|
|
? JSON.parse(state.workerLayout.config)
|
|
: new Promise((resolve, reject) => {
|
|
show({
|
|
admin_id: store.state.user.userId,
|
|
}).then((res) => {
|
|
commit("SET_LAYOUT", res);
|
|
resolve(JSON.parse(res?.config) || [])
|
|
});
|
|
});
|
|
},
|
|
setLayout({ commit }) {
|
|
show({
|
|
admin_id: store.state.user.userId,
|
|
}).then((res) => {
|
|
commit("SET_LAYOUT", res);
|
|
});
|
|
},
|
|
saveLayout({ commit, dispatch, state }, layout) {
|
|
save({
|
|
id: state.workerLayout.id,
|
|
name: "1",
|
|
config: JSON.stringify(layout),
|
|
}).then((res) => {
|
|
dispatch("setLayout");
|
|
Message({
|
|
type: "success",
|
|
message: "保存成功",
|
|
});
|
|
});
|
|
},
|
|
clearLayout({ commit }) {
|
|
commit("SET_LAYOUT",{})
|
|
}
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getter,
|
|
mutations,
|
|
actions,
|
|
};
|