title: InputFormula 公式编辑器 description: type: 0 group: null menuName: InputFormula icon:

order: 21

基本用法

用来输入公式。还是 beta 版本,整体待优化。

```schema: scope=”body” { “type”: “form”, “debug”: true, “body”: [ { “type”: “input-formula”, “name”: “formula”, “label”: “公式”, “evalMode”: true, “value”: “SUM(1 + 2)”, “variables”: [ { “label”: “表单字段”, “children”: [ { “label”: “文章名”, “value”: “name”, “tag”: “文本” }, { “label”: “作者”, “value”: “author”, “tag”: “文本” }, { “label”: “售价”, “value”: “price”, “tag”: “数字” }, { “label”: “出版时间”, “value”: “time”, “tag”: “时间” }, { “label”: “版本号”, “value”: “version”, “tag”: “数字” }, { “label”: “出版社”, “value”: “publisher”, “tag”: “文本” } ] }, { “label”: “流程字段”, “children”: [ { “label”: “联系电话”, “value”: “telphone” }, { “label”: “地址”, “value”: “addr” } ] } ], } ] }

  1. ## 展示模式
  2. 设置`"inputMode": "button"`可以切换编辑器的展示模式为按钮模式。
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "debug": true,
  7. "body": [
  8. {
  9. "type": "input-formula",
  10. "name": "formula",
  11. "label": "公式",
  12. "variableMode": "tree",
  13. "evalMode": false,
  14. "value": "${SUM(1 + 2)}",
  15. "inputMode": "button",
  16. "variables": [
  17. {
  18. "label": "表单字段",
  19. "children": [
  20. {
  21. "label": "文章名",
  22. "value": "name",
  23. "tag": "文本"
  24. },
  25. {
  26. "label": "作者",
  27. "value": "author",
  28. "tag": "文本"
  29. },
  30. {
  31. "label": "售价",
  32. "value": "price",
  33. "tag": "数字"
  34. },
  35. {
  36. "label": "出版时间",
  37. "value": "time",
  38. "tag": "时间"
  39. },
  40. {
  41. "label": "版本号",
  42. "value": "version",
  43. "tag": "数字"
  44. },
  45. {
  46. "label": "出版社",
  47. "value": "publisher",
  48. "tag": "文本"
  49. }
  50. ]
  51. },
  52. {
  53. "label": "流程字段",
  54. "children": [
  55. {
  56. "label": "联系电话",
  57. "value": "telphone"
  58. },
  59. {
  60. "label": "地址",
  61. "value": "addr"
  62. }
  63. ]
  64. }
  65. ],
  66. }
  67. ]
  68. }

设置"inputMode": "input-group"可以切换编辑器的展示模式为输入框组合模式,1.10.0 及以上版本。

```schema: scope=”body” { “type”: “form”, “debug”: true, “body”: [ { “type”: “input-formula”, “name”: “formula”, “label”: “公式”, “variableMode”: “tree”, “evalMode”: true, “value”: “SUM(1 + 2)”, “inputMode”: “input-group”, “variables”: [ { “label”: “表单字段”, “children”: [ { “label”: “文章名”, “value”: “name”, “tag”: “文本” }, { “label”: “作者”, “value”: “author”, “tag”: “文本” }, { “label”: “售价”, “value”: “price”, “tag”: “数字” }, { “label”: “出版时间”, “value”: “time”, “tag”: “时间” }, { “label”: “版本号”, “value”: “version”, “tag”: “数字” }, { “label”: “出版社”, “value”: “publisher”, “tag”: “文本” } ] }, { “label”: “流程字段”, “children”: [ { “label”: “联系电话”, “value”: “telphone” }, { “label”: “地址”, “value”: “addr” } ] } ], } ] }

  1. ## 变量展示模式
  2. 设置不同`variableMode`字段切换变量展示模式,树形结构:
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "debug": true,
  7. "body": [
  8. {
  9. "type": "input-formula",
  10. "name": "formula",
  11. "label": "公式",
  12. "variableMode": "tree",
  13. "evalMode": true,
  14. "variables": [
  15. {
  16. "label": "表单字段",
  17. "children": [
  18. {
  19. "label": "文章名",
  20. "value": "name",
  21. "tag": "文本"
  22. },
  23. {
  24. "label": "作者",
  25. "value": "author",
  26. "tag": "文本"
  27. },
  28. {
  29. "label": "售价",
  30. "value": "price",
  31. "tag": "数字"
  32. },
  33. {
  34. "label": "出版时间",
  35. "value": "time",
  36. "tag": "时间"
  37. },
  38. {
  39. "label": "版本号",
  40. "value": "version",
  41. "tag": "数字"
  42. },
  43. {
  44. "label": "出版社",
  45. "value": "publisher",
  46. "tag": "文本"
  47. }
  48. ]
  49. },
  50. {
  51. "label": "流程字段",
  52. "children": [
  53. {
  54. "label": "联系电话",
  55. "value": "telphone"
  56. },
  57. {
  58. "label": "地址",
  59. "value": "addr"
  60. }
  61. ]
  62. }
  63. ],
  64. }
  65. ]
  66. }

