Property 属性表

使用表格的方式显示只读信息,如产品详情页。

基本用法

```schema: scope=”body” { “type”: “property”, “title”: “机器配置”, “items”: [ { “label”: “cpu”, “content”: “1 core” }, { “label”: “memory”, “content”: “4G” }, { “label”: “disk”, “content”: “80G” }, { “label”: “network”, “content”: “4M”, “span”: 2 }, { “label”: “IDC”, “content”: “beijing” }, { “label”: “Note”, “content”: “其它说明”, “span”: 3 } ] }

  1. ## 简易模式
  2. 默认是表格模式,还可以通过 `"mode"="simple"` 改成简易模式,在这种模式下没有边框,属性名和值是通过 `separator` 来分隔
  3. ```schema: scope="body"
  4. {
  5. "type": "property",
  6. "mode": "simple",
  7. "separator": ":",
  8. "items": [
  9. {
  10. "label": "cpu",
  11. "content": "1 core"
  12. },
  13. {
  14. "label": "memory",
  15. "content": "4G"
  16. },
  17. {
  18. "label": "disk",
  19. "content": "80G"
  20. },
  21. {
  22. "label": "network",
  23. "content": "4M",
  24. "span": 2
  25. },
  26. {
  27. "label": "IDC",
  28. "content": "beijing"
  29. },
  30. {
  31. "label": "Note",
  32. "content": "其它说明",
  33. "span": 3
  34. }
  35. ]
  36. }

使用其它展现

labelcontent 均支持使用 amis 其它渲染组件,比如

```schema: scope=”body” { “type”: “property”, “items”: [ { “label”: “tpl”, “content”: { “type”: “tpl”, “tpl”: “1 Core“ } }, { “label”: “icon”, “content”: { “type”: “icon”, “icon”: “microchip” } }, { “label”: “图片”, “content”: { “type”: “image”, “src”: “https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80“ } } ] }

  1. ## 动态内容
  2. 属性表本身没有数据获取功能,需要结合 [service](./service) 来获取数据,下面的例子为了方便就直接放 page 下的 data 中了,它的效果和用 service 是一样的。
  3. 动态内容有两种情况:
  4. 1. label 固定、content 不同
  5. 2. label content 都不确定
  6. 第一种情况只需要在 content 里使用变量即可,因为可以用任意 amis 节点。
  7. ```schema
  8. {
  9. "type": "page",
  10. "data": {
  11. "cpu": "1 core",
  12. "memory": "4G",
  13. "disk": "80G"
  14. },
  15. "body": {
  16. "type": "property",
  17. "items": [
  18. {
  19. "label": "cpu",
  20. "content": "${cpu}"
  21. },
  22. {
  23. "label": "memory",
  24. "content": "${memory}"
  25. },
  26. {
  27. "label": "disk",
  28. "content": "${disk}"
  29. }
  30. ]
  31. }
  32. }

第二种情况需要使用 source 属性来获取上下文中的内容。

  1. {
  2. "type": "page",
  3. "data": {
  4. "items": [
  5. {
  6. "label": "cpu",
  7. "content": "1 core"
  8. },
  9. {
  10. "label": "memory",
  11. "content": "4G"
  12. },
  13. {
  14. "label": "disk",
  15. "content": "80G"
  16. },
  17. {
  18. "label": "network",
  19. "content": "4M",
  20. "span": 2
  21. },
  22. {
  23. "label": "IDC",
  24. "content": "beijing"
  25. },
  26. {
  27. "label": "Note",
  28. "content": "其它说明",
  29. "span": 3
  30. }
  31. ]
  32. },
  33. "body": {
  34. "type": "property",
  35. "source": "${items}"
  36. }
  37. }

样式控制

通过 labelStylecontentStyle 来控制属性名和属性值的样式,比如水平及垂直方向的对齐方式:

```schema: scope=”body” { “type”: “property”, “labelStyle”: { “textAlign”: “left”, “verticalAlign”: “top” }, “contentStyle”: { “verticalAlign”: “top” }, “items”: [ { “label”: “cpu”, “content”: “1 core” }, { “label”: “memory”, “content”: “4G” }, { “label”: “disk”, “content”: { “type”: “tpl”, “tpl”: “C: 80G
D: 1T
E: 2T“ } }, { “label”: “network”, “content”: “4M”, “span”: 2 }, { “label”: “IDC”, “content”: “beijing” }, { “label”: “Note”, “content”: “其它说明”, “span”: 3 } ] }

  1. 如果是简易模式,因为合并到一个单元格中了,因此只能通过 `contentStyle` 设置单元格样式,`labelStyle` 只能设置属性名文本的样式。
  2. ```schema: scope="body"
  3. {
  4. "type": "property",
  5. "mode": "simple",
  6. "labelStyle": {
  7. "fontWeight": "bold",
  8. "textTransform": "capitalize"
  9. },
  10. "contentStyle": {
  11. "verticalAlign": "top"
  12. },
  13. "items": [
  14. {
  15. "label": "cpu",
  16. "content": "1 core"
  17. },
  18. {
  19. "label": "memory",
  20. "content": "4G"
  21. },
  22. {
  23. "label": "disk",
  24. "content": {
  25. "type": "tpl",
  26. "tpl": "C: 80G<br/>D: 1T<br/>E: 2T</pre>"
  27. }
  28. },
  29. {
  30. "label": "network",
  31. "content": "4M",
  32. "span": 2
  33. },
  34. {
  35. "label": "IDC",
  36. "content": "beijing"
  37. },
  38. {
  39. "label": "Note",
  40. "content": "其它说明",
  41. "span": 3
  42. }
  43. ]
  44. }

显示列数

通过 column 来控制一行显示几列,默认是 3 列,下面示例是改成 2 列的效果

```schema: scope=”body” { “type”: “property”, “column”: 2, “items”: [ { “label”: “cpu”, “content”: “1 core” }, { “label”: “memory”, “content”: “4G” }, { “label”: “disk”, “content”: “80G” }, { “label”: “IDC”, “content”: “beijing” }, { “label”: “network”, “content”: “4M”, “span”: 2 }, { “label”: “Note”, “content”: “其它说明”, “span”: 2 } ] }

  1. ## 隐藏某个属性值
  2. items 里的属性还支持 `visibleOn` `hiddenOn` 表达式,能隐藏部分属性,如果有空间后续组件会自动补上来,如下示例的 memory 隐藏了:
  3. ```schema: scope="body"
  4. {
  5. "type": "property",
  6. "items": [
  7. {
  8. "label": "cpu",
  9. "content": "1 core"
  10. },
  11. {
  12. "label": "memory",
  13. "content": "4G",
  14. "visibleOn": "data.cpu > 1"
  15. },
  16. {
  17. "label": "network",
  18. "content": "4M",
  19. "span": 2
  20. }
  21. ]
  22. }

属性表

属性名 类型 默认值 说明
className string 外层 dom 的类名
style object 外层 dom 的样式
labelStyle object 属性名的样式
contentStyle object 属性值的样式
column number 3 每行几列
mode string ‘table’ 显示模式,目前只有 ‘table’ 和 ‘simple’
separator string ‘,’ ‘simple’ 模式下属性名和值之间的分隔符
items[].label SchemaTpl 属性名
items[].content SchemaTpl 属性值
items[].span SchemaTpl 属性值跨几列
items[].visibleOn 表达式 显示表达式
items[].hiddenOn 表达式 隐藏表达式