diff --git a/tools/schema-builder/src/materails/settings/common.ts b/tools/schema-builder/src/materails/settings/common.ts new file mode 100644 index 000000000..86e343ca4 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/common.ts @@ -0,0 +1,109 @@ +const props = [ + { + name: 'title', + title: { label: '标题', tip: 'title | 标题' }, + setter: 'StringSetter', + }, + { + name: 'code', + title: { label: '字段名', tip: 'key | 字段名' }, + setter: 'StringSetter', + }, + { + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'StringSetter' + }, + { + name: 'props.placeholder', + title: { label: '提示文案', tip: 'placeholder | 提示文案' }, + setter: 'StringSetter' + }, + { + name: 'description', + title: { label: '补充说明', tip: 'description | 补充说明' }, + setter: 'StringSetter', + }, + { + name: 'tooltip.title', + title: { label: '气泡提示', tip: 'tooltip.title | 气泡提示文案' }, + setter: 'StringSetter', + }, + { + name: 'extra', + title: { label: '额外提示', tip: 'extra | 额外的提示信息'}, + setter: 'StringSetter' + }, + { + name: 'disabled', + title: { label: '禁用', tip: 'disabled | 禁用' }, + setter: 'FrExpressionSetter' + }, + { + name: 'hidden', + title: { label: '隐藏', tip: 'hidden | 隐藏' }, + setter: 'FrExpressionSetter' + }, + { + name: 'readOnly', + title: { label: '只读', tip: 'readOnly | 只读' }, + setter: 'FrExpressionSetter' + }, + { + name: 'readOnlyWidget', + title: { label: '只读组件', tip: 'readOnlyWidget | 只读组件' }, + setter: 'StringSetter', + condition: (target: any) => !!target.getProps().getPropValue('readOnly') + } +]; + +export const formItemProps = [ + { + title: '基础配置', + display: 'accordion', + type: 'group', + items: props + } +]; + +const meta = { + componentName: 'FormItem', + title: '高级表单项', + docUrl: '', + screenshot: '', + devMode: 'proCode', + npm: { + package: '@ali/form-render-material', + version: '0.0.1', + exportName: 'FormItem', + main: 'src/index.tsx', + destructuring: true, + subName: '', + }, + category: '表单容器', + group: '基础组件', + props: formItemProps, + configure: { + supports: { + className: true, + style: true, + events: [ + { + name: 'onRefresh', + description: '点击点击刷新的回调 ', + template: 'function onRefresh(){}', + }, + ], + }, + component: { + isContainer: true, + isModal: false, + isMinimalRenderUnit: true, + }, + }, +}; + +export default { + ...meta, + icon: 'https://img.alicdn.com/imgextra/i4/O1CN01gxzRdT1hm9KXRbZkU_!!6000000004319-2-tps-200-200.png', +}; diff --git a/tools/schema-builder/src/materails/settings/index.ts b/tools/schema-builder/src/materails/settings/index.ts new file mode 100644 index 000000000..0269d8982 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/index.ts @@ -0,0 +1,33 @@ +// 常用组件配置 +export { default as input } from './meta/input'; +export { default as number } from './meta/number'; +export { default as select } from './meta/select'; +export { default as radio } from './meta/radio'; +export { default as checkbox } from './meta/checkbox'; +export { default as checkboxes } from './meta/checkboxes'; +export { default as textarea } from './meta/textarea'; +export { default as datePicker } from './meta/date'; +export { default as dateRange } from './meta/dateRange'; +export { default as timePicker } from './meta/time'; +export { default as timeRange } from './meta/timeRange'; + +// 其他组件配置 +export { default as rate } from './meta/rate'; +export { default as _switch } from './meta/switch'; +export { default as slider } from './meta/slider'; +export { default as treeSelect } from './meta/treeSelect'; +export { default as cascader } from './meta/cascader'; + +// 自定义组件配置 +export { default as color } from './meta/color'; +export { default as imageInput } from './meta/imageInput'; +export { default as urlInput } from './meta/urlInput'; +export { default as html } from './meta/html'; +// export { default as upload } from './meta/upload'; + + +// 容器组件配置 +export { default as form } from './meta/form'; +export { default as card } from './meta/card'; +export { default as cardList } from './meta/cardList'; + diff --git a/tools/schema-builder/src/materails/settings/meta/card.ts b/tools/schema-builder/src/materails/settings/meta/card.ts new file mode 100644 index 000000000..4e253b55b --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/card.ts @@ -0,0 +1,119 @@ +import { createMeta } from '../utils'; + +const props: any = [ + { + name: 'title', + title: { label: '标题', tip: 'title | 卡片主题' }, + setter: 'StringSetter' + }, + { + name: 'code', + title: { label: '字段名', tip: 'key | 字段名' }, + setter: 'StringSetter', + }, + { + name: 'description', + title: { label: '描述', tip: 'description | 卡片的描述' }, + setter: 'StringSetter' + }, + { + name: 'column', + title: { + label: '一行多列', + tip: 'column | 表单内容分成几列展示', + }, + defaultValue: 1, + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '一列', + value: 1, + }, + { + title: '两列', + value: 2, + }, + { + title: '三列', + value: 3, + }, + { + title: '四列', + value: 4 + } + ] + } + } + }, + { + name: 'widget', + title: { + label: '类型', + tip: 'widget | 类型', + }, + defaultValue: 1, + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '卡片', + value: 'card', + }, + { + title: '折叠面板', + value: 'collapse', + }, + { + title: '标题线', + value: 'lineTitle', + }, + { + title: '内联', + value: 'subInline' + } + ] + } + } + }, +]; + +const snippets = [ + { + title: '对象', + screenshot: 'icon-object', + schema: { + componentName: 'Card', + props: { + title: '卡片主题', + description: '这是一个对象类型', + column: 3, + type: 'object', + widget: 'collapse' + } + } + } +] + +export default createMeta('Card', { + title: '对象', + category: '布局', + group: '基础组件', + props, + snippets, + configure: { + supports: { + loop: false, + condition: false + }, + component: { + isContainer: true, + isModal: false, + nestingRule: { + parentWhitelist: ['FormRender', 'Card', 'CardList'] + } + } + } +}); diff --git a/tools/schema-builder/src/materails/settings/meta/cardList.ts b/tools/schema-builder/src/materails/settings/meta/cardList.ts new file mode 100644 index 000000000..8d50acb59 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/cardList.ts @@ -0,0 +1,219 @@ +import { createMeta } from '../utils'; + +const props: any = [ + { + name: 'title', + title: { label: '标题', tip: 'title | 卡片主题' }, + setter: 'StringSetter' + }, + { + name: 'code', + title: { label: '字段名', tip: 'key | 字段名' }, + setter: 'StringSetter', + }, + { + name: 'description', + title: { label: '描述', tip: 'description | 卡片的描述' }, + setter: 'StringSetter' + }, + { + title: '模版配置', + display: 'block', + type: 'group', + items: [ + { + name: 'widget', + title: { + label: '类型', + tip: 'widget | 类型', + }, + setter: { + componentName: 'SelectSetter', + props: { + options: [ + { + title: 'SimpleList', + value: 'simpleList', + }, + { + title: 'CardList', + value: 'cardList', + }, + { + title: 'DrawerList', + value: 'drawerList', + }, + { + title: 'TableList', + value: 'tableList' + }, + { + title: 'VirtualList', + value: 'virtualList' + }, + { + title: 'TabList', + value: 'tabList' + } + ] + } + }, + extraProps: { + setValue(target: any, value: string) { + const node = target.getNode(); + + + if (value !== 'cardList') { + node.setPropValue('items.widget', undefined); + node.setPropValue('items.title', undefined); + node.setPropValue('items.description', undefined); + node.setPropValue('items.column', undefined); + } + } + } + }, + { + name: 'items.widget', + title: { + label: '样式类型', + tip: '样式类型', + }, + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '卡片', + value: 'card', + }, + { + title: '折叠面板', + value: 'collapse', + }, + { + title: '标题线', + value: 'lineTitle', + }, + { + title: '内联', + value: 'subInline' + } + ] + } + }, + condition: (target: any) => target.getProps().getPropValue('widget') === 'cardList' + }, + { + name: 'items.title', + title: { label: '标题', tip: 'title | 卡片主题' }, + setter: 'StringSetter', + condition: (target: any) => target.getProps().getPropValue('widget') === 'cardList' + }, + { + name: 'items.description', + title: { label: '描述', tip: 'description | 卡片的描述' }, + setter: 'StringSetter', + condition: (target: any) => target.getProps().getPropValue('widget') === 'cardList' + }, + { + name: 'items.column', + title: { + label: '一行多列', + tip: 'column | 表单内容分成几列展示', + }, + defaultValue: 1, + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '一列', + value: 1, + }, + { + title: '两列', + value: 2, + }, + { + title: '三列', + value: 3, + }, + { + title: '四列', + value: 4 + } + ] + } + }, + condition: (target: any) => target.getProps().getPropValue('widget') === 'cardList', + extraProps: { + setValue(target: any, value: number) { + const node = target.getNode(); + let labelSpan = 8; + let wrapperColSpan = 16; + if (value === 1) { + labelSpan = 4; + wrapperColSpan = 6; + } else if (value === 2) { + wrapperColSpan = 10; + } + node.setPropValue('labelCol.span', labelSpan); + node.setPropValue('wrapperCol.span', wrapperColSpan); + + node.mergeChildren( + (child: any) => { + let span = 24 / value; + child.setPropValue('span', span); + return false; + }, + () => {}, + () => {}, + ); + } + } + } + ] + } +]; + +const snippets = [ + { + title: '列表', + screenshot: 'icon-list', + schema: { + componentName: 'CardList', + props: { + title: '列表', + description: '这是一个列表', + type: 'array', + items: { + title: '卡片主题', + description: '这是一个对象类型', + column: 3, + type: 'object', + } + } + } + } +] + +export default createMeta('CardList', { + title: '列表', + category: '布局', + group: '基础组件', + props, + snippets, + configure: { + supports: { + loop: false, + condition: false + }, + component: { + isContainer: true, + isModal: false, + nestingRule: { + parentWhitelist: ['FormRender', 'Card'] + } + }, + } +}); diff --git a/tools/schema-builder/src/materails/settings/meta/cascader.ts b/tools/schema-builder/src/materails/settings/meta/cascader.ts new file mode 100644 index 000000000..578bf1350 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/cascader.ts @@ -0,0 +1,162 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.options', + title: { label: '选项配置', tip: '选项配置' }, + setter: 'JsonSetter', + }, + { + name: 'props.multiple', + title: { label: '支持多选', tip: '支持多选节点' }, + setter: 'BoolSetter', + }, + { + title: '多选配置', + display: 'popup', + type: 'group', + items: [ + { + name: 'props.maxTagCount', + title: { label: '最大显示数量', tip: '最多显示多少个 tag' }, + setter: 'NumberSetter', + } + ], + condition: (target: any) => { + return !!target.parent.getPropValue("props.multiple") + }, + }, + { + name: 'props.showSearch', + title: { label: '支持搜索', tip: '在选择框中显示搜索框' }, + setter: 'BoolSetter', + }, + { + name: 'props.notFoundContent', + title: { label: '搜索为空提示文案', tip: '搜索为空提示文案' }, + setter: 'StringSetter', + condition: (target: any) => !!target.getProps().getPropValue('F.showSearch'), + }, + { + name: 'props.allowClear', + title: { label: '支持清除', tip: '是否允许清除' }, + setter: 'BoolSetter', + defaultValue: true, + }, + { + name: 'props.changeOnSelect', + title: { + label: '点选触发', + tip: '点选每级菜单选项值都会触发onChange', + }, + setter: 'BoolSetter', + }, + { + name: 'props.expandTrigger', + title: { label: '菜单触发方式', tip: '触发次级菜单的展开的方式' }, + setter: [ + { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '点击', + value: 'click', + }, + { + title: '悬浮', + value: 'hover', + }, + ], + }, + }, + ], + defaultValue: 'click', + }, + { + name: 'props.placement', + title: { label: '浮层预设位置', tip: '浮层预设位置' }, + setter: [ + { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '顶左', + value: 'topLeft', + }, + { + title: '顶右', + value: 'topRight', + }, + { + title: '底左', + value: 'bottomLeft', + }, + { + title: '底右', + value: 'bottomRight', + }, + + ] + } + } + ] + } + ] +}, +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'JsonSetter' +}, +{ + name: 'props.placeholder', + title: { label: '提示文字', tip: 'placeholder | 提示文字' }, + setter: 'StringSetter', + defaultValue: '请选择' +}); + +const snippets = [ + { + label: '级联选择', + screenshot: 'https://img.alicdn.com/imgextra/i1/O1CN01kdq0Ab22ZQL0wXyBR_!!6000000007134-55-tps-183-133.svg', + schema: { + componentName: 'Cascader', + props: { + title: '级联选择', + props: { + options: [ + { + "value": 'zhejiang', + "label": 'Zhejiang', + "children": [ + { + "value": 'hangzhou', + "label": 'Hangzhou', + "children": [ + { + "value": 'xihu', + "label": 'West Lake', + } + ] + } + ] + } + ] + } + } + } + } +]; + +export default createMeta('Cascader', { + title: '级联选择', + category: '其他', + props, + // snippets +}); diff --git a/tools/schema-builder/src/materails/settings/meta/checkbox.ts b/tools/schema-builder/src/materails/settings/meta/checkbox.ts new file mode 100644 index 000000000..7721e3ad2 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/checkbox.ts @@ -0,0 +1,29 @@ +import { mergeProps, createMeta } from '../utils'; + +const props: any = mergeProps( +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'BoolSetter' +}); + +const snippets = [ + { + title: '是否选择', + screenshot:'icon-isNot', + schema: { + componentName: 'Checkbox', + props: { + title: '是否选择', + type: 'boolean' + }, + } + } +]; + +export default createMeta('Checkbox', { + title: '是否选择', + props, + snippets, + priority: 994 +}); diff --git a/tools/schema-builder/src/materails/settings/meta/checkboxes.ts b/tools/schema-builder/src/materails/settings/meta/checkboxes.ts new file mode 100644 index 000000000..dc1157370 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/checkboxes.ts @@ -0,0 +1,73 @@ +import { mergeProps, createMeta, optionsMeta } from '../utils'; + +const props: any = mergeProps([ + optionsMeta, + { + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.direction', + title: { label: '排列方向', tip: '选项的排列方向'}, + defaultValue: 'row', + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '水平', + value: 'row', + }, + { + title: '垂直', + value: 'column', + }, + ] + } + } + } + ] + } +], +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'JsonSetter' +}); + +const snippets = [{ + title: '点击多选', + screenshot: 'icon-checkbox', + schema: { + componentName: 'Checkboxes', + props: { + title: '点击多选', + type: 'array', + props: { + options: [ + { + label: 'A', + value: 'A' + }, + { + label: 'B', + value: 'B' + }, + { + label: 'C', + value: 'C' + } + ], + direction: 'row' + } + } + } +}]; + +export default createMeta('Checkboxes', { + title: '点击多选框', + priority: 996, + props, + snippets +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/color.ts b/tools/schema-builder/src/materails/settings/meta/color.ts new file mode 100644 index 000000000..508d06366 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/color.ts @@ -0,0 +1,28 @@ +import { mergeProps, createMeta } from '../utils'; + +const props: any = mergeProps( +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'StringSetter' +}); + +const snippets = [ + { + title: '颜色选择', + screenshot:'icon-color', + schema: { + componentName: 'Color', + props: { + title: '颜色选择', + }, + } + } +]; + +export default createMeta('Color', { + title: '颜色选择', + category: '其他', + props, + snippets +}); diff --git a/tools/schema-builder/src/materails/settings/meta/date.ts b/tools/schema-builder/src/materails/settings/meta/date.ts new file mode 100644 index 000000000..5616bfd16 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/date.ts @@ -0,0 +1,121 @@ +import { mergeProps, createMeta } from '../utils'; + +// const props = mergeProps({ +// title: '其他配置', +// display: 'accordion', +// type: 'group', +// items: [ +// // { +// // name: 'picker', +// // title: { +// // label: '日期类型', +// // tip: 'picker | 选择器日期类型', +// // }, +// // defaultValue: 'date', +// // setter: { +// // componentName: 'SelectSetter', +// // props: { +// // options: [ +// // { +// // title: '日期', +// // value: 'date', +// // }, +// // { +// // title: '周', +// // value: 'week', +// // }, +// // { +// // title: '月份', +// // value: 'month', +// // }, +// // { +// // title: '季度', +// // value: 'quarter', +// // }, +// // { +// // title: '年份', +// // value: 'year', +// // } +// // ] +// // } +// // }, +// // }, +// // { +// // name: 'format', +// // title: { +// // label: '日期格式', +// // tip: 'format | 设置日期格式', +// // }, +// // defaultValue: 'YYYY-MM-DD', +// // setter: 'StringSetter' +// // }, +// { +// name: 'props.allowClear', +// title: { +// label: '支持清除', +// tip: 'allowClear | 是否允许清除', +// }, +// defaultValue: true, +// setter: 'BoolSetter' +// }, +// { +// name: 'props.showToday', +// title: { +// label: '展示今天按钮', +// tip: 'showToday | 是否展示今天按钮', +// }, +// defaultValue: true, +// setter: 'BoolSetter' +// } +// ] +// }, +// { +// name: 'defaultValue', +// title: { label: '默认值', tip: 'defaultValue | 默认值'}, +// setter: 'CustomDateSetter' +// }, +// { +// name: 'props.placeholder', +// title: { +// label: '提示文字', +// tip: 'placeholder | 输入框提示文字', +// }, +// defaultValue: '请选择日期', +// setter: 'StringSetter' +// }); + +const props = mergeProps( +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'CustomDateSetter' +}, +{ + name: 'props.placeholder', + title: { + label: '提示文字', + tip: 'placeholder | 输入框提示文字', + }, + defaultValue: '请选择日期', + setter: 'StringSetter' +}); + +const snippets = [ + { + title: '日期选择', + screenshot: 'icon-date', + schema: { + componentName: 'DatePicker', + props: { + title: '日期选择', + type: 'string' + } + } + } +] + +export default createMeta('DatePicker', { + title: '日期选择', + props, + snippets +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/dateRange.ts b/tools/schema-builder/src/materails/settings/meta/dateRange.ts new file mode 100644 index 000000000..767d76565 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/dateRange.ts @@ -0,0 +1,177 @@ +import { mergeProps, createMeta } from '../utils'; + +// const props = mergeProps({ +// title: '其他配置', +// display: 'accordion', +// type: 'group', +// items: [ +// // { +// // name: 'picker', +// // title: { +// // label: '日期类型', +// // tip: 'picker | 选择器日期类型', +// // }, +// // defaultValue: 'date', +// // setter: { +// // componentName: 'SelectSetter', +// // props: { +// // options: [ +// // { +// // title: '日期', +// // value: 'date', +// // }, +// // { +// // title: '周', +// // value: 'week', +// // }, +// // { +// // title: '月份', +// // value: 'month', +// // }, +// // { +// // title: '季度', +// // value: 'quarter', +// // }, +// // { +// // title: '年份', +// // value: 'year', +// // } +// // ] +// // } +// // } +// // }, +// // { +// // name: 'format', +// // title: { +// // label: '日期格式', +// // tip: 'format | 设置日期格式', +// // }, +// // defaultValue: 'YYYY-MM-DD', +// // setter: 'StringSetter' +// // }, +// // { +// // name: 'valueType', +// // title: { +// // label: '提交格式', +// // tip: 'valueType | 日期提交时格式', +// // }, +// // defaultValue: 'moment', +// // setter: { +// // componentName: 'SelectSetter', +// // props: { +// // options: [ +// // { title: '默认moment', value: 'moment' }, +// // { title: '毫秒数(YYYY-MM-DD 23:59:59)', value: 'milliseconds-limit'}, +// // { title: '毫秒数(YYYY-MM-DD 00:00:00)', value: 'milliseconds-zero' }, +// // { title: '毫秒数(当前时间毫秒数)', value: 'milliseconds-current' }, +// // { title: 'YYYY-MM-DD', value: 'YYYY-MM-DD'}, +// // { title: 'YYYYMMDD', value: 'YYYYMMDD'}, +// // { title: 'YYYY/MM/DD', value: 'YYYY/MM/DD'} +// // ] +// // } +// // } +// // }, +// { +// name: 'props.allowClear', +// title: { +// label: '支持清除', +// tip: 'allowClear | 是否允许清除', +// }, +// defaultValue: true, +// setter: 'BoolSetter' +// }, +// { +// name: 'props.showToday', +// title: { +// label: '展示今天按钮', +// tip: 'showToday | 是否展示今天按钮', +// }, +// defaultValue: true, +// setter: 'BoolSetter' +// }, +// // { +// // name: 'showTime', +// // title: { +// // label: '时间选择', +// // tip: 'showTime | 是否能选择时间', +// // }, +// // propType: 'bool', +// // setter: 'BoolSetter', +// // setValue(target: any, showTime: any) { +// // if (showTime) { +// // return target.getNode().setPropValue('F.format', 'YYYY-MM-DD hh:mm:ss'); +// // } +// // target.getNode().setPropValue('F.format', 'YYYY-MM-DD'); +// // }, +// // }, +// // { +// // name: 'disabledDate', +// // title: { +// // label: '不可选日期', +// // tip: 'disabledDate | 不可选择的日期', +// // }, +// // setter: [ +// // { +// // componentName: 'MethodSetter', +// // props: { +// // template: +// // 'disabledDate(currentDate,${extParams}){\n// 设置不可选择的日期\nreturn true\n}', +// // } +// // } +// // ] +// // } +// ] +// }, +// { +// name: 'defaultValue', +// title: { label: '默认值', tip: 'defaultValue | 默认值'}, +// setter: 'CustomDateRangeSetter' +// }, +// { +// name: 'props.placeholder', +// title: { +// label: '提示文字', +// tip: 'placeholder | 输入框提示文字', +// }, +// setter: 'JsonSetter', +// defaultValue: ['开始时间', '结束时间'] +// }); + +const props = mergeProps( +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'CustomDateRangeSetter' +}, +{ + name: 'props.placeholder', + title: { + label: '提示文字', + tip: 'placeholder | 输入框提示文字', + }, + setter: 'JsonSetter', + defaultValue: ['开始时间', '结束时间'] +}); + + +const snippets = [ + { + title: '日期区间选择', + screenshot: 'icon-date', + schema: { + componentName: 'DateRange', + props: { + title: '日期区间选择', + type: 'range', + format: 'date', + } + } + } +] + + +export default createMeta('DateRange', { + title: '日期选择区间', + props, + snippets, +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/form.ts b/tools/schema-builder/src/materails/settings/meta/form.ts new file mode 100644 index 000000000..9d3f3ae6f --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/form.ts @@ -0,0 +1,140 @@ + +import { createMeta } from '../utils'; + +const props = [ + { + title: '表单布局', + display: 'accordion', + type: 'group', + items: [ + { + name: 'displayType', + title: { + label: '标签位置', + tip: 'displayType | 标签的展示位置', + }, + defaultValue: 'row', + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '水平居左', + value: 'row' + }, + { + title: '垂直居上', + value: 'column' + }, + { + title: '紧凑', + value: 'inline' + } + ] + } + } + }, + { + name: 'column', + title: { + label: '一行多列', + tip: 'column | 一行多列', + }, + defaultValue: 1, + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '一列', + value: 1 + }, + { + title: '两列', + value: 2 + }, + { + title: '三列', + value: 3 + }, + { + title: '四列', + value: 4 + } + ] + } + } + }, + { + name: 'labelWidth', + title: { + label: '标签宽度', + tip: 'labelWidth | 标签宽度', + }, + setter: 'NumberSetter' + } + ] + }, + { + title: '标签和控件栅格总数不能超过24', + display: 'block', + type: 'group', + items: [ + { + name: 'labelCol', + title: { + label: '标签栅格数', + tip: 'labelCol | 栅格占位格数', + }, + setter: { + componentName: 'NumberSetter', + props: { + min: 0, + max: 24 + } + } + }, + { + name: 'fieldCol', + title: { + label: '控件栅格数', + tip: 'fieldCol | 栅格占位格数' + }, + setter: { + componentName: 'NumberSetter', + props: { + min: 0, + max: 24 + } + } + }, + { + name: 'maxWidth', + title: { + label: '最大宽度', + tip: 'maxWidth | 最大宽度' + }, + defaultValue: '340px', + setter: 'StringSetter' + } + ] + } +]; + +export default createMeta('FormRender', { + title: '表单', + group: '基础组件', + category: '表单', + props, + configure: { + supports: { + loop: false, + condition: false + }, + component: { + isContainer: true, + isModal: false + } + } +}); + diff --git a/tools/schema-builder/src/materails/settings/meta/html.ts b/tools/schema-builder/src/materails/settings/meta/html.ts new file mode 100644 index 000000000..ef4b9e8e7 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/html.ts @@ -0,0 +1,33 @@ +import { mergeProps, createMeta } from '../utils'; + +const props: any = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [] +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'StringSetter' +}); + +const snippets = [ + { + title: 'Html', + screenshot: 'icon-html', + schema: { + componentName: 'Html', + props: { + title: 'Html', + }, + } + } +]; + +export default createMeta('Html', { + title: 'HTML', + category: '其他', + props, + snippets +}); diff --git a/tools/schema-builder/src/materails/settings/meta/imageInput.ts b/tools/schema-builder/src/materails/settings/meta/imageInput.ts new file mode 100644 index 000000000..f728be881 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/imageInput.ts @@ -0,0 +1,28 @@ +import { mergeProps, createMeta } from '../utils'; + +const props: any = mergeProps( +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'StringSetter' +}); + +const snippets = [ + { + title: '图片 URL', + screenshot: 'icon-image', + schema: { + componentName: 'ImageInput', + props: { + title: '图片 URL', + }, + } + } +] + +export default createMeta('ImageInput', { + title: '图片 URL', + category: '其他', + props, + snippets +}); diff --git a/tools/schema-builder/src/materails/settings/meta/input.ts b/tools/schema-builder/src/materails/settings/meta/input.ts new file mode 100644 index 000000000..34c461800 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/input.ts @@ -0,0 +1,55 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.prefix', + title: { label: '前缀', tip: 'prefix | 前缀' }, + setter: 'StringSetter' + }, + { + name: 'props.suffix', + title: { label: '后缀', tip: 'suffix | 后缀' }, + setter: 'StringSetter' + }, + { + name: 'props.addonBefore', + title: { label: '前置标签', tip: 'addonBefore | 前置标签' }, + setter: 'StringSetter' + }, + { + name: 'props.addonAfter', + title: { label: '后置标签', tip: 'addonAfter | 后置标签' }, + setter: 'StringSetter' + }, + { + name: 'props.allowClear', + title: { label: '支持清除', tip: 'allowClear | 支持清除' }, + setter: 'BoolSetter' + } + ] +}); + +const snippets = [ + { + label: '单行文本', + screenshot: 'icon-input', + schema: { + componentName: 'Input', + props: { + title: '单行文本', + type: 'string' + } + } + } +]; + +export default createMeta('Input', { + title: '单行文本', + props, + snippets, + priority: 1000 +}); diff --git a/tools/schema-builder/src/materails/settings/meta/number.ts b/tools/schema-builder/src/materails/settings/meta/number.ts new file mode 100644 index 000000000..70b623696 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/number.ts @@ -0,0 +1,63 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.prefix', + title: { label: '前缀', tip: 'prefix | 前缀' }, + setter: 'StringSetter', + }, + { + name: 'props.addonBefore', + title: { label: '前置标签', tip: 'addonBefore | 前置标签' }, + setter: 'StringSetter', + }, + { + name: 'props.addonAfter', + title: { label: '后置标签', tip: 'addonAfter | 后置标签' }, + setter: 'StringSetter', + }, + { + name: 'props.precision', + title: { label: '数值精度', tip: 'precision | 数值精度' }, + setter: 'NumberSetter', + }, + { + name: 'props.step', + title: { label: '单步步长', tip: 'step | 每次改变步数,可以为小数' }, + setter: ['NumberSetter', 'StringSetter'], + } + ] +}, +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'NumberSetter' +} +); + +const snippets = [ + { + label: '数字输入框', + screenshot: 'icon-inputNumber', + schema: { + componentName: 'InputNumber', + props: { + title: '数字输入框', + type: 'number' + } + } + } +]; + +export default createMeta('InputNumber', { + title: '数字输入框', + props, + snippets, + priority: 999 +}); + + diff --git a/tools/schema-builder/src/materails/settings/meta/radio.ts b/tools/schema-builder/src/materails/settings/meta/radio.ts new file mode 100644 index 000000000..2c00f30c5 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/radio.ts @@ -0,0 +1,74 @@ +import { mergeProps, createMeta, optionsMeta } from '../utils'; + +const props: any = mergeProps([ + optionsMeta, + { + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.direction', + title: { label: '排列方向', tip: '选项的排列方向'}, + defaultValue: 'row', + setter: { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '水平', + value: 'row', + }, + { + title: '垂直', + value: 'column', + }, + ] + } + } + } + ] + } +], +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'JsonSetter' +}); + +const snippets = [ + { + title: '点击单选', + screenshot: 'icon-radio', + schema: { + componentName: 'Radio', + props: { + title: '点击单选', + type: 'string', + props: { + options: [ + { + label: 'A', + value: 'A' + }, + { + label: 'B', + value: 'B' + }, + { + label: 'C', + value: 'C' + } + ] + } + } + } + } +]; + +export default createMeta('Radio', { + title: '点击单选', + props, + snippets, + priority: 997, +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/rate.ts b/tools/schema-builder/src/materails/settings/meta/rate.ts new file mode 100644 index 000000000..e80a6fcc8 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/rate.ts @@ -0,0 +1,51 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.allowClear', + title: { label: '支持清除', tip: '是否允许清除' }, + setter: 'BoolSetter', + defaultValue: true, + }, + { + name: 'props.allowHalf', + title: { label: '支持半选', tip: '支持半选' }, + setter: 'BoolSetter', + }, + { + name: 'props.count', + title: { label: '总数', tip: 'star 总数' }, + setter: 'NumberSetter', + defaultValue: 5, + }, + ] +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'NumberSetter' +}); + +const snippets = [ + { + label: '评分', + screenshot: 'icon-rate', + schema: { + componentName: 'Rate', + props: { + title: '评分' + } + } + } +]; + +export default createMeta('Rate', { + title: '评分', + props, + snippets, + priority: 992 +}); diff --git a/tools/schema-builder/src/materails/settings/meta/select.ts b/tools/schema-builder/src/materails/settings/meta/select.ts new file mode 100644 index 000000000..bdaa1225b --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/select.ts @@ -0,0 +1,158 @@ +import { mergeProps, createMeta, optionsMeta } from '../utils'; + +const otherProps = [ + optionsMeta, + // { + // title: '其他配置', + // display: 'accordion', + // type: 'group', + // items: [ + // // { + // // name: 'props.mode', + // // title: { label: '选择模式', tip: 'props.mode | 选择模式' }, + // // setter: { + // // componentName: 'RadioGroupSetter', + // // props: { + // // options: [ + // // { + // // title: '单选', + // // value: 'single', + // // }, + // // { + // // title: '多选', + // // value: 'multiple', + // // }, + // // { + // // title: 'tags', + // // value: 'tags', + // // } + // // ] + // // } + // // } + // // }, + // // { + // // name: 'props.maxTagCount', + // // title: { label: '最大个数', tip: 'props.maxTagCount | 最多显示多少个tag' }, + // // condition(target: any) { + // // return target.getProps().getPropValue('props.mode') === 'tags'; + // // }, + // // setter: 'NumberSetter' + // // }, + // // { + // // name: 'props.maxTagTextLength', + // // title: { label: '文本长度', tip: 'props.maxTagTextLength | 显示 tag 最大文本长度' }, + // // condition(target: any) { + // // return target.getProps().getPropValue('props.mode') === 'tags'; + // // }, + // // setter: 'NumberSetter' + // // }, + // // { + // // name: 'props.allowClear', + // // title: { + // // label: '支持清除', + // // tip: '是否支持清除', + // // }, + // // setter: 'BoolSetter' + // // }, + // // { + // // name: 'props.showSearch', + // // title: { + // // label: '是否可搜索', + // // tip: '是否可搜索', + // // }, + // // setter: 'BoolSetter' + // // }, + // // { + // // name: 'props.notFoundContent', + // // title: { label: '搜索为空提示文案', tip: '搜索为空提示文案' }, + // // setter: 'StringSetter', + // // condition(target: any) { + // // return !!target.getProps().getPropValue('props.showSearch'); + // // } + // // }, + // // { + // // name: 'props.showArrow', + // // title: { label: '显示下拉箭头', tip: 'props.showArrow | 是否显示下拉小箭头' }, + // // setter: 'BoolSetter', + // // defaultValue: true + // // } + // ] + // } +]; + +const props = mergeProps(otherProps, +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'defaultValue | 默认值'}, + setter: 'JsonSetter' +}, +{ + name: 'props.placeholder', + title: { label: '提示文字', tip: 'placeholder | 提示文字' }, + defaultValue: '请选择', + setter: 'StringSetter', +}); + +const snippets = [ + { + title: '下拉单选', + screenshot: 'icon-select', + schema: { + componentName: 'Select', + props: { + title: '下拉单选', + type: 'string', + props: { + options: [ + { + label: 'A', + value: 'A' + }, + { + label: 'B', + value: 'B' + } + ] + } + } + } + }, + + { + title: '下拉多选', + screenshot: 'icon-multiSelect', + schema: { + componentName: 'Select', + props: { + title: '下拉多选', + type: 'array', + widget: 'multiSelect', + props: { + options: [ + { + label: 'A', + value: 'A' + }, + { + label: 'B', + value: 'B' + } + ] + } + } + } + } +]; + + +export default createMeta('Select', { + title: '下拉选择', + props, + snippets, + priority: 998, +}); + + + + + diff --git a/tools/schema-builder/src/materails/settings/meta/slider.ts b/tools/schema-builder/src/materails/settings/meta/slider.ts new file mode 100644 index 000000000..f0e6d31bc --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/slider.ts @@ -0,0 +1,49 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.hideInput', + title: {label: '隐藏输入框', tip: '隐藏输入框'}, + setter: 'BoolSetter', + }, + // { + // name: 'props.schema.max', + // title: { label: '最大值', tip: '最大值' }, + // setter: 'NumberSetter', + // }, + // { + // name: 'props.schema.min', + // title: { label: '最小值', tip: '最小值' }, + // setter: 'NumberSetter', + // }, + ], +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'NumberSetter' +}); + +const snippets = [ + { + label: '滑动条', + screenshot: 'icon-slider', + schema: { + componentName: 'Slider', + props: { + title: '滑动条' + } + } + } +]; + +export default createMeta('Slider', { + title: '滑动条', + props, + snippets, + priority: 991 +}); diff --git a/tools/schema-builder/src/materails/settings/meta/switch.ts b/tools/schema-builder/src/materails/settings/meta/switch.ts new file mode 100644 index 000000000..95285408a --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/switch.ts @@ -0,0 +1,45 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.checkedChildren', + title: { label: '选中时内容', tip: 'checkedChildren | 选中时内容' }, + setter: 'StringSetter', + }, + { + name: 'props.unCheckedChildren', + title: { label: '非选中时内容', tip: 'unCheckedChildren | 非选中时内容' }, + setter: 'StringSetter', + } + ] +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'BoolSetter' +}); + +const snippets = [ + { + label: '开关', + screenshot: 'icon-switch', + schema: { + componentName: 'Switch', + props: { + title: '开关', + type: 'boolean', + }, + }, + }, +]; + +export default createMeta('Switch', { + title: '开关', + props, + snippets, + priority: 993 +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/textarea.ts b/tools/schema-builder/src/materails/settings/meta/textarea.ts new file mode 100644 index 000000000..96dc02f76 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/textarea.ts @@ -0,0 +1,60 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.allowClear', + title: { label: '支持清除', tip: 'allowClear | 支持清除' }, + setter: 'BoolSetter' + }, + { + name: 'props.showCount', + title: { label: '展示字数', tip: 'showCount | 是否展示字数' }, + setter: 'BoolSetter', + }, + { + name: 'props.autoSize', + title: { label: '高度自动', tip: 'autoSize | 文本域高度自适应内容' }, + setter: 'BoolSetter', + }, + { + name: 'props.rows', + title: { label: '指定行数', tip: 'minRows | 指定显示的行数' }, + setter: 'NumberSetter', + }, + { + name: 'props.minLength', + title: { label: '最小长度', tip: 'minLength | 内容最小长度' }, + setter: 'NumberSetter' + }, + { + name: 'props.maxLength', + title: { label: '最大长度', tip: 'maxLength | 内容最大长度' }, + setter: 'NumberSetter' + }, + ] +}); + +const snippets = [ + { + label: '多行文本', + screenshot: 'icon-textarea', + schema: { + componentName: 'TextArea', + props: { + title: '多行文本', + type: 'string', + } + } + } +] + +export default createMeta('TextArea', { + title: '多行文本', + priority: 995, + props, + snippets, +}); diff --git a/tools/schema-builder/src/materails/settings/meta/time.ts b/tools/schema-builder/src/materails/settings/meta/time.ts new file mode 100644 index 000000000..5a7e55dfe --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/time.ts @@ -0,0 +1,38 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps( +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'CustomTimeSetter' +}, +{ + name: 'props.placeholder', + title: { + label: '提示文字', + tip: 'placeholder | 输入框提示文字', + }, + defaultValue: '请选择时间', + setter: 'StringSetter', +}); + +const snippets = [ + { + title: '时间选择', + screenshot: 'icon-time', + schema: { + componentName: 'TimePicker', + props: { + title: '时间选择', + type: 'string', + format: 'time', + } + } + } +]; + +export default createMeta('TimePicker', { + title: '时间选择', + props, + snippets +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/timeRange.ts b/tools/schema-builder/src/materails/settings/meta/timeRange.ts new file mode 100644 index 000000000..f12183adb --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/timeRange.ts @@ -0,0 +1,39 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps( +{ + name: 'defaultValue', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'CustomTimeRangeSetter' +}, +{ + name: 'props.placeholder', + title: { + label: '提示文字', + tip: 'placeholder | 输入框提示文字', + }, + defaultValue: ['开始时间', '结束时间'], + setter: 'JsonSetter', +}); + +const snippets = [ + { + title: '时间区间选择', + screenshot: 'icon-time', + schema: { + componentName: 'TimeRange', + props: { + title: '时间区间', + type: 'range', + format: 'time' + } + } + } +]; + + +export default createMeta('TimeRange', { + title: '时间区间选择', + props, + snippets +}); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/settings/meta/treeSelect.ts b/tools/schema-builder/src/materails/settings/meta/treeSelect.ts new file mode 100644 index 000000000..43b9534e6 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/treeSelect.ts @@ -0,0 +1,132 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.treeData', + title: { label: '数据源', tip: '数据源' }, + setter: 'JsonSetter', + }, + { + name: 'props.multiple', + title: { + label: '支持多选', + tip: '支持多选(当设置 treeCheckable 时自动变为 true)', + }, + setter: 'BoolSetter', + }, + // { + // name: 'props.showArrow', + // title: { + // label: '下拉图标', + // tip: '是否显示下拉图标,单选模式下默认 `true`', + // }, + // setter: 'BoolSetter', + // defaultValue: true, + // }, + // { + // name: 'props.showSearch', + // title: { label: '是否支持搜索框', tip: '是否支持搜索框' }, + // setter: 'BoolSetter', + // }, + // { + // name: 'props.notFoundContent', + // title: { label: '搜索为空提示文案', tip: '搜索为空提示文案' }, + // setter: 'StringSetter', + // condition: (target: any) => !!target.getProps().getPropValue('props.showSearch'), + // }, + { + name: 'props.allowClear', + title: { label: '支持清除', tip: '是否允许清除' }, + setter: 'BoolSetter', + }, + { + name: 'props.treeCheckable', + title: { label: '显示勾选框', tip: '显示勾选框' }, + setter: 'BoolSetter', + }, + { + name: 'props.treeDefaultExpandAll', + title: { label: '默认展开所有树节点', tip: '默认展开所有树节点' }, + setter: 'BoolSetter', + }, + // { + // name: 'props.labelInValue', + // title: { + // label: '值包含标签', + // tip: + // '是否把每个选项的 label 包装到 value 中,会把 value 类型从 `string` 变为 {value: string, label: ReactNode, halfChecked(treeCheckStrictly 时有效): string[] } 的格式', + // }, + // setter: 'BoolSetter', + // }, + // { + // name: 'props.listHeight', + // title: { label: '设置弹窗滚动高度', tip: '设置弹窗滚动高度' }, + // setter: 'NumberSetter', + // defaultValue: 256, + // }, + // { + // name: 'props.maxTagCount', + // title: { label: '最多显示多少个 tag', tip: '最多显示多少个 tag' }, + // setter: 'NumberSetter', + // }, + ], +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'JsonSetter' +}, +{ + name: 'props.placeholder', + title: { label: '提示文字', tip: 'placeholder | 提示文字' }, + setter: 'StringSetter', + defaultValue: '请选择' +}); + +const snippets = [ + { + label: '树选择', + screenshot: 'icon-tree', + schema: { + componentName: 'TreeSelect', + props: { + title: '树选择', + props: { + treeData: [ + { + value: 'parent 1', + title: 'parent 1', + children: [ + { + value: 'parent 1-0', + title: 'parent 1-0', + children: [ + { + value: 'leaf1', + title: 'leaf1', + }, + { + value: 'leaf2', + title: 'leaf2', + }, + ], + }, + ] + } + ] + } + } + } + } +] + +export default createMeta('TreeSelect', { + title: '树选择', + category: '其他', + props, + snippets +}); diff --git a/tools/schema-builder/src/materails/settings/meta/upload.ts b/tools/schema-builder/src/materails/settings/meta/upload.ts new file mode 100644 index 000000000..00aac58c9 --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/upload.ts @@ -0,0 +1,272 @@ +import { mergeProps, createMeta } from '../utils'; + +const props = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'multiple', + title: { + label: '支持多选文件', + tip: + 'multiple | 是否支持多选文件,`ie10+` 支持。开启后按住 ctrl 可选择多个文件', + }, + setter: 'BoolSetter', + }, + { + name: 'maxCount', + title: { + label: '上传数量限制', + tip: + 'maxCount | 限制上传数量。当为 1 时,始终用最新上传的文件代替当前文件', + }, + setter: 'NumberSetter' + }, + { + name: 'accept', + title: { + label: '上传文件类型', + tip: + 'accept | 接受上传的文件类型, 例如 .doc,.docx,application/msword', + }, + setter: 'StringSetter', + }, + { + name: 'directory', + title: { + label: '文件夹上传', + tip: 'directory | 支持上传文件夹', + }, + setter: 'BoolSetter', + }, + { + title: '高级', + display: 'popup', + type: 'group', + items: [ + { + name: 'openFileDialogOnClick', + title: { + label: '打开文件对话框', + tip: 'openFileDialogOnClick | 点击打开文件对话框', + }, + setter: 'BoolSetter', + defaultValue: true, + }, + { + name: 'showUploadList', + title: { + label: '显示上传列表', + tip: 'showUploadList | 是否显示上传的文件列表,', + }, + setter: 'BoolSetter', + defaultValue: true, + }, + { + name: 'listType', + title: { + label: '上传列表样式', + tip: + 'listType | 上传列表的内建样式,支持三种基本样式 `text`, `picture` 和 `picture-card`', + }, + defaultValue: 'text', + setter: [ + { + componentName: 'RadioGroupSetter', + props: { + options: [ + { + title: '文本', + value: 'text', + }, + { + title: '图片', + value: 'picture', + }, + { + title: '图片卡片', + value: 'picture-card', + }, + ], + }, + }, + ], + }, + ], + }, + { + title: '上传参数', + display: 'popup', + type: 'group', + items: [ + { + name: 'action', + title: { label: '上传地址', tip: 'action | 上传的地址或方法' }, + setter: ['StringSetter', 'FunctionSetter'], + }, + { + name: 'method', + title: { + label: '请求Method', + tip: 'method | 上传请求的 http method', + }, + defaultValue: 'POST', + setter: { + componentName: 'SelectSetter', + props: { + options: [ + { + title: 'GET', + value: 'GET', + }, + { + title: 'POST', + value: 'POST', + }, + { + title: 'PUT', + value: 'PUT', + }, + { + title: 'HEAD', + value: 'HEAD', + }, + { + title: 'OPTIONS', + value: 'OPTIONS', + }, + { + title: 'PATCH', + value: 'PATCH', + }, + { + title: 'DELETE', + value: 'DELETE', + }, + ], + }, + }, + }, + { + name: 'headers', + title: { + label: '上传请求头', + tip: 'headers | 设置上传的请求头部,IE10 以上有效', + }, + setter: 'JsonSetter', + }, + { + name: 'withCredentials', + title: { + label: '携带Cookie', + tip: 'withCredentials | 上传请求时是否携带 cookie', + }, + setter: 'BoolSetter', + }, + { + name: 'data', + title: { + label: '额外参数', + tip: 'data | 上传所需额外参数或返回上传额外参数的方法', + }, + setter: [ + 'JsonSetter', + { + componentName: 'FunctionSetter', + props: { + template: + 'onData(file,${extParams}){\n// 上传所需额外参数\nreturn {};\n}', + }, + }, + 'VariableSetter', + ], + }, + ], + }, + // { + // title: '回调函数', + // display: 'popup', + // type: 'group', + // items: [ + // { + // name: 'beforeUpload', + // title: { + // label: '上传前回调', + // tip: 'beforeUpload | 上传文件之前的回调函数', + // }, + // setter: { + // componentName: 'FunctionSetter', + // props: { + // template: + // 'beforeUpload(file,fileList,${extParams}){\n// 上传文件之前的钩子\nreturn false;\n}', + // }, + // }, + // }, + // { + // name: 'customRequest', + // title: { + // label: '自定义上传', + // tip: + // 'customRequest | 通过覆盖默认的上传行为,可以自定义自己的上传实现', + // }, + // setter: 'FunctionSetter', + // }, + // { + // name: 'isImageUrl', + // title: { + // label: '是否为图片', + // tip: 'isImageUrl | 自定义缩略图是否使用 标签进行显示', + // }, + // setter: { + // componentName: 'FunctionSetter', + // props: { + // template: + // 'isImageUrl(file,${extParams}){\n// 判断是否为图片\nreturn true;\n}', + // }, + // }, + // }, + // { + // name: 'previewFile', + // title: { + // label: '自定义文件预览', + // tip: 'previewFile | 自定义文件预览逻辑', + // }, + // setter: 'FunctionSetter', + // }, + // ], + // }, + ], +}, +null, +{ + name: 'props.placeholder', + title: { + label: '提示文字', + tip: 'placeholder | 按钮提示文字', + }, + defaultValue: '点击上传', + setter: 'StringSetter', +} +); + +const snippets = [ + { + title: '上传', + screenshot: + 'https://img.alicdn.com/imgextra/i3/O1CN012zUx2l1dD6dwQvG2n_!!6000000003701-55-tps-185-59.svg', + schema: { + componentName: 'Upload', + props: { + title: '上传' + } + } + } +]; + +export default createMeta('Upload', { + title: '上传', + category: '其他', + props, + snippets, +}); diff --git a/tools/schema-builder/src/materails/settings/meta/urlInput.ts b/tools/schema-builder/src/materails/settings/meta/urlInput.ts new file mode 100644 index 000000000..dc0ad80ae --- /dev/null +++ b/tools/schema-builder/src/materails/settings/meta/urlInput.ts @@ -0,0 +1,40 @@ +import { mergeProps, createMeta } from '../utils'; + +const props: any = mergeProps({ + title: '其他配置', + display: 'accordion', + type: 'group', + items: [ + { + name: 'props.addonText', + title: { label: '按钮文案', tip: '跳转按钮的文案配置' }, + defaultValue: '测试链接', + setter: 'StringSetter' + } + ] +}, +{ + name: 'default', + title: { label: '默认值', tip: 'default | 默认值'}, + setter: 'StringSetter' +}); + +const snippets = [ + { + title: '链接输入框', + screenshot: 'icon-link', + schema: { + componentName: 'UrlInput', + props: { + title: '链接输入框', + }, + } + } +]; + +export default createMeta('UrlInput', { + title: '链接输入框', + category: '其他', + props, + snippets +}); diff --git a/tools/schema-builder/src/materails/settings/utils.ts b/tools/schema-builder/src/materails/settings/utils.ts new file mode 100644 index 000000000..6519fd9cd --- /dev/null +++ b/tools/schema-builder/src/materails/settings/utils.ts @@ -0,0 +1,102 @@ +import cloneDeep from 'lodash/cloneDeep'; +import { formItemProps } from './common'; + +export const mergeProps = (fieldProps: any, initialValueProps?: any, placeholder?: any) => { + let result: any = cloneDeep(formItemProps); + + if (initialValueProps) { + result[0].items.splice(2, 1, initialValueProps); + } + + if (placeholder) { + result[0].items.splice(3, 1 , placeholder) + } + + result = result.concat(fieldProps); + return result; +}; + +export const uuid = () => { + return ((Math.random() * 1e6) >> 0).toString(36); +}; + + +export const createMeta = (componentName: string, params: any) => { + return { + componentName, + docUrl: '', + screenshot: '', + devMode: 'proCode', + npm: { + package: '@ali/form-render-material', + version: '1.0.0', + exportName: componentName, + main: 'src/index.tsx', + destructuring: true, + subName: '', + }, + configure: { + supports: { + loop: false, + condition: false + }, + component: { + isContainer: false, + isModal: false, + nestingRule: { + parentWhitelist: ['FormRender', 'Card', 'CardList', 'TableList'] + } + }, + }, + group: '基础组件', + category: '常用', + icon: 'https://img.alicdn.com/imgextra/i4/O1CN01gxzRdT1hm9KXRbZkU_!!6000000004319-2-tps-200-200.png', + ...params + }; +} + +export const optionsMeta = { + display: 'accordion', + name: 'props.options', + title: { label: '选项配置', tip: 'options | 选项配置' }, + setter: { + componentName: 'ArraySetter', + props: { + itemSetter: { + componentName: 'ObjectSetter', + initialValue: () => ({ + label: '选项名', + value: uuid() + }), + props: { + config: { + items: [ + { + name: 'label', + title: '选项名', + important: true, + setter: 'StringSetter', + }, + { + name: 'value', + title: '选项值', + setter: ['StringSetter', 'NumberSetter'], + important: true, + }, + // { + // name: 'tooltip.title', + // title: '气泡提示', + // setter: 'StringSetter', + // }, + { + name: 'disabled', + title: '禁用', + setter: 'JsonSetter', + } + ] + } + } + } + } + } +}; \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/Card/index.less b/tools/schema-builder/src/materails/widgets/components/Card/index.less new file mode 100644 index 000000000..c0e623d8e --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/Card/index.less @@ -0,0 +1,21 @@ +.fr-obj-card { + border-radius: 4px; + border-color: #f4f4f4; + margin-bottom: 24px; + width: 100%; + + .ant-card-head { + border: none + } + + .ant-card-body { + padding: 12px 24px !important; + } + + .fr-header-desc { + font-size: 12px; + word-break: break-all; + color: rgba(0, 0, 0, .45); + margin-left: 6px; + } +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/Card/index.tsx b/tools/schema-builder/src/materails/widgets/components/Card/index.tsx new file mode 100644 index 000000000..af8ffeaf9 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/Card/index.tsx @@ -0,0 +1,69 @@ +import React from 'react'; +import { Card, Row, Col } from 'antd'; +import BoxPanel from '../../hoc/components/PanelView' +import { ParentContext } from '../../utils/context'; + +import './index.less'; + +const BoxCard = ({ children, title, description }: any) => { + if (!title) { + return ( + + + {children} + + + ) + } + + return ( + + + {title} + {description && ( + + {description} + + )} + + } + > + + {children} + + + + + ); +} + +export default (props: any) => { + const { + labelWidth, + labelCol, + fieldCol, + column, + maxWidth, + formRef, + } = props; + + const context = { + column, + labelWidth, + maxWidth, + labelCol, + fieldCol, + getForm: () => { + return formRef; + } + }; + + return ( + + + + ); +}; diff --git a/tools/schema-builder/src/materails/widgets/components/CardList/index.less b/tools/schema-builder/src/materails/widgets/components/CardList/index.less new file mode 100644 index 000000000..c0e623d8e --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/CardList/index.less @@ -0,0 +1,21 @@ +.fr-obj-card { + border-radius: 4px; + border-color: #f4f4f4; + margin-bottom: 24px; + width: 100%; + + .ant-card-head { + border: none + } + + .ant-card-body { + padding: 12px 24px !important; + } + + .fr-header-desc { + font-size: 12px; + word-break: break-all; + color: rgba(0, 0, 0, .45); + margin-left: 6px; + } +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/CardList/index.tsx b/tools/schema-builder/src/materails/widgets/components/CardList/index.tsx new file mode 100644 index 000000000..1e02b2af0 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/CardList/index.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { Card, Row, Col } from 'antd'; +import BoxPanel from '../../hoc/components/PanelView' + +import './index.less'; + +const BoxCard = ({ children, title, description }: any) => { + if (!title) { + return ( + + + {children} + + + ) + } + + return ( + + + {title} + {description && ( + + {description} + + )} + + } + > + + {children} + + + + + ); +} + +export default BoxCard; diff --git a/tools/schema-builder/src/materails/widgets/components/FormItem/index.tsx b/tools/schema-builder/src/materails/widgets/components/FormItem/index.tsx new file mode 100644 index 000000000..ac2d56519 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/FormItem/index.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import withFormItemHoc from '../../hoc/FormItemHoc'; + + +const FormItem: React.FC = (props: any) => { + const { children, renderReadOnly, ...otherProps } = props; + if (renderReadOnly) { + return renderReadOnly(otherProps); + } + + return React.Children.map(children, (item => { + return React.cloneElement(item, otherProps) + })); +} + +export default withFormItemHoc(FormItem); + + + diff --git a/tools/schema-builder/src/materails/widgets/components/FormRender/index.less b/tools/schema-builder/src/materails/widgets/components/FormRender/index.less new file mode 100644 index 000000000..bc2e6cf16 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/FormRender/index.less @@ -0,0 +1,8 @@ +.form-design { + padding: 24px; + min-height: calc(100% - 20px); + + .ant-picker { + width: 100%; + } +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/FormRender/index.tsx b/tools/schema-builder/src/materails/widgets/components/FormRender/index.tsx new file mode 100644 index 000000000..d2ec3c4cf --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/FormRender/index.tsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { Form, Row } from 'antd'; +import FormContext from '../../utils/context'; +import './index.less'; + +const layoutMap: any = { + column: 'vertical', + row: 'horizontal', + inline: 'inline' +} + +export default (props: any) => { + const { children, displayType='column', ...otherProps } = props; + + const { + labelWidth, + labelCol, + fieldCol, + column, + maxWidth, + formRef, + } = props; + + const context = { + displayType, + column, + labelWidth, + maxWidth, + labelCol, + fieldCol, + getForm: () => { + return formRef; + } + }; + + + return ( + +
+ + {children} + +
+
+ ); +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/ImageInput/index.tsx b/tools/schema-builder/src/materails/widgets/components/ImageInput/index.tsx new file mode 100644 index 000000000..d443683a2 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/ImageInput/index.tsx @@ -0,0 +1,34 @@ +import { PictureOutlined } from '@ant-design/icons'; +import { Input, Popover } from 'antd'; +import React from 'react'; + +const DEFAULT_IMG = + 'https://img.alicdn.com/tfs/TB14tSiKhTpK1RjSZFKXXa2wXXa-354-330.png'; + +const PreviewNode = ({ value }: any) => { + return ( + + } + className="fr-preview" + placement="bottom" + > + + + ); +}; + +const ImageInput = (props: any) => { + const { value, ...rest } = props + + return ( + } {...rest} /> + ); +} + +export default ImageInput; diff --git a/tools/schema-builder/src/materails/widgets/components/Slider/index.tsx b/tools/schema-builder/src/materails/widgets/components/Slider/index.tsx new file mode 100644 index 000000000..cc7d3185c --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/Slider/index.tsx @@ -0,0 +1,7 @@ +import { Slider } from "form-render"; + +const FSlider = (props: any) => { + return +} + +export default FSlider \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/TimePicker/index.tsx b/tools/schema-builder/src/materails/widgets/components/TimePicker/index.tsx new file mode 100644 index 000000000..7e052c5dc --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/TimePicker/index.tsx @@ -0,0 +1,7 @@ +import { TimePicker } from "form-render"; + +const FTimePicker = (props: any) => { + return +} + +export default FTimePicker \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/TimeRange/index.tsx b/tools/schema-builder/src/materails/widgets/components/TimeRange/index.tsx new file mode 100644 index 000000000..e24b0fe3d --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/TimeRange/index.tsx @@ -0,0 +1,7 @@ +import { TimeRange } from "form-render"; + +const FTimeRange = (props: any) => { + return +} + +export default FTimeRange \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/components/Upload/index.tsx b/tools/schema-builder/src/materails/widgets/components/Upload/index.tsx new file mode 100644 index 000000000..c091c2ee4 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/Upload/index.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { Upload, Button } from 'antd'; +import { UploadOutlined } from '@ant-design/icons'; + +export default (props: any) => { + + return ( + + + + ); +} + diff --git a/tools/schema-builder/src/materails/widgets/components/UrlInput/index.tsx b/tools/schema-builder/src/materails/widgets/components/UrlInput/index.tsx new file mode 100644 index 000000000..55f7b417d --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/components/UrlInput/index.tsx @@ -0,0 +1,64 @@ +import React from 'react'; +import { Input } from 'antd'; +import { isUrl } from '../../utils'; + +const UrlNode = ({ value, addonText = '测试链接' }: any) => { + const useUrl = isUrl(value); + + if (useUrl) { + return ( + + {addonText} + + ); + } + + return
{addonText}
; +}; + + +const Url = (props: any) => { + const { + value, + prefix, + suffix, + addonText, + onChange, + ...rest + } = props; + + const handleChange = (e: any) => { + let _value = e.target.value; + if (!_value) { + onChange(_value); + return; + } + if (prefix) { + _value = prefix + _value; + } + if (suffix) { + _value = _value + suffix; + } + onChange(_value); + }; + + return ( + + } + {...rest} + /> + ) +} + +export default Url; diff --git a/tools/schema-builder/src/materails/widgets/hoc/ColHoc/index.tsx b/tools/schema-builder/src/materails/widgets/hoc/ColHoc/index.tsx new file mode 100644 index 000000000..ec9ae597c --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/ColHoc/index.tsx @@ -0,0 +1,18 @@ +import React, { Component } from 'react'; +import { Form, Col } from 'antd'; +import FormContext from '../../utils/context'; + +function withColHoc(WrapperComponent: any) { + return class ColHoc extends Component { + + render() { + return ( + + + + ); + } + } +} + +export default withColHoc; diff --git a/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/index.tsx b/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/index.tsx new file mode 100644 index 000000000..e4b5302c6 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/index.tsx @@ -0,0 +1,71 @@ +import React from 'react'; +import { Form, Col } from 'antd'; +import FormContext, { ParentContext } from '../../utils/context'; +import { getLabel, getColSpan } from './module'; + +import getFormItemLayout from '../../utils/layout'; + + + +const RenderItem = (_props: any) => { + const { WrapperComponent, getValueFromKey, staticProps, componentId, props, title, description, defaultValue: initialValue, hidden, ...otherItem } = _props; + const formItemProps = { ...otherItem, initialValue }; + + const _labelCol = getValueFromKey('labelCol'); + const _fieldCol = getValueFromKey('fieldCol'); + const displayType = getValueFromKey('displayType'); + const labelWidth = getValueFromKey('labelWidth'); + const column = getValueFromKey('column'); + const span = getColSpan(column, _props); + + const { labelCol, fieldCol } = getFormItemLayout(Math.floor(24 / span * 1), _props, { displayType, labelWidth, _labelCol, _fieldCol }); + + const content = ( + + + + ); + + return ( + {content} + ); +} + + + + + + +function withFormItemHoc(WrapperComponent: any, staticProps?: any) { + return class FormItemHoc extends React.Component { + getValueFromKey = (formCtx: any, parentCtx: any) => (key: string) => { + return this.props[key] ?? parentCtx[key] ?? formCtx[key]; + } + + render() { + return ( + + {formCtx => ( + + {parentCtx => } + + )} + + ) + } + } +} + +export default withFormItemHoc; diff --git a/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/module.tsx b/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/module.tsx new file mode 100644 index 000000000..001f5a00d --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/FormItemHoc/module.tsx @@ -0,0 +1,45 @@ +import React from 'react'; + +export const getLabel = (title: string, description: string) => { + return ( + <> + {title} + {description && ( + + ({description}) + + )} + + ); +}; + +export const getColSpan = (column: number, schema: any) => { + let span = 24; + + if (column) { + span = 24 / column; + } + + // 兼容 1.0 逻辑 + if (schema.width) { + if (schema.width === '100%') { + span = 24; + } else if (schema.width === '50%') { + span = 12; + } else if (schema.width === '20%') { + span = 5; + } else if (schema.width < '50%') { + span = 8; + } + } + + if (schema.cellSpan) { + span = schema.cellSpan * span; + } + + if (schema.span) { + span = schema.span; + } + + return span; +}; \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/hoc/components/HeaderTitle/index.less b/tools/schema-builder/src/materails/widgets/hoc/components/HeaderTitle/index.less new file mode 100644 index 000000000..e69de29bb diff --git a/tools/schema-builder/src/materails/widgets/hoc/components/HeaderTitle/index.tsx b/tools/schema-builder/src/materails/widgets/hoc/components/HeaderTitle/index.tsx new file mode 100644 index 000000000..235d37ba1 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/components/HeaderTitle/index.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import './index.less'; + +const HeaderTitle = (props: any) => { + const { title, description } = props; + + return ( +
+ {title} + {description && ( {description} )} +
+ ); +} + +export default HeaderTitle diff --git a/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.less b/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.less new file mode 100644 index 000000000..ba772dc30 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.less @@ -0,0 +1,6 @@ +.fr-panel-bordered { + border-radius: 4px; + border: 1px solid #f4f4f4; + padding: 52px 24px 0px 24px; + margin-bottom: 24px; +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.tsx b/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.tsx new file mode 100644 index 000000000..58504ba66 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/hoc/components/PanelView/index.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import classnames from 'classnames' +import './index.less'; + +const PanelView = ({ children, bordered } : any) => { + return
{children}
; +} + +export default PanelView; diff --git a/tools/schema-builder/src/materails/widgets/index.ts b/tools/schema-builder/src/materails/widgets/index.ts new file mode 100644 index 000000000..0132574e1 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/index.ts @@ -0,0 +1,69 @@ +import { + Input as AntdInput, + InputNumber as AntdInputNumber, + Select as AntdSelect, + DatePicker as AntdDatePicker, + Switch as AntdSwitch, + Rate as AntdRate, + Cascader as AntdCascader, + TimePicker as AntdTimePicker, + TreeSelect as AntdTreeSelect, + Checkbox as AntdCheckbox, + Radio as AntdRadio, + Table, + Button as AntdButton +} from 'antd'; + +import { + DatePicker as FDatePicker, + DateRange as FDateRange, + Color as FColor, + Html as FHtml +} from 'form-render'; + +import withFormItemHoc from './hoc/FormItemHoc'; +import withColHoc from './hoc/ColHoc'; + +import FUpload from './components/Upload'; +import FUrlInput from './components/UrlInput'; +import FImageInput from './components/ImageInput'; +import FTimeRange from './components/TimeRange'; +import FTimePicker from './components/TimePicker'; +import FSlider from './components/Slider'; + + +export const Input = withFormItemHoc(AntdInput); +export const InputNumber = withFormItemHoc(AntdInputNumber, {style: { width: '100%'}}); +export const TextArea = withFormItemHoc(AntdInput.TextArea); + +export const Select = withFormItemHoc(AntdSelect); +export const Checkbox = withFormItemHoc(AntdCheckbox); +export const Checkboxes = withFormItemHoc(AntdCheckbox.Group); +export const Radio = withFormItemHoc(AntdRadio.Group); + +export const DatePicker = withFormItemHoc(FDatePicker, {style: { width: '100%'}}); +export const DateRange = withFormItemHoc(FDateRange, {style: { width: '100%'}}); +export const TimePicker = withFormItemHoc(FTimePicker, {style: { width: '100%'}}); +export const TimeRange = withFormItemHoc(FTimeRange, {style: { width: '100%'}}); + +export const Switch = withFormItemHoc(AntdSwitch); +export const Slider = withFormItemHoc(FSlider); +export const Rate = withFormItemHoc(AntdRate); + +export const Cascader = withFormItemHoc(AntdCascader); +export const TreeSelect = withFormItemHoc(AntdTreeSelect); + +export const Button = withFormItemHoc(AntdButton); + + +export const Color = withFormItemHoc(FColor); +export const UrlInput = withFormItemHoc(FUrlInput); +export const ImageInput = withFormItemHoc(FImageInput); +export const Html = withFormItemHoc(FHtml); +export const Upload = withFormItemHoc(FUpload) + +export { default as FormRender } from './components/FormRender'; +export { default as FormItem } from './components/FormItem'; +export { default as Card } from './components/Card'; +export { default as CardList } from './components/CardList'; +export const TableList = withColHoc(Table); \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/utils/context.ts b/tools/schema-builder/src/materails/widgets/utils/context.ts new file mode 100644 index 000000000..1d4f13ff9 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/utils/context.ts @@ -0,0 +1,7 @@ +import React from "react"; + +const FormContext = React.createContext({}); + +export const ParentContext = React.createContext({}); + +export default FormContext; diff --git a/tools/schema-builder/src/materails/widgets/utils/hoc.tsx b/tools/schema-builder/src/materails/widgets/utils/hoc.tsx new file mode 100644 index 000000000..c722d801a --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/utils/hoc.tsx @@ -0,0 +1,90 @@ +import React, { ComponentType } from 'react'; +import moment from 'moment'; +import { get, set, has } from './index'; + +function convertProps( + props: Record, + list: string[], + mapper: (v: any, key: string) => any, +) { + const out: Record = {}; + list.forEach(key => { + if (has(props, key)) { + set(out, key, mapper(get(props, key), key)); + } + }); + return out; +} + +/** + * 简单包装,不做任何处理 + * 部分组件ref比较特殊,包一层会解决这个问题 + */ +export function withWrap(Comp: any) { + return (props: any) => { + return ; + }; +} + +/** + * 某些组件会用React.Children.only检查子节点 + * 需要做处理避免报错 + */ +export function withSingleChild( + Comp: any, + needsConvert = ['children'], +) { + return (props: any) => { + const convertedProps = convertProps(props, needsConvert, prop => { + let node = React.Children.toArray(prop)[0]; + if (node === null || typeof node !== 'object') { + node =
{node}
; + } + return node; + }); + + return ; + }; +} + +export function withSingleFunctionChild(Comp: any) { + return (props: any) => { + const { children } = props; + + let node; + if (typeof children === 'function') { + node = children; + } + if ( + Array.isArray(children) && + children.length === 1 && + typeof children[0] === 'function' + ) { + node = children[0]; + } + + if (node) { + return {node}; + } + return
{children}
; + }; +} + +/** + * moment对象在序列化后会被转为字符串 + * 需要让日期类组件支持接受字符串值 + */ +export function withMomentProps(Comp: any, needsConvert = ['value', 'defaultValue']) { + return (props: any) => { + const convertedProps = convertProps(props, needsConvert, prop => { + if (prop) { + if (Array.isArray(prop)) { + return prop.map(v => (moment.isMoment(v) ? v : moment(v))); + } + return moment.isMoment(prop) ? prop : moment(prop); + } + }); + + return ; + }; +} diff --git a/tools/schema-builder/src/materails/widgets/utils/index.ts b/tools/schema-builder/src/materails/widgets/utils/index.ts new file mode 100644 index 000000000..450bb43bd --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/utils/index.ts @@ -0,0 +1,29 @@ +export { default as get } from 'lodash/get'; +export { default as set } from 'lodash/set'; +export { default as has } from 'lodash/has'; +export { default as isNumber } from 'lodash/isNumber'; + + +// simple uuid +export function uuid() { + return ((Math.random() * 1e6) >> 0).toString(36); +} + +export function isObject (value: any) { + return Object.prototype.toString.call(value) === '[object Object]'; +} + +export function getStringToNumber (str: any) { + const reg = /^[\d]+$/; + if (reg.test(str)) { + return parseInt(str); + } + return str; +} + +export function isUrl(url: string) { + const protocolRE = /^(?:\w+:)?\/\/(\S+)$/; + // const domainRE = /^[^\s\.]+\.\S{2,}$/; + if (typeof url !== 'string') return false; + return protocolRE.test(url); +} \ No newline at end of file diff --git a/tools/schema-builder/src/materails/widgets/utils/layout.ts b/tools/schema-builder/src/materails/widgets/utils/layout.ts new file mode 100644 index 000000000..7b60284c8 --- /dev/null +++ b/tools/schema-builder/src/materails/widgets/utils/layout.ts @@ -0,0 +1,68 @@ +export default (column: number, schema: any, { labelWidth, displayType, _labelCol, _fieldCol }: any) => { + let labelCol: any = { span: 5 }; + let fieldCol: any = { span: 9 }; + + if (column === 2) { + labelCol = { span: 6 }; + fieldCol = { span: 14 } + } + + if (column > 2) { + labelCol = { span: 7 }; + fieldCol = { span: 16 } + } + + if (displayType === 'column') { + labelCol = {}; + fieldCol = {}; + } + + if (_labelCol) { + labelCol = _labelCol; + if (displayType === 'column') { + labelCol = {}; + } + } + + if (_fieldCol) { + fieldCol = _fieldCol; + if (typeof _fieldCol === 'number') { + fieldCol = { span: _fieldCol } + } + } + + if (displayType === 'inline') { + labelCol = {}; + fieldCol = {}; + } + + // 兼容一下 1.0 版本 + if (labelWidth && displayType !== 'column') { + labelCol = { flex : labelWidth + 'px' }; + fieldCol = { flex: 'auto' }; + } + + // 自定义进行覆盖 + if (schema.cellSpan) { + fieldCol = {}; + } + + + if (schema.labelCol) { + labelCol = schema.labelCol; + } + + if (schema.fieldCol) { + fieldCol = schema.fieldCol; + } + + if (typeof labelCol === 'number') { + labelCol = { span: labelCol } + } + + if (typeof fieldCol === 'number') { + fieldCol = { span: fieldCol } + } + + return { labelCol, fieldCol } +} \ No newline at end of file