vendor: amis 6.13.0 base (fork root)

This commit is contained in:
2026-06-16 22:14:57 +08:00
commit 8c8e4247a9
3840 changed files with 2467374 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
export default {
title: '表单内锚点导航示例',
body: [
{
type: 'form',
mode: 'horizontal',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '',
body: [
{
type: 'anchor-nav',
links: [
{
title: '员工基本信息',
body: [
{
type: 'fieldSet',
title: '员工基本信息',
body: [
{
name: 'name',
type: 'input-text',
label: '用户名'
},
{
name: 'age',
type: 'input-text',
label: '年龄'
}
]
}
]
},
{
title: '在职信息',
body: [
{
type: 'fieldSet',
title: '地址信息',
body: [
{
name: 'home',
type: 'input-text',
label: '居住地址'
},
{
name: 'address',
type: 'input-text',
label: '工作地址'
}
]
}
]
},
{
title: '教育经历',
body: [
{
type: 'fieldSet',
title: '教育经历',
body: [
{
name: 'school1',
type: 'input-text',
label: '经历1'
},
{
name: 'school2',
type: 'input-text',
label: '经历2'
},
{
name: 'school2',
type: 'input-text',
label: '经历2'
}
]
}
]
},
{
title: '紧急联系人信息',
body: [
{
type: 'fieldSet',
title: '紧急联系人信息',
body: [
{
name: 'contact1',
type: 'input-text',
label: '联系人1'
},
{
name: 'contact2',
type: 'input-text',
label: '联系人2'
},
{
name: 'contact3',
type: 'input-text',
label: '联系人3'
}
]
}
]
}
]
}
]
}
]
};

View File

@@ -0,0 +1,678 @@
export default {
title: 'Combo 示例',
body: [
{
type: 'tabs',
tabs: [
{
title: '基本用法',
hash: 'basic',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'input-text',
label: '文本',
name: 'a'
},
{
type: 'divider'
},
{
type: 'combo',
name: 'combo1',
label: '组合多条多行',
multiple: true,
multiLine: true,
value: [{}],
items: [
{
name: 'a',
label: '文本',
type: 'input-text',
placeholder: '文本',
value: '',
size: 'full'
},
{
name: 'b',
label: '选项',
type: 'select',
options: ['a', 'b', 'c'],
size: 'full'
}
]
},
{
type: 'button',
label: '独立排序',
level: 'dark',
className: 'm-t-n-xs',
size: 'sm',
actionType: 'dialog',
visibleOn: 'data.combo1.length > 1',
dialog: {
title: '对 Combo 进行 拖拽排序',
body: {
type: 'form',
body: [
{
type: 'combo',
name: 'combo1',
label: false,
multiple: true,
draggable: true,
addable: false,
removable: false,
value: [{}],
items: [
{
name: 'a',
type: 'static',
tpl: '${a} - ${b}'
}
]
}
]
},
actions: [
{
type: 'submit',
mergeData: true,
label: '确认',
level: 'primary'
},
{
type: 'button',
actionType: 'close',
label: '取消'
}
]
}
},
{
type: 'combo',
name: 'combo2',
label: '组合多条单行',
multiple: true,
value: [{}],
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
value: '',
columnClassName: 'w-sm'
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c']
}
]
},
{
type: 'divider'
},
{
type: 'combo',
name: 'combo3',
label: '组合单条多行',
multiLine: true,
items: [
{
name: 'a',
label: '文本',
type: 'input-text',
placeholder: '文本',
value: '',
size: 'full'
},
{
name: 'b',
label: '选项',
type: 'select',
options: ['a', 'b', 'c']
}
]
},
{
type: 'combo',
name: 'combo4',
label: '组合单条单行',
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
value: '',
size: 'full'
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c']
}
]
}
]
}
]
},
{
title: '内联样式',
hash: 'inline',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
body: [
{
type: 'combo',
name: 'combo11',
label: '组合多条多行内联',
multiple: true,
multiLine: true,
inline: true,
value: [{}],
items: [
{
name: 'a',
label: '文本',
type: 'input-text',
placeholder: '文本',
value: ''
},
{
name: 'b',
label: '选项',
type: 'select',
options: ['a', 'b', 'c']
}
]
},
{
type: 'combo',
name: 'combo22',
label: '组合多条单行内联',
multiple: true,
inline: true,
value: [{}],
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
value: ''
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c']
}
]
},
{
type: 'divider'
},
{
type: 'combo',
name: 'combo33',
label: '组合单条多行内联',
multiLine: true,
inline: true,
items: [
{
name: 'a',
label: '文本',
type: 'input-text',
placeholder: '文本',
value: ''
},
{
name: 'b',
label: '选项',
type: 'select',
options: ['a', 'b', 'c']
}
]
},
{
type: 'combo',
name: 'combo44',
label: '组合单条单行内联',
inline: true,
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
value: ''
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c']
}
]
}
]
}
]
},
{
title: '唯一验证',
hash: 'unique',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'combo',
name: 'combo666',
label: '组合多条唯一',
multiple: true,
value: [{}],
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
value: '',
unique: true
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c'],
unique: true
}
]
}
]
}
]
},
{
title: '可拖拽排序',
hash: 'sortable',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'combo',
name: 'combo777',
label: '可拖拽排序',
multiple: true,
value: [
{a: '1', b: 'a'},
{a: '2', b: 'b'}
],
draggable: true,
items: [
{
name: 'a',
type: 'input-text',
placeholder: '文本',
unique: true
},
{
name: 'b',
type: 'select',
options: ['a', 'b', 'c'],
unique: true
}
]
}
]
}
]
},
{
title: '值打平',
hash: 'flat',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'combo',
name: 'combo888',
label: '可打平只存储值',
multiple: true,
flat: true,
value: ['red', 'pink'],
draggable: true,
items: [
{
name: 'a',
type: 'input-color',
placeholder: '选取颜色'
}
]
},
{
type: 'static',
name: 'combo888',
label: '当前值',
tpl: '<pre>${combo888|json}</pre>'
}
]
}
]
},
{
title: '条件',
hash: 'conditions',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'tpl',
tpl:
'<p class="m-b-xl">添加时可选择类型,比如这个例子,可以选择是文本类型还是数字类型</p>'
},
{
type: 'combo',
name: 'combo-conditions1',
label: '单选',
value: {
type: 'number'
},
multiLine: true,
conditions: [
{
label: '文本',
test: 'this.type === "text"',
scaffold: {
type: 'text',
label: '文本',
name: ''
},
items: [
{
label: '名称',
name: 'label',
type: 'input-text'
},
{
label: '字段名',
name: 'name',
type: 'input-text'
}
]
},
{
label: '数字',
test: 'this.type === "number"',
scaffold: {
type: 'number',
label: '数字',
name: ''
},
items: [
{
label: '名称',
name: 'label',
type: 'input-text'
},
{
label: '字段名',
name: 'name',
type: 'input-text'
},
{
label: '最小值',
name: 'min',
type: 'input-number'
},
{
label: '最大值',
name: 'max',
type: 'input-number'
},
{
label: '步长',
name: 'step',
type: 'input-number'
}
]
}
]
},
{
type: 'combo',
name: 'combo-conditions2',
label: '多选',
value: [
{
type: 'text'
}
],
multiLine: true,
multiple: true,
typeSwitchable: false,
conditions: [
{
label: '文本',
test: 'this.type === "text"',
scaffold: {
type: 'text',
label: '文本',
name: ''
},
items: [
{
label: '名称',
name: 'label',
type: 'input-text'
},
{
label: '字段名',
name: 'name',
type: 'input-text'
}
]
},
{
label: '数字',
test: 'this.type === "number"',
scaffold: {
type: 'number',
label: '数字',
name: ''
},
items: [
{
label: '名称',
name: 'label',
type: 'input-text'
},
{
label: '字段名',
name: 'name',
type: 'input-text'
},
{
label: '最小值',
name: 'min',
type: 'input-number'
},
{
label: '最大值',
name: 'max',
type: 'input-number'
},
{
label: '步长',
name: 'step',
type: 'input-number'
}
]
}
]
}
]
}
]
},
{
title: 'Tabs',
hash: 'tabs',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'combo',
name: 'combo101',
label: '组合多条多行',
multiple: true,
multiLine: true,
value: [{}],
tabsMode: true,
tabsStyle: 'card',
maxLength: 3,
items: [
{
name: 'a',
label: '文本',
type: 'input-text',
placeholder: '文本',
value: '',
size: 'full'
},
{
name: 'b',
label: '选项',
type: 'select',
options: ['a', 'b', 'c'],
size: 'full'
}
]
}
]
}
]
},
{
title: '其他',
hash: 'others',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
wrapWithPanel: false,
className: 'm-t',
// debug: true,
body: [
{
type: 'input-text',
disabled: true,
label: '父级值',
name: 'a_super',
value: '123'
},
{
type: 'combo',
name: 'combo999',
label: '可获取父级数据',
multiple: true,
canAccessSuperData: true,
strictMode: false,
items: [
{
name: 'a_super',
type: 'input-text'
}
]
},
{
type: 'combo',
name: 'combo9999',
label: '显示序号',
multiple: true,
items: [
{
type: 'tpl',
tpl: '<%= data.index + 1%>',
className: 'p-t-xs',
mode: 'inline'
},
{
name: 'a',
type: 'input-text'
}
]
}
]
}
]
}
]
}
]
};

