[关闭]
@lina 2018-01-30T14:35:51.000000Z 字数 52756 阅读 1580

AMis 文档


title: 渲染器

AMis 页面是通过 Json 配置出来的,是由一个一个渲染模型组成的,掌握他们规则,就能灵活配置出各种页面。

Page

Json 配置最外层是一个 Page 渲染器。效果如下:(Demo 支持修改配置,及时渲染)。然后在各个区域(容器)内中放各种子组件拼凑出页面。

  1. {
  2. "type": "page",
  3. "title": "Title",
  4. "subTitle": "SubTitle",
  5. "remark": "Remark",
  6. "aside": "Aside",
  7. "body": "Body",
  8. "toolbar": "Toolbar"
  9. }
属性名 类型 默认值 说明
type string "page" 指定为 Page 渲染器,默认就是这个值,所以不用写。
title string 页面标题
subTitle string 页面子标题
remark string 页面描述,由一个 tooltip 展示内容。
aside Container 往页面的边栏区域加内容
toolbar Container 往页面的右上角加内容,需要注意的是,当有 Title 是,区域在右上角,没有时区域就在顶部
body Container 往页面的内容区域加内容
className string 外层 dom 类名
toolbarClassName string hidden-xs v-middle padder-md text-right bg-light b-b Toolbar dom 类名
bodyClassName string wrapper Body dom 类名
asideClassName string w bg-light dk b-r bg-auto Aside dom 类名
headerClassName string bg-light b-b wrapper Header 区域 dom 类名
initApi Api Page 用来获取初始数据的 api。返回的数据可以整个 page 级别使用。详情

Form

Form 是 AMis 中用得最多的渲染模型了,它可以作为 Container 的成员,放在你想要放置的区域。

比如:

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "form",
  5. "name": "sample1",
  6. "api": "/api/mock/saveForm",
  7. "controls": [
  8. {
  9. "name": "email",
  10. "label": "Email",
  11. "type": "email",
  12. "desc": "描述文字"
  13. },
  14. {
  15. "name": "text",
  16. "type": "text",
  17. "label": "Text"
  18. }
  19. ]
  20. }
  21. }
属性名 类型 默认值 说明
type string "form" 指定为 Form 渲染器
name string 给当前 form 取个名字,可用来跟其他 Renderer 交互。
className string 外层 Dom 的类名
title string "表单" Form 的标题
mode string normal 表单展示方式,可以是:normalhorizontal 或者 inline 示例
horizontal Object {"left":"col-sm-2", "right":"col-sm-10", "offset":"col-sm-offset-2"} 当 mode 为 horizontal 时有用,用来控制 label 和 input 的宽度占比。
horizontalDeeper Object {"left":"col-sm-4", "right":"col-sm-8", "offset":"col-sm-offset-4"} 当 mode 为 horizontal 时有用,用来控制深层表单的 label 和 input 的宽度占比。(表单和表单可以用数组组合起来用,这样表单的层级就更深了)
controls Array of FormItem Form 表单项集合 详情
tabs Array of Tab Form 表单项集合 详情
fieldSet Array of FieldSet Form 表单项集合 详情
submitText String "提交" 默认的提交按钮名称,如果设置成空,则可以把默认按钮去掉。
actions Array of Action Form 提交按钮,成员为 Action 详情
messages Object 消息提示覆写,默认消息读取的是 API 返回的消息,但是在此可以覆写它。
messages.fetchSuccess string 获取成功时提示
messages.fetchFailed string 获取失败时提示
messages.saveFailed string 保存成功时提示
messages.saveSuccess string 保存失败时提示
wrapWithPanel boolean true 是否让 Form 用 panel 包起来,设置为 false 后,actions 将无效。
api Api Form 用来保存数据的 api。详情
initApi Api Form 用来获取初始数据的 api。详情
initAsyncApi Api Form 用来获取初始数据的 api,与initApi不同的是,会一直轮训请求该接口,直到返回 finished 属性为 true 才 结束。详情
initFetch boolean true 设置了initApi或者initAsyncApi后,默认会开始就发请求,设置为false后就不会起始就请求接口
initFinishedField string finished 设置了initAsyncApi后,默认会从返回数据的data.finished来判断是否完成,也可以设置成其他的xxx,就会从data.xxx中获取
initCheckInterval number 3000 设置了initAsyncApi以后,默认拉取的时间间隔
schemaApi Api Form 用来获取远程 Schema 的 api。详情
asyncApi Api 设置此属性后,表单提交发送保存接口后,还会继续轮训请求该接口,直到返回 finished 属性为 true 才 结束。详情
checkInterval number 3000 轮训请求的时间间隔,默认为 3秒。设置 asyncApi 才有效
finishedField string "finished" 如果决定结束的字段名不是 finished 请设置此属性,比如 is_success
submitOnChange boolean false 表单修改即提交
primaryField string "id" 设置主键 id, 当设置后,检测表单是否完成时(asyncApi),只会携带此数据。
target string 默认表单提交自己会通过发送 api 保存数据,但是也可以设定另外一个 form 的 name 值,或者另外一个 CRUD 模型的 name 值。 如果 target 目标是一个 Form ,则目标 Form 会重新触发 initApischemaApi,api 可以拿到当前 form 数据。如果目标是一个 CRUD 模型,则目标模型会重新触发搜索,参数为当前 Form 数据。
collapsable boolean false 当通过 fieldSet 方式设置 FormItem 时有效。开启可收起与展开功能。
redirect string 设置此属性后,Form 保存成功后,自动跳转到指定页面。支持相对地址,和绝对地址(相对于组内的)。
autoFocus boolean true 是否自动聚焦。
attachChanged boolean false 是否将表单是否修改过发送给后端
changedKey string isChanged 是否修改过表单提交给后端时,发送的key
changedTrueValue boolean/string/number true 如果修改过发送给后端的值
changedFalseValue boolean/string/number false 如果没有修改过发送给后端的值

