@ywfe/materials-design
Version:
YwDesign for lowcode
216 lines (213 loc) • 5.77 kB
text/typescript
import { IPublicTypeComponentMetadata } from '@alilc/lowcode-types';
import { FormItemsProps, IPublicTypeSnippetMore, YwButtonBaseProps, layoutConfig } from '../_base';
import { getRefConfig, getPropValueWithPath, uuid } from '../_utils';
const refConfig = getRefConfig('data_add_dialog');
const DataAddDialogMeta: IPublicTypeComponentMetadata = {
componentName: 'DataAddDialog',
title: '新增数据',
docUrl: '',
screenshot: '',
group: '基础组件',
category: '弹窗',
devMode: 'proCode',
npm: {
package: '@ywfe/materials-design',
version: '0.0.1-beta.6',
exportName: 'YwFormDialog',
main: 'src/index.tsx',
destructuring: true,
subName: '',
},
configure: {
props: [
refConfig,
{
name: 'title',
display: 'block',
title: { label: '弹窗标题', tip: 'title | 标题' },
setter: {
componentName: 'StringSetter',
props: {
placeholder: '请输入',
},
},
},
...YwButtonBaseProps,
{
title: { label: '布局配置', tip: 'props | 布局配置' },
type: 'group',
display: 'accordion',
extraProps: {
defaultCollapsed: true,
},
supportVariable: false,
items: layoutConfig,
},
FormItemsProps,
{
title: {
label: '表单默认值',
tip: 'initialValues | 表单默认值',
},
display: 'inline',
name: 'initialValues',
description: '表单默认值',
setter: {
componentName: 'JsonSetter',
isRequired: false,
initialValue: {},
},
},
{
title: {
label: '表单初始化',
tip: 'onFormInit | 表单初始化',
},
name: 'onFormInit',
setter: {
componentName: 'SchemaFunctionSetter',
props: {
title: 'getDataSource',
async: true,
properties: {
input: {
type: 'object',
properties: {
form: {
type: 'object',
},
},
required: ['form'],
},
body: {
type: 'array',
items: [
{
type: 'JSExpression',
run: 'console.log(form);',
},
],
},
},
},
},
},
{
title: {
label: '确定操作',
tip: 'onConfirm | 确定操作',
},
name: 'onConfirm',
setter: (target) => {
const ref = getPropValueWithPath(target, '.ref');
return {
componentName: 'SchemaFunctionSetter',
props: {
title: 'getDataSource',
async: true,
properties: {
input: {
type: 'object',
properties: {
values: {
type: 'string',
},
},
required: ['values'],
},
body: {
type: 'array',
items: [
{
type: 'Function',
properties: {
template: 'RequestFunction',
variable: 'requestRes',
extraProps: {
params: '{{values}}',
},
},
},
{
type: 'JSExpression',
run: 'if (requestRes) this.reload && this.reload()',
},
{
type: 'Function',
properties: {
template: 'DispatchFunction',
extraProps: {
path: ref,
type: 'add',
data: '{{undefined}}',
},
},
},
],
},
output: 'requestRes',
},
},
};
},
},
],
supports: {
events: [
{
name: 'onConfirm',
description: '确认事件',
},
{
name: 'onCancel',
description: '取消事件',
template: 'function onCancel() {\n this.setState({\n isShowDialog: false\n });\n}',
},
{
name: 'onFormInit',
description: '表单初始化事件',
template: 'function onFormInit(_form) {\n this.setState({\n form: _form\n });\n}',
},
{
name: 'onOpen',
description: '弹窗打开事件(开发中)',
},
],
style: true,
className: true,
loop: false,
},
component: {
isContainer: false,
isMinimalRenderUnit: true,
isModal: true,
},
},
};
const snippets: IPublicTypeSnippetMore[] = [
{
title: '新增数据',
screenshot: 'https://yw-fed-static.oss-cn-hangzhou.aliyuncs.com/lowcode/dialog',
svgId: 'icon-xinzengshuju',
schema: {
componentName: 'DataAddDialog',
props: {
btnText: '新增数据',
btnType: 'primary',
title: '新增数据',
items: [
{
component: 'Input',
title: '表单项',
name: `input_${uuid()}`,
},
],
visible: undefined,
},
},
},
];
export default {
...DataAddDialogMeta,
snippets,
};