View File

@@ -0,0 +1,138 @@
export default {
title: '条件生成器',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
mode: 'horizontal',
horizontal: {
leftFixed: true
},
actions: [
{
label: '查看数据',
type: 'button',
actionType: 'dialog',
dialog: {
title: '数据',
body: '<pre>${conditions|json:2}</pre>'
}
}
],
body: [
{
type: 'condition-builder',
label: '条件组件',
name: 'conditions',
description:
'适合让用户自己拼查询条件,然后后端根据数据生成 query where',
fields: [
{
name: 'switch',
type: 'custom',
label: '开关',
value: {
name: 'checkbox',
type: 'checkbox',
label: '勾选框',
option: '选项说明'
},
operators: [
'equal',
{
label: '属于',
value: 'belong'
},
{
label: '不属于',
value: 'not_belong',
values: [
{
type: 'input-date',
name: 'date1',
label: '日期',
inputFormat: 'YYYY年MM月DD日'
},
{
type: 'tpl',
tpl: '~'
},
{
type: 'input-date',
name: 'date2',
label: '日期',
inputFormat: 'YYYY年MM月DD日'
}
]
}
]
},
{
label: '文本',
type: 'text',
name: 'text'
},
{
label: '数字',
type: 'number',
name: 'number'
},
{
label: '布尔',
type: 'boolean',
name: 'boolean'
},
{
label: '选项',
type: 'select',
name: 'select',
options: [
{
label: 'A',
value: 'a'
},
{
label: 'B',
value: 'b'
},
{
label: 'C',
value: 'c'
},
{
label: 'D',
value: 'd'
},
{
label: 'E',
value: 'e'
}
]
},
{
label: '日期',
children: [
{
label: '日期',
type: 'date',
name: 'date'
},
{
label: '时间',
type: 'time',
name: 'time'
},
{
label: '日期时间',
type: 'datetime',
name: 'datetime'
}
]
}
]
}
]
}
]
};

View File

@@ -0,0 +1,233 @@
// @ts-nocheck
import React from 'react';
import {FormItem, Renderer} from 'amis-core';
@FormItem({
type: 'my-custom'
})
class MyFormItem extends React.Component {
render() {
const {value, onChange} = this.props;
return (
<div>
<p>这个是个自定义组件。通过注册渲染器的方式实现。</p>
<p>当前值:{JSON.stringify(value)}</p>
<a
className="btn btn-default"
onClick={() => onChange(Math.round(Math.random() * 10000))}
>
随机修改
</a>
</div>
);
}
}
@Renderer({
test: /(^|\/)my\-renderer$/,
autoVar: true
})
class CustomRenderer extends React.Component {
render() {
const {tip, source} = this.props;
return source ? (
<div>{`非 FormItem 类型的渲染器注册,通过变量获取 x 的值为:${source}`}</div>
) : (
<div>{tip}</div>
);
}
}
export default {
title: '自定义组件示例',
body: [
{
type: 'form',
mode: 'horizontal',
api: '/api/mock2/form/saveForm?waitSeconds=2',
debug: true,
actions: [
{
type: 'submit',
label: '提交',
primary: true
}
],
body: [
{
label: '姓名',
type: 'text',
name: 'name'
},
{
type: 'divider'
},
{
label: '使用 custom 组件',
name: 'name',
type: 'custom',
onMount: (dom, data, onChange) => {
const button = document.createElement('button');
button.innerText = '点击修改姓名';
button.onclick = event => {
onChange('new name', 'name');
event.preventDefault();
};
dom.appendChild(button);
},
onUpdate: (dom, data) => {
console.log('数据有变化', data);
}
},
{
type: 'divider'
},
{
name: 'a',
asFormItem: true,
children: ({value, onChange}) => (
<div>
<p>这是使用 children 的方式,也无需注册。</p>
<p>当前值:{value}</p>
<a
className="btn btn-default"
onClick={() => onChange(Math.round(Math.random() * 10000))}
>
随机修改
</a>
</div>
)
},
{
type: 'divider'
},
{
name: 'b',
type: 'my-custom',
label: '自定义FormItem'
},
{
type: 'divider'
},
{
type: 'control',
body: {
type: 'my-renderer',
source: '${x}'
}
},
{
type: 'divider'
},
{
label: '',
asFormItem: true,
children: ({render}) => (
<div>
<p>组合现有组件</p>
{render(
'formitem',
[
{
type: 'input-text',
name: 'x',
label: 'X',
value: '1'
},
{
type: 'input-text',
name: 'y',
label: 'Y'
}
],
{
formMode: 'normal'
}
)}
</div>
)
},
{
name: 'c',
label: '',
asFormItem: true,
component: ({render, value, onChange, name}) => {
function handleXChange(x) {
value = {
...value,
x
};
onChange(value);
// 一定要 return false
return false;
}
function handleYChange(y) {
value = {
...value,
y
};
onChange(value);
// 一定要 return false
return false;
}
return (
<div>
<p>组合现有组件并控制数据</p>
{render(
'item1',
{
type: 'input-text',
name: 'x',
label: 'X'
},
{
value: value?.x || '',
onChange: handleXChange
}
)}
{render(
'item2',
{
type: 'input-text',
name: 'y',
label: 'Y'
},
{
value: value?.y || '',
onChange: handleYChange
}
)}
</div>
);
}
}
]
},
{
type: 'my-renderer',
tip: '放表单外的情况'
}
]
};

View File

@@ -0,0 +1,275 @@
export default {
definitions: {
options: {
type: 'combo',
multiple: true,
multiLine: true,
items: [
{
type: 'group',
body: [
{
label: '名称',
name: 'label',
type: 'input-text',
required: true
},
{
label: '值',
name: 'value',
type: 'input-text',
required: true
}
]
},
{
$ref: 'options',
label: '子选项',
name: 'children',
addButtonText: '新增子选项'
}
]
},
queryItem: {
type: 'combo',
multiple: true,
multiLine: true,
typeSwitchable: false,
conditions: [
{
label: '条件',
test: "!data.hasOwnProperty('connect')",
scaffold: {},
items: [
{
type: 'group',
className: 'm-b-none',
body: [
{
name: 'key',
type: 'input-text',
placeholder: '字段名',
required: true
},
{
name: 'type',
type: 'select',
value: 0,
options: [
{
label: 'int64',
value: 0
},
{
label: 'double64',
value: 1
},
{
label: 'string',
value: 2
},
{
label: 'version',
value: 3
}
]
},
{
type: 'formula',
name: 'opt',
formula: '""',
condition: '${type}'
},
{
name: 'opt',
type: 'select',
placeholder: '请选择',
required: true,
options: [
{
label: '>',
value: '>',
visibleOn: '~[0,1,3].indexOf(this.type)'
},
{
label: '<',
value: '<',
visibleOn: '~[0,1,3].indexOf(this.type)'
},
{
label: '==',
value: '=='
},
{
label: '>=',
value: '>=',
visibleOn: '~[0,1,3].indexOf(this.type)'
},
{
label: '<=',
value: '<=',
visibleOn: '~[0,1,3].indexOf(this.type)'
},
{
label: 'in',
value: 'in'
},
{
label: 'not in',
value: 'not in'
},
{
label: '!=',
value: '!='
}
]
},
{
name: 'val',
type: 'input-text',
placeholder: '值',
required: true,
visibleOn:
'~[">", "<", ">=", "<=", "==", "!="].indexOf(this.opt)'
},
{
name: 'val',
type: 'array',
required: true,
minLength: 1,
items: {
type: 'input-text',
placeholder: '值',
required: true
},
visibleOn: '~["in", "not in"].indexOf(this.opt)'
}
]
}
]
},
{
label: '组合',
test: "data.hasOwnProperty('connect')",
scaffold: {
connect: '&',
exprs: [{}]
},
items: [
{
type: 'button-group-select',
name: 'connect',
value: '&',
clearable: false,
size: 'xs',
options: [
{
label: 'AND',
value: '&'
},
{
label: 'OR',
value: '|'
}
]
},
{
$ref: 'queryItem',
name: 'exprs',
minLength: 1,
value: [{}]
}
]
}
]
},
queryGroup: {
type: 'combo',
multiple: false,
multiLine: true,
items: [
{
type: 'button-group-select',
name: 'connect',
value: '&',
// label: "连接方式",
// mode: 'inline',
clearable: false,
size: 'sm',
options: [
{
label: 'AND',
value: '&'
},
{
label: 'OR',
value: '|'
}
]
},
{
$ref: 'queryItem',
name: 'exprs',
minLength: 1,
value: [{}]
}
]
}
},
type: 'page',
title: '引用',
body: [
'<p>引用可以用来减少重复的结构定义,<code>最主要的是可以用来实现结构的递归定义</code>。</p>',
{
type: 'form',
api: '/api/mock/saveForm',
mode: 'horizontal',
body: [
{
$ref: 'options',
name: 'options',
value: [
{
label: '选项1',
value: '1'
}
],
minLength: 1,
label: '选项配置'
}
]
},
{
type: 'form',
api: '/api/mock/saveForm',
body: [
{
$ref: 'queryGroup',
name: 'q',
value: {},
label: 'Query'
},
{
type: 'static',
name: 'q',
label: '当前值',
tpl: '<pre>${q|json}</pre>'
}
]
}
]
};

