vue+antv@g6实现表格内容连接以及表格内容可编辑

 实现效果图

话不多说,直接上代码:

init(){
      const containerRef = this.$refs.containerRef
      this.graph = new G6.Graph({
        container: containerRef,
        height:this.content_height,
        defaultNode: {
            type: 'image',
            size: [20, 20],
            clipCfg: {
              show: false,
              type: 'circle',
              r: 30,
              style: {
                lineWidth: 1,
              },
            },
          },
      });
      const data = {
        nodes:[],
        edges:[]
      }
      var row_index = 0
      const nodeList = (list) => {
        list.forEach((item, index) => {
          row_index = row_index + 1
          if (item.list.length==0) {
            let image_url = ""
            var location_x = 160;
            var location_y = 86+36*row_index;
            if(item.process){
              image_url = "jg"
              location_x = location_x
            }else if(item.move){
              image_url = "move"
              location_x = location_x + 80*1
            }else if(item.save){
              image_url = "save"
              location_x = location_x + 80*2
            }else if(item.check){
              image_url = "check"
              location_x = location_x + 80*3
            }else if(item.rework){
              image_url = "fg"
              location_x = location_x + 80*4
            }else if(item.discard){
              image_url = "bf"
              location_x = location_x + 80*4 + 90
            }else if(item.return_goods){
              image_url = "back"
              location_x = location_x + 80*5 + 100
            }
            var node = {
              id: item.no,
              x: location_x,
              y: location_y,
              anchorPoints: [
                [0.5, 0],//上中
                [0, 0.5],//左中
                [1, 0.5],//右中
                [0.5, 1],//下中
              ],
              img: require(`@/assets/flow_images/${image_url}.png`)
            }
            data.nodes.push(node)
            var node_size = data.nodes.length
            if(node_size>1){
              //x轴对比,判定是左连接还是又连接
              var last_x = data.nodes[node_size-2].x
              var now_x = data.nodes[node_size-1].x
              var targetAnchor = 0;
              if(last_x>now_x){
                targetAnchor = 2
              }else if ( last_x<now_x) {
                targetAnchor = 1
              }
              data.edges.push({
                source: data.nodes[node_size-2].id,
                target: data.nodes[node_size-1].id,
                sourceAnchor: 3,
                targetAnchor,
                type:'polyline',
                style:{
                  endArrow: true,
                  stroke:'#F6BD16'
                }
              })
            }
          }else{
            nodeList(item.list)
          }
        })
      }
      nodeList(this.datas)
      this.content_height = 100+36*row_index
      this.graph.changeSize(this.content_width, this.content_height)
      this.graph.data(data);
      this.graph.render();
    }
<div ref="containerRef" class="overlap-element1" >
        <vxe-grid ref="process_table" id="process_table"  show-overflow
          v-bind="gridOptions" :border="true" :data="datas"
          size="mini"
          @toggle-tree-expand="expandTree"
          :toolbar-config="tableToolbar" :loading="loading"
          @cell-click="cellClickEvent"
          :menu-config="tableMenu"
          @menu-click="contextMenuClickEvent">
          <template #loading>
            <div class="first-loading-wrp">
              <div class="loading-wrp" style="padding:20px">
                <span class="dot dot-spin">
                  <i></i>
                  <i></i>
                  <i></i>
                  <i></i>
                </span>
              </div>
              <div style="font-size:14px;color:#1890ff;font-weight: bold;">加载中...</div>
            </div>
          </template>
          <template #process_header="{ column }">
            <span style="color:#ffba00">
              {{ column.title }}<br>
              <img :src="process_icon[column.property]" style="width: 18px;">
            </span>
          </template>
          <template #equip_default="{ row,column }">
            <template v-if="row[column.property]!=null">
              <vxe-button v-for="(item,index) in row[column.property].split(',')" :key="index" status="warning" >
                {{ item }}
              </vxe-button>
            </template>
          </template>
          <template #toolbar_buttons>
            <span style="margin-left: 10px;font-size: 20px;color:#ff5500;" ><i class="vxe-icon-warning-circle" title="若需添加或编辑内容,请在已有内容的文本框中点击右键操作!"></i></span>
            <span style="margin-left: 10px;" />
            <!-- <el-button type="info" size="mini" round >
              <i class="vxe-icon-download"></i>
              导出
            </el-button> -->
          </template>
        </vxe-grid>
      </div>

这里面还涉及画布与表格同步移动,还有部分样式修改

<style scoped>
  .vxe-grid.size--mini {
    position: absolute;
    font-size: 12px;
    width:100%;
  }
  .content {
    position: relative; /* 容器相对定位 */
    width:v-bind(content_width+'px');
    height:v-bind(div_height+'px');
    overflow-x: scroll; /* 显示滚动条 */
    overflow-y: scroll;
  }
  .overlap-element1, .overlap-element2 {
    position: absolute; /* 绝对定位 */
    top: 0;
    left: 0;
    width: 150%;
    background-color: #f0f0f0;
  }
</style>
<style>
  canvas {
    display: inline-block;
    position: relative;
    pointer-events: none;
  }
</style>

业务需求太磨人了,网上案例也特别少,以上就是上面效果图实现代码,分享给有需要的人

  • 15
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

simple8973

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

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

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

打赏作者

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

抵扣说明:

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

余额充值