appPageConifg.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { useReducer } from "react"
  2. export type Config = {
  3. bannerType?: number,//banner类型; 0:小说 1:页面路径 banners组件使用
  4. activityPagePath?: string,//banner类型 1的时候使用页面路径
  5. bannerImage?: string,//banner图片
  6. bookId?: string,//小说ID
  7. categoryId?: string,//分类ID
  8. bookIds?: any[],//用于分类自义定书籍的参数
  9. }
  10. type State = {
  11. tabs: 0 | 1,//男生女生选项
  12. isWorkDirection: boolean,//当前页面是否存在男频女频
  13. compAc: string,//当前选中的组件,切换tabs请0
  14. index: number,//每次操作修改数据都递增,为了检测到数据变动
  15. activePage: string,//当前选中的页面
  16. templateName:string,//模板名称
  17. pageConfigList: {
  18. pageUrl: string,//组件所在页面地址
  19. workDirectionListDTOS: {
  20. workDirection?: 0 | 1,//作品方向;0-男频 1-女频
  21. componentConfigList: {
  22. appComponentId: number | string,//组件ID
  23. componentType: string,//组件类型
  24. showRightButton?: boolean,//是否展示左侧按钮
  25. componentName?: string,//组件名称
  26. remark?: string,//备注
  27. configs?: Config[],//组件内的配置
  28. }[]
  29. }[]
  30. }[],
  31. }
  32. type Action = {
  33. params?: any,
  34. type: "setAll",
  35. }
  36. export function reducer(state: State, action: Action) {
  37. let { type, params } = action
  38. switch (type) {
  39. case 'setAll':
  40. return { ...state, ...params }
  41. default:
  42. return state;
  43. }
  44. }
  45. export default (): { state: State, dispatch: React.Dispatch<Action> } => {
  46. const [state, dispatch] = useReducer(reducer, {
  47. tabs: 0,
  48. isWorkDirection: false,
  49. compAc: "",
  50. index: 0,
  51. activePage: "",
  52. pageConfigList: []
  53. })
  54. console.log("state", state)
  55. return {
  56. state,
  57. dispatch
  58. }
  59. }