View File

@@ -0,0 +1,46 @@
import React from 'react';
export default {
title: 'Editor',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '',
body: [
{
name: 'javascript',
type: 'editor',
label: 'Javascript',
language: 'javascript',
value: 'console.log(1, 2, 3);'
},
{
name: 'html',
type: 'editor',
language: 'html',
label: 'Html',
value:
'<html><head><title>Hello</title></head><body><p>world</p></body></html>'
},
{
name: 'css',
type: 'editor',
language: 'css',
label: 'CSS',
value: 'body {color: red;}'
},
{
name: 'json',
type: 'editor',
language: 'json',
label: 'JSON',
value: `{"a": 1, "b": 2}`
}
]
}
]
};

View File

@@ -0,0 +1,152 @@
export default {
title: 'FieldSet 示例',
body: [
{
type: 'form',
mode: 'horizontal',
api: '/api/mock2/saveForm?waitSeconds=2',
actions: [
{
type: 'submit',
label: '提交',
primary: true
}
],
collapsable: true,
title: 'fieldSet 可以对表单元素做个分组',
body: [
{
type: 'fieldSet',
title: '基本信息',
collapsable: true,
body: [
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'input-password',
name: 'password',
label: false,
placeholder: 'Password'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'checkbox',
name: 'rememberMe',
label: false,
option: 'Remember me'
}
]
}
]
},
{
title: '其他信息',
type: 'fieldSet',
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'divider'
},
{
type: 'checkbox',
name: 'rememberMe',
option: '记住我'
}
]
}
]
},
{
title: 'FieldSet 样式集',
type: 'form',
body: [
{
title: '超级小',
type: 'fieldSet',
collapsable: true,
size: 'xs',
body: [
{
type: 'plain',
text: '文本 ...'
}
]
},
{
title: '小尺寸',
type: 'fieldSet',
collapsable: true,
size: 'sm',
body: [
{
type: 'plain',
text: '文本 ...'
}
]
},
{
title: '正常尺寸',
type: 'fieldSet',
collapsable: true,
size: 'base',
body: [
{
type: 'plain',
text: '文本 ...'
}
]
},
{
title: '中大尺寸',
type: 'fieldSet',
collapsable: true,
size: 'md',
body: [
{
type: 'plain',
text: '文本 ...'
}
]
},
{
title: '超大尺寸',
type: 'fieldSet',
collapsable: true,
size: 'lg',
body: [
{
type: 'plain',
text: '文本 ...'
}
]
}
]
}
]
};

View File

@@ -0,0 +1,115 @@
export default {
title: 'FieldSet In Tabs',
remark: '',
body: {
type: 'form',
body: [
{
type: 'tabs',
collapsable: true,
tabs: [
{
title: 'Tab A',
body: [
{
type: 'fieldset',
body: [
{
type: 'tabs',
title: 'Group A',
tabs: [
{
title: 'SubTab A',
body: [
{
name: 'a',
type: 'input-text',
label: 'Text'
},
{
name: 'a',
type: 'input-text',
label: 'Text'
}
]
},
{
title: 'SubTab B',
body: [
{
name: 'a',
type: 'input-text',
label: 'Text'
},
{
name: 'a',
type: 'input-text',
label: 'Text'
}
]
}
]
},
{
type: 'tabs',
title: 'Group B',
body: [
{
name: 'a',
type: 'input-text',
label: 'Text'
},
{
name: 'a',
type: 'input-text',
label: 'Text'
}
]
}
]
}
]
},
{
title: 'Tab B',
body: [
{
type: 'fieldset',
title: 'Group A',
body: [
{
name: 'a',
type: 'input-text',
label: 'Text'
},
{
name: 'a',
type: 'input-text',
label: 'Text'
}
]
},
{
type: 'fieldset',
title: 'Group B',
body: [
{
name: 'a',
type: 'input-text',
label: 'Text'
},
{
name: 'a',
type: 'input-text',
label: 'Text'
}
]
}
]
}
]
}
]
}
};

View File

@@ -0,0 +1,126 @@
export default {
title: '公式示例',
body: [
'<p>通过公式,可以动态的设置目标值。</p>',
{
type: 'form',
title: '自动应用',
api: '/api/mock2/form/saveForm',
body: [
{
type: 'input-number',
name: 'a',
label: 'A'
},
{
type: 'input-number',
name: 'b',
label: 'B'
},
{
type: 'input-number',
name: 'sum',
label: '和',
disabled: true,
description: '自动计算 A + B'
},
{
type: 'formula',
name: 'sum',
value: 0,
formula: 'a + b'
}
]
},
{
type: 'form',
title: '手动应用',
api: '/api/mock2/form/saveForm',
body: [
{
type: 'input-number',
name: 'a',
label: 'A'
},
{
type: 'input-number',
name: 'b',
label: 'B'
},
{
type: 'group',
body: [
{
type: 'input-number',
name: 'sum',
label: '和',
disabled: true,
columnClassName: 'col-sm-11'
},
{
type: 'button',
label: '计算',
columnClassName: 'col-sm-1 v-bottom',
target: 'theFormula'
}
]
},
{
type: 'formula',
name: 'sum',
id: 'theFormula',
value: 0,
formula: 'a + b',
initSet: false,
autoSet: false
}
]
},
{
type: 'form',
title: '条件应用',
api: '/api/mock2/form/saveForm',
body: [
{
type: 'radios',
name: 'radios',
inline: true,
label: 'radios',
options: [
{
label: 'a',
value: 'a'
},
{
label: 'b',
value: 'b'
}
],
description: 'radios 变化会自动清空 B'
},
{
type: 'input-text',
name: 'b',
label: 'B'
},
{
type: 'formula',
name: 'b',
value: 'some string',
formula: "''",
condition: '${radios}',
initSet: false
}
]
}
]
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
export default {
title: '其他类型演示',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: 'Hint demo',
mode: 'horizontal',
horizontal: {
leftFixed: true
},
body: [
{
type: 'input-group',
size: 'md',
label: 'Icon 组合',
body: [
{
type: 'icon',
addOnclassName: 'no-bg',
className: 'text-sm',
icon: 'search',
vendor: 'iconfont'
},
{
type: 'input-text',
placeholder: '搜索作业ID/名称',
inputClassName: 'b-l-none p-l-none',
name: 'jobName'
}
]
},
{
name: 'a',
type: 'input-text',
label: 'ID',
value: '',
size: 'xs',
hint: '比如输入 a-xxxx-xxx'
},
{
name: 'b',
type: 'input-text',
label: 'ID',
value: '',
size: 'sm',
hint: '比如输入 a-xxxx-xxx'
},
{
name: 'c',
type: 'input-text',
label: 'ID',
value: '',
size: 'md',
hint: '比如输入 a-xxxx-xxx'
},
{
name: 'd',
type: 'input-text',
label: 'ID',
value: '',
size: 'lg',
hint: '比如输入 a-xxxx-xxx'
},
{
name: 'tag',
type: 'input-tag',
label: 'Tag',
size: 'md',
clearable: true,
placeholder: '多个标签以逗号分隔',
options: ['周小度', '杜小度']
}
]
}
]
};

View File

