const renderOptions = (
count = 3,
render = index => ({label: `选项${index}`, value: index})
) => [...Array(count)].map((item, index) => render(index));
const renderSelectValues = count =>
[...Array(count)].map((item, index) => index).join(',');
export default {
title: '表单及表单项切换输入态展示态',
data: {
id: 1
},
body: [
{
type: 'form',
title: '整个表单状态切换',
mode: 'horizontal',
labelWidth: 150,
id: 'allFormSwitch',
data: {
isStatic: false
},
body: [
{
type: 'input-text',
name: 'var1',
label: '输入框',
value: 'text'
},
{
type: 'input-color',
name: 'var2',
label: '颜色选择',
value: '#F0F'
},
{
type: 'switch',
name: 'switch',
label: '开关',
option: '开关说明',
value: true
},
{
type: 'checkboxes',
name: 'checkboxes',
label: '多选框',
value: renderSelectValues(12),
multiple: true,
options: renderOptions(12)
},
{
type: 'input-tag',
name: 'select11',
label: '标签选择',
inline: true,
value: renderSelectValues(12),
options: renderOptions(12)
},
{
type: 'button-toolbar',
name: 'button-toolbar',
buttons: [
{
type: 'button',
label: '提交',
level: 'primary',
visibleOn: '${!isStatic}',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'allFormSwitch',
args: {
value: {
isStatic: true
}
}
},
{
actionType: 'static',
componentId: 'allFormSwitch'
}
]
}
}
},
{
type: 'button',
label: '编辑',
level: 'primary',
visibleOn: '${isStatic}',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'allFormSwitch',
args: {
value: {
isStatic: false
}
}
},
{
actionType: 'nonstatic',
componentId: 'allFormSwitch'
}
]
}
}
}
],
className: 'show'
}
],
actions: []
},
{
type: 'form',
title: '单个表单项状态切换',
mode: 'horizontal',
labelWidth: 150,
body: [
{
type: 'input-text',
id: 'formItemSwitch',
name: 'var1',
label: '使用事件动作状态切换',
value: 'text'
},
{
type: 'button-toolbar',
name: 'button-toolbar',
buttons: [
{
type: 'button',
label: '输入态',
level: 'primary',
onEvent: {
click: {
actions: [
{
actionType: 'nonstatic',
componentId: 'formItemSwitch'
}
]
}
}
},
{
type: 'button',
label: '展示态',
level: 'primary',
onEvent: {
click: {
actions: [
{
actionType: 'static',
componentId: 'formItemSwitch'
}
]
}
}
}
],
className: 'show'
}
],
actions: []
},
{
type: 'form',
title: '表单项展示态属性',
mode: 'horizontal',
labelWidth: 150,
body: [
{
type: 'input-text',
id: 'formItemInputText',
name: 'var1',
label: '输入态
不设置
或static: false',
value: 'text',
static: false,
desc: '使用staticOn 支持表达式控制,用法类似'
},
{
type: 'input-text',
id: 'formItemInputText',
name: 'var1',
label: '展示态
static: true',
value: 'text',
static: true
},
{
type: 'input-text',
id: 'formItemInputText',
name: 'var2',
label: '空值时的占位 staticPlaceholder',
staticPlaceholder: '空值占位符,默认为 -',
static: true
},
{
type: 'input-text',
name: 'var3',
label: '自定义展示态schema',
value: '表单项value',
static: true,
staticSchema: [
'自定义前缀 | ',
{
type: 'tpl',
tpl: '${var3}'
},
' | 自定义后缀'
]
}
],
actions: []
},
{
type: 'form',
api: '/api/mock2/saveForm?waitSeconds=2',
id: 'myform',
mode: 'horizontal',
autoFocus: true,
panel: false,
debug: false,
title: '目前支持输入态展示态切换的表单项',
labelWidth: 150,
staticClassName: 'now-is-static',
body: [
{
type: 'button-toolbar',
name: 'button-toolbar',
buttons: [
{
type: 'button',
label: '切换为输入态',
level: 'primary',
onEvent: {
click: {
actions: [
{
actionType: 'nonstatic',
componentId: 'myform'
}
]
}
}
},
{
type: 'button',
label: '切换为展示态',
level: 'primary',
onEvent: {
click: {
actions: [
{
actionType: 'static',
componentId: 'myform'
}
]
}
}
}
],
className: 'show'
},
{
type: 'input-text',
name: 'var1',
label: '文本',
value: 'text',
desc: '这是一段描述文字',
id: 'my-input-text'
},
{
type: 'input-password',
name: 'password',
label: '密码',
inline: true,
value: '123456'
},
{
type: 'input-email',
validations: 'isEmail',
label: '邮箱',
name: 'email',
value: 'hello@baidu.com'
},
{
type: 'input-url',
validations: 'isUrl',
label: 'url',
name: 'url',
value: 'https://www.baidu.com'
},
{
type: 'input-number',
name: 'number',
label: '数字',
placeholder: '',
inline: true,
value: 99999,
min: 1,
max: 1000000,
kilobitSeparator: true,
prefix: '前缀',
suffix: '后缀'
},
{
type: 'divider'
},
{
type: 'native-date',
name: 'native-date',
label: 'native日期选择',
value: '2022-08-18'
},
{
type: 'native-time',
name: 'native-time',
label: 'native时间选择',
value: '16:10'
},
{
type: 'native-number',
name: 'native-number',
label: 'native数字输入',
value: '6'
},
{
type: 'divider'
},
{
type: 'input-tag',
name: 'tag',
label: '标签',
placeholder: '',
clearable: true,
value: 'zhugeliang,caocao',
options: [
{
label: '诸葛亮',
value: 'zhugeliang'
},
{
label: '曹操',
value: 'caocao'
},
{
label: '钟无艳',
value: 'zhongwuyan'
},
{
label: '野核',
children: [
{
label: '李白',
value: 'libai'
},
{
label: '韩信',
value: 'hanxin'
},
{
label: '云中君',
value: 'yunzhongjun'
}
]
}
]
},
{
type: 'divider'
},
{
type: 'checkboxes',
name: 'checkboxes',
label: '多选框',
value: '1,2',
options: [
{
label: '选项1',
value: 1
},
{
label: '选项2',
value: 2
},
{
label: '选项3',
value: 3
}
]
},
{
type: 'divider'
},
{
type: 'radios',
name: 'radios',
label: '单选',
value: 3,
options: [
{
label: '选项1',
value: 1
},
{
label: '选项2',
value: 2
},
{
label: '选项3',
value: 3
}
]
},
{
type: 'divider'
},
{
type: 'button-group-select',
name: 'btn-group',
label: '按钮组',
description: '类似于单选效果',
value: 1,
options: [
{
label: '选项 A',
value: 1
},
{
label: '选项 B',
value: 2
},
{
label: '选项 C',
value: 3
}
]
},
{
type: 'divider'
},
{
type: 'list-select',
name: 'List',
label: 'List',
desc: '也差不多,只是展示方式不一样',
value: 3,
options: [
{
label: '选项 A',
value: 1
},
{
label: '选项 B',
value: 2
},
{
label: '选项 C',
value: 3
}
]
},
{
type: 'divider'
},
{
type: 'list-select',
name: 'list2',
label: 'List',
desc: '可多选',
multiple: true,
value: renderSelectValues(2),
options: renderOptions(3)
},
{
type: 'divider'
},
{
type: 'list-select',
name: 'list4',
label: 'List',
imageClassName: 'thumb-lg',
desc: '支持放张图片',
value: renderSelectValues(2),
options: renderOptions(3, index => ({
image: '/examples/static/photo/3893101144.jpg',
value: index,
label: `图片${index}`
}))
},
{
type: 'divider'
},
{
type: 'list-select',
name: 'list5',
label: 'List',
desc: '支持文字排版',
multiple: true,
value: 1,
options: renderOptions(3, index => ({
value: index,
body: '