Tab 结构:

```schema: scope=”body” { “type”: “form”, “debug”: true, “body”: [ { “type”: “input-formula”, “name”: “formula”, “label”: “公式”, “variableMode”: “tabs”, “evalMode”: false, “variables”: [ { “label”: “表单字段”, “children”: [ { “label”: “文章名”, “value”: “name”, “tag”: “文本” }, { “label”: “作者”, “value”: “author”, “tag”: “文本” }, { “label”: “售价”, “value”: “price”, “tag”: “数字” }, { “label”: “出版时间”, “value”: “time”, “tag”: “时间” }, { “label”: “版本号”, “value”: “version”, “tag”: “数字” }, { “label”: “出版社”, “value”: “publisher”, “tag”: “文本” } ] }, { “label”: “流程字段”, “children”: [ { “label”: “联系电话”, “value”: “telphone” }, { “label”: “地址”, “value”: “addr” } ] } ], } ] }

  1. ## 高亮文本
  2. 通过配置`allowInput``false`可以高亮文本内容,但是只能在编辑器中编辑
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "debug": true,
  7. "body": [
  8. {
  9. "type": "input-formula",
  10. "name": "formula",
  11. "allowInput": false,
  12. "label": "公式",
  13. "evalMode": true,
  14. "value": "SUM(1 + 2)",
  15. "variables": [
  16. {
  17. "label": "表单字段",
  18. "children": [
  19. {
  20. "label": "文章名",
  21. "value": "name",
  22. "tag": "文本"
  23. },
  24. {
  25. "label": "作者",
  26. "value": "author",
  27. "tag": "文本"
  28. },
  29. {
  30. "label": "售价",
  31. "value": "price",
  32. "tag": "数字"
  33. },
  34. {
  35. "label": "出版时间",
  36. "value": "time",
  37. "tag": "时间"
  38. },
  39. {
  40. "label": "版本号",
  41. "value": "version",
  42. "tag": "数字"
  43. },
  44. {
  45. "label": "出版社",
  46. "value": "publisher",
  47. "tag": "文本"
  48. }
  49. ]
  50. },
  51. {
  52. "label": "流程字段",
  53. "children": [
  54. {
  55. "label": "联系电话",
  56. "value": "telphone"
  57. },
  58. {
  59. "label": "地址",
  60. "value": "addr"
  61. }
  62. ]
  63. }
  64. ],
  65. }
  66. ]
  67. }

属性表

属性名 类型 默认值 说明
title string '公式编辑器' 弹框标题
header string - 编辑器 header 标题,如果不设置,默认使用表单项label字段
evalMode boolean true 表达式模式 或者 模板模式,模板模式则需要将表达式写在 ${} 中间。
variables {label: string; value: string; children?: any[]; tag?: string}[] [] 可用变量
variableMode string list 可配置成 tabs 或者 tree 默认为列表,支持分组。
functions Object[] - 可以不设置,默认就是 amis-formula 里面定义的函数,如果扩充了新的函数则需要指定
inputMode `’button’ \ ‘input-button’ \ ‘input-group’` - 控件的展示模式
icon string - 按钮图标,例如fa fa-list
btnLabel string '公示编辑' 按钮文本,inputModebutton时生效
level `’info’ \ ‘success’ \ ‘warning’ \ ‘danger’ \ ‘link’ \ ‘primary’ \ ‘dark’ \ ‘light’` default 按钮样式
allowInput boolean - 输入框是否可输入
btnSize `’xs’ \ ‘sm’ \ ‘md’ \ ‘lg’` - 按钮大小
borderMode `’full’ \ ‘half’ \ ‘none’` - 输入框边框模式
placeholder string '暂无数据' 输入框占位符
className string - 控件外层 CSS 样式类名
variableClassName string - 变量面板 CSS 样式类名
functionClassName string - 函数面板 CSS 样式类名