@@ -0,0 +1,127 @@
export default {
type: 'page',
body: {
type: 'form',
title: 'input-kvs 实现复杂嵌套数据结构',
mode: 'horizontal',
debug: true,
submitText: '',
submitOnChange: false,
body: [
{
type: 'input-kvs',
name: 'dataModel',
addButtonText: '新增数据源权限',
keyItem: {
label: '数据源名',
type: 'select',
options: ['local-mysql', 'remote-postgres', 'cloud-oracle']
},
valueItems: [
{
label: '数据源级别权限',
type: 'checkboxes',
name: 'permissions',
joinValues: false,
extractValue: true,
options: [
{
label: '查询',
value: 'select'
},
{
label: '写入',
value: 'insert'
},
{
label: '更新',
value: 'update'
},
{
label: '删除',
value: 'delete'
}
]
},
{
type: 'input-kvs',
label: '表权限',
addButtonText: '新增表权限',
name: 'dataModel',
keyItem: {
label: '表名',
mode: 'horizontal',
type: 'select',
options: ['table1', 'table2', 'table3']
},
valueItems: [
{
type: 'switch',
name: 'canInsert',
mode: 'horizontal',
label: '是否可写入'
},
{
type: 'switch',
name: 'canDelete',
mode: 'horizontal',
label: '是否可删除'
},
{
type: 'input-kvs',
label: '字段级别权限',
addButtonText: '新增字段权限',
name: 'field',
keyItem: {
label: '字段名',
mode: 'horizontal',
type: 'select',
options: ['id', 'title', 'content']
},
valueIsArray: true,
valueItems: [
{
type: 'checkboxes',
name: '_value',
joinValues: false,
extractValue: true,
options: [
{
label: '查询',
value: 'select'
},
{
label: '写入',
value: 'insert'
},
{
label: '更新',
value: 'update'
},
{
label: '删除',
value: 'delete'
}
]
}
]
},
{
name: 'fieldSelectExp',
label: '字段表达式权限',
type: 'input-array',
value: ['SUM(fieldKey)'],
addButtonText: '新增表达式权限',
inline: true,
items: {
size: 'md',
type: 'input-text'
}
}
]
}
]
}
]
}
};

View File

@@ -0,0 +1,641 @@
export default {
title: '表单各种展示模式汇总',
remark: '展示各种模式的 Form',
body: [
{
type: 'grid',
columns: [
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '常规模式',
mode: 'normal',
body: [
{
type: 'input-email',
name: 'email',
required: true,
placeholder: '请输入邮箱',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password',
label: '密码',
required: true,
placeholder: '请输入密码',
size: 'full'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住登录'
},
{
type: 'submit',
label: '登录'
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '常规模式 input md 尺寸',
mode: 'normal',
body: [
{
type: 'input-email',
name: 'email',
required: true,
placeholder: '请输入邮箱',
label: '邮箱',
size: 'md',
remark: 'xxxx',
hint: 'bla bla bla'
},
{
type: 'input-password',
name: 'password',
label: '密码',
required: true,
placeholder: '请输入密码',
size: 'md'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住登录'
},
{
type: 'submit',
label: '登录'
}
]
}
]
},
{
type: 'grid',
columns: [
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '水平模式,左右摆放 左右比率分配 ',
mode: 'horizontal',
autoFocus: false,
horizontal: {
left: 'col-sm-2',
right: 'col-sm-10',
offset: 'col-sm-offset-2'
},
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱',
required: true,
desc: '表单描述文字'
},
{
type: 'input-password',
name: 'password',
label: '密码',
placeholder: '输入密码'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住登录'
},
{
type: 'control',
body: {
type: 'submit',
label: 'Submit'
}
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '水平模式,左右摆放 左侧固定宽度 input md 尺寸',
mode: 'horizontal',
autoFocus: false,
horizontal: {
leftFixed: 'xs'
},
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱',
required: true,
desc: '表单描述文字',
size: 'md',
remark: 'xxxx',
hint: 'bla bla bla'
},
{
type: 'input-password',
name: 'password',
label: '密码',
placeholder: '输入密码',
size: 'md'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住登录'
},
{
type: 'control',
body: {
type: 'submit',
label: 'Submit'
}
}
]
}
]
},
{
type: 'form',
className: 'm-b',
// debug: true,
body: [
{
type: 'property',
title: '机器配置',
items: [
{
label: 'cpu',
content: {
type: 'select',
name: 'cpu',
value: '1',
options: [
{
label: '1 core',
value: '1'
},
{
label: '4 core',
value: '4'
},
{
label: '8 core',
value: '8'
}
]
}
},
{
label: 'memory',
content: '4G'
},
{
label: 'disk',
content: '80G'
},
{
label: 'network',
content: '4M',
span: 2
},
{
label: 'IDC',
content: 'beijing'
},
{
label: 'Note',
content: {
type: 'textarea',
required: true,
name: 'note',
placeholder: 'Enter...'
},
span: 3
}
]
}
],
actions: [
{
type: 'submit',
label: 'Submit'
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '内联模式',
mode: 'inline',
autoFocus: false,
body: [
{
type: 'input-email',
name: 'email',
placeholder: 'Enter Email',
label: '邮箱'
},
{
type: 'input-password',
name: 'password',
placeholder: '密码',
remark: 'Bla bla bla'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住登录'
},
{
type: 'submit',
label: '登录'
},
{
type: 'button',
label: '导出',
url: 'http://www.baidu.com/',
level: 'success'
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '常规模式下用数组包起来还能控制一行显示多个',
mode: 'normal',
autoFocus: false,
body: [
{
type: 'input-text',
name: 'name',
placeholder: '请输入...',
label: '名字',
size: 'full'
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: '输入邮箱',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password',
label: '密码',
placeholder: '请输入密码',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email2',
mode: 'inline',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password2',
label: '密码',
mode: 'inline',
placeholder: '请输入密码',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email3',
mode: 'inline',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full',
columnClassName: 'v-bottom'
},
{
type: 'input-password',
name: 'password3',
label: '密码',
placeholder: '请输入密码',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email4',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password4',
label: '密码',
placeholder: '请输入密码',
mode: 'inline',
size: 'full',
columnClassName: 'v-bottom'
}
]
},
{
type: 'divider'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住我'
},
{
type: 'submit',
label: '提交'
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '水平模式用数组包起来也能控制一行显示多个',
mode: 'horizontal',
autoFocus: false,
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full'
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email2',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password2',
label: '密码',
placeholder: '请输入密码',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email3',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password3',
label: '密码',
placeholder: '请输入密码',
size: 'full'
},
{
type: 'input-password',
name: 'password3',
label: '密码',
placeholder: '请输入密码',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email4',
placeholder: '请输入邮箱地址',
label: '邮箱',
size: 'full',
columnClassName: 'col-sm-6',
horizontal: {
left: 'col-sm-4',
right: 'col-sm-8'
}
},
{
type: 'input-password',
name: 'password4',
label: '密码',
placeholder: '请输入密码',
mode: 'inline',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
label: '邮箱',
gap: 'xs',
body: [
{
label: false,
type: 'input-email',
name: 'email5',
placeholder: '请输入邮箱地址',
size: 'full'
},
{
type: 'input-password',
name: 'password5',
label: '密码',
placeholder: '请输入密码',
mode: 'inline',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
label: '邮箱',
description: 'bla bla',
gap: 'xs',
body: [
{
type: 'input-email',
name: 'email6',
placeholder: '请输入邮箱地址',
mode: 'inline'
},
{
type: 'input-password',
name: 'password6',
// label: "密码",
placeholder: '请输入密码',
labelClassName: 'w-auto p-r-none',
mode: 'inline'
}
]
},
{
type: 'divider'
},
{
type: 'group',
label: '邮箱',
description: 'bla bla',
direction: 'vertical',
body: [
{
type: 'input-email',
name: 'email9',
mode: 'normal',
placeholder: '请输入邮箱地址',
inline: true,
description: 'Bla blamfejkf fdjk'
},
{
type: 'input-password',
name: 'password9',
mode: 'normal',
placeholder: '请输入密码',
labelClassName: 'w-auto p-r-none'
}
]
},
{
type: 'divider'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住我'
},
{
type: 'submit',
label: 'Submit'
}
]
},
{
type: 'form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: 'Inline form 用数组包起来还能控制一行显示多个',
mode: 'inline',
submitText: null,
autoFocus: false,
body: [
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: 'Enter Email',
label: '邮箱',
size: 'full'
},
{
type: 'input-password',
name: 'password',
placeholder: 'Password',
size: 'full'
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: 'Enter Email',
label: '邮箱',
size: 'full'
},
{
type: 'checkbox',
name: 'rememberMe',
label: '记住我',
size: 'full'
},
{
type: 'button-toolbar',
buttons: [
{
type: 'submit',
label: '登录'
},
{
type: 'button',
label: '导出',
url: 'http://www.baidu.com/',
level: 'success'
}
]
}
]
}
]
}
]
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
export default {
title: '显隐切换示例',
body: [
{
name: 'hiddenOn',
type: 'form',
mode: 'horizontal',
api: '/api/mock2/saveForm?waitSeconds=2',
title: 'Hide On 和 disabledOn 示例',
body: [
{
type: 'radios',
name: 'type',
label: '类型选择',
inline: true,
value: '1',
options: [
{
label: '类型 1',
value: '1'
},
{
label: '类型 2',
value: '2'
},
{
label: '类型 3',
value: '3'
}
],
description: '<span class="text-danger">请切换类型来看效果</span>'
},
{
type: 'input-text',
label: '所有可见',
name: 'text1'
},
{
type: 'input-text',
label: '类型2 可见',
hiddenOn: 'data.type != 2',
name: 'text2'
},
{
type: 'input-text',
label: '类型3 不可点',
disabledOn: 'data.type == 3',
name: 'text3'
},
{
type: 'input-text',
required: true,
label: '必填字段',
name: 'test4'
},
{
type: 'button-toolbar',
buttons: [
{
type: 'submit',
disabledOn: 'data.type == 1',
label: '类型1不可点'
},
{
type: 'reset',
label: '类型3出现且不可点',
visibleOn: 'data.type == 3',
disabledOn: 'data.type == 3'
},
{
type: 'button',
label: 'Baidu',
actionType: 'url',
url: 'http://www.baidu.com?a=1&b=$test4'
},
{
type: 'button',
actionType: 'ajax',
label: 'No Submit',
api: '/api/mock2/saveForm?waitSeconds=5'
},
{
type: 'submit',
actionType: 'ajax',
label: 'Submit',
api: '/api/mock2/saveForm?waitSeconds=5'
}
]
}
]
}
]
};

