2020-07-28 10:03:53 +08:00
|
|
|
|
---
|
|
|
|
|
title: Editor 编辑器
|
2020-08-13 19:01:07 +08:00
|
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
type: 0
|
|
|
|
|
group: null
|
|
|
|
|
menuName: Editor
|
2020-08-13 19:01:07 +08:00
|
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
order: 19
|
|
|
|
|
---
|
2020-08-13 19:01:07 +08:00
|
|
|
|
|
2021-07-28 12:20:21 +08:00
|
|
|
|
用于实现代码编辑,如果要实现富文本编辑请使用 [Rich-Text](./input-rich-text)。
|
2021-01-07 23:35:03 +08:00
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 基本用法
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"label": "编辑器"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 支持的语言
|
|
|
|
|
|
|
|
|
|
可以设置`language`配置高亮的语言,支持的语言有:
|
|
|
|
|
|
2021-04-08 21:14:29 +08:00
|
|
|
|
`bat`、 `c`、 `coffeescript`、 `cpp`、 `csharp`、 `css`、 `dockerfile`、 `fsharp`、 `go`、 `handlebars`、 `html`、 `ini`、 `java`、 `javascript`、 `json`、 `less`、 `lua`、 `markdown`、 `msdax`、 `objective-c`、 `php`、 `plaintext`、 `postiats`、 `powershell`、 `pug`、 `python`、 `r`、 `razor`、 `ruby`、 `sb`、 `scss`、`shell`、 `sol`、 `sql`、 `swift`、 `typescript`、 `vb`、 `xml`、 `yaml`
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"label": "JSON编辑器",
|
|
|
|
|
"language": "json"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-04-08 21:14:29 +08:00
|
|
|
|
> 因为性能原因,上面的例子不支持实时修改 language 生效
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
当然你也可以使用`xxx-editor`这种形式,例如`"type": "json-editor"`
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "json-editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"label": "JSON编辑器"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-10-30 15:11:26 +08:00
|
|
|
|
## 只读模式
|
|
|
|
|
|
|
|
|
|
使用 `disabled: true`。
|
|
|
|
|
|
2021-09-08 16:56:08 +08:00
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "json-editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"disabled": true,
|
|
|
|
|
"label": "JSON编辑器"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-07-28 12:20:21 +08:00
|
|
|
|
## 全屏模式
|
|
|
|
|
|
|
|
|
|
设置`allowFullscreen`属性为`true`,显示编辑器的全屏模式开关,开关开启后编辑器进入全屏模式。
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-07-28 12:20:21 +08:00
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"label": "支持全屏模式的编辑器",
|
|
|
|
|
"allowFullscreen": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-11-12 14:07:58 +08:00
|
|
|
|
## 编辑器展现控制
|
|
|
|
|
|
|
|
|
|
通过 `options` 来控制编辑器展现,比如下面的配置可以关闭行号
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "editor",
|
|
|
|
|
"name": "editor",
|
|
|
|
|
"label": "编辑器",
|
|
|
|
|
"options": {
|
|
|
|
|
"lineNumbers": "off"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 属性表
|
|
|
|
|
|
|
|
|
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
|
|
|
|
|
2021-07-28 12:20:21 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------- | --------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| language | `string` | `javascript` | 编辑器高亮的语言,支持通过 `${xxx}` 变量获取 |
|
|
|
|
|
| size | `string` | `md` | 编辑器高度,取值可以是 `md`、`lg`、`xl`、`xxl` |
|
|
|
|
|
| allowFullscreen | `boolean` | `false` | 是否显示全屏模式开关 |
|
2021-11-12 14:07:58 +08:00
|
|
|
|
| options | `object` | | monaco 编辑器的其它配置,比如是否显示行号等,请参考[这里](https://microsoft.github.io/monaco-editor/api/enums/monaco.editor.EditorOption.html),不过无法设置 readOnly,只读模式需要使用 `disabled: true` |
|