表单中,主要的成员由表单项组成,有三种设置方式,分别是:controls、[tabs](#tabs(form)和fieldSet

controls

类型是数组,成员主要是FormItem,默认一行一个(当然 form 是 inline 模式时例外),如果想一行多个,可以将多个FormItem合并成数组作为 controls 的成员。

```schema:height="360" scope="body"
{
"type": "form",
"name": "sample2",
"controls": [
{
"type": "text",
"name": "test",
"label": "Label",
"placeholder": "Placeholder"
},

{
  "type": "divider"
},

[
  {
    "type": "text",
    "name": "test1",
    "label": "Label",
    "placeholder": "Placeholder"
  },

  {
    "type": "text",
    "name": "test2",
    "label": "Label",
    "placeholder": "Placeholder"
  }
]

]
}

  1. 水平模式的 Form 也能很好的展现。
  2. <div class="md-section-divider"></div>
  3. ```schema:height="370" scope="body"
  4. {
  5. "type": "form",
  6. "mode": "horizontal",
  7. "name": "sample3",
  8. "controls": [
  9. {
  10. "type": "text",
  11. "name": "test",
  12. "label": "Label",
  13. "placeholder": "Placeholder"
  14. },
  15. {
  16. "type": "divider"
  17. },
  18. [
  19. {
  20. "type": "text",
  21. "name": "test1",
  22. "label": "Label",
  23. "placeholder": "Placeholder"
  24. },
  25. {
  26. "type": "text",
  27. "name": "test2",
  28. "label": "Label",
  29. "placeholder": "Placeholder"
  30. }
  31. ],
  32. {
  33. "type": "divider"
  34. },
  35. [
  36. {
  37. "type": "text",
  38. "name": "test3",
  39. "label": "Label",
  40. "inline": true,
  41. "placeholder": "Placeholder"
  42. },
  43. {
  44. "inline": true,
  45. "inlineLabelClassName": "w-auto",
  46. "type": "text",
  47. "name": "test4",
  48. "label": "Label",
  49. "placeholder": "Placeholder"
  50. }
  51. ]
  52. ]
  53. }

tabs(form)

FormItem 可以通过 controls 设置,也可以通过 tabs 设置。格式如下:

Array of Tab

```schema:height="400" scope="body"
{
"type": "form",
"title": "",
"api": "/api/mock/saveForm",
"name": "sample4",
"actions": [
{
"type": "submit",
"label": "保存",
"primary": true
}
],
"tabs": [
{
"title": "Tab 1",
"controls": [
{
"type": "text",
"name": "test",
"label": "Label",
"placeholder": "Placeholder"
},

    {
      "type": "divider"
    },

    [
      {
        "type": "text",
        "name": "test1",
        "label": "Label",
        "placeholder": "Placeholder"
      },

      {
        "type": "text",
        "name": "test2",
        "label": "Label",
        "placeholder": "Placeholder"
      }
    ]
  ]
},

{
  "title": "Tab 2",
  "controls": [
    {
      "type": "text",
      "name": "test",
      "label": "Label",
      "placeholder": "Placeholder",
      "desc": "Description"
    }
  ]
}

]
}

  1. <div class="md-section-divider"></div>
  2. ### fieldSet
  3. 除了用 [tabs](#tabs(form)) 来分组 [FormItem](#FormItem) 外,还可以用 filedSet。格式如下:
  4. Array of `FieldSet` 或者 `FieldSet`
  5. * `title` FieldSet 的标题
  6. * `collapsed` 是否默认收起, 使用此属性时,记得给 form 开启 `collapsable`
  7. * `controls` FieldSet 里面的 controls
  8. * `className` FieldSet 里面的 类名,可以考虑添加 `fieldSet`、`fieldSet-xs`、`fieldSet-sm`、`fieldSet-md` 或者 `fieldSet-lg`。
  9. * `hiddenOn` 通过[表达式](#表达式)来配置当前表单项是否隐藏。
  10. * `visibleOn` 通过[表达式](#表达式)来配置当前表单项是否显示。
  11. <div class="md-section-divider"></div>
  12. ```schema:height="600" scope="body"
  13. {
  14. "type": "form",
  15. "api": "/api/mock/saveForm",
  16. "collapsable": true,
  17. "name": "sample5",
  18. "actions": [
  19. {
  20. "type": "submit",
  21. "label": "保存",
  22. "primary": true
  23. }
  24. ],
  25. "fieldSet": [
  26. {
  27. "title": "基本信息",
  28. "controls": [
  29. {
  30. "type": "text",
  31. "name": "test",
  32. "label": "Label",
  33. "placeholder": "Placeholder"
  34. },
  35. {
  36. "type": "divider"
  37. },
  38. [
  39. {
  40. "type": "text",
  41. "name": "test1",
  42. "label": "Label",
  43. "placeholder": "Placeholder"
  44. },
  45. {
  46. "type": "text",
  47. "name": "test2",
  48. "label": "Label",
  49. "placeholder": "Placeholder"
  50. }
  51. ]
  52. ]
  53. },
  54. {
  55. "title": "附加信息",
  56. "collapsed": true,
  57. "controls": [
  58. {
  59. "type": "text",
  60. "name": "test",
  61. "label": "Label",
  62. "placeholder": "Placeholder",
  63. "desc": "Description"
  64. }
  65. ]
  66. }
  67. ]
  68. }

FormItem

Form 中主要是由各种 FormItem 组成。FormItem 中主要包含这些字段。

```schema:height="200" scope="form-item" asideWidth="400"
{
"type": "text",
"name": "test1",
"label": "Label",
"desc": "Description...",
"placeholder": "Placeholder",
"validations": "matchRegexp: /^a/, minLength:3,maxLength:5",
"validationErrors": {
"matchRegexp": "必须为a开头",
"minLength": "小朋友,最低为$1个字符!"
}
}

  1. 不同类型的表单,可配置项还有增多,具体请看下面对应的类型。
  2. <div class="md-section-divider"></div>
  3. ### basic
  4. 基本的表单类型如: text, number, url, email, hidden, password, textarea
  5. * `source` 配置autoCompleteapi, autoComplete.api不同的是, 配置source会在组件初始化拉取,以后输入的时候不会再拉取。
  6. * `options` 选项配置,类型为数组,成员格式如下。
  7. * `label` 文字
  8. * `value`
  9. * `autoComplete` 如果设置为`string`类型,即为Api 地址,每次输入框的值发生变化都会请求该接口[详情](/docs/api#select)
  10. * `autoComplete.api` 同上。
  11. * `autoComplete.matchHighlight` 默认为 `true`,当不存在tpl的时候,按照默认的方式渲染建议列表会标红输入项,设为`false`则不标红。
  12. * `autoComplete.lazySeconds` 防抖时间,默认为500毫秒,输入后多少毫秒开始拉取api
  13. * `autoComplete.maxCount` 默认为 `100`, 默认前端最多展示多少项
  14. * `autoComplete.matchReg` 用在两个地方, 一是当`source`配置生效的时候,用来过滤建议;而是标红输入项,比如`/^(${value})/`, `${value}`会被替换成输入框的值, 第一个括号会被分组捕获作为标红的地方。
  15. * `autoComplete.reqOn` 默认为`true`, 当满足什么条件的时候才触发拉取接口
  16. * `autoComplete.reqField` 默认为`value`, 指定一个字段作为请求接口时的key
  17. * `autoComplete.tpl` 设置建议的每一条的tpl[详情](/docs/renderers#tpl)
  18. * `autoComplete.reqOn` 默认为`true`, 当满足什么条件的时候才触发拉取接口
  19. * `autoComplete.multiple` 默认为`false`, 是否支持多个输入
  20. * `autoComplete.delimiter` 默认为`;`,如果支持多个输入,用什么字符分割
  21. <div class="md-section-divider"></div>
  22. ```schema:height="450" scope="form"
  23. [
  24. {
  25. "type": "text",
  26. "name": "test1",
  27. "label": "Text"
  28. },
  29. {
  30. "type": "number",
  31. "name": "test2",
  32. "label": "Number"
  33. },
  34. {
  35. "type": "url",
  36. "name": "test3",
  37. "label": "Url"
  38. },
  39. {
  40. "type": "email",
  41. "name": "test4",
  42. "label": "Email"
  43. },
  44. {
  45. "type": "hidden",
  46. "name": "test5"
  47. },
  48. {
  49. "type": "password",
  50. "name": "test6",
  51. "label": "Password"
  52. },
  53. {
  54. "type": "textarea",
  55. "name": "test7",
  56. "label": "Textarea"
  57. }
  58. ]

divider

分割线

```schema:height="200" scope="form-item" asideWidth="400"
{
"type": "divider"
}

  1. <div class="md-section-divider"></div>
  2. ### select
  3. 选项表单。
  4. * `options` 选项配置,类型为数组,成员格式如下。
  5. * `label` 文字
  6. * `value` 值
  7. * `source` Api 地址,如果选项不固定,可以通过配置 `source` 动态拉取。[详情](/docs/api#select) 另外也可以用 `$xxxx` 来获取当前作用域中的变量。
  8. * `multiple` 默认为 `false`, 设置成 `true` 表示可多选。
  9. * `joinValues` 默认为 `true`
  10. * 单选模式:当用户选中某个选项时,选项中的 value 将被作为该表单项的值提交,否则,整个选项对象都会作为该表单项的值提交。
  11. * 多选模式:选中的多个选项的 `value` 会通过 `delimiter` 连接起来,否则直接将以数组的形式提交值。
  12. * `delimiter` 默认为 `,`
  13. * `clearable` 默认为 `false`, 当设置为 `true` 时,已选中的选项右侧会有个小 `X` 用来取消设置。
  14. * `searchable` 默认为 `true`,表示可以通过输入部分内容检索出选项。
  15. 单选
  16. <div class="md-section-divider"></div>
  17. ```schema:height="250" scope="form" asideWidth="350"
  18. [
  19. {
  20. "type": "select",
  21. "name": "select",
  22. "label": "单选",
  23. "clearable": true,
  24. "options": [
  25. {
  26. "label": "Option A",
  27. "value": "a"
  28. },
  29. {
  30. "label": "Option B",
  31. "value": "b"
  32. }
  33. ]
  34. },
  35. {
  36. "type": "static",
  37. "name": "select",
  38. "label": "当前值"
  39. }
  40. ]

多选

```schema:height="280" scope="form" asideWidth="350"
[
{
"type": "select",
"name": "select",
"label": "多选",
"clearable": true,
"multiple": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
},

{
  "type": "static",
  "name": "select",
  "label": "当前值"
}

]

  1. <div class="md-section-divider"></div>
  2. ### chained-select
  3. 无限级别下拉,只支持单选,且必须和 `source` 搭配,通过 API 拉取数据,只要 API 有返回结果,就能一直无限级别下拉下去。
  4. <div class="md-section-divider"></div>
  5. ```schema:height="300" scope="form-item"
  6. {
  7. "name": "select3",
  8. "type": "chained-select",
  9. "label": "Chained Select",
  10. "source": "/api/mock/chainedOptions?waitSeconds=1&value=$value&level=$level&maxLevel=4&waiSeconds=1"
  11. }

checkbox

可选框

```schema:height="200" scope="form-item" asideWidth="400"
{
"name": "checkbox",
"type": "checkbox",
"label": "Checkbox"
}

  1. <div class="md-section-divider"></div>
  2. ### checkboxes
  3. 复选框
  4. * `options` 选项配置,类型为数组,成员格式如下。
  5. * `label` 文字
  6. * `value` 值
  7. * `source` Api 地址,如果选项不固定,可以通过配置 `source` 动态拉取。[详情](/docs/api#select)
  8. * `joinValues` 默认为 `true` 选中的多个选项的 `value` 会通过 `delimiter` 连接起来,否则直接将以数组的形式提交值。
  9. * `delimiter` 默认为 `,`
  10. * `columnsCount` 默认为 `1` 可以配置成一行显示多个。
  11. * `checkAll` 默认为 `false` 开启后支持全选。
  12. * `checkAllLabel` 默认为 `全选` 全选的文字。
  13. * `defaultCheckAll` 是否默认全选,默认为`false`。
  14. * `addable` 是否可以手动输入增加,默认为`false`。
  15. * `addClassName` 手动输入框的className。
  16. <div class="md-section-divider"></div>
  17. ```schema:height="330" scope="form" asideWidth="400"
  18. [
  19. {
  20. "name": "checkboxes",
  21. "type": "checkboxes",
  22. "label": "Checkboxes",
  23. "options": [
  24. {
  25. "label": "OptionA",
  26. "value": "a"
  27. },
  28. {
  29. "label": "OptionB",
  30. "value": "b"
  31. },
  32. {
  33. "label": "OptionC",
  34. "value": "c"
  35. },
  36. {
  37. "label": "OptionD",
  38. "value": "d"
  39. }
  40. ]
  41. },
  42. {
  43. "type": "static",
  44. "name": "checkboxes",
  45. "label": "当前值"
  46. }
  47. ]

radios

单选框

```schema:height="330" scope="form" asideWidth="400"
[
{
"name": "radios",
"type": "radios",
"label": "Radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
},

{
    "type": "static",
    "name": "radios",
    "label": "当前值"
}

]

  1. <div class="md-section-divider"></div>
  2. ### list
  3. 简单的列表选择框。
  4. * `options` 选项配置,类型为数组,成员格式如下。
  5. * `label` 文字
  6. * `value` 值
  7. * `image` 图片的 http 地址。
  8. * `source` Api 地址,如果选项不固定,可以通过配置 `source` 动态拉取。[详情](/docs/api#select)
  9. * `multiple` 默认为 `false`, 设置成 `true` 表示可多选。
  10. * `joinValues` 默认为 `true`
  11. * 单选模式:当用户选中某个选项时,选项中的 value 将被作为该表单项的值提交,否则,整个选项对象都会作为该表单项的值提交。
  12. * 多选模式:选中的多个选项的 `value` 会通过 `delimiter` 连接起来,否则直接将以数组的形式提交值。
  13. * `delimiter` 默认为 `,`
  14. * `clearable` 默认为 `true`, 表示可以取消选中。
  15. 单选
  16. <div class="md-section-divider"></div>
  17. ```schema:height="250" scope="form" asideWidth="350"
  18. [
  19. {
  20. "type": "list",
  21. "name": "select",
  22. "label": "单选",
  23. "clearable": true,
  24. "options": [
  25. {
  26. "label": "Option A",
  27. "value": "a"
  28. },
  29. {
  30. "label": "Option B",
  31. "value": "b"
  32. }
  33. ]
  34. },
  35. {
  36. "type": "static",
  37. "name": "select",
  38. "label": "当前值"
  39. }
  40. ]

多选

```schema:height="280" scope="form" asideWidth="350"
[
{
"type": "list",
"name": "select",
"label": "多选",
"clearable": true,
"multiple": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
},

{
  "type": "static",
  "name": "select",
  "label": "当前值"
}

]

  1. 多选
  2. <div class="md-section-divider"></div>
  3. ```schema:height="280" scope="form" asideWidth="350"
  4. [
  5. {
  6. "type": "list",
  7. "name": "select",
  8. "label": "图片",
  9. "clearable": true,
  10. "options": [
  11. {
  12. "label": "OptionA",
  13. "value": "a",
  14. "image": "raw:https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
  15. },
  16. {
  17. "label": "OptionB",
  18. "value": "b",
  19. "image": "raw:https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
  20. },
  21. {
  22. "label": "OptionC",
  23. "value": "c",
  24. "image": "raw:https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
  25. },
  26. {
  27. "label": "OptionD",
  28. "value": "d",
  29. "image": "raw:https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
  30. }
  31. ]
  32. },
  33. {
  34. "type": "static",
  35. "name": "select",
  36. "label": "当前值"
  37. }
  38. ]

switch

可选框,和 checkbox 完全等价。

```schema:height="200" scope="form-item" asideWidth="400"
{
"name": "switch",
"type": "switch",
"label": "Switch"
}

  1. <div class="md-section-divider"></div>
  2. ### button
  3. 按钮, 包含 `button`、`submit` 和 `reset`。 字段说明。
  4. * `label` 按钮文字
  5. * `icon` 按钮图标。可以使用来自 fontawesome 的图标。
  6. * `level` 按钮级别。 包含: `primary`、`success`、`info`、`warning`和`danger`。
  7. * `size` 按钮大小。 包含: `xs`、`sm`、`md`和`lg`
  8. * `className` 按钮的类名。
  9. 如果按钮是 `button` 类型,则还需要配置 [Action](#action) 中定义的属性,否则,AMis 不知道如何响应当前按钮点击。
  10. <div class="md-section-divider"></div>
  11. ```schema:height="300" scope="form" asideWidth="400"
  12. [
  13. {
  14. "type": "text",
  15. "name": "test",
  16. "label": "Text"
  17. },
  18. {
  19. "type": "button",
  20. "label": "Button",
  21. "actionType": "dialog",
  22. "dialog": {
  23. "confirmMode": false,
  24. "title": "提示",
  25. "body": "对,你刚点击了!"
  26. }
  27. },
  28. {
  29. "type": "submit",
  30. "level": "primary",
  31. "label": "Submit"
  32. },
  33. {
  34. "type": "reset",
  35. "label": "Reset",
  36. "level": "danger"
  37. }
  38. ]

button-toolbar

从上面的例子可以看出,当按钮独立配置的时候,是独占一行的,如果想让多个按钮在一起放置,可以利用 button-toolbar

```schema:height="200" scope="form" asideWidth="400"
[
{
"type": "text",
"name": "test",
"label": "Text"
},

{
"type": "button-toolbar",
"buttons": [
{
"type": "button",
"label": "Button",
"actionType": "dialog",
"dialog": {
"confirmMode": false,
"title": "提示",
"body": "对,你刚点击了!"
}
},

  {
    "type": "submit",
    "label": "Submit"
  },

  {
    "type": "reset",
    "label": "Reset"
  }
]

}
]

  1. <div class="md-section-divider"></div>
  2. ### button-group
  3. 按钮集合,直接看示例吧。
  4. <div class="md-section-divider"></div>
  5. ```schema:height="200" scope="form" asideWidth="400"
  6. [
  7. {
  8. "type": "text",
  9. "name": "test",
  10. "label": "Text"
  11. },
  12. {
  13. "type": "button-toolbar",
  14. "buttons": [
  15. {
  16. "type": "button-group",
  17. "buttons": [
  18. {
  19. "type": "button",
  20. "label": "Button",
  21. "actionType": "dialog",
  22. "dialog": {
  23. "confirmMode": false,
  24. "title": "提示",
  25. "body": "对,你刚点击了!"
  26. }
  27. },
  28. {
  29. "type": "submit",
  30. "label": "Submit"
  31. },
  32. {
  33. "type": "reset",
  34. "label": "Reset"
  35. }
  36. ]
  37. },
  38. {
  39. "type": "submit",
  40. "icon": "fa fa-check text-success"
  41. },
  42. {
  43. "type": "reset",
  44. "icon": "fa fa-times text-danger"
  45. }
  46. ]
  47. }
  48. ]

button-group 有两种模式,除了能让按钮组合在一起,还能做类似于单选功能。

```schema:height="250" scope="form" asideWidth="350"
[
{
"type": "button-group",
"name": "select",
"label": "单选",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
]
},

{
  "type": "static",
  "name": "select",
  "label": "当前值"
}

]

  1. <div class="md-section-divider"></div>
  2. ### date
  3. 日期类型。
  4. * `format` 默认 `X` 即时间戳格式,用来提交的时间格式。更多格式类型请参考 moment.
  5. * `inputFormat` 默认 `LL` 用来配置显示的时间格式。
  6. * `placeholder` 默认 `请选择日期`
  7. * `value` 这里面 value 需要特殊说明一下,因为支持相对值。如:
  8. * `-2mins` 2分钟前
  9. * `+2days` 2天后
  10. * `-10week` 十周前
  11. * `minDate` 限制最小日期,可用 `${xxx}` 取值,或者输入相对时间,或者时间戳。如:`${start}`、`+3days`、`+3days+2hours`或者 `${start|default:-2days}+3days`
  12. * `maxDate` 限制最小日期,可用 `${xxx}` 取值,或者输入相对时间,或者时间戳。如:`${start}`、`+3days`、`+3days+2hours`或者 `${start|default:-2days}+3days`
  13. 可用单位: `min`、`hour`、`day`、`week`、`month`、`year`。所有单位支持复数形式。
  14. <div class="md-section-divider"></div>
  15. ```schema:height="250" scope="form" asideWidth="350"
  16. [
  17. {
  18. "type": "date",
  19. "name": "select",
  20. "label": "日期"
  21. },
  22. {
  23. "type": "static",
  24. "name": "select",
  25. "label": "当前值"
  26. }
  27. ]

datetime

日期类型。

日期类型。

```schema:height="250" scope="form" asideWidth="350"
[
{
"type": "datetime",
"name": "select",
"label": "日期"
},

{
  "type": "static",
  "name": "select",
  "label": "当前值"
}

]

  1. <div class="md-section-divider"></div>
  2. ### time
  3. 日期类型。
  4. 日期类型。
  5. * `format` 默认 `X` 即时间戳格式,用来提交的时间格式。更多格式类型请参考 moment.
  6. * `inputFormat` 默认 `HH:mm` 用来配置显示的时间格式。
  7. * `placeholder` 默认 `请选择日期`
  8. * `timeConstraints` 请参考: https://github.com/YouCanBookMe/react-datetime
  9. * `value` 这里面 value 需要特殊说明一下,因为支持相对值。如:
  10. * `-2mins` 2分钟前
  11. * `+2days` 2天后
  12. * `-10week` 十周前
  13. * `minTime` 限制最小时间,可用 `${xxx}` 取值,或者输入相对时间,或者时间戳。如:`${start}`、`+3days`、`+3days+2hours`或者 `${start|default:-2days}+3days`
  14. * `maxTime` 限制最大时间,可用 `${xxx}` 取值,或者输入相对时间,或者时间戳。如:`${start}`、`+3days`、`+3days+2hours`或者 `${start|default:-2days}+3days`
  15. 可用单位: `min`、`hour`、`day`、`week`、`month`、`year`。所有单位支持复数形式。
  16. <div class="md-section-divider"></div>
  17. ```schema:height="250" scope="form" asideWidth="350"
  18. [
  19. {
  20. "type": "time",
  21. "name": "select",
  22. "label": "日期"
  23. },
  24. {
  25. "type": "static",
  26. "name": "select",
  27. "label": "当前值"
  28. }
  29. ]

date-range

日期类型。

```schema:height="250" scope="form" asideWidth="350"
[
{
"type": "date-range",
"name": "select",
"label": "日期范围"
},

{
  "type": "static",
  "name": "select",
  "label": "当前值"
}

]

  1. 考虑到大家都习惯用两个字段来存储,那么就用 date 来代替吧。
  2. <div class="md-section-divider"></div>
  3. ```schema:height="250" scope="form" asideWidth="350"
  4. [
  5. [
  6. {
  7. "type": "date",
  8. "name": "start",
  9. "label": "开始日期",
  10. "maxDate": "$end"
  11. },
  12. {
  13. "type": "date",
  14. "name": "end",
  15. "label": "结束日期",
  16. "minDate": "$start"
  17. }
  18. ],
  19. {
  20. "type": "static",
  21. "name": "select",
  22. "label": "当前值",
  23. "desc": "包含开始日期和结束日期",
  24. "tpl": "$start - $end"
  25. }
  26. ]

static

纯用来展现数据的。

```schema:height="250" scope="form-item" asideWidth="350"
{
"type": "static",
"name": "select",
"label": "Label",
"value": "A"
}

  1. <div class="md-section-divider"></div>
  2. ### static-xxx
  3. 现在支持`text`、`plain`、`json`、`date`、`datetime`、`time`、`date-range`、`html`、`tpl`、`map`、`image`、`pic`、`picture`、`progress`、`status`
  4. 纯用来展示数据的,用法跟crud里面的[Column](#Column)一样, 注意不能用里面的编辑属性,比如quickEdit。
  5. <div class="md-section-divider"></div>
  6. ```schema:height="250" scope="form-item" asideWidth="350"
  7. {
  8. "type": "static-json",
  9. "name": "json",
  10. "label": "Label",
  11. "value": {
  12. "a":"dd",
  13. "b":"asdasd"
  14. }
  15. }

table(form-item)

主要用来展现数据的,可以用来展示数组类型的数据,比如multiple的子form。

```schema:height="250" scope="form" asideWidth="350"
[
{
"type": "form",
"name": "form",
"label": "子Form",
"btnLabel": "设置子表单",
"multiple": true,
"form": {
"title": "配置子表单",
"controls": [
{
"name": "a",
"label": "A",
"type": "text"
},
{
"name": "b",
"label": "B",
"type": "text"
}
]
}
},
{
"type":"table",
"name":"form",
"columns":[
{
"name": "a",
"label": "A"
},
{
"name": "b",
"label": "B"
}
]
}
]

  1. 当然也可以用来作为表单输入。
  2. * `editable` 表示可编辑
  3. * `addable` 表示可新增
  4. * `removable` 表示可删除
  5. * `maxLength` 表示数组最大长度
  6. * `minLength` 表示数组最小长度
  7. <div class="md-section-divider"></div>
  8. ```schema:height="250" scope="form-item" asideWidth="350"
  9. {
  10. "type":"table",
  11. "name":"form",
  12. "editable": true,
  13. "addable": true,
  14. "removable": true,
  15. "columns":[
  16. {
  17. "name": "a",
  18. "label": "A"
  19. },
  20. {
  21. "name": "b",
  22. "label": "B",
  23. "quickEdit": {
  24. "type": "select",
  25. "options": [
  26. {
  27. "label": "A",
  28. "value": "a"
  29. },
  30. {
  31. "label": "B",
  32. "value": "b"
  33. }
  34. ]
  35. }
  36. }
  37. ]
  38. }

matrix

矩阵类型的输入框。

```schema:height="250" scope="form-item" asideWidth="350"
{
"type": "matrix",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}

  1. <div class="md-section-divider"></div>
  2. ### tree
  3. 树形结构输入框。
  4. * `options` 类似于 [select](#select) 中 `options` 只是支持通过 `children` 无限嵌套。
  5. * `source` Api 地址,如果选项不固定,可以通过配置 `source` 动态拉取。[详情](/docs/api#tree)
  6. <div class="md-section-divider"></div>
  7. ```schema:height="300" scope="form-item" asideWidth="350"
  8. {
  9. "type": "tree",
  10. "name": "tree",
  11. "label": "Tree",
  12. "options": [
  13. {
  14. "label": "Folder A",
  15. "value": 1,
  16. "children": [
  17. {
  18. "label": "file A",
  19. "value": 2
  20. },
  21. {
  22. "label": "file B",
  23. "value": 3
  24. }
  25. ]
  26. },
  27. {
  28. "label": "file C",
  29. "value": 4
  30. },
  31. {
  32. "label": "file D",
  33. "value": 5
  34. }
  35. ]
  36. }

image

图片格式输入,默认 AMis 会直接存储在贴吧的 hiphoto 里面,提交到 form 是直接的图片 url。

```schema:height="250" scope="form-item" asideWidth="350"
{
"type": "image",
"name": "image",
"label": "Images"
}

  1. <div class="md-section-divider"></div>
  2. ### file
  3. 文件输入,AMis 也默认处理了图片存储,提交给 API 的是文件的下载地址。
  4. * `reciever` 默认 `/api/upload/file` 如果想自己存储,请设置此选项。
  5. * `accept` 默认 `text/plain` 默认只支持纯文本,要支持其他类型,请配置此属性。
  6. * `maxSize` 默认没有限制,当设置后,文件大小大于此值将不允许上传。
  7. * `multiple` 是否多选。
  8. * `maxLength` 默认没有限制,当设置后,一次只允许上传指定数量文件。
  9. * `joinValues` 多选时是否将多个值用 `delimiter` 连接起来。
  10. * `delimiter` 链接符
  11. * `autoUpload` 是否选择完就自动开始上传?默认为 `true`
  12. * `fileField` 默认 `file`, 如果你不想自己存储,则可以忽略此属性。
  13. * `downloadUrl` 默认显示文件路径的时候会支持直接下载,可以支持加前缀如:`http://xx.dom/filename=` ,如果不希望这样,可以把当前配置项设置为 `false`。
  14. * `useChunk` 默认为 'auto' amis 所在服务器,限制了文件上传大小不得超出10M,所以 amis 在用户选择大文件的时候,自动会改成分块上传模式。
  15. * `chunkSize` 分块大小,默认为 5M.
  16. * `startChunkApi` 默认 `/api/upload/startChunk` 想自己存储时才需要关注。
  17. * `chunkApi` 默认 `/api/upload/chunk` 想自己存储时才需要关注。
  18. * `finishChunkApi` 默认 `/api/upload/finishChunk` 想自己存储时才需要关注。
  19. <div class="md-section-divider"></div>
  20. ```schema:height="250" scope="form-item" asideWidth="350"
  21. {
  22. "type": "file",
  23. "name": "file",
  24. "label": "File",
  25. "maxSize": 1048576
  26. }

rich-text

富文本编辑器

```schema:height="350" scope="form-item" asideWidth="350"
{
"type": "rich-text",
"name": "html",
"label": "Rich Text"
}

  1. <div class="md-section-divider"></div>
  2. ### xxx-editor
  3. IDE输入,目前支持多种语言,包括`json-editor`, `js-editor`, `jsx-editor`, `css-editor`, `sql-editor`, `markdown-editor`, `shell-editor`, `python-editor`, `yaml-editor`, `java-editor`
  4. <div class="md-section-divider"></div>
  5. ```schema:height="350" scope="form-item" asideWidth="350"
  6. {
  7. "type": "json-editor",
  8. "name": "html",
  9. "label": "json-editor"
  10. }

combo

组合模式,支持自由组合多个表单项。

```schema:height="450" scope="form" asideWidth="350"
[
{
"type": "combo",
"name": "combo",
"label": "单选组合项",
"controls": [
{
"name": "a",
"type": "text"
},
{
"name": "b",
"type": "select",
"options": ["a", "b", "c"]
}
]
},
{
"type": "static",
"name": "combo",
"label": "当前值"
},

{
"type": "combo",
"name": "combo2",
"label": "多选组合项",
"multiple": true,
"draggable": true,
"controls": [
{
"label": "字段1",
"name": "a",
"type": "text"
},
{
"label": "字段2",
"name": "b",
"type": "select",
"options": ["a", "b", "c"],
"unique": true
}
]
},
{
"type": "static",
"name": "combo2",
"label": "当前值"
}
]

  1. combo 多行模式。
  2. <div class="md-section-divider"></div>
  3. ```schema:height="450" scope="form" asideWidth="350"
  4. [
  5. {
  6. "type": "combo",
  7. "name": "combo",
  8. "label": "多选组合form",
  9. "multiple": true,
  10. "form":{
  11. "mode":"normal",
  12. "controls": [
  13. {
  14. "label": "字段1",
  15. "name": "a",
  16. "type": "text"
  17. },
  18. {
  19. "label": "字段2",
  20. "name": "b",
  21. "type": "select",
  22. "options": ["a", "b", "c"]
  23. }
  24. ]
  25. }
  26. },
  27. {
  28. "type": "static",
  29. "name": "combo",
  30. "label": "当前值"
  31. },
  32. {
  33. "type": "combo",
  34. "name": "xxx",
  35. "label": "单选组合form",
  36. "form":{
  37. "mode":"normal",
  38. "controls": [
  39. {
  40. "name": "a",
  41. "type": "text"
  42. },
  43. {
  44. "name": "b",
  45. "type": "select",
  46. "options": ["a", "b", "c"]
  47. }
  48. ]
  49. }
  50. },
  51. {
  52. "type": "static",
  53. "name": "xxx",
  54. "label": "当前值"
  55. }
  56. ]

form(子Form)

formItem 还可以是子表单类型。

```schema:height="400" scope="form" asideWidth="350"
[
{
"type": "form",
"name": "form",
"label": "子Form",
"btnLabel": "设置子表单",
"form": {
"title": "配置子表单",
"controls": [
{
"name": "a",
"label": "A",
"type": "text"
},

  {
    "name": "b",
    "label": "B",
    "type": "text"
  }
]

}
},
{
"type": "static",
"name": "form",
"label": "当前值"
},
{
"type": "form",
"name": "form2",
"label": "多选",
"multiple": true,
"maxLength":3,
"btnLabel": "设置子表单",
"form": {
"title": "配置子表单",
"controls": [
{
"name": "a",
"label": "A",
"type": "text"
},

  {
    "name": "b",
    "label": "B",
    "type": "text"
  }
]

}
},
{
"type": "static",
"name": "form2",
"label": "当前值"
}
]

  1. <div class="md-section-divider"></div>
  2. ### repeat
  3. 可用来设置重复频率
  4. * `options` 默认: `hourly,daily,weekly,monthly`, 可用配置 `secondly,minutely,hourly,daily,weekdays,weekly,monthly,yearly`
  5. * `placeholder` 默认为 `不重复`, 当不指定值时的说明。
  6. <div class="md-section-divider"></div>
  7. ```schema:height="300" scope="form-item" asideWidth="350"
  8. {
  9. "type": "repeat",
  10. "name": "repeat",
  11. "label": "重复频率"
  12. }

hbox(form-item)

支持 form 内部再用 hbox 布局。

```schema:height="200" scope="form-item" asideWidth="350"
{
"type": "hbox",
"columns": [
{
"columnClassName": "w-sm",
"controls": [
{
"name": "text",
"type": "text",
"label": false,
"placeholder": "Text"
}
]
},

{
     "controls": [
        {
            "name": "text",
            "type": "text",
            "label": "Text"
        }
    ]
}

]
}

  1. <div class="md-section-divider"></div>
  2. ### grid(form-item)
  3. 支持 form 内部再用 grid 布局。
  4. |属性名 | 类型 | 默认值 | 说明 |
  5. |---|---|---|---|
  6. | columns[x] | [Form](#Form) | | 成员是一个 Form 配置 |
  7. | columns[x].xs | `int` | | 宽度占比: 1 - 12 |
  8. | columns[x].xsHidden | `boolean` | | 是否隐藏 |
  9. | columns[x].xsOffset | `int` | | 偏移量 1 - 12 |
  10. | columns[x].xsPull | `int` | | 靠左的距离占比:1 - 12 |
  11. | columns[x].xsPush | `int` | | 靠右的距离占比: 1 - 12 |
  12. | columns[x].sm | `int` | | 宽度占比: 1 - 12 |
  13. | columns[x].smHidden | `boolean` | | 是否隐藏 |
  14. | columns[x].smOffset | `int` | | 偏移量 1 - 12 |
  15. | columns[x].smPull | `int` | | 靠左的距离占比:1 - 12 |
  16. | columns[x].smPush | `int` | | 靠右的距离占比: 1 - 12 |
  17. | columns[x].md | `int` | | 宽度占比: 1 - 12 |
  18. | columns[x].mdHidden | `boolean` | | 是否隐藏 |
  19. | columns[x].mdOffset | `int` | | 偏移量 1 - 12 |
  20. | columns[x].mdPull | `int` | | 靠左的距离占比:1 - 12 |
  21. | columns[x].mdPush | `int` | | 靠右的距离占比: 1 - 12 |
  22. | columns[x].lg | `int` | | 宽度占比: 1 - 12 |
  23. | columns[x].lgHidden | `boolean` | | 是否隐藏 |
  24. | columns[x].lgOffset | `int` | | 偏移量 1 - 12 |
  25. | columns[x].lgPull | `int` | | 靠左的距离占比:1 - 12 |
  26. | columns[x].lgPush | `int` | | 靠右的距离占比: 1 - 12 |
  27. <div class="md-section-divider"></div>
  28. ```schema:height="200" scope="form-item" asideWidth="350"
  29. {
  30. "type": "grid",
  31. "columns": [
  32. {
  33. "md": 3,
  34. "controls": [
  35. {
  36. "name": "text",
  37. "type": "text",
  38. "label": false,
  39. "placeholder": "Text"
  40. }
  41. ]
  42. },
  43. {
  44. "md": 9,
  45. "controls": [
  46. {
  47. "name": "text",
  48. "type": "text",
  49. "label": "Text"
  50. }
  51. ]
  52. }
  53. ]
  54. }

panel(form-item)

还是为了布局,可以把一部分 form-item 合并到一个 panel 里面单独展示。

```schema:height="400" scope="form-item" asideWidth="350"
{
"type": "hbox",
"columns": [
{
"controls": [
{
"name": "text",
"type": "text",
"label": false,
"placeholder": "Text"
}
]
},

{
     "columnClassName": "w-xl",
     "controls": [
        {
            "type": "panel",
            "title": "bla bla",
            "controls": [
                {
                    "name": "text",
                    "type": "text",
                    "label": false,
                    "placeholder": "Text 1"
                },

                {
                    "name": "text2",
                    "type": "text",
                    "label": false,
                    "placeholder": "Text 2"
                }
            ]
        }
    ]
}

]
}

  1. <div class="md-section-divider"></div>
  2. ### tpl(form-item)
  3. 具体请查看 [tpl](#tpl)
  4. <div class="md-section-divider"></div>
  5. ## Tpl
  6. tpl 类型的渲染器支持用 JS 模板引擎来组织输出,采用的 lodash 的 [template](https://lodash.com/docs/4.15.0#template),关于语法部分,请前往 lodash 文档页面。
  7. <div class="md-section-divider"></div>
  8. ```schema:height="200"
  9. {
  10. "data": {
  11. "user": "no one"
  12. },
  13. "body": {
  14. "type": "tpl",
  15. "tpl": "User: <%= data.user%>"
  16. }
  17. }

可用 js 方法。

如:

  1. {
  2. "data": {
  3. "user": "no one"
  4. },
  5. "body": {
  6. "type": "tpl",
  7. "tpl": "User: <%= formatDate(data.time, 'YYYY-MM-DD') %>"
  8. }
  9. }

如果只想简单取下变量,可以用 $xxx 或者 ${xxx}。同时如果不指定类型,默认就是 tpl, 所以以上示例可以简化为。

取值支持多级,如果层级比较深可以用 . 来分割如: ${xx.xxx.xx}
另外 $& 表示直接获取当前的 data

  1. {
  2. "data": {
  3. "user": "no one"
  4. },
  5. "body": "User: $user"
  6. }

通过 $xxx 取到的值,默认是不做任何处理,如果希望把 html 转义了的,请使用:${xxx | html}

从上面的语法可以看出来,取值时是支持指定 filter 的,那么有哪些 filter 呢?

组合使用。

Plain

plain, 单纯的文字输出来。

  1. {
  2. "body": {
  3. "type": "plain",
  4. "text": "Pure Text <html>"
  5. }
  6. }

Html

html, 当需要用到变量时,请用 Tpl 代替。

  1. {
  2. "body": {
  3. "type": "html",
  4. "html": "支持 Html <code>Html</code>"
  5. }
  6. }

Action

Action 是一种特殊的渲染器,它本身是一个按钮,同时它能触发事件。

示例:

Dialog

Dialog 由 Action 触发。他是一个类似于 Page 的容器模型。

属性名 类型 默认值 说明
type string "dialog" 指定为 Dialog 渲染器
title string 或者 Container 弹出层标题
body Container 往 Dialog 内容区加内容
size string 指定 dialog 大小,支持: xssmmdlg
bodyClassName string modal-body Dialog body 区域的样式类名
closeOnEsc boolean false 是否支持按 Esc 关闭 Dialog
disabled boolean false 如果设置此属性,则该 Dialog 只读没有提交操作。
actions Array Of Action 可以不设置,默认只有【确认】和【取消】两个按钮。额外支持 actionType 为 cancelnextDemo

CRUD

增删改查模型,主要用来展现列表,并支持各类【增】【删】【改】【查】的操作。复杂示例请前往 Demo

CRUD 支持三种模式:tablegridlist,默认为 table,每种的配置有些不一样,所以这里分开介绍。

Table(CRUD)

属性名 类型 默认值 说明
type string "crud" 指定为 CRUD 渲染器
mode string "table" 指定为 Table 模式
title string "表格" 可设置成空,当设置成空时,没有标题栏
className string 表格外层 Dom 的类名
api Api CRUD 用来获取列表数据的 api。详情
columns Array of Column 用来设置列信息
filter Form 设置过滤器,当该表单提交后,会把数据带给当前 crud 刷新列表。
initFetch boolean true 是否初始化的时候拉取数据, 只针对有filter的情况, 没有filter初始都会拉取数据
clearCache boolean false 当crud销毁的时候是否删除内存中的数据
syncLocation boolean true 是否将过滤条件的参数同步到地址栏
draggable boolean false 是否可通过拖拽排序
draggableOn boolean 表达式来配置是否可拖拽排序
saveOrderApi Api 保存排序的 api。详情
quickSaveApi Api 快速编辑后用来批量保存的 API。详情
quickSaveItemApi Api 快速编辑配置成及时保存时使用的 API。详情
messages Object 覆盖消息提示,如果不指定,将采用 api 返回的 message
bulkActions Array Of Action 批量操作列表,配置后,表格可进行选中操作。
defaultChecked boolean false 当可批量操作时,默认是否全部勾选。
switchPerPage boolean false 是否可修改每页显示多少个。
showPageInfo boolean true 是否显示列表信息,比如一共多少页,有多少条数据。
columnsTogglable boolean true 是否可以用户控制显示与不显示某些列。
messages.fetchFailed string 获取失败时提示
messages.saveOrderFailed string 保存顺序失败提示
messages.saveOrderSuccess string 保存顺序成功提示
messages.quickSaveFailed string 快速保存失败提示
messages.quickSaveSuccess string 快速保存成功提示
primaryField string "id" 设置 ID 字段名。
defaultParams Object 设置默认filter默认参数,会在查询的时候一起发给后端
pageField string "page" 设置分页页码字段名。
perPageField string "perPage" 设置分页一页显示的多少条数据的字段名。注意:最好与defaultParams一起使用,请看下面例子。
orderField string 设置用来确定位置的字段名,设置后新的顺序将被赋值到该字段中。
toolbar Container toolbar 容器,可以用来放子模型。
toolbarInline boolean false 配置 toolbar 是否和header 区域现有的分页,批量操作放置在一条上面,否则会另外独占一行。
showHeader boolean true 可以用来配置是否显示 header
showFooter boolean true 可以用来配置是否显示 footer

```schema:height="800" scope="body"
{
"type": "crud",
"api": "/api/sample",
"syncLocation": false,
"title": null,
"perPageField":"rn",
"defaultParams":{
"rn": 10
},
"columns": [
{
"name": "id",
"label": "ID",
"width": 20,
"sortable": true
},
{
"name": "engine",
"label": "Rendering engine",
"sortable": true,
"toggled": false
},
{
"name": "browser",
"label": "Browser",
"sortable": true
},
{
"name": "platform",
"label": "Platform(s)",
"sortable": true
},
{
"name": "version",
"label": "Engine version"
}
]
}

  1. <div class="md-section-divider"></div>
  2. #### Column
  3. * `type` 默认为 `text`,支持: `text`、`html`、`tpl`、`image`、`progress`、`status`、`date`、`datetime`、`time`、`json`、`map`和`operation`。
  4. * `name` 用来关联列表数据中的变量 `key`。
  5. * `label` 列标题。
  6. * `sortable` 开启后可以根据当前列排序(后端排序)。
  7. * `localSortable` 开启后可以根据当前列排序(前端排序,本页排序)。
  8. * `copyable` 开启后,会支持内容点击复制。
  9. * `width` 列宽度。
  10. * `quickEdit` 是否支持快速编辑。 支持两种配置。
  11. * [FormItem](#FormItem) 无需配置 name, 自动采用 column 上的 name 值。
  12. * `boolean` false 不启用,true 启用,且快速编辑的表单为 text 类型。等价于:`{type: "text"}`
  13. * `popOver` 是否支持点击查看详情。当内容较长时,可以开启此配置。
  14. * `toggled` 控制默认是展示还是不展示,只有 Table 的 `columnsTogglable` 开启了才有效。
  15. * `labelGroup` 设置本列的group名,会在表头上面再加一层group显示。
  16. * `tooltip` 设置后鼠标移上去有小tip提示,值为tpl字符串,支持[tpl](#tpl)。
  17. * `searchable` 设置快速过滤功能,跟filter功能一样, 支持两种配置。
  18. * [FormItem](#FormItem) 无需配置 name, 自动采用 column 上的 name 值。
  19. * `boolean` false 不启用,true 启用,且快速编辑的表单为 text 类型。等价于:`{type: "text"}`
  20. <div class="md-section-divider"></div>
  21. #### html(Column)
  22. 当 column 为 html 类型时才支持 html 标签。
  23. <div class="md-section-divider"></div>
  24. #### tpl(Column)
  25. 支持 JS 模板引擎,用法和外层 [tpl](#tpl) 一样。
  26. <div class="md-section-divider"></div>
  27. #### map(Column)
  28. 使用此类型,允许配置将值映射成其他内容显示。
  29. 如:
  30. <div class="md-section-divider"></div>

{
"type": "map",
"name": "status",
"label": "Map 类型",
"map": {
"1": "新建",
"2": "已上线",
"3": "已删除"
}
}

  1. <div class="md-section-divider"></div>
  2. #### image(Column)
  3. 图片类型,让值以图片的形式展示。
  4. <div class="md-section-divider"></div>
  5. #### progress(Column)
  6. 进度类型,要求值是 0 - 100 的数值。
  7. <div class="md-section-divider"></div>
  8. #### status(column)
  9. 状态类型,非零飘绿,零值飘红。
  10. <div class="md-section-divider"></div>
  11. #### date(column)
  12. 日期类型,自动将时间戳格式的数值以 `format=LL` 的形式展示。
  13. * `format` 默认为 `LL` 格式说明请参考 [moment 文档](http://momentjs.com/docs/#/displaying/format/)。
  14. * `valueFormat` 默认为 `X` 格式说明请参考, (PS: 可以留空) [moment 文档](http://momentjs.com/docs/#/parsing/)。
  15. <div class="md-section-divider"></div>
  16. #### datetime(column)
  17. 日期类型,自动将时间戳格式的数值以 `format=LLL` 的形式展示。
  18. * `format` 默认为 `LLL` 格式说明请参考 [moment 文档](http://momentjs.com/docs/#/displaying/format/)。
  19. * `valueFormat` 默认为 `X` 格式说明请参考, (PS: 可以留空) [moment 文档](http://momentjs.com/docs/#/parsing/)。
  20. <div class="md-section-divider"></div>
  21. #### time(column)
  22. 日期类型,自动将时间戳格式的数值以 `format=LT` 的形式展示。
  23. * `format` 默认为 `LT` 格式说明请参考 [moment 文档](http://momentjs.com/docs/#/displaying/format/)。
  24. * `valueFormat` 默认为 `X` 格式说明请参考, (PS: 可以留空) [moment 文档](http://momentjs.com/docs/#/parsing/)。
  25. <div class="md-section-divider"></div>
  26. #### json(column)
  27. json 类型,方便查看复杂对象。
  28. * levelExpand 初始展开第几层,从0开始
  29. * expandDefaultLevel 点击后展开几级
  30. <div class="md-section-divider"></div>
  31. #### list(column)
  32. 如果需要展示的数据是数组格式,则可以考虑用 list 来展示。
  33. * listItem 每行的具体展示内容。
  34. * listItem.title
  35. * listItem.subTitle
  36. * listItem.desc
  37. * listItem.avatar
  38. * listItem.body
  39. * listItem.actions
  40. Demo 待补充。
  41. <div class="md-section-divider"></div>
  42. #### operation(Column)
  43. 一般 Column 里面都会配置一个 `Operation` 来实现单条操作。通过配置 `buttons` 来设置按钮。 `buttons` 中可以放 [button](#button) 或者 [button-group](#button-group)。
  44. <div class="md-section-divider"></div>
  45. ```schema:height="800" scope="body"
  46. {
  47. "type": "crud",
  48. "api": "/api/sample",
  49. "syncLocation": false,
  50. "title": null,
  51. "columns": [
  52. {
  53. "name": "id",
  54. "label": "ID",
  55. "width": 20
  56. },
  57. {
  58. "name": "engine",
  59. "label": "Rendering engine",
  60. "sortable": true
  61. },
  62. {
  63. "type": "operation",
  64. "label": "操作",
  65. "width": 200,
  66. "buttons": [
  67. {
  68. "type": "button-group",
  69. "buttons": [
  70. {
  71. "type": "button",
  72. "label": "查看",
  73. "actionType": "dialog",
  74. "dialog": {
  75. "disabled": true,
  76. "body": {
  77. "type": "form",
  78. "controls": [
  79. {
  80. "name": "engine",
  81. "label": "Rendering engine",
  82. "type": "static"
  83. }
  84. ]
  85. }
  86. }
  87. },
  88. {
  89. "type": "button",
  90. "label": "编辑",
  91. "actionType": "dialog",
  92. "dialog": {
  93. "body": {
  94. "api": "/api/sample/$id",
  95. "type": "form",
  96. "controls": [
  97. {
  98. "name": "engine",
  99. "label": "Rendering engine",
  100. "type": "text"
  101. }
  102. ]
  103. }
  104. }
  105. },
  106. {
  107. "type": "button",
  108. "label": "删除",
  109. "level": "danger",
  110. "actionType": "ajax",
  111. "confirmText": "确定?",
  112. "api": "delete:/api/sample/$id"
  113. }
  114. ]
  115. }
  116. ]
  117. }
  118. ]
  119. }

Grid(CRUD)

Table(CRUD) 基本上差不多,主要区别是,不再配置 columns 而是配置 card

属性名 类型 默认值 说明
type string "crud" 指定为 CRUD 渲染器
mode string "grid" 指定为 Grid 模式
title string "表格" 可设置成空,当设置成空时,没有标题栏
className string 表格外层 Dom 的类名
api Api CRUD 用来获取列表数据的 api。详情
cardClassName string "col-sm-6 col-md-4 col-lg-3" 用来设置卡片信息
columnsCount int 当设置了此属性后,会忽略 cardClassName 的配置,直接固定一行显示 columnsCount 个。
card Card 用来设置卡片信息
filter Form 设置过滤器,当该表单提交后,会把数据带给当前 crud 刷新列表。
syncLocation boolean true 是否将过滤条件的参数同步到地址栏
draggable boolean false 是否可通过拖拽排序
saveOrderApi Api 保存排序的 api。详情
quickSaveApi Api 快速编辑后用来批量保存的 API。详情
quickSaveItemApi Api 快速编辑配置成及时保存时使用的 API。详情
messages Object 覆盖消息提示,如果不指定,将采用 api 返回的 message
bulkActions Array Of Action 批量操作列表,配置后,表格可进行选中操作。
defaultChecked boolean false 当可批量操作时,默认是否全部勾选。
switchPerPage boolean false 是否可修改每页显示多少个。
showPageInfo boolean true 是否显示列表信息,比如一共多少页,有多少条数据。
columnsTogglable boolean true 是否可以用户控制显示与不显示某些列。
messages.fetchFailed string 获取失败时提示
messages.saveOrderFailed string 保存顺序失败提示
messages.saveOrderSuccess string 保存顺序成功提示
messages.quickSaveFailed string 快速保存失败提示
messages.quickSaveSuccess string 快速保存成功提示
primaryField string "id" 设置 ID 字段名。
pageField string "page" 设置分页页码字段名。
perPageField string "perPage" 设置分页一页显示的多少条数据的字段名。
orderField string 设置用来确定位置的字段名,设置后新的顺序将被赋值到该字段中。

```schema:height="800" scope="body"
{
"type": "crud",
"api": "/api/admin/user/inGroup?groupId=1",
"syncLocation": false,
"mode": "grid",
"defaultParams": {
"perPage": 6
},
"switchPerPage": false,
"placeholder": "没有用户信息",
"columnsCount": 2,
"card": {
"header": {
"className": "bg-white",
"title": "realName",
"desc": "{avatar | raw}",
"highlight": "isSuperAdmin",
    "avatarClassName": "pull-left thumb-md avatar b-3x m-r"
  },
  "bodyClassName": "padder m-b",
  "body": "\n      <% if (data.roles && data.roles.length) { %>\n        <% data.roles.map(function(role) { %>\n          <span class=\"label label-default\"><%- role.name %></span>\n        <% }) %>\n      <% } else { %>\n        <p class=\"text-muted\">没有分配角色</p>\n      <% } %>\n      ",
  "actions": [
    {
      "label": "编辑",
      "actionType": "dialog",
      "dialog": {
        "title": null,
        "name": "amis-user-edit",
        "api": "/api/admin/user/
id?groupId=1", "tabs": [ { "title": "基本信息", "controls": [ { "type": "hidden", "name": "id" }, { "name": "name", "label": "帐号", "disabled": true, "type": "text" }, { "type": "divider" }, { "name": "email", "label": "邮箱", "type": "text", "disabled": true }, { "type": "divider" }, { "name": "isAmisOwner", "label": "管理员", "desc": "设置是否为超级管理", "type": "switch" } ] }, { "title": "角色信息", "controls": [ { "name": "roles", "label": "关联角色", "type": "checkboxes", "source": "/api/admin/user/roles?groupId=1", "placeholder": "当前组下还没创建角色" } ] }, { "title": "设置权限", "controls": [ { "name": "permissions", "label": "权限信息", "type": "checkboxes", "source": "/api/admin/user/permissions?groupId=1", "desc": "推荐通过用户组管理权限, 但是还是可以给个人配置独立权限." } ] } ] } }, { "label": "移除", "confirmText": "您确定要移除该用户?", "actionType": "ajax", "action": "delete:/api/admin/user/$id?groupId=1"
}
]
}
}

  1. <div class="md-section-divider"></div>
  2. ### List(CRUD)
  3. 跟 [Table(CRUD)](#Table(CRUD)) 基本上差不多,主要区别是,不再配置 `columns` 而是配置 `listItem`。
  4. |属性名 | 类型 | 默认值 | 说明 |
  5. |---|---|---|---|
  6. | type | `string` | | `"crud"` 指定为 CRUD 渲染器 |
  7. | mode | `string` | | `"list"` 指定为 List 模式 |
  8. | title | `string` | `"表格"` | 可设置成空,当设置成空时,没有标题栏 |
  9. | className | `string` | | 表格外层 Dom 的类名 |
  10. | api | [Api](#api) | | CRUD 用来获取列表数据的 api。[详情](/docs/api#crud) |
  11. | listItem | [listItem](#listItem) | | 用来设置卡片信息 |
  12. | filter | [Form](#form) | | 设置过滤器,当该表单提交后,会把数据带给当前 crud 刷新列表。 |
  13. | syncLocation | `boolean` | `true` | 是否将过滤条件的参数同步到地址栏 |
  14. | draggable | `boolean` | `false` | 是否可通过拖拽排序 |
  15. | saveOrderApi | [Api](#api) | | 保存排序的 api。[详情](/docs/api#crud) |
  16. | quickSaveApi | [Api](#api) | | 快速编辑后用来批量保存的 API。[详情](/docs/api#crud) |
  17. | quickSaveItemApi | [Api](#api) | | 快速编辑配置成及时保存时使用的 API。[详情](/docs/api#crud) |
  18. | messages | `Object` | | 覆盖消息提示,如果不指定,将采用 api 返回的 message |
  19. | bulkActions | Array Of [Action](#action) | | 批量操作列表,配置后,表格可进行选中操作。 |
  20. | defaultChecked | `boolean` | `false` | 当可批量操作时,默认是否全部勾选。 |
  21. | switchPerPage | `boolean` | `false` | 是否可修改每页显示多少个。 |
  22. | showPageInfo | `boolean` | `true` | 是否显示列表信息,比如一共多少页,有多少条数据。 |
  23. | columnsTogglable | `boolean` | `true` | 是否可以用户控制显示与不显示某些列。 |
  24. | messages.fetchFailed | `string` | | 获取失败时提示 |
  25. | messages.saveOrderFailed | `string` | | 保存顺序失败提示 |
  26. | messages.saveOrderSuccess | `string` | | 保存顺序成功提示 |
  27. | messages.quickSaveFailed | `string` | | 快速保存失败提示 |
  28. | messages.quickSaveSuccess | `string` | | 快速保存成功提示 |
  29. | primaryField | `string` | `"id"` | 设置 ID 字段名。 |
  30. | pageField | `string` | `"page"` | 设置分页页码字段名。 |
  31. | perPageField | `string` | `"perPage"` | 设置分页一页显示的多少条数据的字段名。 |
  32. | orderField | `string` | | 设置用来确定位置的字段名,设置后新的顺序将被赋值到该字段中。 |
  33. <div class="md-section-divider"></div>
  34. #### listItem
  35. * `title` 标题
  36. * `subTitle` 副标题
  37. * `desc` 描述
  38. * `avatar` 图片
  39. * `actions` 按钮集合。关于按钮部分查看 [Button](#button)
  40. <div class="md-section-divider"></div>
  41. ```schema:height="800" scope="body"
  42. {
  43. "type": "crud",
  44. "api": "/api/admin/permission/inGroup?groupId=1",
  45. "mode": "list",
  46. "placeholder": "当前组内, 还没有配置任何权限.",
  47. "title": null,
  48. "listItem": {
  49. "title": "$name",
  50. "subTitle": "$desc",
  51. "actions": [
  52. {
  53. "icon": "fa fa-edit",
  54. "tooltip": "编辑",
  55. "actionType": "dialog",
  56. "dialog": {
  57. "title": "编辑能力(权限)",
  58. "name": "amis-permission-edit",
  59. "api": "/api/admin/permission/$id?groupId=1",
  60. "controls": [
  61. {
  62. "type": "hidden",
  63. "name": "id"
  64. },
  65. {
  66. "name": "name",
  67. "label": "权限名称",
  68. "type": "text",
  69. "disabled": true
  70. },
  71. {
  72. "type": "divider"
  73. },
  74. {
  75. "name": "desc",
  76. "label": "描述",
  77. "type": "textarea"
  78. }
  79. ]
  80. }
  81. },
  82. {
  83. "tooltip": "删除",
  84. "disabledOn": "~[\"admin:permission\", \"admin:user\", \"admin:role\", \"admin:acl\", \"admin:page\", \"page:readAll\", \"admin:settings\"].indexOf(name)",
  85. "icon": "fa fa-times",
  86. "confirmText": "您确定要移除该权限?",
  87. "actionType": "ajax",
  88. "action": "delete:/api/admin/permission/$id?groupId=1"
  89. }
  90. ]
  91. }
  92. }

Panel

可以把相关信息以盒子的形式展示到一块。

属性名 类型 默认值 说明
type string "panel" 指定为 Panel 渲染器
className string "panel-default" 外层 Dom 的类名
headerClassName string "panel-heading" header 区域的类名
footerClassName string "panel-footer bg-light lter wrapper" footer 区域的类名
actionsClassName string "panel-footer" actions 区域的类名
bodyClassName string "panel-body" body 区域的类名
title string 标题
header Container 顶部容器
body Container 内容容器
footer Container 底部容器
actions Array Of Button 按钮区域

```schema:height="300" scope="body"
{
"type": "panel",
"title": "Panel Heading",
"body": "Panel Body",
"actions": [
{
"type": "button",
"label": "Action 1",
"actionType": "dialog",
"dialog": {
"confirmMode": false,
"title": "提示",
"body": "对,你刚点击了!"
}
},

    {
      "type": "button",
      "label": "Action 2",
      "actionType": "dialog",
      "dialog": {
        "confirmMode": false,
        "title": "提示",
        "body": "对,你刚点击了!"
      }
    }
]

}

  1. <div class="md-section-divider"></div>
  2. ## Wrapper
  3. 简单的一个容器。
  4. |属性名 | 类型 | 默认值 | 说明 |
  5. |---|---|---|---|
  6. | type | `string` | `"wrapper"` | 指定为 Wrapper 渲染器 |
  7. | className | `string` | | 外层 Dom 的类名 |
  8. | size | `string` | | 支持: `xs`、`sm`、`md`和`lg` |
  9. | body | [Container](#container) | | 内容容器 |
  10. <div class="md-section-divider"></div>
  11. ```schema:height="200" scope="body"
  12. {
  13. "type": "wrapper",
  14. "body": "Wrapped Body"
  15. }

Service

功能型容器,自身不负责展示内容,主要职责在于通过配置的 api 拉取数据,数据可用于子组件。
该组件初始化时就会自动拉取一次数据,后续如果需要刷新,请结合 Action 实现,可以把 Action 的 actionType 设置为 reload, target 为该组件。
同时该组件,还支持 api 数值自动监听,比如 getData?type=$type 只要当前环境 type 值发生变化,就会自动重新拉取。

属性名 类型 默认值 说明
type string "service" 指定为 service 渲染器
className string 外层 Dom 的类名
body Container 内容容器
api api 数据源 API 地址
initFetch boolean 是否默认拉取
schemaApi api 用来获取远程 Schema 的 api

```schema:height="200" scope="body"
{
"type": "service",
"api": "/api/mock/pageInfo",
"body": {
"type": "panel",
"title": "{time}"
}
}

  1. <div class="md-section-divider"></div>
  2. ## Chart
  3. 图表渲染器,采用echarts渲染,配置格式跟echarts相同,配置文档[文档](http://echarts.baidu.com/option.html#title)
  4. |属性名 | 类型 | 默认值 | 说明 |
  5. |---|---|---|---|
  6. | type | `string` | `"chart"` | 指定为 chart 渲染器 |
  7. | className | `string` | | 外层 Dom 的类名 |
  8. | body | [Container](#container) | | 内容容器 |
  9. | api | [api](#api) | | 配置项远程地址 |
  10. | initFetch | `boolean` | | 是否默认拉取 |
  11. | interval | `number` | | 刷新时间(最低3000) |
  12. | config | `object/string` | | 设置eschars的配置项,当为`string`的时候可以设置function等配置项|
  13. | style | `object` | | 设置根元素的style |
  14. <div class="md-section-divider"></div>
  15. ```schema:height="300" scope="body"
  16. {
  17. "type": "chart",
  18. "api": "/api/mock/chart",
  19. "interval": 3000
  20. }

video

视频播放器。

属性名 类型 默认值 说明
type string "video" 指定为 video 渲染器
className string 外层 Dom 的类名
src string 视频地址
poster string 视频封面地址
muted boolean 是否静音
autoPlay boolean 是否自动播放

```schema:height="500" scope="body"
{
"type": "video",
"autoPlay": false,
"src": "raw:https://media.w3.org/2010/05/sintel/trailer_hd.mp4",
"poster": "raw:https://video-react.js.org/assets/poster.png"
}

  1. <div class="md-section-divider"></div>
  2. ## table
  3. 类似与 CRUD 的,但是该组件没有 CRUD 那么强大的交互功能,只能做简单的渲染,不负责数据的拉取,但是他可以绑定作用域中的变量,或者结合 service 组件通过 api 拉取后再绑定。
  4. |属性名 | 类型 | 默认值 | 说明 |
  5. |---|---|---|---|
  6. | type | `string` | | `"table"` 指定为 table 渲染器 |
  7. | className | `string` | | 表格外层 Dom 的类名 |
  8. | columns | Array of [Column](#column) | | 用来设置列信息 |
  9. | rows | * | | 数据或者 "${xxxx}" 从当前作用域中取变量 |
  10. | placeholder | string | ‘暂无数据’ | 当没数据的时候的文字提示 |
  11. <div class="md-section-divider"></div>
  12. ```schema:height="700" scope="body"
  13. {
  14. "type": "service",
  15. "api": "/api/sample?perPage=5",
  16. "body": [
  17. {
  18. "type": "panel",
  19. "title": "简单表格示例1",
  20. "body": {
  21. "type": "table",
  22. "rows": "$rows",
  23. "columns": [
  24. {
  25. "name": "engine",
  26. "label": "Engine"
  27. },
  28. {
  29. "name": "version",
  30. "label": "Version"
  31. }
  32. ]
  33. }
  34. },
  35. {
  36. "type": "panel",
  37. "title": "简单表格示例2",
  38. "body": {
  39. "type": "table",
  40. "rows": "$rows",
  41. "columns": [
  42. {
  43. "name": "engine",
  44. "label": "Engine"
  45. },
  46. {
  47. "name": "version",
  48. "label": "Version"
  49. }
  50. ]
  51. }
  52. }
  53. ]
  54. }

Card

卡片的展示形式。

属性名 类型 默认值 说明
type string "card" 指定为 Card 渲染器
className string "panel-default" 外层 Dom 的类名
header Object Card 头部内容设置
header.className string 头部类名
header.title string 标题
header.subTitle string 副标题
header.desc string 描述
header.avatar string 图片
header.highlight boolean 是否点亮
header.avatarClassName string "pull-left thumb avatar b-3x m-r" 图片类名
body Container 内容区域
bodyClassName string "padder m-t-sm m-b-sm" 内容区域类名
actions Array Of Button 按钮区域

```schema:height="300" scope="body"
{
"type": "card",
"header": {
"title": "Title",
"subTitle": "Sub Title",
"desc": "desc",
"avatarClassName": "pull-left thumb-md avatar b-3x m-r",
"avatar": "raw:http://hiphotos.baidu.com/fex/%70%69%63/item/c9fcc3cec3fdfc03ccabb38edd3f8794a4c22630.jpg"
},
"body": "Body",
"actions": [
{
"type": "button",
"label": "Action 1",
"actionType": "dialog",
"dialog": {
"confirmMode": false,
"title": "提示",
"body": "对,你刚点击了!"
}
},

    {
      "type": "button",
      "label": "Action 2",
      "actionType": "dialog",
      "dialog": {
        "confirmMode": false,
        "title": "提示",
        "body": "对,你刚点击了!"
      }
    }
]

}

  1. <div class="md-section-divider"></div>
  2. ## Tabs
  3. |属性名 | 类型 | 默认值 | 说明 |
  4. |---|---|---|---|
  5. | type | `string` | `"tabs"` | 指定为 Tabs 渲染器 |
  6. | className | `string` | | 外层 Dom 的类名 |
  7. | tabsClassName | `string` | | Tabs Dom 的类名 |
  8. | tabs | `Array` | | tabs 内容 |
  9. | tabs[x].title | `string` | | Tab 标题 |
  10. | tabs[x].icon | `icon` | | Tab 的图标 |
  11. | tabs[x].tab | [Container](#container) | | 内容区 |
  12. | tabs[x].hash | `string` | | 设置以后将跟url的hash对应 |
  13. | tabs[x].reload | `boolean` | | 设置以后内容每次都会重新渲染,对于crud的重新拉取很有用 |
  14. | tabs[x].className | `string` | `"bg-white b-l b-r b-b wrapper-md"` | Tab 区域样式 |
  15. <div class="md-section-divider"></div>
  16. ```schema:height="300" scope="body"
  17. {
  18. "type": "tabs",
  19. "tabs": [
  20. {
  21. "title": "Tab 1",
  22. "tab": "Content 1"
  23. },
  24. {
  25. "title": "Tab 2",
  26. "tab": "Content 2"
  27. }
  28. ]
  29. }

Grid

属性名 类型 默认值 说明
type string "grid" 指定为 Grid 渲染器
className string 外层 Dom 的类名
columns Array 列集合
columns[x] Container 成员可以是其他渲染器
columns[x].xs int 宽度占比: 1 - 12
columns[x].xsHidden boolean 是否隐藏
columns[x].xsOffset int 偏移量 1 - 12
columns[x].xsPull int 靠左的距离占比:1 - 12
columns[x].xsPush int 靠右的距离占比: 1 - 12
columns[x].sm int 宽度占比: 1 - 12
columns[x].smHidden boolean 是否隐藏
columns[x].smOffset int 偏移量 1 - 12
columns[x].smPull int 靠左的距离占比:1 - 12
columns[x].smPush int 靠右的距离占比: 1 - 12
columns[x].md int 宽度占比: 1 - 12
columns[x].mdHidden boolean 是否隐藏
columns[x].mdOffset int 偏移量 1 - 12
columns[x].mdPull int 靠左的距离占比:1 - 12
columns[x].mdPush int 靠右的距离占比: 1 - 12
columns[x].lg int 宽度占比: 1 - 12
columns[x].lgHidden boolean 是否隐藏
columns[x].lgOffset int 偏移量 1 - 12
columns[x].lgPull int 靠左的距离占比:1 - 12
columns[x].lgPush int 靠右的距离占比: 1 - 12

更多使用说明,请参看 Grid Props

```schema:height="300" scope="body"
[
{
"type": "grid",
"className": "b-a bg-dark lter",
"columns": [
{
"type": "plain",
"text": "md: 3",
"md": 3,
"className": "b-r"
},

        {
            "type": "plain",
            "text": "md: 9",
            "md": 9
        }
    ]
},

{
    "type": "grid",
    "className": "b-a m-t bg-dark lter",
    "columns": [
        {
            "type": "plain",
            "text": "mdOffset: 3",
            "mdOffset": 3
        }
    ]
}

]

  1. <div class="md-section-divider"></div>
  2. ## HBox
  3. |属性名 | 类型 | 默认值 | 说明 |
  4. |---|---|---|---|
  5. | type | `string` | `"hbox"` | 指定为 HBox 渲染器 |
  6. | className | `string` | | 外层 Dom 的类名 |
  7. | columns | `Array` | | 列集合 |
  8. | columns[x] | [Container](#Container) | | 成员可以是其他渲染器 |
  9. | columns[x].columnClassName | `string` | `"wrapper-xs"` | 列上类名 |
  10. <div class="md-section-divider"></div>
  11. ```schema:height="300" scope="body"
  12. [
  13. {
  14. "type": "hbox",
  15. "className": "b-a bg-dark lter",
  16. "columns": [
  17. {
  18. "type": "plain",
  19. "text": "Col A",
  20. "columnClassName": "wrapper-xs b-r"
  21. },
  22. "Col B"
  23. ]
  24. },
  25. {
  26. "type": "hbox",
  27. "className": "b-a m-t bg-dark lter",
  28. "columns": [
  29. {
  30. "type": "plain",
  31. "text": "w-md",
  32. "columnClassName": "w-md wrapper-xs bg-primary b-r"
  33. },
  34. "..."
  35. ]
  36. }
  37. ]

iFrame

如果需要内嵌外部站点,可用 iframe 来实现。

```schema:height="300" scope="body"
{
"type": "iframe",
"src": "raw:http://www.baidu.com",
"style": {
"height": 260
}
}

  1. <div class="md-section-divider"></div>
  2. ## Nav
  3. |属性名 | 类型 | 默认值 | 说明 |
  4. |---|---|---|---|
  5. | type | `string` | `"tabs"` | 指定为 Nav 渲染器 |
  6. | className | `string` | | 外层 Dom 的类名 |
  7. | stacked | `boolean` | `true` | 设置成 false 可以以 tabs 的形式展示 |
  8. | links | `Array` | | 链接集合 |
  9. | links[x].label | `string` | | 名称 |
  10. | links[x].to | `string` | | 链接地址 |
  11. | links[x].icon | `string` | | 图标 |
  12. 链接集合。
  13. <div class="md-section-divider"></div>
  14. ```schema:height="300" scope="body"
  15. {
  16. "type": "nav",
  17. "stacked": true,
  18. "className": "w-md",
  19. "links": [
  20. {
  21. "label": "Nav 1",
  22. "to": "/docs/index",
  23. "icon": "fa fa-user"
  24. },
  25. {
  26. "label": "Nav 2",
  27. "to": "/docs/api"
  28. },
  29. {
  30. "label": "Nav 3",
  31. "to": "/docs/renderers"
  32. }
  33. ]
  34. }

```schema:height="300" scope="body"
{
"type": "nav",
"stacked": false,
"links": [
{
"label": "Nav 1",
"to": "/docs/index",
"icon": "fa fa-user"
},

    {
        "label": "Nav 2",
        "to": "/docs/api"
    },

    {
        "label": "Nav 3",
        "to": "/docs/renderers"
    }
]

}

  1. <div class="md-section-divider"></div>
  2. ## Tasks
  3. 任务操作集合,类似于 orp 上线。
  4. <div class="md-section-divider"></div>
  5. ```schema:height="300" scope="body"
  6. {
  7. "type": "tasks",
  8. "name": "tasks",
  9. "items": [
  10. {
  11. "label": "hive 任务",
  12. "key": "hive",
  13. "status": 4,
  14. "remark": "查看详情<a target=\"_blank\" href=\"http://www.baidu.com\">日志</a>。"
  15. },
  16. {
  17. "label": "小流量",
  18. "key": "partial",
  19. "status": 4
  20. },
  21. {
  22. "label": "全量",
  23. "key": "full",
  24. "status": 4
  25. }
  26. ]
  27. }
属性名 类型 默认值 说明
type string "tasks" 指定为 Tasks 渲染器
className string 外层 Dom 的类名
tableClassName string table Dom 的类名
items Array 任务列表
items[x].label string 任务名称
items[x].key string 任务键值,请唯一区分
items[x].remark string 当前任务状态,支持 html
items[x].status string 任务状态: 0: 初始状态,不可操作。1: 就绪,可操作状态。2: 进行中,还没有结束。3:有错误,不可重试。4: 已正常结束。5:有错误,且可以重试。
checkApi api 返回任务列表,返回的数据请参考 items。
submitApi api 提交任务使用的 API
reSubmitApi api 如果任务失败,且可以重试,提交的时候会使用此 API
interval number 3000 当有任务进行中,会每隔一段时间再次检测,而时间间隔就是通过此项配置,默认 3s。
taskNameLabel string 任务名称 任务名称列说明
operationLabel string 操作 操作列说明
statusLabel string 状态 状态列说明
remarkLabel string 备注 备注列说明
btnText string 上线 操作按钮文字
retryBtnText string 重试 重试操作按钮文字
btnClassName string btn-sm btn-default 配置容器按钮 className
retryBtnClassName string btn-sm btn-danger 配置容器重试按钮 className
statusLabelMap array ["label-warning", "label-info", "label-success", "label-danger", "label-default", "label-danger"] 状态显示对应的类名配置
statusTextMap array ["未开始", "就绪", "进行中", "出错", "已完成", "出错"] 状态显示对应的文字显示配置

```schema:height="300" scope="body"
[
{
"type": "tasks",
"name": "tasks",
"checkApi": "/api/mock/tasks"
},

"为了演示,目前获取的状态都是随机出现的。"]

  1. <div class="md-section-divider"></div>
  2. ## 类型说明
  3. <div class="md-section-divider"></div>
  4. ### Container
  5. Container 不是一个特定的渲染器,而是 AMis 中一个特殊类型,它是以下类型的任何一种。
  6. * `String` 字符串,可以包含 `html` 片段。
  7. * `Object` 指定一个渲染器如: `{"type": "button", "label": "按钮"}`
  8. * `Array` 还可以是一个数组,数组的成员可以就是一个 `Container`.
  9. 示例:
  10. <div class="md-section-divider"></div>
  11. ```json
  12. {
  13. "container": "普通一段字符串"
  14. }
  1. {
  2. "container": {
  3. "type": "button",
  4. "label": "按钮"
  5. }
  6. }
  1. {
  2. "container": [
  3. "普通一段字符串",
  4. {
  5. "type": "button",
  6. "label": "按钮"
  7. },
  8. [
  9. "普通一段字符串",
  10. "普通一段字符串"
  11. ]
  12. ]
  13. }

API

Api 类型可以是字符串或者对象。API 中可以直接设置数据发送结构,注意看示例。

** 注意 **

AMis 所有值为 url 的如: "http://www.baidu.com" 都会被替换成 proxy 代理,如果不希望这么做,请明确指示如: "raw:http://www.baidu.com"。还有为了安全,AMis 默认只能转发公司内部 API 接口,如果您的接口在外网环境,也请明确指示如:"external:http://www.baidu.com"

表达式

配置项中,所有 boolean 类型的配置,都可以用 JS 表达式来配置。所有boolean 配置项,后面加个 On 则是表达式配置方式,可以用 js 语法来根据当前模型中的数据来决定是否启用。
如:FormItem 中的 disabledOnhiddenOnvisibleOnCRUD 中的 draggableOn 等等。

```schema:height="300" scope="form"
[
{
"type": "radios",
"name": "foo",
"inline": true,
"label": " ",
"options": [
{
"label": "类型1",
"value": 1
},
{
"label": "类型2",
"value": 2
},
{
"label": "类型3",
"value": 3
}
]
},

{
    "type": "text",
    "name": "text",
    "placeholder": "类型1 可见",
    "visibleOn": "data.foo == 1"
},

 {
     "type": "text",
     "name": "text2",
     "placeholder": "类型2 不可点",
     "disabledOn": "data.foo == 2"
 },

{
"type": "button",
"label": "类型三不能提交",
"level": "primary",
"disabledOn": "data.foo == 3"
}

]
```

为了能加入权限控制,表达是中允许可以用 acl.can 方法来检测当前用户是否拥有某个权限。
如: {"disabledOn": "!can('some-resource')"}。权限能力部分,请前往能力管理
权限配置请前往权限配置管理。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注