View File

@@ -0,0 +1,133 @@
export default {
title: '动态拉取选项',
name: 'page-form-remote',
body: [
{
type: 'form',
title: '动态表单元素示例',
name: 'demo-form',
api: '/api/mock2/form/saveForm?waitSeconds=2',
mode: 'horizontal',
actions: [
{
type: 'submit',
label: '提交'
}
],
body: [
{
name: 'select',
type: 'select',
label: '动态选项',
source: '/api/mock2/form/getOptions?waitSeconds=1',
description: '通过接口一口气拉取选项',
clearable: true,
searchable: true
},
{
type: 'divider'
},
{
name: 'select2',
type: 'select',
label: '选项自动补全',
autoComplete: '/api/mock2/options/autoComplete?term=$term',
placeholder: '请输入',
description: '通过接口自动补全'
},
{
type: 'divider'
},
{
type: 'input-text',
name: 'text',
label: '文本提示',
source: '/api/mock2/form/getOptions?waitSeconds=1',
placeholder: '请选择',
creatable: true
},
{
type: 'divider'
},
{
name: 'text2',
type: 'input-text',
label: '文本自动补全',
clearable: true,
autoComplete: '/api/mock2/options/autoComplete2?term=$term',
description: '通过接口自动补全'
},
{
name: 'chained',
type: 'chained-select',
label: '级联选项',
source:
'/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4&waiSeconds=1',
desc: '无限级别, 只要 api 返回数据就能继续往下选择. 当没有下级时请返回 null.',
value: 'a,b'
},
{
type: 'divider'
},
{
name: 'tree',
showOutline: true,
type: 'input-tree',
label: '动态树',
source: '/api/mock2/options/tree?waitSeconds=1'
},
{
type: 'divider'
},
{
name: 'tree',
type: 'input-tree',
label: '树懒加载',
multiple: true,
deferApi: '/api/mock2/form/deferOptions?label=${label}&waitSeconds=2',
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
defer: true
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
type: 'divider'
},
{
name: 'matrix',
type: 'matrix-checkboxes',
label: '动态矩阵开关',
source: '/api/mock2/options/matrix?waitSeconds=1'
}
]
}
]
};

View File

@@ -0,0 +1,20 @@
import React from 'react';
export default {
title: '富文本编辑器',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: 'Form elements',
body: [
{
name: 'html',
type: 'input-rich-text',
label: '富文本',
value: '<p>Just do <code>IT</code></p>'
}
]
}
]
};

View File

