mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-26 00:45:08 +08:00
vue2: 移除 js-cookie ,使用 localStorage
This commit is contained in:
@ -1,66 +1,66 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const state = {
|
||||
sidebar: {
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
||||
opened: localStorage.getItem("sidebarStatus")
|
||||
? !!+localStorage.getItem("sidebarStatus")
|
||||
: true,
|
||||
withoutAnimation: false,
|
||||
hide: false
|
||||
hide: false,
|
||||
},
|
||||
device: 'desktop',
|
||||
size: Cookies.get('size') || 'medium'
|
||||
}
|
||||
device: "desktop",
|
||||
size: localStorage.getItem("size") || "medium",
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
TOGGLE_SIDEBAR: state => {
|
||||
TOGGLE_SIDEBAR: (state) => {
|
||||
if (state.sidebar.hide) {
|
||||
return false;
|
||||
}
|
||||
state.sidebar.opened = !state.sidebar.opened
|
||||
state.sidebar.withoutAnimation = false
|
||||
state.sidebar.opened = !state.sidebar.opened;
|
||||
state.sidebar.withoutAnimation = false;
|
||||
if (state.sidebar.opened) {
|
||||
Cookies.set('sidebarStatus', 1)
|
||||
localStorage.setItem("sidebarStatus", 1);
|
||||
} else {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
localStorage.setItem("sidebarStatus", 0);
|
||||
}
|
||||
},
|
||||
CLOSE_SIDEBAR: (state, withoutAnimation) => {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
state.sidebar.opened = false
|
||||
state.sidebar.withoutAnimation = withoutAnimation
|
||||
localStorage.setItem("sidebarStatus", 0);
|
||||
state.sidebar.opened = false;
|
||||
state.sidebar.withoutAnimation = withoutAnimation;
|
||||
},
|
||||
TOGGLE_DEVICE: (state, device) => {
|
||||
state.device = device
|
||||
state.device = device;
|
||||
},
|
||||
SET_SIZE: (state, size) => {
|
||||
state.size = size
|
||||
Cookies.set('size', size)
|
||||
state.size = size;
|
||||
localStorage.setItem("size", size);
|
||||
},
|
||||
SET_SIDEBAR_HIDE: (state, status) => {
|
||||
state.sidebar.hide = status
|
||||
}
|
||||
}
|
||||
state.sidebar.hide = status;
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
toggleSideBar({ commit }) {
|
||||
commit('TOGGLE_SIDEBAR')
|
||||
commit("TOGGLE_SIDEBAR");
|
||||
},
|
||||
closeSideBar({ commit }, { withoutAnimation }) {
|
||||
commit('CLOSE_SIDEBAR', withoutAnimation)
|
||||
commit("CLOSE_SIDEBAR", withoutAnimation);
|
||||
},
|
||||
toggleDevice({ commit }, device) {
|
||||
commit('TOGGLE_DEVICE', device)
|
||||
commit("TOGGLE_DEVICE", device);
|
||||
},
|
||||
setSize({ commit }, size) {
|
||||
commit('SET_SIZE', size)
|
||||
commit("SET_SIZE", size);
|
||||
},
|
||||
toggleSideBarHide({ commit }, status) {
|
||||
commit('SET_SIDEBAR_HIDE', status)
|
||||
}
|
||||
}
|
||||
commit("SET_SIDEBAR_HIDE", status);
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
actions,
|
||||
};
|
||||
|
Reference in New Issue
Block a user