Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

前后端数据交互,结构转换问题

好急啊,朋友们,帮帮忙,解决的话发红包请喝xbk,骗人是小狗。

我们这边在开发一个流程设计器,类似钉钉流程设计器那样的。

image.png

前端这边交互的数据格式是这样的:

let originNodes = [
  {
    key: 1,
    tit: "审批单位",
    name: "",
    type: 1,
  },
  {
    conditions: [
      {
        key: 3,
        tit: "条件1",
        value: "项目总投资大于30万",
        type: 2,
        child: [
          {
            key: 4,
            tit: "审批单位",
            name: "",
            type: 1, //1审批单位  2条件分支 3抄送 4办理
          },
          {
            key: 5,
            tit: "条件分支",
            name: "",
            type: 2, //1审批单位  2条件分支 3抄送 4办理
            conditions: [
              {
                key: 6,
                tit: "条件1-1",
                name: "",
                type: 2, //1审批单位  2条件分支 3抄送 4办理
                child: [
                  {
                    key: 7,
                    tit: "审批单位",
                    name: "",
                    type: 1, //1审批单位  2条件分支 3抄送 4办理
                  },
                ],
              },
              {
                key: 8,
                tit: "条件1-2",
                name: "",
                type: 2, //1审批单位  2条件分支 3抄送 4办理
                child: [
                  {
                    key: 9,
                    tit: "审批单位",
                    name: "",
                    type: 3, //1审批单位  2条件分支 3抄送 4办理
                  },
                ],
              },
            ],
          },
          {
            key: 10,
            tit: "审批单位2",
            name: "",
            type: 4, //1审批单位  2条件分支 3抄送 4办理
          },
        ],
      },
      {
        key: 11,
        tit: "条件2",
        value: "项目总投资大于30万",
        type: 2,
        child: [
          {
            key: 12,
            tit: "审批单位",
            name: "",
            type: 1, //1审批单位  2条件分支 3抄送 4办理
          },
        ],
      },
      {
        key: 13,
        tit: "条件2",
        value: "项目总投资大于30万",
        type: 2,
        child: [],
      },
      {
        key: 14,
        tit: "条件2",
        value: "项目总投资大于30万",
        type: 2,
        child: [],
      },
      {
        key: 15,
        tit: "条件2",
        value: "项目总投资大于30万",
        type: 2,
        child: [],
      },
    ],
  },
  {
    key: 16,
    tit: "审批单位",
    name: "",
    type: 1,
  },
]

但是可恶的后端却要这种格式:

let nodes = {
  name:'发起'
  childNode:{
    childNode:{
      name:'审批',
      preId:'start',
      nodeId:'a',
      conditionNodes:[
        {
          name:'条件1',
          nodeId:'b',
          preId:'a',
          childNode:{
            name:'审批',
            nodeId:'d',
            preId:'b',
            conditionNodes:[
              {
                name:'条件1',
                nodeId:'f',
                preId:'d',
                childNode:{
                  name:'审批',
                  nodeId:'h',
                  preId:'f',
                  childNode:{
                    name:'办理',
                    nodeId:'J',
                    preId:'h',
                    childNode:{
                      name:'审批',
                      nodeId:'k',
                      preId:'j',
                    }
                  }
                }
              },
              {
                name:'条件2',
                nodeId:'g',
                preId:'d',
                childNode:{
                  name:'抄送',
                  nodeId:'i',
                  preId:'g',
                  childNode:{
                    name:'办理',
                    nodeId:'J',
                    preId:'i',
                    childNode:{
                      name:'审批',
                      nodeId:'k',
                      preId:'j',
                    }
                  }
                }
              }
            ]
          }
        },
        {
          name:'条件2',
          nodeId:'c',
          preId:'a',
          childNode:{
            name:'审批',
            nodeId:'e',
            preId:'c',
            childNode:{
              name:'审批',
              nodeId:'k',
              preId:'e',
            }
          }
        }
      ]
    }
  }
}

前端按顺序往数组里插入节点,应该很好理解;但后端是根据流程条数,上图有3条线,组成深层次的数据格式,不知道这样描述对不对。

想了半天,感觉还是得靠群众的力量才能解决这个难题了,求帮忙,解决了发红包哈哈哈!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...