@@ -0,0 +1,159 @@
import React from 'react';
import {TitleBar} from 'amis-ui';
import {render} from 'amis';
const Schema = {
title: 'Person',
type: 'object',
properties: {
firstName: {
title: 'First Name',
type: 'string'
},
lastName: {
type: 'string'
},
age: {
description: 'Age in years',
type: 'integer',
minimum: 0
},
tag: {
type: 'array',
description: 'Tags',
default: ['IT'],
items: {
type: 'text'
}
},
clients: {
type: 'array',
description: 'Tags',
items: {
type: 'object',
properties: {
firstName: {
title: 'First Name',
type: 'string'
},
lastName: {
type: 'string'
}
}
}
}
},
required: ['firstName', 'lastName']
};
function property2control(property, key, schema) {
const requiredList = schema.required || [];
const rest = {};
const validations = {};
let type = 'text';
if (property.type === 'integer') {
type = 'number';
typeof property.minimum === 'number' && (rest.min = property.minimum);
// property.max
} else if (property.type === 'array') {
type = 'combo';
const items = property.items;
if (items.type === 'object') {
rest.controls = makeControls(items.properties, items);
rest.multiLine = true;
} else {
type = 'array';
rest.inline = true;
rest.items = property2control(items, 'item', property);
}
}
if (typeof property.minimum === 'number') {
validations.minimum = property.minimum;
}
return {
name: key,
type,
required: !!~requiredList.indexOf(key),
label: property.title || property.description,
desc: property.title && property.description,
value: property.default,
validations,
...rest
};
}
function makeControls(properties, schema) {
const keys = Object.keys(properties);
return keys.map(key => property2control(properties[key], key, schema));
}
function JSONSchme2AMisSchema(schema) {
if (schema.type !== 'object') {
throw new Error('JSONSchme2AMisSchema 只支持 object 转换');
}
return {
title: schema.title,
type: 'form',
mode: 'horizontal',
controls: makeControls(schema.properties, schema)
};
}
const amisFormSchema = JSONSchme2AMisSchema(Schema);
export default class JSONSchemaForm extends React.Component {
state = {
data: {}
};
renderForm() {
return render({
type: 'page',
title: '',
body: {
...amisFormSchema,
onChange: values =>
this.setState({
data: {
...values
}
})
}
});
}
render() {
return (
<div>
<TitleBar title="JSON Schema Form" />
<div className="wrapper">
<div>
<h3>Schema</h3>
<pre>
<code>{JSON.stringify(Schema, null, 2)}</code>
</pre>
</div>
<div>
<h3>Form</h3>
{this.renderForm()}
</div>
<div>
<h3>Data</h3>
<pre>
<code>{JSON.stringify(this.state.data, null, 2)}</code>
</pre>
</div>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,189 @@
export default {
title: '所有 Form 元素列举',
data: {
id: 1,
image: __uri('../../static/photo/3893101144.jpg'),
images: [
{
image: __uri('../../static/photo/4f3cb4202335.jpg'),
src: __uri('../../static/photo/4f3cb4202335.jpg')
},
{
image: __uri('../../static/photo/d8e4992057f9.jpg'),
src: __uri('../../static/photo/d8e4992057f9.jpg')
},
{
image: __uri('../../static/photo/1314a2a3d3f6.jpg'),
src: __uri('../../static/photo/1314a2a3d3f6.jpg')
},
{
image: __uri('../../static/photo/8f2e79f82be0.jpg'),
src: __uri('../../static/photo/8f2e79f82be0.jpg')
},
{
image: __uri('../../static/photo/552b175ef11d.jpg'),
src: __uri('../../static/photo/552b175ef11d.jpg')
}
]
},
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: '表单项静态展示',
mode: 'horizontal',
body: [
{
type: 'static',
label: '文本',
value: '文本'
},
{
type: 'divider'
},
{
type: 'static',
label: '模板',
tpl: '自己拼接 HTML 取变量 \\${id}: ${id}'
},
{
type: 'divider'
},
{
type: 'static-date',
label: '日期',
value: Math.round(Date.now() / 1000)
},
{
type: 'divider'
},
{
type: 'static-datetime',
label: '日期时间',
value: Math.round(Date.now() / 1000)
},
{
type: 'divider'
},
{
type: 'control',
label: '映射',
body: {
type: 'mapping',
value: Math.floor(Math.random() * 5),
map: {
'*': "<span class='label label-default'>-</span>",
'0': "<span class='label label-info'>一</span>",
'1': "<span class='label label-success'>二</span>",
'2': "<span class='label label-danger'>三</span>",
'3': "<span class='label label-warning'>四</span>",
'4': "<span class='label label-primary'>五</span>"
}
}
},
{
type: 'divider'
},
{
type: 'control',
label: '进度',
body: {
type: 'progress',
value: 66.66
}
},
{
type: 'divider'
},
{
type: 'static-image',
label: '图片',
name: 'image',
thumbMode: 'cover',
thumbRatio: '4:3',
title: '233',
imageCaption: 'jfe fjkda fejfkda fejk fdajf dajfe jfkda',
popOver: {
title: '查看大图',
body: '<div class="w-xxl"><img class="w-full" src="${image}"/></div>'
}
},
{
type: 'divider'
},
{
type: 'static-image',
label: '图片自带放大',
name: 'image',
thumbMode: 'cover',
thumbRatio: '4:3',
title: '233',
imageCaption: 'jfe fjkda fejfkda fejk fdajf dajfe jfkda',
enlargeAble: true,
showToolbar: true,
originalSrc: '${image}'
},
{
type: 'static-images',
label: '图片集',
name: 'images',
thumbMode: 'cover',
thumbRatio: '4:3',
enlargeAble: true,
showToolbar: true,
originalSrc: '${src}' // 注意这个取变量是想对数组成员取的。
},
{
type: 'divider'
},
{
type: 'static-json',
label: 'JSON',
value: {a: 1, b: 2, c: {d: 3}}
},
{
type: 'divider'
},
{
type: 'static',
label: '可复制',
value: '文本',
copyable: {
content: '内容,支持变量 ${id}'
}
},
{
type: 'divider'
},
{
type: 'static',
name: 'text',
label: '可快速编辑',
value: '文本',
quickEdit: true
}
]
}
]
};

View File

@@ -0,0 +1,274 @@
/**
* @file 基于 amis 实现简单样式编辑
*/
// 此文件是基于 https://github.com/ChromeDevTools/devtools-frontend/blob/master/third_party/blink/renderer/core/css/css_properties.json5 编译出来的
const cssProperties = __inline('./css_properties.json');
const propertiesOptions = [];
const valueTypeControls = [];
let valueControls = [];
cssProperties.data.sort((a, b) => {
return a.name.localeCompare(b.name);
});
for (const property of cssProperties.data) {
if (property.svg || property.name.startsWith('-')) {
// 忽略 svg 相关或古老的 -webkit 属性
continue;
}
propertiesOptions.push(property.name);
let valueTypeOptions = property.typedom_types || [];
// 原来的定义中并没有这个类型
if (property.type_name === 'StyleColor') {
valueTypeOptions.push('Color');
valueTypeOptions.push('ColorRGBA');
}
valueTypeOptions.sort();
// 有些属性是中有 keyword 类型但没 keywords 列表,比如 scroll-margin-left,这时要去掉这个类型
if (!property.keywords) {
valueTypeOptions = valueTypeOptions.filter(function (item) {
return item !== 'Keyword';
});
}
if (valueTypeOptions.length > 0) {
valueTypeControls.push({
name: 'valueType',
label: '值类型',
visibleOn: `data.property === "${property.name}"`,
type: 'select',
value: valueTypeOptions[0],
options: valueTypeOptions
});
}
if (property.keywords) {
const keywords = property.keywords;
keywords.sort();
valueControls.push({
name: 'value',
visibleOn: `data.property === "${property.name}" && data.valueType === "Keyword"`,
label: '值',
type: 'select',
options: keywords
});
}
}
valueControls = valueControls.concat([
{
name: 'value',
visibleOn: `data.valueType === "Color"`,
label: '值',
type: 'input-color'
},
{
name: 'value',
format: 'rgba',
visibleOn: `data.valueType === "ColorRGBA"`,
label: '值',
type: 'input-color'
},
{
name: 'value',
visibleOn: `data.valueType === "Number"`,
label: '值',
type: 'input-number'
},
{
type: 'input-group',
label: '值',
visibleOn: `data.valueType === "Length"`,
body: [
{
name: 'value',
label: '值',
type: 'input-number'
},
{
type: 'select',
name: 'valueUnit',
// https://www.w3.org/TR/css3-values/#lengths
options: [
'em',
'ex',
'ch',
'rem',
'vm',
'vh',
'vmin',
'vmax',
'cm',
'mm',
'Q',
'in',
'pt',
'pc',
'px'
],
value: 'px'
}
]
},
{
name: 'value',
visibleOn: `data.valueType === "Percentage"`,
label: '值',
type: 'input-text',
addOn: {
type: 'static',
label: '%'
}
},
{
name: 'value',
visibleOn: `data.valueType === "Angle"`,
label: '值',
type: 'input-group',
body: [
{
name: 'value',
label: '值',
type: 'input-number'
},
{
type: 'select',
name: 'valueUnit',
// https://www.w3.org/TR/css3-values/#angles
options: ['deg', 'grad', 'rad', 'turn'],
value: 'px'
}
]
},
{
name: 'value',
visibleOn: `data.valueType === "Time"`,
label: '值',
type: 'input-group',
body: [
{
name: 'value',
label: '值',
type: 'input-number'
},
{
type: 'select',
name: 'valueUnit',
// https://www.w3.org/TR/css3-values/#time
options: ['s', 'ms'],
value: 's'
}
]
},
{
name: 'value',
visibleOn: `data.valueType === "Frequency"`,
label: '值',
type: 'input-group',
body: [
{
name: 'value',
label: '值',
type: 'input-number'
},
{
type: 'select',
name: 'valueUnit',
// https://www.w3.org/TR/css3-values/#frequency
options: ['Hz', 'kHz'],
value: 'Hz'
}
]
},
{
name: 'value',
visibleOn: `data.valueType === "Frequency"`,
label: '值',
type: 'input-group',
body: [
{
name: 'value',
label: '值',
type: 'input-number'
},
{
type: 'select',
name: 'valueUnit',
// https://www.w3.org/TR/css3-values/#resolution
options: ['dpi', 'dpcm', 'dppx'],
value: 'dpi'
}
]
},
{
name: 'value',
visibleOn: `data.valueType === "Position"`,
label: '值',
type: 'input-tag',
// https://www.w3.org/TR/css3-values/#position
options: ['top', 'left', 'bottom', 'right', 'center']
},
// 这些类型支持起来好麻烦,先不弄
{
name: 'value',
visibleOn: `!data.valueType || data.valueType === "Flex" || data.valueType === "Transform" || data.valueType === "Unparsed"|| data.valueType === "Image"`,
label: '值',
type: 'input-text'
}
]);
export default {
title: '样式编辑',
data: {
style: [
{property: 'display', valueType: 'Keyword', value: 'inline'},
{property: 'color', valueType: 'Color', value: '#5240a5'},
{property: 'width', valueType: 'Percentage', value: '30'},
{
property: 'object-position',
valueType: 'Position',
value: ['left', '50%']
}
]
},
body: [
{
type: 'form',
api: '/api/mock2/saveForm',
title: '',
body: [
{
type: 'static',
value:
'演示基于 combo 及显隐联动来实现简易样式编辑,同时用来测试性能。'
},
{
type: 'combo',
name: 'style',
label: '样式列表',
multiple: true,
items: [
{
name: 'property',
label: '属性',
type: 'select',
searchable: true,
unique: true,
options: propertiesOptions
},
...valueTypeControls,
...valueControls
]
}
]
}
]
};

View File

@@ -0,0 +1,59 @@
export default {
title: 'SubForm 示例',
body: [
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
title: 'Form elements',
mode: 'horizontal',
// debug: true,
body: [
{
type: 'input-sub-form',
label: '子表单单条',
name: 'subForm1',
btnLabel: '点击设置${a}',
form: {
title: '子表单',
body: [
{
name: 'a',
type: 'input-text',
label: 'Foo'
},
{
name: 'b',
type: 'switch',
label: 'Boo'
}
]
}
},
{
type: 'input-sub-form',
label: '子表单多条',
name: 'subForm2',
labelField: 'a',
btnLabel: '点击设置',
multiple: true,
form: {
title: '子表单',
body: [
{
name: 'a',
type: 'input-text',
label: 'Foo'
},
{
name: 'b',
type: 'switch',
label: 'Boo'
}
]
}
}
]
}
]
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,214 @@
export default {
title: '表格编辑',
body: {
type: 'form',
mode: 'horizontal',
api: '/api/mock2/form/saveForm?waitSeconds=2',
actions: [
{
type: 'submit',
label: '提交',
primary: true
}
],
body: [
{
type: 'input-table',
name: 'tableAffixHeader',
label: '头部固定',
affixHeader: true,
columns: [
{
name: 'aa',
label: 'AA',
type: 'input-text'
},
{
name: 'cc',
label: 'CC',
type: 'select',
options: [
{
label: 'AA',
value: 'aa'
},
{
label: 'CC',
value: 'cc'
}
]
}
]
},
{
type: 'combo',
name: 'colors',
label: 'Combo',
multiple: true,
draggable: true,
multiLine: true,
value: [
{
color: 'green',
name: '颜色'
}
],
items: [
{
type: 'input-color',
name: 'color',
clearable: false
},
{
type: 'input-text',
name: 'name',
placeholder: '说明文字'
}
]
},
{
type: 'static',
label: '当前值',
tpl: '<pre>${colors|json}</pre>'
},
{
type: 'input-table',
name: 'colors',
label: 'Table',
draggable: true,
addable: true,
removable: true,
needConfirm: false,
columns: [
{
label: 'Color',
name: 'color',
type: 'input-color',
quickEdit: false
},
{
label: '说明文字',
name: 'name'
}
]
},
{
type: 'control',
body: {
type: 'button',
label: 'Table2新增一行',
target: 'table2',
actionType: 'add'
}
},
{
type: 'input-table',
name: 'table2',
label: 'Table2',
editable: true,
addable: true,
removable: true,
draggable: true,
columns: [
{
name: 'a',
label: 'A'
},
{
name: 'b',
label: 'B',
quickEdit: {
type: 'select',
options: [
{
label: 'A',
value: 'a'
},
{
label: 'B',
value: 'b'
}
]
}
}
]
},
{
type: 'input-table',
name: 'table3',
label: 'Table3(指定第2列只有update时能编辑)',
editable: true,
addable: true,
removable: true,
draggable: true,
columns: [
{
name: 'a',
label: 'A',
quickEdit: true
},
{
name: 'b',
label: 'B',
quickEdit: false,
quickEditOnUpdate: {
type: 'select',
options: [
{
label: 'A',
value: 'a'
},
{
label: 'B',
value: 'b'
}
]
}
}
]
},
{
type: 'input-table',
name: 'table5',
label: '内容自适应',
autoFillHeight: true,
tableContentClassName: 'max-h-60',
columns: [
{
name: 'aa',
label: 'AA',
type: 'input-text'
},
{
name: 'cc',
label: 'CC',
type: 'select',
options: [
{
label: 'AA',
value: 'aa'
},
{
label: 'CC',
value: 'cc'
}
]
}
]
}
],
data: {
table5: Array.from({length: 20}, (_, index) => ({
aa: index % 2 == 0 ? 'hello' : 'hi',
cc: index % 2 == 0 ? 'aa' : 'cc'
})),
tableAffixHeader: Array.from({length: 5}, (_, index) => ({
aa: index % 2 == 0 ? 'hello' : 'hi',
cc: index % 2 == 0 ? 'aa' : 'cc'
}))
}
}
};

View File

@@ -0,0 +1,202 @@
export default {
title: 'Tabs 示例',
body: [
{
type: 'form',
mode: 'horizontal',
api: '/api/mock2/form/saveForm?waitSeconds=2',
title: '',
actions: [
{
type: 'button',
actionType: 'dialog',
label: '弹框中的 Tabs',
level: 'info',
dialog: {
title: '',
// size: "md",
body: {
type: 'form',
mode: 'horizontal',
horizontal: {
leftFixed: 'xs'
},
api: '/api/mock2/form/saveForm?waitSeconds=2',
actions: [
{
type: 'submit',
label: '提交',
primary: true
}
],
body: [
{
type: 'tabs',
tabs: [
{
title: '基本信息',
body: [
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email1',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'input-password',
name: 'password',
placeholder: '密码',
label: false
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email2',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'checkbox',
name: 'rememberMe',
label: false,
option: '记住我'
}
]
}
]
},
{
title: '其他信息',
body: [
{
type: 'input-email',
name: 'email3',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'divider'
},
{
type: 'checkbox',
name: 'rememberMe2',
option: '记住我'
}
]
}
]
}
]
}
}
},
{
type: 'submit',
label: '提交',
primary: true
}
],
body: [
{
type: 'tabs',
name: 'outertabs',
className: 'm-b',
tabs: [
{
title: '基本信息',
hash: 'tab1',
body: [
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'input-password',
name: 'password',
placeholder: '密码',
label: false
}
]
},
{
type: 'divider'
},
{
type: 'group',
body: [
{
type: 'input-email',
name: 'email2',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'checkbox',
name: 'rememberMe',
label: false,
option: '记住我'
}
]
}
]
},
{
title: '其他信息',
hash: 'tab2',
body: [
{
type: 'input-email',
name: 'email3',
placeholder: '请输入邮箱地址',
label: '邮箱'
},
{
type: 'divider'
},
{
type: 'checkbox',
name: 'rememberMe4',
label: '记住我'
}
]
}
]
},
{
type: 'radios',
name: 'outertabs',
label: 'Tabs值',
mode: 'normal',
description:
'如果 tabs 设置了 name 是可以跟表单值联动的,默认并不会开启此功能。',
options: [
{
label: '基本信息',
value: '基本信息'
},
{
label: '其他信息',
value: '其他信息'
}
]
}
]
}
]
};

