前端组件数据映射解析(自定义表格生成)

一、前端功能样式

功能:拖拽前端组件,生成表格模板;

二、源数据格式

1、使用前端组件对应的模板数据

{
  "widgetList": [
    {
      "type": "input",
      "icon": "text-field",
      "formItemFlag": true,
      "options": {
        "name": "input97070",
        "label": "部门",
        "labelAlign": "",
        "type": "text",
        "defaultValue": "",
        "placeholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "showPassword": false,
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": [],
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "minLength": null,
        "maxLength": null,
        "showWordLimit": false,
        "prefixIcon": "",
        "suffixIcon": "",
        "appendButton": false,
        "appendButtonDisabled": false,
        "buttonIcon": "el-icon-search",
        "onCreated": "",
        "onMounted": "",
        "onInput": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "input97070"
    },
    {
      "type": "textarea",
      "icon": "textarea-field",
      "formItemFlag": true,
      "options": {
        "name": "textarea68973",
        "label": "内容",
        "labelAlign": "",
        "rows": 3,
        "defaultValue": "",
        "placeholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "minLength": null,
        "maxLength": null,
        "showWordLimit": false,
        "onCreated": "",
        "onMounted": "",
        "onInput": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "textarea68973"
    },
    {
      "type": "number",
      "icon": "number-field",
      "formItemFlag": true,
      "options": {
        "name": "number41441",
        "label": "数量",
        "labelAlign": "",
        "defaultValue": 0,
        "placeholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "min": -100000000000,
        "max": 100000000000,
        "precision": 0,
        "step": 1,
        "controlsPosition": "right",
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "number41441"
    },
    {
      "type": "radio",
      "icon": "radio-field",
      "formItemFlag": true,
      "options": {
        "name": "radio83714",
        "label": "性别",
        "labelAlign": "",
        "defaultValue": 2,
        "columnWidth": "200px",
        "size": "",
        "displayStyle": "inline",
        "buttonStyle": false,
        "border": false,
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "optionItems": [
          {
            "label": "男",
            "value": 1
          },
          {
            "label": "女",
            "value": 2
          },
          {
            "label": "非",
            "value": 3
          }
        ],
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onValidate": ""
      },
      "id": "radio83714"
    },
    {
      "type": "time",
      "icon": "time-field",
      "formItemFlag": true,
      "options": {
        "name": "time40033",
        "label": "时间",
        "labelAlign": "",
        "defaultValue": null,
        "placeholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "editable": false,
        "format": "HH:mm:ss",
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "time40033"
    },
    {
      "type": "time-range",
      "icon": "time-range-field",
      "formItemFlag": true,
      "options": {
        "name": "timerange72033",
        "label": "时间段",
        "labelAlign": "",
        "defaultValue": null,
        "startPlaceholder": "",
        "endPlaceholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "editable": false,
        "format": "HH:mm:ss",
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "timerange72033"
    },
    {
      "type": "checkbox",
      "icon": "checkbox-field",
      "formItemFlag": true,
      "options": {
        "name": "checkbox28173",
        "label": "多选框",
        "labelAlign": "",
        "defaultValue": [],
        "columnWidth": "200px",
        "size": "",
        "displayStyle": "inline",
        "buttonStyle": false,
        "border": false,
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "optionItems": [
          {
            "label": "选项1",
            "value": 1
          },
          {
            "label": "选项2",
            "value": 2
          },
          {
            "label": "选项3",
            "value": 3
          }
        ],
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onValidate": ""
      },
      "id": "checkbox28173"
    },
    {
      "type": "select",
      "icon": "select-field",
      "formItemFlag": true,
      "options": {
        "name": "select28498",
        "label": "核酸要求",
        "labelAlign": "",
        "defaultValue": "",
        "placeholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "filterable": false,
        "allowCreate": false,
        "remote": false,
        "automaticDropdown": false,
        "multiple": false,
        "multipleLimit": 0,
        "optionItems": [
          {
            "label": "select 1",
            "value": 1
          },
          {
            "label": "select 2",
            "value": 2
          },
          {
            "label": "select 3",
            "value": 3
          }
        ],
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onRemoteQuery": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "select28498"
    },
    {
      "type": "cascader",
      "icon": "cascader-field",
      "formItemFlag": true,
      "options": {
        "name": "cascader77996",
        "label": "下拉框",
        "defaultValue": "",
        "placeholder": "",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "columnWidth": "200px",
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "filterable": false,
        "multiple": true,
        "checkStrictly": false,
        "optionItems": [
          {
            "label": "select 1",
            "value": 1,
            "children": [
              {
                "label": "child 1",
                "value": 11
              }
            ]
          },
          {
            "label": "select 2",
            "value": 2
          },
          {
            "label": "select 3",
            "value": 3
          }
        ],
        "required": false,
        "requiredHint": "",
        "customRule": "",
        "customRuleHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "cascader77996"
    },
    {
      "type": "rich-editor",
      "icon": "rich-editor-field",
      "formItemFlag": true,
      "options": {
        "name": "richeditor73236",
        "label": "富文本",
        "placeholder": "",
        "labelWidth": null,
        "labelHidden": false,
        "columnWidth": "200px",
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "customRule": "",
        "customRuleHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "minLength": null,
        "maxLength": null,
        "showWordLimit": false,
        "onCreated": "",
        "onMounted": "",
        "onValidate": ""
      },
      "id": "richeditor73236"
    },
    {
      "type": "picture-upload",
      "icon": "picture-upload-field",
      "formItemFlag": true,
      "options": {
        "name": "pictureupload112914",
        "label": "picture-upload",
        "labelWidth": null,
        "labelHidden": false,
        "columnWidth": "200px",
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "customRule": "",
        "customRuleHint": "",
        "uploadURL": "",
        "uploadTip": "",
        "withCredentials": false,
        "multipleSelect": false,
        "showFileList": true,
        "limit": 3,
        "fileMaxSize": 5,
        "fileTypes": [
          "jpg",
          "jpeg",
          "png"
        ],
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onBeforeUpload": "",
        "onUploadSuccess": "",
        "onUploadError": "",
        "onFileRemove": "",
        "onValidate": ""
      },
      "id": "pictureupload112914"
    },
    {
      "type": "time-range",
      "icon": "time-range-field",
      "formItemFlag": true,
      "options": {
        "name": "timerange121422",
        "label": "time-range",
        "labelAlign": "",
        "defaultValue": null,
        "startPlaceholder": "",
        "endPlaceholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "editable": false,
        "format": "HH:mm:ss",
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "timerange121422"
    },
    {
      "type": "html-text",
      "icon": "html-text",
      "formItemFlag": false,
      "options": {
        "name": "htmltext47253",
        "columnWidth": "200px",
        "hidden": false,
        "htmlContent": "<b>html text</b>",
        "customClass": "",
        "onCreated": "",
        "onMounted": "",
        "label": "html-text"
      },
      "id": "htmltext47253"
    },
    {
      "type": "static-text",
      "icon": "static-text",
      "formItemFlag": false,
      "options": {
        "name": "statictext67021",
        "columnWidth": "200px",
        "hidden": false,
        "textContent": "static text",
        "fontSize": "13px",
        "customClass": "",
        "onCreated": "",
        "onMounted": "",
        "label": "static-text"
      },
      "id": "statictext67021"
    },
    {
      "type": "slider",
      "icon": "slider-field",
      "formItemFlag": true,
      "options": {
        "name": "slider43739",
        "label": "slider",
        "labelAlign": "",
        "columnWidth": "200px",
        "showStops": true,
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "min": 0,
        "max": 100,
        "step": 10,
        "range": false,
        "height": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onValidate": ""
      },
      "id": "slider43739"
    },
    {
      "type": "rate",
      "icon": "rate-field",
      "formItemFlag": true,
      "options": {
        "name": "rate104562",
        "label": "rate",
        "labelAlign": "",
        "defaultValue": 0,
        "columnWidth": "200px",
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "max": 5,
        "lowThreshold": 2,
        "highThreshold": 4,
        "allowHalf": false,
        "showText": false,
        "showScore": false,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onValidate": ""
      },
      "id": "rate104562"
    },
    {
      "type": "date-range",
      "icon": "date-range-field",
      "formItemFlag": true,
      "options": {
        "name": "daterange46456",
        "label": "date-range",
        "labelAlign": "",
        "type": "daterange",
        "defaultValue": null,
        "startPlaceholder": "",
        "endPlaceholder": "",
        "columnWidth": "200px",
        "size": "",
        "labelWidth": null,
        "labelHidden": false,
        "readonly": false,
        "disabled": false,
        "hidden": false,
        "clearable": true,
        "editable": false,
        "format": "yyyy-MM-dd",
        "valueFormat": "yyyy-MM-dd",
        "required": false,
        "requiredHint": "",
        "validation": "",
        "validationHint": "",
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onFocus": "",
        "onBlur": "",
        "onValidate": ""
      },
      "id": "daterange46456"
    },
    {
      "type": "switch",
      "icon": "switch-field",
      "formItemFlag": true,
      "options": {
        "name": "switch13873",
        "label": "switch",
        "labelAlign": "",
        "defaultValue": false,
        "columnWidth": "200px",
        "labelWidth": null,
        "labelHidden": false,
        "disabled": false,
        "hidden": false,
        "customClass": "",
        "labelIconClass": null,
        "labelIconPosition": "rear",
        "labelTooltip": null,
        "switchWidth": 40,
        "activeText": "",
        "inactiveText": "",
        "activeColor": null,
        "inactiveColor": null,
        "onCreated": "",
        "onMounted": "",
        "onChange": "",
        "onValidate": ""
      },
      "id": "switch13873"
    }
  ],
  "formConfig": {
    "modelName": "formData",
    "refName": "vForm",
    "rulesName": "rules",
    "labelWidth": 80,
    "labelPosition": "left",
    "size": "",
    "labelAlign": "label-left-align",
    "cssCode": "",
    "customClass": "",
    "functions": "",
    "layoutType": "PC",
    "onFormCreated": "",
    "onFormMounted": "",
    "onFormDataChange": "",
    "dataSources": [],
    "onFormValidate": ""
  }
}

2、填写表格后对应的数据

{
	"input97070": "深圳部门",
	"textarea68973": "内容test",
	"number41441": 66,
	"radio83714": 2,
	"time40033": "11:17:22",
	"timerange72033": ["11:17:46",
	"12:17:46"],
	"checkbox28173": [1,
	2],
	"select28498": 3,
	"cascader77996": [[1,
	11],
	[2]],
	"richeditor73236": "<p>富文本测试</p>",
	"pictureupload112914": null,
	"timerange121422": ["11:18:07",
	"12:18:07"],
	"slider43739": 50,
	"rate104562": 4,
	"daterange46456": ["2022-08-13",
	"2022-08-19"],
	"switch13873": true
}

三、解析方法

1、解析台账数据

思路:

表头:通过前端组件标签id,关联标签label和台账数据值;

数据:通过单选框,下拉框等组件的value值关联组件label;

/**
     * 数据组装2,样式:返回结果中有两个list,一个放表头,一个按顺序放内容
     * @param ledgerLists
     * @return
     */
    private Object parseLedger2(List<GetLedgerListOutputBO> ledgerLists) {
        Map<String,Object> result=new HashMap<>();
        try{
            GetLedgerListOutputBO getLedgerListOutputBO = ledgerLists.stream().filter(e -> !StringUtils.isEmpty(e.getLedgerTemplateContent())).findFirst().get();
            String ledgerTemplateContent = !ObjectUtils.isEmpty(getLedgerListOutputBO)?getLedgerListOutputBO.getLedgerTemplateContent():null;
            if(StringUtils.isEmpty(ledgerTemplateContent)){
                return result;
            }
            //获取模板标签名map
            Map<String, String> templateNormalMap = new HashMap<>();//date,input
            Map<String, String> templatePictureMap = new HashMap<>();//picture-upload
            HashMap<String, String> templateTimeMap = new HashMap<>();//time-range,date-range
            HashMap<String, String> templateRadioMap = new HashMap<>();//radio
            HashMap<Object, String> radioOptionItemsMap = new HashMap<>();//radio:optionItems
            HashMap<String, String> templateCheckboxMap = new HashMap<>();//checkbox
            HashMap<Object, String> checkboxOptionItemsMap = new HashMap<>();//checkbox:optionItems
            HashMap<String, String> templateSelectSingleMap = new HashMap<>();//select(single)
            HashMap<Object, String> selectSingleOptionItemsMap = new HashMap<>();//select(single):optionItems
            HashMap<String, String> templateSelectMoreMap = new HashMap<>();//select(more)
            HashMap<Object, String> selectMoreOptionItemsMap = new HashMap<>();//select(more):optionItems
            HashMap<String, String> templateCascadeSingleMap = new HashMap<>();//cascader(single)
            HashMap<Object, String> cascaderSingleOptionItemsMap = new HashMap<>();//cascader(single):optionItems
            HashMap<String, String> templateCascaderMoreMap = new HashMap<>();//cascader(more)
            HashMap<Object, String> cascaderMoreOptionItemsMap = new HashMap<>();//cascader(more):optionItems


            JSONObject templateObject = JSONObject.parseObject(ledgerTemplateContent);
            if(null !=templateObject){
                JSONArray widgetList = templateObject.getJSONArray("widgetList");
                if(null !=widgetList){
                    for(int i=0;i<widgetList.size();i++){
                        JSONObject corn = widgetList.getJSONObject(i);
                        if(null !=corn){
                            String id = corn.getString("id");
                            String type = corn.getString("type");
                            JSONObject options = corn.getJSONObject("options");
                            if(null !=options){
                                String label = options.getString("label");
                                Boolean multiple = options.getBoolean("multiple");
                                JSONArray optionItems = options.getJSONArray("optionItems");
                                if(WidgetTypeConstant.STATIC_TEXT.equals(type)){
                                    continue;
                                }
                                //图片组件id,label映射
                                if(WidgetTypeConstant.PICTURE_UPLOAD.equals(type)){
                                    templatePictureMap.put(id,label);
                                //时间段组件id,label映射
                                }else if (WidgetTypeConstant.TIME_RANGE.equals(type) || WidgetTypeConstant.DATA_RANGE.equals(type)){
                                    templateTimeMap.put(id,label);
                                //单选框组件id,label映射
                                }else if(WidgetTypeConstant.RADIO.equals(type)){
                                    templateRadioMap.put(id,label);
                                    if(null !=optionItems){
                                        for(int j=0;j<optionItems.size();j++){
                                            JSONObject optionItem = optionItems.getJSONObject(j);
                                            if(null !=optionItem){
                                                radioOptionItemsMap.put(optionItem.getInteger("value"),optionItem.getString("label"));
                                            }
                                        }
                                    }
                                //多选框组件id,label映射
                                }else if(WidgetTypeConstant.CHECKBOX.equals(type)){
                                    templateCheckboxMap.put(id,label);
                                    if(null !=optionItems){
                                        for(int j=0;j<optionItems.size();j++){
                                            JSONObject optionItem = optionItems.getJSONObject(j);
                                            if(null !=optionItem){
                                                checkboxOptionItemsMap.put(optionItem.getInteger("value"),optionItem.getString("label"));
                                            }
                                        }
                                    }
                                //下拉框组件(单选)id,label映射
                                }else if(WidgetTypeConstant.SELECT.equals(type) && null !=multiple && !multiple){
                                    templateSelectSingleMap.put(id,label);
                                    if(null !=optionItems){
                                        for(int j=0;j<optionItems.size();j++){
                                            JSONObject optionItem = optionItems.getJSONObject(j);
                                            if(null !=optionItem){
                                                selectSingleOptionItemsMap.put(optionItem.getInteger("value"),optionItem.getString("label"));
                                            }
                                        }
                                    }

                                //下拉框组件(多选)id,label映射
                                }else if(WidgetTypeConstant.SELECT.equals(type)  && null !=multiple && multiple){
                                    templateSelectMoreMap.put(id,label);
                                    if(null !=optionItems){
                                        for(int j=0;j<optionItems.size();j++){
                                            JSONObject optionItem = optionItems.getJSONObject(j);
                                            if(null !=optionItem){
                                                selectMoreOptionItemsMap.put(optionItem.getInteger("value"),optionItem.getString("label"));
                                            }
                                        }
                                    }
                                //级联框组件(单选)id,label映射
                                }else if(WidgetTypeConstant.CASCADER.equals(type)  && null !=multiple && !multiple){
                                    templateCascadeSingleMap.put(id,label);
                                    recursionOptionItems(cascaderSingleOptionItemsMap,optionItems);
                                //级联框组件(多选)id,label映射
                                }else if(WidgetTypeConstant.CASCADER.equals(type)  && null !=multiple && multiple){
                                    templateCascaderMoreMap.put(id,label);
                                    recursionOptionItems(cascaderMoreOptionItemsMap,optionItems);
                                }
                                //其他组件id,label映射
                                else {
                                    templateNormalMap.put(id,label);
                                }
                            }
                        }
                    }
                }
            }
            ArrayList<Object> ledgerContextList = new ArrayList<>();
            //获取台账map
            ledgerLists.forEach(e->{
                List<Object> ledgerContext = new ArrayList<>();
                String ledgerContentJson = e.getLedgerContent();
                if(!StringUtils.isEmpty(ledgerContentJson)){
                    JSONObject ledgerObject = JSONObject.parseObject(ledgerContentJson);
                    //其他组件id,value映射
                    templateNormalMap.forEach((key, value) -> {
                        String s = ledgerObject.getString(key);
                        ledgerContext.add(s);
                    });
                    //时间段组件id,value映射
                    templateTimeMap.forEach((key,value)->{
                        JSONArray array = ledgerObject.getJSONArray(key);
                        ledgerContext.add(array);
                    });
                    //单选框组件id,value映射
                    templateRadioMap.forEach((key,value)->{
                        Integer radioValue = ledgerObject.getInteger(key);
                        if(null !=radioValue){
                            String s = radioOptionItemsMap.get(radioValue);
                            ledgerContext.add(s);
                        }
                    });
                    //多选框组件id,value映射
                    templateCheckboxMap.forEach((key,value)->{
                        JSONArray checkboxValueArray = ledgerObject.getJSONArray(key);
                        if(null !=checkboxValueArray){
                            List<String> checkboxValues = new ArrayList<>();
                            for(int j=0;j<checkboxValueArray.size();j++){
                                Integer checkboxValue = checkboxValueArray.getInteger(j);
                                if(null !=checkboxValue){
                                    String s = checkboxOptionItemsMap.get(checkboxValue);
                                    checkboxValues.add(s);
                                }
                            }
                            ledgerContext.add(checkboxValues);
                        }
                    });
                    //下拉框组件(单选)id,value映射
                    templateSelectSingleMap.forEach((key,value)->{
                        Integer selectValue = ledgerObject.getInteger(key);
                        if(null !=selectValue){
                            String s = selectSingleOptionItemsMap.get(selectValue);
                            ledgerContext.add(s);
                        }
                    });
                    //下拉框组件(多选)id,value映射
                    templateSelectMoreMap.forEach((key,value)->{
                        JSONArray selectValueArray = ledgerObject.getJSONArray(key);
                        if(null !=selectValueArray){
                            List<String> selectMoreValues = new ArrayList<>();
                            for(int j=0;j<selectValueArray.size();j++){
                                Integer selectValue = selectValueArray.getInteger(j);
                                if(null !=selectValue){
                                    String s = selectMoreOptionItemsMap.get(selectValue);
                                    selectMoreValues.add(s);
                                }
                            }
                            ledgerContext.add(selectMoreValues);
                        }
                    });
                    //级联框组件(单选)id,value映射
                    templateCascadeSingleMap.forEach((key,value)->{
                        JSONArray cascaderSingleArray = ledgerObject.getJSONArray(key);
                        if(null !=cascaderSingleArray){
                            List<String> cascaderSingleValues = new ArrayList<>();
                            for(int j=0;j<cascaderSingleArray.size();j++){
                                Integer cascaderValue = cascaderSingleArray.getInteger(j);
                                if(null !=cascaderValue){
                                    String s = cascaderSingleOptionItemsMap.get(cascaderValue);
                                    cascaderSingleValues.add(s);
                                }
                            }
                            ledgerContext.add(cascaderSingleValues);
                        }
                    });
                    //级联框组件(多选)id,value映射
                    templateCascaderMoreMap.forEach((key,value)->{
                        JSONArray cascaderMoreListArray = ledgerObject.getJSONArray(key);
                        if(null !=cascaderMoreListArray){
                            List<Object> cascaderMoreListValues = new ArrayList<>();
                            for(int j=0;j<cascaderMoreListArray.size();j++){
                                JSONArray cascaderMoreArray = cascaderMoreListArray.getJSONArray(j);
                                if(null !=cascaderMoreArray){
                                    List<String> cascaderMoreValues = new ArrayList<>();
                                    for(int v=0;v<cascaderMoreArray.size();v++){
                                        Integer cascaderMoreValue = cascaderMoreArray.getInteger(v);
                                        if(null !=cascaderMoreValue){
                                            String s = cascaderMoreOptionItemsMap.get(cascaderMoreValue);
                                            cascaderMoreValues.add(s);
                                        }
                                    }
                                    cascaderMoreListValues.add(cascaderMoreValues);
                                }
                            }
                            ledgerContext.add(cascaderMoreListValues);
                        }
                    });
                    //图片组件组件id,value映射
                    templatePictureMap.forEach((key,value)->{
                        JSONArray pictures = ledgerObject.getJSONArray(key);
                        if(null !=pictures){
                            List<String> urls = new ArrayList<>();
                            for(int i=0;i<pictures.size();i++){
                                JSONObject picture = pictures.getJSONObject(i);
                                if(null !=picture){
                                    String url = picture.getString("url");
                                    urls.add(url);
                                }
                            }
                            ledgerContext.add(urls);
                        }
                    });
                    ledgerContextList.add(ledgerContext);
                }
            });
            List<String> header1 = new ArrayList<>(templateNormalMap.values());
            List<String> header2 = new ArrayList<>(templateTimeMap.values());
            List<String> header3 = new ArrayList<>(templateRadioMap.values());
            List<String> header4 = new ArrayList<>(templateCheckboxMap.values());
            List<String> header5 = new ArrayList<>(templateSelectSingleMap.values());
            List<String> header6 = new ArrayList<>(templateSelectMoreMap.values());
            List<String> header7 = new ArrayList<>(templateCascadeSingleMap.values());
            List<String> header8 = new ArrayList<>(templateCascaderMoreMap.values());
            List<String> header9 = new ArrayList<>(templatePictureMap.values());

            header1.addAll(header2);
            header1.addAll(header3);
            header1.addAll(header4);
            header1.addAll(header5);
            header1.addAll(header6);
            header1.addAll(header7);
            header1.addAll(header8);
            header1.addAll(header9);

            result.put("header",header1);
            result.put("context",ledgerContextList);
        }catch (Exception e){
            log.error("LedgerServiceImpl.parseLedger2 e:{}",JSONObject.toJSONString(e));
        }

        return result;
    }

    /**
     * 递归,解析optionItems中的value,label
     * @param cascaderSingleOptionItemsMap
     * @param optionItems
     */
    private void recursionOptionItems(HashMap<Object, String> cascaderSingleOptionItemsMap, JSONArray optionItems) {
        if(null !=optionItems){
            for(int j=0;j<optionItems.size();j++){
                JSONObject optionItem = optionItems.getJSONObject(j);
                if(null !=optionItem){
                    cascaderSingleOptionItemsMap.put(optionItem.getInteger("value"),optionItem.getString("label"));
                    JSONArray children = optionItem.getJSONArray("children");
                    recursionOptionItems(cascaderSingleOptionItemsMap,children);
                }
            }
        }
    }

四、解析结果及样式

1、后端接口组装数据结果

{
    "code": 200,
    "data": {
        "context": [
            [
                "666",
                "13:56:07",
                "2022-08-12",
                "部门1",
                [
                    "2022-08-13",
                    "2022-09-04"
                ],
                [
                    "13:56:09",
                    "14:56:09"
                ],
                "女",
                [
                    "选项2",
                    "选项3"
                ],
                "select 1",
                [
                    "广东省",
                    "深圳市"
                ],
                [
                    "http://121.36.30.198:80/obs-box-device/ledger/img/20220813/3d346253e59e4b1cab1e7bf4c64069eb.png?AWSAccessKeyId=FB3AZG8TINNQCE2RTIDO&Expires=1660380992&Signature=AAWUVKUUARhAd%2FzjXIRkO6czLTM%3D",
                    "http://121.36.30.198:80/obs-box-device/ledger/img/20220813/9708391cf0cf45519b49d7d5c1d6a7e1.png?AWSAccessKeyId=FB3AZG8TINNQCE2RTIDO&Expires=1660380992&Signature=b6wPR3ovVr%2FuwdDjgdHeJSstP0c%3D"
                ]
            ],
            [
                "888",
                "13:55:49",
                "2022-08-11",
                "部门2",
                [
                    "2022-08-11",
                    "2022-09-05"
                ],
                [
                    "13:56:51",
                    "14:55:52"
                ],
                "男",
                [
                    "选项2",
                    "选项1"
                ],
                "select 2",
                [
                    "湖南省"
                ],
                [
                    "http://121.36.30.198:80/obs-box-device/ledger/img/20220813/42a4e6b5846a4b3d896de27dec68b03e.png?AWSAccessKeyId=FB3AZG8TINNQCE2RTIDO&Expires=1660381028&Signature=Zh00KBD94gq4UQOU9zT9RJL2FvA%3D"
                ]
            ],
            [
                "234",
                "15:20:57",
                "2022-08-26",
                "1124",
                [
                    "2022-08-26",
                    "2022-09-21"
                ],
                [
                    "15:20:59",
                    "16:20:59"
                ],
                "变态",
                [
                    "选项2"
                ],
                "select 2",
                [
                    "江西省"
                ],
                [
                    "http://121.36.30.198:80/obs-box-device/ledger/img/20220813/331911044ad44cd58cbc40e82534d4c9.png?AWSAccessKeyId=FB3AZG8TINNQCE2RTIDO&Expires=1660386077&Signature=X2BfzmMjZnKzenu6LMBlbJBGu4o%3D"
                ]
            ]
        ],
        "header": [
            "计数",
            "时刻",
            "日期",
            "部门",
            "日期范围",
            "时刻范围",
            "性别",
            "多选项",
            "下拉选项-单选",
            "省市级联选择",
            "图片"
        ]
    },
    "subCode": "",
    "success": true,
    "message": ""
}

2、前端展示效果 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值