记一次antv-G6操作历史实现思路

需求背景:

实际业务场景中,在对图(antv-G6)操作过程中,希望对操作历史有所记录,实现返回上一级操作的功能

思路:

因为返回上一次操作需要上一级操作的服务名,所以考虑用栈压入每次操作的服务名,点击返回上一级时,取出服务名查询

(特别的,初始化时,返回上一级需要特别处理)

部分实现代码:
      const toolbar = new G6.ToolBar({
        className: 'g6-toolbar-ul',
        getContent: () => {
          const outDiv = document.createElement('div');
          outDiv.style.width = '90px';
          outDiv.innerHTML = `<ul>
              <li code= 'goback'>返回列表</li>
              <li code= 'gobackPre'>返回上一级</li>
            </ul>`
          return outDiv
        },
        handleClick: (code, graph) => {
          if (code === 'goback') {
            this.$router.push({ name: 'severMap'});
          }
          if (code === 'gobackPre') {
            if (this.stack.length == 0) {
              return true;
            }else {
            graph.destroy();
            this.srvName = this.stack.pop();
            this.init(this.srvName);
            this.initSize();
            }
          }
        }
      });
      //节点双击事件
      this.graph.on('node:dblclick', (e) => {
        this.stack.push(this.srvName);
        this.srvName = e.item._cfg.model.srvEnName;
        axios({
          method: 'get',
          url: bcocUrl + '/srvmap/selectCallSrvMapList?srvName=' + this.srvName,
          headers: { 'Content-Type': 'application/json' }
        })
          .then((response) => {
            var data = response.data.obj;
            for (let i = 0; i < data.children.length; i++) {
              data.children[i].srvEnName = fittingString(data.children[i].srvEnName, 300, 12);
              if (data.children[i].children != null) {
                for (let d = 0; d < data.children[i].children.length; d++) {
                  data.children[i].children[d].srvEnName = fittingString(data.children[i].children[d].srvEnName, 320, 12);
                }
              }
            };
            data.srvEnName = fittingString(data.srvEnName, 300, 12);

            for (let i = 0; i < data.children.length; i++) {
              if (data.children[i].srvType === '0') {
                data.children[i].type = 'card-node';
              }else {
                data.children[i].type = 'node-card';
              }
              if (data.children[i].children != null) {
                for (let d = 0; d < data.children[i].children.length; d++) {
                  if (data.children[i].children[d].srvType === '0') {
                    data.children[i].children[d].type = 'card-node';
                  }else {
                    data.children[i].children[d].type = 'node-card';
                  }
                }
              }
            };

            graph.data(data);
            graph.render();
            graph.fitView();
            //获取div parentContent 的宽度和高度
            this.canvasWidth = this.$refs.parentContent.clientWidth
            this.canvasHeight = this.$refs.parentContent.clientHeight
            //修改画布的大小
            this.graph.changeSize(this.canvasWidth, this.canvasHeight)
            //将图移动到画布中心位置
            this.graph.fitCenter()
          })
        .catch((response) => console.log(response));
      })
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Bin,

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

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

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

打赏作者

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

抵扣说明:

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

余额充值