View File

@@ -0,0 +1,132 @@
export default {
type: 'page',
body: {
type: 'form',
title: '详情',
name: 'scene_detail',
mode: 'horizontal',
submitText: '',
submitOnChange: false,
actions: [
{
type: 'button',
label: '修改',
actionType: 'drawer',
drawer: {
type: 'form',
position: 'left',
title: '修改内容',
body: [
{
type: 'input-text',
label: '标题',
name: 'name',
required: true
},
{
label: '描述',
type: 'input-text',
name: 'typeDesc',
required: true
},
{
label: '内容',
type: 'textarea',
name: 'contents',
required: true
}
]
}
}
],
body: [
{
type: 'input-tree',
name: 'tree',
label: '树',
options: [
{
label: 'Folder A',
value: 1,
children: [
{
label: 'file A',
value: 2
},
{
label: 'file B',
value: 3
}
]
},
{
label: 'file C',
value: 4
},
{
label: 'file D',
value: 5
}
]
},
{
type: 'divider'
},
{
type: 'tree',
name: 'trees',
label: '树多选',
multiple: true,
options: [
{
label: 'Folder A',
value: 1,
children: [
{
label: 'file A',
value: 2
},
{
label: 'file B',
value: 3
}
]
},
{
label: 'file C',
value: 4
},
{
label: 'file D',
value: 5
}
]
},
{
type: 'divider'
},
{
name: 'select',
type: 'tree-select',
label: '动态选项',
source: '/api/mock2/form/getTreeOptions?waitSeconds=1',
description: '通过接口一口气拉取选项',
clearable: true,
searchable: true
},
{
type: 'divider'
},
{
name: 'select2',
type: 'tree-select',
label: '选项自动补全',
autoComplete: '/api/mock2/tree/autoComplete?term=$term',
placeholder: '请输入',
description: '通过接口自动补全',
multiple: true
}
]
}
};

View File

@@ -0,0 +1,535 @@
export default {
title: 'Transfer 穿梭器 示例',
body: [
{
type: 'form',
title: '',
mode: 'horizontal',
actions: [
{
type: 'submit',
label: '提交'
}
],
body: [
{
label: '默认',
type: 'transfer',
name: 'transfer1',
// showArrow: true,
options: [
{
label: '诸葛亮',
value: 'zhugeliang'
},
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
},
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
},
{
label: '分组',
type: 'transfer',
name: 'transfer2',
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '表格形式',
type: 'transfer',
name: 'transfer3',
selectMode: 'table',
columns: [
{
name: 'label',
label: '英雄'
},
{
name: 'position',
label: '位置'
}
],
options: [
{
label: '诸葛亮',
value: 'zhugeliang',
position: '中单'
},
{
label: '曹操',
value: 'caocao',
position: '上单'
},
{
label: '钟无艳',
value: 'zhongwuyan',
position: '上单'
},
{
label: '李白',
value: 'libai',
position: '打野'
},
{
label: '韩信',
value: 'hanxin',
position: '打野'
},
{
label: '云中君',
value: 'yunzhongjun',
position: '打野'
}
]
},
{
label: '树型展示',
type: 'transfer',
name: 'transfer4',
selectMode: 'tree',
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '级联选择',
type: 'transfer',
name: 'transfer5',
selectMode: 'chained',
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '带搜索',
type: 'transfer',
name: 'transfer6',
selectMode: 'chained',
searchable: true,
sortable: true,
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '组合穿梭器',
type: 'tabs-transfer',
name: 'a',
sortable: true,
selectMode: 'tree',
searchable: true,
options: [
{
label: '成员',
selectMode: 'tree',
children: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '用户',
selectMode: 'chained',
children: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
}
]
},
{
label: '延时加载',
type: 'transfer',
name: 'transfer7',
selectMode: 'tree',
deferApi: '/api/mock2/form/deferOptions?label=${label}',
options: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
defer: true
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
label: '关联选择模式',
type: 'transfer',
name: 'b',
sortable: true,
searchable: true,
deferApi: '/api/mock2/form/deferOptions?label=${label}',
selectMode: 'associated',
leftMode: 'tree',
leftOptions: [
{
label: '法师',
children: [
{
label: '诸葛亮',
value: 'zhugeliang'
}
]
},
{
label: '战士',
children: [
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
}
]
},
{
label: '打野',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
],
options: [
{
ref: 'zhugeliang',
children: [
{
label: 'A',
value: 'a'
}
]
},
{
ref: 'caocao',
children: [
{
label: 'B',
value: 'b'
},
{
label: 'C',
value: 'c'
}
]
},
{
ref: 'zhongwuyan',
children: [
{
label: 'D',
value: 'd'
},
{
label: 'E',
value: 'e'
}
]
},
{
ref: 'libai',
defer: true
},
{
ref: 'hanxin',
defer: true
},
{
ref: 'yunzhongjun',
defer: true
}
]
}
]
}
]
};

