antv g6的撤销、重做功能

1.撤销

 const undo = () => {
    const undoStack = graph.value.getUndoStack();
    console.log(undoStack);
    if (!undoStack || undoStack.length === 0) {
      return;
    }
    const currentData = undoStack.pop();
    console.log(currentData);
    if (currentData) {
      const { action } = currentData;
      console.log(action);
      graph.value.pushStack(action, currentData.data, 'redo');
      let data = currentData.data.before;
      if (action === 'add') {
        data = currentData.data.after;
      }
      if (!data) return;
      switch (action) {
        case 'visible': {
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const item = graph.value.findById(model.id);
              if (model.visible) {
                graph.value.showItem(item, false);
              } else {
                graph.value.hideItem(item, false);
              }
            });
          });
          break;
        }
        case 'render':
        case 'update':
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const item = graph.value.findById(model.id);
              delete model.id;
              graph.value.updateItem(item, model, false);
              if (item.getType() === 'combo') graph.value.updateCombo(item as ICombo);
            });
          });
          break;
        case 'changedata':
          graph.value.changeData(data, false);
          break;
        case 'delete': {
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const itemType = model.itemType;
              delete model.itemType;
              graph.value.addItem(itemType, model, false);
            });
          });
          break;
        }
        case 'add':
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              graph.value.removeItem(model.id, false);
            });
          });
          break;
        case 'updateComboTree':
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              graph.value.updateComboTree(model.id, model.parentId, false);
            });
          });
          break;
        case 'createCombo':
          const afterCombos = currentData.data.after.combos;
          const createdCombo = afterCombos[afterCombos.length - 1];
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              graph.value.updateComboTree(model.id, model.parentId, false);
            });
          });
          graph.value.removeItem(createdCombo.id, false);
          break;
        case 'uncombo':
          const targetCombo = data.combos[data.combos.length - 1];
          const childrenIds = data.nodes
            .concat(data.combos)
            .map((child) => child.id)
            .filter((id) => id !== targetCombo.id);
          graph.value.createCombo(targetCombo, childrenIds, false);
          break;
        case 'layout':
          graph.value.updateLayout(data, undefined, undefined, false);
          break;
        default:
      }
    }
  };

2.重做

// 重做
  const redo = () => {
    const redoStack = graph.value.getRedoStack();
    console.log(redoStack);
    if (!redoStack || redoStack.length === 0) {
      return;
    }
    const currentData = redoStack.pop();
    console.log(currentData);
    if (currentData) {
      const { action } = currentData;
      let data = currentData.data.after;
      graph.value.pushStack(action, currentData.data);
      if (action === 'delete') {
        data = currentData.data.before;
      }
      if (!data) return;
      switch (action) {
        case 'visible': {
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const item = graph.value.findById(model.id);
              if (model.visible) {
                graph.value.showItem(item, false);
              } else {
                graph.value.hideItem(item, false);
              }
            });
          });
          break;
        }
        case 'render':
        case 'update':
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const item = graph.value.findById(model.id);
              delete model.id;
              graph.value.updateItem(item, model, false);
              if (item.getType() === 'combo') graph.value.updateCombo(item as ICombo);
            });
          });
          break;
        case 'changedata':
          graph.value.changeData(data, false);
          break;
        case 'delete':
          if (data.edges) {
            data.edges.forEach((model) => {
              graph.value.removeItem(model.id, false);
            });
          }
          if (data.nodes) {
            data.nodes.forEach((model) => {
              graph.value.removeItem(model.id, false);
            });
          }
          if (data.combos) {
            data.combos.forEach((model) => {
              graph.value.removeItem(model.id, false);
            });
          }
          break;
        case 'add': {
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              const itemType = model.itemType;
              delete model.itemType;
              graph.value.addItem(itemType, model, false);
            });
          });
          break;
        }
        case 'updateComboTree':
          Object.keys(data).forEach((key) => {
            const array = data[key];
            if (!array) return;
            array.forEach((model) => {
              graph.value.updateComboTree(model.id, model.parentId, false);
            });
          });
          break;
        case 'createCombo':
          const createdCombo = data.combos[data.combos.length - 1];
          graph.value.createCombo(
            createdCombo,
            createdCombo.children.map((child) => child.id),
            false,
          );
          break;
        case 'uncombo':
          const beforeCombos = currentData.data.before.combos;
          const targertCombo = beforeCombos[beforeCombos.length - 1];
          graph.value.uncombo(targertCombo.id, false);
          break;
        case 'layout':
          graph.value.updateLayout(data, undefined, undefined, false);
          break;
        default:
      }
    }
  };

### 如何在Spring Boot项目中集成LangChain4J #### 配置依赖项 为了使Spring Boot应用程序能够使用LangChain4J库,首先需要更新`pom.xml`文件来引入必要的依赖关系。考虑到当前基于Spring Boot 2.X和JDK 8的环境设置[^1],可以在项目的构建配置文件中加入如下Maven依赖: ```xml <dependency> <groupId>com.langchain4j</groupId> <artifactId>langchain4j-core</artifactId> <version>${langchain4j.version}</version> </dependency> ``` 这里`${langchain4j.version}`应替换为实际使用的LangChain4J版本号。 #### 初始化组件和服务 一旦添加了所需的依赖包,在应用启动时就可以通过创建相应的Bean实例来进行初始化操作。这通常是在某个配置类里完成的,比如下面的例子展示了如何定义一个简单的服务bean用于处理链上数据交互: ```java import com.langchain4j.client.LangChainClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class LangChainConfig { @Bean public LangChainClient langChainClient() { return new LangChainClient(/* 可选参数 */); } } ``` 上述代码片段假设存在名为`LangChainClient`的客户端接口或实现类,它负责与区块链网络通信并提供相应功能支持。 #### 使用自动装配简化开发流程 如果希望进一步减少样板代码量,则可以考虑利用Spring框架提供的@Autowired特性来自动生成所需对象实例。例如,在控制器或其他业务逻辑层可以直接注入之前声明过的`LangChainClient` bean而无需手动new出来: ```java @RestController @RequestMapping("/api/langchain") public class LangChainController { private final LangChainClient client; @Autowired public LangChainController(LangChainClient client) { this.client = client; } // 定义API端点... } ``` 这样做的好处是可以让开发者专注于编写核心业务逻辑而不是担心底层资源管理问题。 #### 处理多入口点的情况 对于那些可能拥有多个带有`main()`函数的应用程序来说——无论是因为它们各自携带了`@SpringBootApplication`注解还是仅仅作为普通的Java程序运行——需要注意的是,默认情况下只有第一个被发现的此类方法会被视为应用程序的主要入口。为了避免潜在冲突,建议指定特定的目标类作为主类,可以通过调整maven插件配置中的属性来达成此目的[^2]: ```xml <build> ... <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.example.MyApplicationWithMainMethod</mainClass> </configuration> </plugin> </plugins> ... </build> ``` 这样做能确保即使在同一工程中有其他候选者也不会干扰到预期的行为表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

文哈哈wcx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值