撤消按钮刚进入页面时可以点击,会清空组件

来源:15-20 -问卷编辑器增加撤销重做-工具栏按钮和快捷键

ygqygq2

2023-05-10

刚进入编辑器页面,直接点撤消就把所有组件全清了。尝试过导出 canUndo、canRedo,disabled 使用它们判断,但是效果还是不怎么好。

export const useGetComponentInfo = () => {
  // 获取 redux 中的组件信息
  const componentsTodos = useSelector<StateType>((state) => state.components) as StateWithHistory<ComponentsStateType>;
  // const components = useSelector <StateType>((state) => state.components.present) as ComponentsStateType;
  const components = componentsTodos.present as ComponentsStateType;
  const canUndo = componentsTodos.past.length > 0;
  const canRedo = componentsTodos.future.length > 0;

  const { componentList = [], selectedId, copiedComponent } = components;

  const selectedComponent = componentList.find((c) => c.fe_id === selectedId);

  return {
    componentList,
    canUndo,
    canRedo,
    selectedId,
    selectedComponent,
    copiedComponent,
  };
};
写回答

1回答

双越

2023-05-11

给你一个解决思路:

  1. 初始化画布,设置问卷内容的 reducer ,单独出来

  2. 配置 undo 时忽略掉这个 reducer

这样就不会有这个问题了

0
6
weixin_慕少7054963
回复
桐子酱Virginia
回复 桐子酱Virginia:这个应该和上面提到的逻辑是一样: store.dispatch(ActionCreators.clearHistory()) // Remove all items from past[] and future[] arrays
2024-07-30
共6条回复

React18+ Nest.js 全栈开发仿问卷星项目

React18+TS4+Antd5+Next.js13 ,B端+C 端,完整业务

383 学习 · 252 问题

查看课程