70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
import { createContext } from "react";
|
|
|
|
export const Context = createContext({});
|
|
|
|
// Map 页面唯一状态源:页面组件只读取这些状态,通过 actions 修改,避免再用 mitt 同步 React 状态。
|
|
export const initialMapState = {
|
|
coverMaskVisible: false,
|
|
currentPort: "",
|
|
currentBranchOffice: "",
|
|
area: "",
|
|
bottomUtilsCurrentIndex: "",
|
|
pureMap: false,
|
|
headerTitle: "秦港股份安全监管平台",
|
|
bottomUtilsResetVersion: 0,
|
|
rightUtilsResetVersion: 0,
|
|
};
|
|
|
|
export const MAP_ACTION = {
|
|
SELECT_PORT: "selectPort",
|
|
SELECT_BRANCH_OFFICE: "selectBranchOffice",
|
|
SET_AREA: "setArea",
|
|
SET_BOTTOM_UTILS_INDEX: "setBottomUtilsIndex",
|
|
RESET_BOTTOM_UTILS: "resetBottomUtils",
|
|
RESET_RIGHT_UTILS: "resetRightUtils",
|
|
SET_PURE_MAP: "setPureMap",
|
|
SET_COVER_MASK_VISIBLE: "setCoverMaskVisible",
|
|
};
|
|
|
|
export function mapReducer(state, action) {
|
|
switch (action.type) {
|
|
case MAP_ACTION.SELECT_PORT: {
|
|
const data = action.payload;
|
|
return {
|
|
...state,
|
|
currentPort: data.id,
|
|
currentBranchOffice: data.id === "00003" ? "" : data.corpinfoId || state.currentBranchOffice,
|
|
headerTitle: data.id === "00003"
|
|
? "秦港股份安全监管平台"
|
|
: `${data.name}安全监管平台`,
|
|
};
|
|
}
|
|
case MAP_ACTION.SELECT_BRANCH_OFFICE: {
|
|
const data = action.payload;
|
|
return {
|
|
...state,
|
|
currentBranchOffice: data.id,
|
|
headerTitle: `${data.corpName || data.name}安全监管平台`,
|
|
};
|
|
}
|
|
case MAP_ACTION.SET_AREA:
|
|
return { ...state, area: action.payload };
|
|
case MAP_ACTION.SET_BOTTOM_UTILS_INDEX:
|
|
return { ...state, bottomUtilsCurrentIndex: action.payload };
|
|
case MAP_ACTION.RESET_BOTTOM_UTILS:
|
|
return {
|
|
...state,
|
|
bottomUtilsCurrentIndex: -1,
|
|
bottomUtilsResetVersion: state.bottomUtilsResetVersion + 1,
|
|
};
|
|
case MAP_ACTION.RESET_RIGHT_UTILS:
|
|
return { ...state, rightUtilsResetVersion: state.rightUtilsResetVersion + 1 };
|
|
case MAP_ACTION.SET_PURE_MAP:
|
|
return { ...state, pureMap: action.payload };
|
|
case MAP_ACTION.SET_COVER_MASK_VISIBLE:
|
|
return { ...state, coverMaskVisible: action.payload };
|
|
default:
|
|
return state;
|
|
}
|
|
}
|