{
  "type": "page",
  "title": "Welcome to Steedos",
  "body": [
    {
      "type": "service",
      "id": "instance_tasks_list_service",
      "className": "h-full w-full p-0 m-0",
      "pageGridClassName": "h-full m-0",
      "body": [
        {
          "type": "steedos-object-listview",
          "objectApiName": "instance_tasks",
          "columnsTogglable": false,
          "filterVisible": true,
          "showHeader": true,
          "id": "u:d29cef0d1007",
          "showDisplayAs": true,
          "className": "h-full w-full bg-white instance-tasks-list",
          "hiddenColumnOperation": true,
          "formFactor": "LARGE",
          "headerToolbarItems": [
            {
              "type": "button",
              "label": "",
              "icon": "fa fa-bars",
              "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
              "align": "right",
              "onEvent": {
                "click": {
                  "actions": [
                    {
                      "actionType": "custom",
                      "script": "console.log(event.target);document.querySelector('.instances-customPage').classList.toggle('instances-sidebar-open');if(window.innerWidth < 768){document.querySelector('.isInset').classList.toggle('inset-0')}"
                    }
                  ]
                }
              },
              "id": "u:115e270cae4d"
            }
          ],
          "listName": "inbox",
          "rowClassNameExpr": "<%=(data.is_read === false && (!data.clientIds || data.clientIds.length == 0 || !data.clientIds.includes(data._id))) ? 'unread-instance' : '' %>",
          "rebuildOn": "\\${flowId || categoryId}",
          "adaptor": "const isSearch = _.some(_.keys(api.body.self), key => key.includes('__keywords') || key.includes('__searchable__'));\nif(payload.data.count==0 && !isSearch){\n    const searchParams = new URLSearchParams(window.location.search);\n    const flowId = searchParams.get(\"flowId\");\n    const categoryId = searchParams.get(\"categoryId\");\n    const pathname = window.location.pathname;\n    if(flowId || categoryId){\n      window.FlowRouter.go(pathname + \"?additionalFilters=&flowId=&categoryId=\");\n    }\n    // if(flowId) {\n    //     window.FlowRouter.go(pathname + \"?additionalFilters=['category','=','\" + categoryId +\"']&flowId=&categoryId=\" + categoryId);\n    // }else if(categoryId) {\n    //     window.FlowRouter.go(pathname + \"?additionalFilters=&flowId=&categoryId=\");\n    // }\n};\nif (api.body.self.listName == \"inbox\") {\n  _.each(payload.data.rows, function (item, index) {\n    if (item.type == 'cc') {\n      item.instance_name += '（传阅）';\n    }\n    if (item.instance__expand.values) {\n      const form_fields = api.body.self.form_fields;\n      _.each(item.instance__expand.values, function (field, field_code) {\n        const form_field = _.find(form_fields, { code: field_code });\n        if (form_field && form_field.type == \"group\") {\n          if (form_field.is_multiselect) {\n            item.instance__expand.values[field_code] = field && field.length > 0 ? _.map(field, 'fullname').toString() : \"\";\n          } else {\n            item.instance__expand.values[field_code] = field ? field.fullname : \"\";\n          }\n        } else if (form_field && form_field.type == \"user\") {\n          if (form_field.is_multiselect) {\n            item.instance__expand.values[field_code] = field && field.length > 0 ? _.map(field, 'name').toString() : \"\";\n          } else {\n            item.instance__expand.values[field_code] = field ? field.name : \"\";\n          }\n        }\n      })\n    }\n  })\n}\n",
          "crudDataFilter": "if (data && data.flowId && (data.listName == 'inbox' || 'monitor') && window.innerWidth > 768) {\r\n  var api = {\r\n    url: \"${context.rootUrl}/graphql\",\r\n    method: \"post\",\r\n    dataType: \"json\",\r\n    data: {\r\n      \"query\": '{flow: flows__findOne(id:\"' + data.flowId + '\"){form__expand{current}}}'\r\n    },\r\n    headers: {\r\n      Authorization:\r\n        \"Bearer ${context.tenantId},${context.authToken}\",\r\n    },\r\n  };\r\n  return env.fetcher(api).then((result) => {\r\n    if (result.data && result.data.flow && result.data.flow.form__expand.current.fields && result.data.flow.form__expand.current.fields.length > 0) {\r\n      let fields = result.data.flow.form__expand.current.fields;\r\n      fields.forEach(function (field) {\r\n        if (field.is_list_display) {\r\n          crud.columns.push({\r\n            \"name\": \"instance__expand.values.\" + field.code,\r\n            \"label\": field.name || field.code,\r\n            \"width\": \"unset\",\r\n            \"type\": \"text\",\r\n            \"className\": \" whitespace-nowrap\",\r\n            \"static\": true,\r\n            \"options\": null\r\n          });\r\n        }\r\n      })\r\n      let schemaApiService = SteedosUI.getRef('steedosPageObjectControl').parent.getComponentById(\"instance_tasks_list_service\");\r\n      schemaApiService && schemaApiService.setData({ form_fields: fields, isFlowDataDone: true });\r\n      crud.api.sendOn = \"this.isFlowDataDone\";\r\n    }\r\n    return crud;\r\n  });\r\n} else {\r\n  let schemaApiService = SteedosUI.getRef('steedosPageObjectControl').parent.getComponentById(\"instance_tasks_list_service\");\r\n  schemaApiService && schemaApiService.setData({ isFlowDataDone: true });\r\n  crud.api.sendOn = \"this.isFlowDataDone\"; if(data.display == 'split'){Object.assign(crud, {\"onEvent\":{\"rowClick\":{\"actions\":[{\"actionType\":\"custom\",\"script\":\"const clientIds = event.data.clientIds || []; clientIds.push(event.data.item._id);doAction({actionType: 'setValue', componentId: 'service_listview_instance_tasks', args: {value: {clientIds: clientIds}}})\"}]}},\"id\":\"u:af8bd61b2b28\"});} ; \r\n  return crud;\r\n}\r\n"
        },
        {
          "type": "action",
          "body": [
            {
              "type": "action",
              "className": {
                "mobileCss": "${window:innerWidth < 768}",
                "pcCss": "${window:innerWidth > 768}",
                "instances-sidebar-wrapper px-0 fixed z-20 h-full h-fill ease-in-out duration-300 flex flex-col overflow-y-auto bg-white block -translate-x-0 py-0": "true"
              },
              "body": [
                {
                  "type": "service",
                  "id": "u:workflow_nav_service",
                  "className": "w-full h-full border-r",
                  "onEvent": {
                    "@data.changed.instance_tasks": {
                      "actions": [
                        {
                          "actionType": "setValue",
                          "args": {
                            "value": {
                              "workflowNavApiCacheKey": "${_|now|date:'x'}"
                            }
                          }
                        }
                      ]
                    }
                  },
                  "body": [
                    {
                      "type": "input-tree",
                      "name": "tree",
                      "treeContainerClassName": "h-full",
                      "className": "instance-box-tree bg-white h-full w-full p-0",
                      "id": "u:9f3dd961ca12",
                      "stacked": true,
                      "multiple": false,
                      "enableNodePath": false,
                      "hideRoot": true,
                      "showIcon": true,
                      "initiallyOpen": false,
                      "virtualThreshold": 100000,
                      "value": "${CONCATENATE('/app/', appId, '/', objectName, '/grid/', listViewId, '?additionalFilters=', additionalFilters,'&flowId=',flowId,'&categoryId=',categoryId)}",
                      "size": "md",
                      "onEvent": {
                        "change": {
                          "actions": [
                            {
                              "actionType": "setValue",
                              "componentId": "instance_tasks_list_service",
                              "args": {
                                "value": {
                                  "isFlowDataDone": false
                                }
                              }
                            },
                            {
                              "actionType": "custom",
                              "script": "if (window.innerWidth < 768) { document.querySelector('.instances-customPage').classList.remove('instances-sidebar-open'); document.querySelector('.isInset').classList.remove('inset-0') }\n//获取上一次的flowId和categoryId\nconst lastFlowId = event.data.flowId;\nconst lastCategoryId = event.data.categoryId;\n//从value中获取最新的flowId\nvar flowIdRegex = /&flowId=([^&]+)/;\nvar flowIdMatch = event.data.value.match(flowIdRegex);\nconst flowId = flowIdMatch && flowIdMatch.length > 0 ? flowIdMatch[1] : \"\";\n//从value中获取最新的categoryId\nvar categoryIdRegex = /&categoryId=([^&]+)/;\nvar categoryIdMatch = event.data.value.match(categoryIdRegex);\nconst categoryId = categoryIdMatch && categoryIdMatch.length > 0 ? categoryIdMatch[1] : \"\";\n//获取上一次的listname和最新的listname\nconst lastListName = event.data.listName;\nconst listName = event.data.value.split('?')[0].split('instance_tasks/grid/')[1];\n//切换流程时清除过滤条件\nif (lastListName == \"inbox\" && listName == \"inbox\" && (flowId != lastFlowId || categoryId != lastCategoryId)) {\n  listViewPropsStoreKey = window.location.pathname + \"/crud\";\n  sessionStorage.removeItem(listViewPropsStoreKey);\n  sessionStorage.removeItem(listViewPropsStoreKey + \"/query\");\n}\n\n"
                            },
                            {
                              "actionType": "setValue",
                              "args": {
                                "value": {
                                  "additionalFilters": [
                                    "${event.data.options.name}",
                                    "=",
                                    "${event.data.options.value}"
                                  ]
                                }
                              },
                              "componentId": "instance_tasks_list_service",
                              "expression": "${event.data.options.level>=10}"
                            },
                            {
                              "args": {
                                "link": "${event.data.value}",
                                "blank": false
                              },
                              "actionType": "link"
                            }
                          ]
                        }
                      },
                      "menuTpl": {
                        "type": "wrapper",
                        "className": "flex flex-row  p-0 m-0",
                        "body": [
                          {
                            "type": "tpl",
                            "className": "flex-1 w-6/12",
                            "tpl": "${label}",
                            "id": "u:adf0cfafa63c"
                          },
                          {
                            "type": "tpl",
                            "className": "-mx-11 ",
                            "tpl": "",
                            "badge": {
                              "className": "h-0",
                              "offset": [
                                -20,
                                12
                              ],
                              "mode": "text",
                              "text": "${tag | toInt}",
                              "overflowCount": 999
                            },
                            "id": "u:ac230c095386"
                          }
                        ],
                        "id": "u:74a18fd2df0b"
                      },
                      "unfoldedLevel": 2,
                      "source": "${options}"
                    }
                  ],
                  "api": {
                    "method": "get",
                    "url": "${context.rootUrl}/api/${appId}/workflow/nav?cacheKey=${workflowNavApiCacheKey}",
                    "cache": 1800000,
                    "headers": {
                      "Authorization": "Bearer ${context.tenantId},${context.authToken}"
                    },
                    "messages": {
                    }
                  },
                  "messages": {
                  }
                }
              ],
              "id": "u:5d1f5d7c38d2"
            }
          ],
          "onEvent": {
            "click": {
              "actions": [
                {
                  "actionType": "custom",
                  "script": "if(window.innerWidth < 768){document.querySelector('.instances-customPage').classList.remove('instances-sidebar-open');document.querySelector('.isInset').classList.remove('inset-0') }"
                }
              ]
            }
          },
          "className": {
            "absolute isInset": "true"
          },
          "id": "u:c8fc09ce5d6b"
        }
      ],
      "onEvent": {
        "@data.changed.steedos_keyvalues": {
          "actions": [
            {
              "actionType": "broadcast",
              "args": {
                "eventName": "@data.changed.instance_tasks"
              },
              "data": {
                "objectName": "instance_tasks",
                "recordId": "reload"
              }
            }
          ]
        }
      },
      "data": {
        "isFlowDataDone": false
      }
    }
  ],
  "regions": [
    "body"
  ],
  "data": {
    "objectName": "instance_tasks",
    "initialValues": {},
    "title": ""
  },
  "id": "u:7e20ab64163e",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  },
  "bodyClassName": {
    "p-0 instances-customPage instances-sidebar": "true",
    "pc instances-sidebar-open instances-minwidth": "${window:innerWidth > 768}"
  },
  "css": {
    ".instances-customPage.instances-sidebar.instances-sidebar-open.pc": {
      "margin-left": "240px"
    },
    ".instances-sidebar-wrapper": {
      "transition": "0.5s ease transform",
      "will-change": "transform",
      "transform": "translate(-100%,0)",
      "-webkit-transform": "translate(-100%,0)",
      "-moz-transform": "translate(-100%,0)",
      "-ms-transform": "translate(-100%,0)",
      "-o-transform": "translate(-100%,0)",
      "width": "240px"
    },
    ".instances-customPage.instances-sidebar-open .instances-sidebar-wrapper": {
      "transform": "translate(0,0)",
      "-webkit-transform": "translate(0,0)",
      "-moz-transform": "translate(0,0)",
      "-ms-transform": "translate(0,0)",
      "-o-transform": "translate(0,0)"
    },
    ".pcCss": {
      "top": "90px",
      "left": "0px"
    },
    ".sidebar .pcCss": {
      "left": "220px"
    },
    ".mobileCss": {
      "top": "50px",
      "left": "0px",
      "padding-bottom": "65px"
    },
    ".instances-minwidth": {
      "min-width": "388px"
    }
  }
}