View File

@@ -0,0 +1,72 @@
const renderOptions = (n, callback) => {
return [...new Array(n)].map((item, index) => callback(index));
};
const options = renderOptions(1000, index => {
const value = `${10000 + index * 3}`;
return {
value: value,
label: value,
children:
index % 10 === 0
? renderOptions(20, i => {
return {
value: `value-${value}-${i}`,
label: `label-${value}-${i}`
};
})
: undefined
};
});
export default {
type: 'form',
debug: true,
body: [
{
// type: 'input-tree',
type: 'tree-select',
// "type": "nested-select",
name: 'output_fields',
label: '输出字段',
description:
'输出字段中的制表符会转换为"\\t",换行符会转换为"\
"',
mode: 'horizontal',
multiple: true,
required: true,
clearable: true,
withChildren: true,
extractValue: true,
joinValues: true,
cascade: true,
borderMode: 'full',
searchable: true,
options: options,
initiallyOpen: false,
draggable: true
},
{
label: '选项',
type: 'input-tree',
name: 'input-tree',
searchable: true,
multiple: true,
menuTpl: '<div>${label} 值:${value}, 当前是否选中: ${checked}</div>',
options: options
},
{
label: '选项',
type: 'input-tree',
name: 'radio',
options: options.map(item =>
item.children ? {...item, disabled: true} : item
),
joinValues: false,
extractValues: false,
enableNodePath: true,
pathSeparator: '.'
}
]
};

View File

@@ -0,0 +1,402 @@
export default {
title: '表单验证示例',
toolbar: "<a target='_blank' href='/docs/renderers/Form/FormItem'>文档</a>",
body: [
{
type: 'grid',
columns: [
{
body: [
{
type: 'form',
autoFocus: false,
messages: {
validateFailed: '请仔细检查表单规则,部分表单项没通过验证'
},
title: '表单',
actions: [
{
type: 'submit',
label: '提交'
}
],
api: '/api/mock2/form/saveFormFailed?waitSeconds=2',
mode: 'horizontal',
body: [
{
type: 'input-text',
name: 'test',
label: '必填',
required: true
},
{
type: 'divider'
},
{
name: 'test1',
type: 'input-email',
label: 'Email'
},
{
type: 'divider'
},
{
name: 'url',
type: 'input-url',
label: 'URL'
},
{
type: 'divider'
},
{
name: 'num',
type: 'input-text',
label: '数字',
validations: 'isNumeric'
},
{
type: 'divider'
},
{
name: 'alpha',
type: 'input-text',
label: '字母或数字',
validations: 'isAlphanumeric'
},
{
type: 'divider'
},
{
name: 'int',
type: 'input-text',
label: '整形',
validations: 'isInt'
},
{
type: 'divider'
},
{
name: 'minLength',
type: 'input-text',
label: '长度限制',
validations: 'minLength:2,maxLength:10'
},
{
type: 'divider'
},
{
name: 'min',
type: 'input-text',
label: '数值限制',
validations: 'maximum:10,minimum:2'
},
{
type: 'divider'
},
{
name: 'reg',
type: 'input-text',
label: '正则',
validations: 'matchRegexp:/^abc/',
validationErrors: {
matchRegexp: '请输入abc开头的好么?'
}
},
{
type: 'divider'
},
{
name: 'test2',
type: 'input-text',
label: '服务端验证'
}
]
}
]
},
{
body: [
{
type: 'form',
name: 'form2',
api: '/api/mock2/form/saveForm',
debug: true,
debugConfig: {
levelExpand: 3
},
title: '<b>日期时间相关校验规则</b>',
data: {
datetime1: '2022-09-10 00:00:00',
datetime2: '2022-10-01 00:00:00',
datetime3: '2022-10-01 00:00:00',
datetime4: '2022-10-01 00:00:01',
datetime5: '2022-09-30 23:59:59',
datetime6: '2022-09-30 23:59:59'
},
body: [
{
type: 'input-datetime',
label: 'isDateTimeSame',
name: 'datetime1',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeSame: '2022-10-01 00:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-datetime',
label: 'isDateTimeBefore',
name: 'datetime2',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeBefore: '2022-10-01 00:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-datetime',
label: 'isDateTimeAfter',
name: 'datetime3',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeAfter: '2022-10-01 00:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-datetime',
label: 'isDateTimeSameOrBefore',
name: 'datetime4',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeSameOrBefore: '2022-10-01 00:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-datetime',
label: 'isDateTimeSameOrAfter',
name: 'datetime5',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeSameOrAfter: '2022-10-01 00:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-datetime',
label: 'isDateTimeBetween',
name: 'datetime6',
format: 'YYYY-MM-DD HH:mm:ss',
validations: {
isDateTimeBetween: [
'2022-10-01 00:00:00',
'2022-10-03 00:00:00',
'second',
'[]'
]
},
validationErrors: {
isDateTimeBetween:
'选择的日期有误,日期必须在 $1 ~ $2 范围内'
}
}
]
},
{
type: 'form',
name: 'form3',
api: '/api/mock2/form/saveForm',
debug: true,
debugConfig: {
levelExpand: 3
},
title: '<b>日期时间相关校验规则(带变量)</b>',
body: [
{
type: 'input-datetime',
label: '开始日期时间',
name: 'startTime',
inputFormat: 'YYYY-MM-DD HH:mm:ss',
format: 'YYYY-MM-DD HH:mm:ss',
required: true,
validations: {
isDateTimeSameOrBefore: '${endTime}'
},
validationErrors: {
isDateTimeSameOrBefore:
'当前日期值不合法,开始时间不能大于结束时间'
}
},
{
type: 'input-datetime',
label: '结束日期时间',
name: 'endTime',
inputFormat: 'YYYY-MM-DD HH:mm:ss',
format: 'YYYY-MM-DD HH:mm:ss',
required: true
}
]
}
]
},
{
body: [
{
type: 'form',
name: 'form4',
api: '/api/mock2/form/saveForm',
debug: true,
debugConfig: {
levelExpand: 3
},
title: '<b>时间相关校验规则</b>',
data: {
time1: '16:00:00',
time2: '16:00:00',
time3: '16:00:00',
time4: '16:00:01',
time5: '16:00:01',
time6: '15:00:01'
},
body: [
{
type: 'input-time',
label: 'isTimeSame',
name: 'time1',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeSame: '16:00:01'
}
},
{
type: 'divider'
},
{
type: 'input-time',
label: 'isTimeBefore',
name: 'time2',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeBefore: '15:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-time',
label: 'isTimeAfter',
name: 'time3',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeAfter: '16:00:30'
}
},
{
type: 'divider'
},
{
type: 'input-time',
label: 'isTimeSameOrBefore',
name: 'time4',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeSameOrBefore: '16:00:00'
}
},
{
type: 'divider'
},
{
type: 'input-time',
label: 'isTimeSameOrAfter',
name: 'time5',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeSameOrAfter: '16:30:00'
}
},
{
type: 'divider'
},
{
type: 'input-time',
label: 'isTimeBetween',
name: 'time6',
format: 'HH:mm:ss',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
validations: {
isTimeBetween: ['03:00:00', '15:00:00', 'second', '[]']
},
validationErrors: {
isTimeBetween: '选择的时间有误,时间必须在 $1 ~ $2 范围内'
}
}
]
},
{
type: 'form',
name: 'form5',
api: '/api/mock2/form/saveForm',
debug: true,
debugConfig: {
levelExpand: 3
},
title: '<b>时间相关校验规则(带变量)</b>',
body: [
{
type: 'input-time',
label: '开始时间',
name: 'startTime',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
format: 'HH:mm:ss',
validations: {
isRequired: true,
isTimeSameOrBefore: '${endTime}'
},
validationErrors: {
isTimeSameOrBefore:
'当前时间值不合法,开始时间不能大于结束时间 $1'
}
},
{
type: 'input-time',
label: '结束时间',
name: 'endTime',
timeFormat: 'HH:mm:ss',
inputFormat: 'HH:mm:ss',
format: 'HH:mm:ss',
required: true
}
]
}
]
}
]
}
]
};

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff