mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-15 09:21:13 +08:00
c591ab4381
* 尝试使用 vite 跑开发环境 * 尝试使用 vite 跑开发环境 * 尝试使用 vite 跑开发环境 * 尝试使用 vite 跑开发环境 * 样式文档调整 * 修复有多个 __inline 时的报错 * scirpt 调整 * feat:chart接入事件动作 (#5669) * chore: input-group 没有 name 不应该报 warning (#5667) * chore: 处理编译TS Warning,调整TableStore中label解析的顺序 (#5670) * feat: timeline时间轴支持自定义图标 (#5668) * fix:折叠器Collapse自定义图标&inputNumber对含后缀生效 * 修改 * 正则修改 * 正则修改 * 正则修改 * feat:将默认px替换为rem 2px===0.125rem * feat:timeline时间轴支持自定义图标 Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * fix: 调整echarts-stat使用方式,兼容vite打包异步非esm模块 (#5672) * feat: chart 支持配置加载 geojson 及百度地图 (#5674) * feat: chart 支持配置 geoURL 及 geoName * 增加百度地图配置 * chore: 修复 coverage 运行报错 (#5678) * chore: coverage 执行换成 v8 解决内存问题 (#5679) * 尝试使用 vite 跑开发环境 * amis-formula 也添加 esm 模块 * 代码合并有问题,做些调整 Co-authored-by: hsm-lv <80095014+hsm-lv@users.noreply.github.com> Co-authored-by: 吴多益 <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Co-authored-by: 徐佳豪 <1440054388@qq.com> Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: 刘丹 <365533093@qq.com>
233 lines
5.0 KiB
TypeScript
233 lines
5.0 KiB
TypeScript
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: '放表单外的情况'
|
||
}
|
||
]
|
||
};
|