update 响应式处理
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
const layout = (state = {
|
||||
siderCollapsed: false
|
||||
}, action) => {
|
||||
import { SETTING_KEY } from "common/storage"
|
||||
import { SIDER_BREAK_POINT } from "util/global"
|
||||
|
||||
const defaultState = {
|
||||
siderCollapsed: false,
|
||||
allowSiderCollapsed: true
|
||||
}
|
||||
|
||||
const localStorageState = () => {
|
||||
return JSON.parse(window.localStorage.getItem(SETTING_KEY))
|
||||
}
|
||||
|
||||
const mergeState = {
|
||||
...defaultState,
|
||||
...localStorageState()
|
||||
}
|
||||
|
||||
const layout = (state = mergeState, action) => {
|
||||
switch (action.type) {
|
||||
// 打开窗口
|
||||
case 'OPEN_WINDOW':
|
||||
@@ -13,8 +28,23 @@ const layout = (state = {
|
||||
return state
|
||||
// 侧边收起状态
|
||||
case 'TOGGLE_COLLAPSED':
|
||||
const _state = { ...state, siderCollapsed: action.siderCollapsed }
|
||||
return _state
|
||||
{
|
||||
if (window.innerWidth <= SIDER_BREAK_POINT) {
|
||||
return state
|
||||
}
|
||||
const _state = { ...state, siderCollapsed: action.siderCollapsed }
|
||||
window.localStorage.setItem(SETTING_KEY, JSON.stringify(_state))
|
||||
return _state
|
||||
}
|
||||
case 'AUTO_TOGGLE_COLLAPSED':
|
||||
{
|
||||
const _state = {
|
||||
...state,
|
||||
siderCollapsed: localStorageState().siderCollapsed || action.siderCollapsed,
|
||||
allowSiderCollapsed: !action.siderCollapsed
|
||||
}
|
||||
return _state
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user