12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { useReducer } from "react"
- export type Config = {
- bannerType?: number,//banner类型; 0:小说 1:页面路径 banners组件使用
- activityPagePath?: string,//banner类型 1的时候使用页面路径
- bannerImage?: string,//banner图片
- bookId?: string,//小说ID
- categoryId?: string,//分类ID
- bookIds?: any[],//用于分类自义定书籍的参数
- }
- type State = {
- tabs: 0 | 1,//男生女生选项
- isWorkDirection: boolean,//当前页面是否存在男频女频
- compAc: string,//当前选中的组件,切换tabs请0
- index: number,//每次操作修改数据都递增,为了检测到数据变动
- activePage: string,//当前选中的页面
- templateName:string,//模板名称
- pageConfigList: {
- pageUrl: string,//组件所在页面地址
- workDirectionListDTOS: {
- workDirection?: 0 | 1,//作品方向;0-男频 1-女频
- componentConfigList: {
- appComponentId: number | string,//组件ID
- componentType: string,//组件类型
- showRightButton?: boolean,//是否展示左侧按钮
- componentName?: string,//组件名称
- remark?: string,//备注
- configs?: Config[],//组件内的配置
- }[]
- }[]
- }[],
-
- }
- type Action = {
- params?: any,
- type: "setAll",
- }
- export function reducer(state: State, action: Action) {
- let { type, params } = action
- switch (type) {
- case 'setAll':
- return { ...state, ...params }
- default:
- return state;
- }
- }
- export default (): { state: State, dispatch: React.Dispatch<Action> } => {
- const [state, dispatch] = useReducer(reducer, {
- tabs: 0,
- isWorkDirection: false,
- compAc: "",
- index: 0,
- activePage: "",
- pageConfigList: []
- })
- console.log("state", state)
- return {
- state,
- dispatch
- }
- }
|