name: table_design
amis_schema: |-
  {
      "type": "service",
      "body": [
          {
              "type": "button",
              "label": "设置字段",
              "id": "u:table_design",
              "onEvent": {
                  "click": {
                      "weight": 0,
                      "actions": [
                          {
                              "ignoreError": false,
                              "actionType": "dialog",
                              "dialog": {
                                  "type": "dialog",
                                  "title": "设置字段",
                                  "body": [
                                      {
                                          "type": "button-group",
                                          "id": "u:173771bbd1fc",
                                          "buttons": [
                                              {
                                                  "type": "button",
                                                  "label": "新建",
                                                  "onEvent": {
                                                      "click": {
                                                          "actions": [
                                                              {
                                                                  "ignoreError": false,
                                                                  "actionType": "dialog",
                                                                  "dialog": {
                                                                      "type": "dialog",
                                                                      "title": "新建",
                                                                      "body": [
                                                                          {
                                                                              "type": "service",
                                                                              "body": [
                                                                                  {
                                                                                      "type": "steedos-object-form",
                                                                                      "label": "对象表单",
                                                                                      "objectApiName": "b6_fields",
                                                                                      "mode": "edit",
                                                                                      "enableInitApi": false,
                                                                                      "className": "",
                                                                                      "id": "u:6b0ec7966e4e",
                                                                                      "submitSuccActions": [
                                                                                          {
                                                                                              "actionType": "reload",
                                                                                              "componentId": "u:d6234e18fa74",
                                                                                              "groupType": "component"
                                                                                          },
                                                                                          {
                                                                                              "actionType": "broadcast",
                                                                                              "args": {
                                                                                                  "eventName": "broadcast_service_listview_b6_data_rebuild"
                                                                                              }
                                                                                          }
                                                                                      ],
                                                                                      "defaultData": {
                                                                                          "table_id": "${_master.recordId}"
                                                                                      },
                                                                                      "fieldsExtend": "{\n  \"table_id\": {\n    \"visible_on\": \"${false}\"\n  }\n}",
                                                                                      "visibleOn": "${!!_formulaVariablesLoaded}"
                                                                                  }
                                                                              ],
                                                                              "dsType": "api",
                                                                              "api": {
                                                                                  "url": "${context.rootUrl}/api/v1/b6_fields",
                                                                                  "method": "get",
                                                                                  "requestAdaptor": "api.url += '?filters=[\"table_id\", \"=\", \"' + context._master.recordId + '\"]&fields=[\"label\",\"name\",\"type\"]';\nreturn api;",
                                                                                  "adaptor": "var formulaVariables = [];\nvar fTypeTags = {\n  \"text\": \"文本\",\n  \"textarea\": \"长文本\",\n  \"number\": \"数字\",\n  \"select\": \"单选\",\n  \"select-multiple\": \"多选\",\n  \"boolean\": \"勾选\",\n  \"date\": \"日期\",\n  \"datetime\": \"日期时间\",\n  \"formula\": \"公式\",\n};\nvar getFormulaVariableTag = function (type) { \n  var tag = fTypeTags[type] || type;\n  return tag;\n}\nif (payload.data.items && payload.data.items.length) { \n  formulaVariables = payload.data.items.map(function (n) {\n    return {\n      \"label\": n.label,\n      \"value\": n.name,\n      \"tag\": getFormulaVariableTag(n.type)\n    }\n  })\n}\npayload.data = {\n  _b6_fields__formula_variables: formulaVariables,\n  _formulaVariablesLoaded: true\n}\nreturn payload;",
                                                                                  "messages": {},
                                                                                  "data": {}
                                                                              },
                                                                              "data": {
                                                                                  "_formulaVariablesLoaded": false
                                                                              },
                                                                              "id": "u:5da8793f0071"
                                                                          }
                                                                      ],
                                                                      "id": "u:b7df4c75cba3",
                                                                      "actions": [
                                                                          {
                                                                              "type": "button",
                                                                              "actionType": "cancel",
                                                                              "label": "取消",
                                                                              "id": "u:d727f2a03df4"
                                                                          },
                                                                          {
                                                                              "type": "button",
                                                                              "actionType": "confirm",
                                                                              "label": "确定",
                                                                              "primary": true,
                                                                              "id": "u:1f4e248f851b"
                                                                          }
                                                                      ],
                                                                      "showCloseButton": true,
                                                                      "closeOnOutside": false,
                                                                      "closeOnEsc": false,
                                                                      "showErrorMsg": true,
                                                                      "showLoading": true,
                                                                      "draggable": false,
                                                                      "actionType": "dialog",
                                                                      "editorSetting": {
                                                                          "displayName": "新建"
                                                                      },
                                                                      "resizable": false,
                                                                      "onEvent": {
                                                                          "confirm": {
                                                                              "weight": 0,
                                                                              "actions": []
                                                                          }
                                                                      },
                                                                      "size": "lg"
                                                                  },
                                                                  "size": "lg"
                                                              }
                                                          ]
                                                      }
                                                  },
                                                  "id": "u:f4bb2603b8e2",
                                                  "level": "primary"
                                              },
                                              {
                                                  "type": "button",
                                                  "label": "排序",
                                                  "disabledOn": "${filters.length}",
                                                  "onEvent": {
                                                      "click": {
                                                          "actions": [
                                                              {
                                                                  "componentId": "u:d6234e18fa74",
                                                                  "groupType": "component",
                                                                  "actionType": "initDrag"
                                                              }
                                                          ]
                                                      }
                                                  },
                                                  "id": "u:f4bb2603b8e2"
                                              }
                                          ]
                                      },
                                      {
                                          "type": "crud",
                                          "hideQuickSaveBtn": true,
                                          "syncLocation": false,
                                          "api": {
                                              "method": "get",
                                              "url": "/api/v1/b6_fields?sort=sort_no",
                                              "messages": {},
                                              "requestAdaptor": "const masterRecordId = context._master.recordId;\nlet filters = [\"table_id\", \"=\", masterRecordId];\nconst contextFilters = context && context.filters;\nif (contextFilters?.length) {\n  filters = [filters, contextFilters]\n} \napi.url = api.url + \"&skip=\" + context.top * (context.page - 1);\napi.url = api.url + '&filters=' + JSON.stringify(filters);\nreturn api;",
                                              "adaptor": ""
                                          },
                                          "saveOrderApi": {
                                              "url": "/api/builder6/b6_crud/order/b6_fields",
                                              "data": {
                                                  "insertBefore": "${insertBefore}",
                                                  "insertAfter": "${insertAfter}"
                                              }
                                          },
                                          "bulkActions": [],
                                          "columns": [
                                              {
                                                  "name": "_id",
                                                  "label": "ID",
                                                  "type": "text",
                                                  "hidden": true,
                                                  "id": "u:5963440c8296"
                                              },
                                              {
                                                  "name": "label",
                                                  "label": "显示名",
                                                  "sortable": true,
                                                  "type": "text",
                                                  "id": "u:ac13847067a1"
                                              },
                                              {
                                                  "name": "name",
                                                  "label": "字段名",
                                                  "sortable": true,
                                                  "type": "text",
                                                  "id": "u:1dd5b59242c4"
                                              },
                                              {
                                                  "name": "type",
                                                  "label": "字段类型",
                                                  "type": "select",
                                                  "static": true,
                                                  "sortable": true,
                                                  "options": [
                                                      {
                                                          "label": "文本",
                                                          "value": "text"
                                                      },
                                                      {
                                                          "label": "长文本",
                                                          "value": "textarea"
                                                      },
                                                      {
                                                          "label": "数字",
                                                          "value": "number"
                                                      },
                                                      {
                                                          "label": "单选",
                                                          "value": "select"
                                                      },
                                                      {
                                                          "label": "多选",
                                                          "value": "select-multiple"
                                                      },
                                                      {
                                                          "label": "勾选",
                                                          "value": "boolean"
                                                      },
                                                      {
                                                          "label": "日期",
                                                          "value": "date"
                                                      },
                                                      {
                                                          "label": "日期时间",
                                                          "value": "datetime"
                                                      },
                                                      {
                                                          "label": "公式",
                                                          "value": "formula"
                                                      }
                                                  ],
                                                  "id": "u:7227be25ce12"
                                              },
                                              {
                                                  "type": "operation",
                                                  "label": "操作",
                                                  "width": 100,
                                                  "fixed": "right",
                                                  "buttons": [
                                                      {
                                                          "type": "button",
                                                          "icon": "fa fa-eye",
                                                          "actionType": "dialog",
                                                          "dialog": {
                                                              "type": "dialog",
                                                              "title": "查看",
                                                              "size": "lg",
                                                              "body": [
                                                                  {
                                                                      "type": "service",
                                                                      "body": [
                                                                          {
                                                                              "type": "steedos-object-form",
                                                                              "id": "u:fe44bc0ba67a",
                                                                              "mode": "read",
                                                                              "label": "对象表单",
                                                                              "objectApiName": "b6_fields",
                                                                              "recordId": "${_id}",
                                                                              "enableInitApi": true,
                                                                              "className": "",
                                                                              "fieldsExtend": "{\n  \"table_id\": {\n    \"visible_on\": \"${false}\"\n  }\n}",
                                                                              "visibleOn": "${!!_formulaVariablesLoaded}"
                                                                          }
                                                                      ],
                                                                      "dsType": "api",
                                                                      "api": {
                                                                          "url": "${context.rootUrl}/api/v1/b6_fields",
                                                                          "method": "get",
                                                                          "requestAdaptor": "api.url += '?filters=[\"table_id\", \"=\", \"' + context._master.recordId + '\"]&fields=[\"label\",\"name\",\"type\"]';\nreturn api;",
                                                                          "adaptor": "var formulaVariables = [];\nvar fTypeTags = {\n  \"text\": \"文本\",\n  \"textarea\": \"长文本\",\n  \"number\": \"数字\",\n  \"select\": \"单选\",\n  \"select-multiple\": \"多选\",\n  \"boolean\": \"勾选\",\n  \"date\": \"日期\",\n  \"datetime\": \"日期时间\",\n  \"formula\": \"公式\",\n};\nvar getFormulaVariableTag = function (type) { \n  var tag = fTypeTags[type] || type;\n  return tag;\n}\nif (payload.data.items && payload.data.items.length) { \n  formulaVariables = payload.data.items.map(function (n) {\n    return {\n      \"label\": n.label,\n      \"value\": n.name,\n      \"tag\": getFormulaVariableTag(n.type)\n    }\n  })\n}\npayload.data = {\n  _b6_fields__formula_variables: formulaVariables,\n  _formulaVariablesLoaded: true\n}\nreturn payload;",
                                                                          "messages": {},
                                                                          "data": {}
                                                                      },
                                                                      "data": {
                                                                          "_formulaVariablesLoaded": false
                                                                      },
                                                                      "id": "u:6c02fbd691a2"
                                                                  }
                                                              ],
                                                              "actionType": "dialog",
                                                              "id": "u:5df0ff2a1edd",
                                                              "actions": [
                                                                  {
                                                                      "type": "button",
                                                                      "actionType": "cancel",
                                                                      "label": "取消",
                                                                      "id": "u:9a90722a7cfa"
                                                                  },
                                                                  {
                                                                      "type": "button",
                                                                      "actionType": "confirm",
                                                                      "label": "确定",
                                                                      "primary": true,
                                                                      "id": "u:5d03414533af"
                                                                  }
                                                              ],
                                                              "showCloseButton": true,
                                                              "closeOnOutside": false,
                                                              "closeOnEsc": false,
                                                              "showErrorMsg": true,
                                                              "showLoading": true,
                                                              "draggable": false
                                                          },
                                                          "id": "u:6953bff06696"
                                                      },
                                                      {
                                                          "type": "button",
                                                          "icon": "fa fa-pencil",
                                                          "actionType": "dialog",
                                                          "dialog": {
                                                              "type": "dialog",
                                                              "title": "编辑",
                                                              "size": "lg",
                                                              "body": [
                                                                  {
                                                                      "type": "service",
                                                                      "body": [
                                                                          {
                                                                              "type": "steedos-object-form",
                                                                              "id": "u:fe44bc0ba67a",
                                                                              "mode": "edit",
                                                                              "label": "对象表单",
                                                                              "objectApiName": "b6_fields",
                                                                              "recordId": "${_id}",
                                                                              "enableInitApi": true,
                                                                              "className": "",
                                                                              "submitSuccActions": [
                                                                                  {
                                                                                      "actionType": "reload",
                                                                                      "componentId": "u:d6234e18fa74",
                                                                                      "groupType": "component"
                                                                                  },
                                                                                  {
                                                                                      "actionType": "broadcast",
                                                                                      "args": {
                                                                                          "eventName": "broadcast_service_listview_b6_data_rebuild"
                                                                                      }
                                                                                  }
                                                                              ],
                                                                              "fieldsExtend": "{\n  \"table_id\": {\n    \"visible_on\": \"${false}\"\n  }\n}",
                                                                              "visibleOn": "${!!_formulaVariablesLoaded}"
                                                                          }
                                                                      ],
                                                                      "dsType": "api",
                                                                      "api": {
                                                                          "url": "${context.rootUrl}/api/v1/b6_fields",
                                                                          "method": "get",
                                                                          "requestAdaptor": "api.url += '?filters=[\"table_id\", \"=\", \"' + context._master.recordId + '\"]&fields=[\"label\",\"name\",\"type\"]';\nreturn api;",
                                                                          "adaptor": "var formulaVariables = [];\nvar fTypeTags = {\n  \"text\": \"文本\",\n  \"textarea\": \"长文本\",\n  \"number\": \"数字\",\n  \"select\": \"单选\",\n  \"select-multiple\": \"多选\",\n  \"boolean\": \"勾选\",\n  \"date\": \"日期\",\n  \"datetime\": \"日期时间\",\n  \"formula\": \"公式\",\n};\nvar getFormulaVariableTag = function (type) { \n  var tag = fTypeTags[type] || type;\n  return tag;\n}\nif (payload.data.items && payload.data.items.length) { \n  formulaVariables = payload.data.items.map(function (n) {\n    return {\n      \"label\": n.label,\n      \"value\": n.name,\n      \"tag\": getFormulaVariableTag(n.type)\n    }\n  })\n}\npayload.data = {\n  _b6_fields__formula_variables: formulaVariables,\n  _formulaVariablesLoaded: true\n}\nreturn payload;",
                                                                          "messages": {},
                                                                          "data": {}
                                                                      },
                                                                      "id": "u:714939d3f3cc",
                                                                      "data": {
                                                                          "_formulaVariablesLoaded": false
                                                                      }
                                                                  }
                                                              ],
                                                              "actionType": "dialog",
                                                              "id": "u:dbbd6d64d949",
                                                              "actions": [
                                                                  {
                                                                      "type": "button",
                                                                      "actionType": "cancel",
                                                                      "label": "取消",
                                                                      "id": "u:30d4bab40dff"
                                                                  },
                                                                  {
                                                                      "type": "button",
                                                                      "actionType": "confirm",
                                                                      "label": "确定",
                                                                      "primary": true,
                                                                      "id": "u:bc50710298c1"
                                                                  }
                                                              ],
                                                              "showCloseButton": true,
                                                              "closeOnOutside": false,
                                                              "closeOnEsc": false,
                                                              "showErrorMsg": true,
                                                              "showLoading": true,
                                                              "draggable": false
                                                          },
                                                          "id": "u:c52f85b98640"
                                                      },
                                                      {
                                                          "type": "button",
                                                          "icon": "fa fa-times text-danger",
                                                          "confirmText": "确定要删除吗",
                                                          "onEvent": {
                                                              "click": {
                                                                  "weight": 0,
                                                                  "actions": [
                                                                      {
                                                                          "ignoreError": false,
                                                                          "actionType": "ajax",
                                                                          "outputVar": "responseResult",
                                                                          "options": {},
                                                                          "api": {
                                                                              "url": "/api/v1/b6_fields/${_id}",
                                                                              "method": "delete",
                                                                              "requestAdaptor": "",
                                                                              "adaptor": "",
                                                                              "messages": {}
                                                                          }
                                                                      },
                                                                      {
                                                                          "componentId": "u:d6234e18fa74",
                                                                          "groupType": "component",
                                                                          "actionType": "reload"
                                                                      },
                                                                      {
                                                                          "actionType": "broadcast",
                                                                          "args": {
                                                                              "eventName": "broadcast_service_listview_b6_data_rebuild"
                                                                          }
                                                                      }
                                                                  ]
                                                              }
                                                          },
                                                          "id": "u:0a119a9ef3bb"
                                                      }
                                                  ],
                                                  "id": "u:293c7e7b65ef",
                                                  "placeholder": "-"
                                              }
                                          ],
                                          "id": "u:d6234e18fa74",
                                          "perPageAvailable": [
                                              10
                                          ],
                                          "messages": {},
                                          "primaryField": "_id",
                                          "filter": null,
                                          "perPageField": "top"
                                      }
                                  ],
                                  "id": "u:set_fields_dialog",
                                  "data": {
                                      "_crud_conditions": {},
                                      "filters": [],
                                      "_crud_ordering": false,
                                      "_master": "${_master}"
                                  },
                                  "actions": [
                                      {
                                          "type": "button",
                                          "actionType": "cancel",
                                          "label": "取消",
                                          "id": "u:cd0da5df3e78"
                                      },
                                      {
                                          "type": "button",
                                          "actionType": "confirm",
                                          "label": "确定",
                                          "primary": true,
                                          "id": "u:3ca3a2bb15b0"
                                      }
                                  ],
                                  "showCloseButton": true,
                                  "closeOnOutside": false,
                                  "closeOnEsc": false,
                                  "showErrorMsg": true,
                                  "showLoading": true,
                                  "draggable": false,
                                  "actionType": "dialog",
                                  "size": "lg"
                              }
                          }
                      ]
                  }
              },
              "editorState": "default"
          }
      ],
      "regions": [
          "body"
      ],
      "data": {
          "context": {},
          "dataComponentId": "",
          "record_id": "",
          "record": {},
          "permissions": {}
      },
      "id": "u:d1ab787d7dac",
      "bodyClassName": "p-0",
      "dsType": "api",
      "editorState": "default",
      "asideResizor": false,
      "pullRefresh": {
          "disabled": true
      }
  }
is_enable: true
label: 设置字段
locked: false
'on': record_only
type: amis_button
visible: true
sort: 10
